You are here

public function CrawlerTest::testSiblings in Zircon Profile 8

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

File

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

Class

CrawlerTest

Namespace

Symfony\Component\DomCrawler\Tests

Code

public function testSiblings() {
  $crawler = $this
    ->createTestCrawler()
    ->filterXPath('//li')
    ->eq(1);
  $this
    ->assertNotSame($crawler, $crawler
    ->siblings(), '->siblings() returns a new instance of a crawler');
  $this
    ->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->siblings() returns a new instance of a crawler');
  $nodes = $crawler
    ->siblings();
  $this
    ->assertEquals(2, $nodes
    ->count());
  $this
    ->assertEquals('One', $nodes
    ->eq(0)
    ->text());
  $this
    ->assertEquals('Three', $nodes
    ->eq(1)
    ->text());
  $nodes = $this
    ->createTestCrawler()
    ->filterXPath('//li')
    ->eq(0)
    ->siblings();
  $this
    ->assertEquals(2, $nodes
    ->count());
  $this
    ->assertEquals('Two', $nodes
    ->eq(0)
    ->text());
  $this
    ->assertEquals('Three', $nodes
    ->eq(1)
    ->text());
  try {
    $this
      ->createTestCrawler()
      ->filterXPath('//ol')
      ->siblings();
    $this
      ->fail('->siblings() throws an \\InvalidArgumentException if the node list is empty');
  } catch (\InvalidArgumentException $e) {
    $this
      ->assertTrue(true, '->siblings() throws an \\InvalidArgumentException if the node list is empty');
  }
}