LoginSignup
0
0

More than 5 years have passed since last update.

DOMDocumentを使ってViewのテスト

Posted at

Sample

// DOMDocumentを使う準備
        $dom = new DOMDocument('1.0', 'UTF-8');

// View(HTML出力)をロード
        $dom->loadHtml($this->view);

// タグ検索はXPath使う
        $xPath = new DOMXPath($dom);

// この例は<input id="BlockPublishStart" />なタグを検索
// queryにヒットした結果が全て返ってくるのでヒットするのが1つでも  ->item(0) で指定して何個目をとるか指定必要
        $inputPublishStart = $xPath->query('//input[@id="BlockPublishStart"]')->item(0);

// ->getAttributeで属性が取れるので属性テスト
        $this->assertEquals('yyyy-mm-dd hh:nn', $inputPublishStart->getAttribute('placeholder'));
        $this->assertContains('=\'2014-01-01 09:00:00\'', $inputPublishStart->getAttribute('ng-init'));
        $this->assertEquals('text', $inputPublishStart->getAttribute('type'));
        $this->assertEquals('2014-01-01 09:00:00', $inputPublishStart->getAttribute('value'));
        $this->assertEquals('data[Block][publish_start]', $inputPublishStart->getAttribute('name'));

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0