ZF-7564: CSS and XPath assertions/queries do not work when document begins with XML declaration

Description

The following test fails:


class MyTest extends Zend_Test_PHPUnit_ControllerTestCase
{
    public function testFoo()
    {
        $this->dispatch('/');
        $this->assertQuery('form#foo');
    }
}

when requested document begins with XML declaration:


<?xml version="1.0" encoding="UTF-8" ?>

and passes if there is no such declaration.

What is more interesing


$this->assertQuery('#foo');

passes. Same applies to corresponding XPath queries (CSS queries are translated into XPath queries):


$this->assertXpath('//form[@id="foo"]');

fails, but the following passes


$this->assertXpath('//*[@id="foo"]');

Comments

Could you maybe investigate if this is a problem with Zend_Dom_Query instead?

Yes, the bug itself is in Zend_Dom_Query component, but since Zend_Test_PHPUnit is using it, both components are affected. Anyway, the query component should be fixed.

I've tried a number of documents with the XML declaration, and in all cases, the queries you specified worked fine -- both the CSS selector and XPath queries.

If you can provide sample content and queries that fail, please re-open this issue or open a new one.