1

我正在使用Goutte(它是 Symfony 功能测试组件的独立包)来测试 Wordpress 主题:

public function testDocumentHasBasicNodes(){
    $this->assertEquals(1, $this->crawler->filter('title')->count(),
            'document shall have a TITLE node');

    $this->assertEquals(1, $this->crawler->filter('meta')->count(),
            'document shall have a meta[charset="utf-8"] node');
}

第一个测试通过但:

indexTest::testDocumentHasBasicNodes
document shall have a meta[charset="utf-8"] node
Failed asserting that 0 matches expected 1.

所以总结一下我的问题:
如何使用 Goutte / Symfony CSS Selector 组件按属性获取节点?

4

1 回答 1

2

您可以像这样按属性过滤。

$this->assertEquals(1, $this->crawler->filter('meta[charset="utf-8"]')->count(),
    'document shall have a meta[charset="utf-8"] node');
于 2012-11-27T04:45:43.840 回答