You are here

public function CrawlerTest::testAddContent in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/dom-crawler/Tests/CrawlerTest.php \Symfony\Component\DomCrawler\Tests\CrawlerTest::testAddContent()

@covers Symfony\Component\DomCrawler\Crawler::addContent

File

vendor/symfony/dom-crawler/Tests/CrawlerTest.php, line 209

Class

CrawlerTest

Namespace

Symfony\Component\DomCrawler\Tests

Code

public function testAddContent() {
  $crawler = new Crawler();
  $crawler
    ->addContent('<html><div class="foo"></html>', 'text/html; charset=UTF-8');
  $this
    ->assertEquals('foo', $crawler
    ->filterXPath('//div')
    ->attr('class'), '->addContent() adds nodes from an HTML string');
  $crawler = new Crawler();
  $crawler
    ->addContent('<html><div class="foo"></html>', 'text/html; charset=UTF-8; dir=RTL');
  $this
    ->assertEquals('foo', $crawler
    ->filterXPath('//div')
    ->attr('class'), '->addContent() adds nodes from an HTML string with extended content type');
  $crawler = new Crawler();
  $crawler
    ->addContent('<html><div class="foo"></html>');
  $this
    ->assertEquals('foo', $crawler
    ->filterXPath('//div')
    ->attr('class'), '->addContent() uses text/html as the default type');
  $crawler = new Crawler();
  $crawler
    ->addContent('<html><div class="foo"></div></html>', 'text/xml; charset=UTF-8');
  $this
    ->assertEquals('foo', $crawler
    ->filterXPath('//div')
    ->attr('class'), '->addContent() adds nodes from an XML string');
  $crawler = new Crawler();
  $crawler
    ->addContent('<html><div class="foo"></div></html>', 'text/xml');
  $this
    ->assertEquals('foo', $crawler
    ->filterXPath('//div')
    ->attr('class'), '->addContent() adds nodes from an XML string');
  $crawler = new Crawler();
  $crawler
    ->addContent('foo bar', 'text/plain');
  $this
    ->assertCount(0, $crawler, '->addContent() does nothing if the type is not (x|ht)ml');
  $crawler = new Crawler();
  $crawler
    ->addContent('<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><span>中文</span></html>');
  $this
    ->assertEquals('中文', $crawler
    ->filterXPath('//span')
    ->text(), '->addContent() guess wrong charset');
  $crawler = new Crawler();
  $crawler
    ->addContent(iconv('UTF-8', 'SJIS', '<html><head><meta charset="Shift_JIS"></head><body>日本語</body></html>'));
  $this
    ->assertEquals('日本語', $crawler
    ->filterXPath('//body')
    ->text(), '->addContent() can recognize "Shift_JIS" in html5 meta charset tag');
}