Skip to content

$singleTextNode->is(':text') throws #49

@rulatir

Description

@rulatir

Guidelines

Description of the bug

Invoking ->is(':text') on a QueryPath object that contains a single text node throws.

This is the sixth PHP DOM library I'm trying this week, so with each new one I start by writing a couple of suitability tests. This is the first suitability test I wrote for querypath, and should serve as repro.

Expected: passing test

Actual:

Error: Call to undefined method DOMText::getElementsByTagName()
/home/rulatir/projects/cdatify/vendor/gravitypdf/querypath/src/CSS/DOMTraverser.php:595
/home/rulatir/projects/cdatify/vendor/gravitypdf/querypath/src/CSS/DOMTraverser.php:444
/home/rulatir/projects/cdatify/vendor/gravitypdf/querypath/src/CSS/DOMTraverser.php:144
/home/rulatir/projects/cdatify/vendor/gravitypdf/querypath/src/DOMQuery.php:161
/home/rulatir/projects/cdatify/vendor/gravitypdf/querypath/src/DOMQuery.php:1481
/home/rulatir/projects/cdatify/vendor/gravitypdf/querypath/src/Helpers/QueryChecks.php:66
/home/rulatir/projects/cdatify/tests/QueryPathSuitability.php:26

QueryPath version

3.2.3

PHP Version and environment (server type, cli provider etc., enclosing libraries and their respective versions)

8.3.4 (cli) on up-to-date Arch Linux

Minimal reproducible PHP+HTML snippet to replicate bug

<?php

use PHPUnit\Framework\TestCase;

class QueryPathSuitability extends TestCase
{
    public function testCheckingNodeType(): void
    {
        $q = html5qp('<processing-container>whatever</processing-container>');

        $container = $q->find('processing-container');
        self::assertEquals(1, $container->length);

        $contents = $container->contents();
        self::assertEquals(1, $contents->length);

        $firstItem = $contents->eq(0);
        self::assertEquals(1, $firstItem->length);

        // RELEVANT BIT STARTS HERE

        // nonidiomatic way works
        self::assertStringContainsString("Text", get_class($firstItem->toArray()[0]));

        // idiomatic way throws
        self::assertTrue($firstItem->is(':text'));
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions