Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DomCrawler] fix tests to run assertions on returned Crawler instances #39691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/Symfony/Component/DomCrawler/Tests/AbstractCrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function testEq()
{
$crawler = $this->createTestCrawler()->filterXPath('//li');
$this->assertNotSame($crawler, $crawler->eq(0), '->eq() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->eq() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->eq(0), '->eq() returns a new instance of a crawler');

$this->assertEquals('Two', $crawler->eq(1)->text(), '->eq() returns the nth node of the list');
$this->assertCount(0, $crawler->eq(100), '->eq() returns an empty crawler if the nth node does not exist');
Expand Down Expand Up @@ -412,7 +412,7 @@ public function testFilterXPath()
{
$crawler = $this->createTestCrawler();
$this->assertNotSame($crawler, $crawler->filterXPath('//li'), '->filterXPath() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->filterXPath() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->filterXPath('//li'), '->filterXPath() returns a new instance of a crawler');

$crawler = $this->createTestCrawler()->filterXPath('//ul');
$this->assertCount(6, $crawler->filterXPath('//li'), '->filterXPath() filters the node list with the XPath expression');
Expand Down Expand Up @@ -579,7 +579,7 @@ public function testFilter()
{
$crawler = $this->createTestCrawler();
$this->assertNotSame($crawler, $crawler->filter('li'), '->filter() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->filter() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->filter('li'), '->filter() returns a new instance of a crawler');

$crawler = $this->createTestCrawler()->filter('ul');

Expand Down Expand Up @@ -632,7 +632,7 @@ public function testSelectLink()
{
$crawler = $this->createTestCrawler();
$this->assertNotSame($crawler, $crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->selectLink() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler');

$this->assertCount(1, $crawler->selectLink('Fabien\'s Foo'), '->selectLink() selects links by the node values');
$this->assertCount(1, $crawler->selectLink('Fabien\'s Bar'), '->selectLink() selects links by the alt attribute of a clickable image');
Expand All @@ -651,7 +651,7 @@ public function testSelectImage()
{
$crawler = $this->createTestCrawler();
$this->assertNotSame($crawler, $crawler->selectImage('Bar'), '->selectImage() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->selectImage() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->selectImage('Bar'), '->selectImage() returns a new instance of a crawler');

$this->assertCount(1, $crawler->selectImage('Fabien\'s Bar'), '->selectImage() selects images by alt attribute');
$this->assertCount(2, $crawler->selectImage('Fabien"s Bar'), '->selectImage() selects images by alt attribute');
Expand All @@ -662,7 +662,7 @@ public function testSelectButton()
{
$crawler = $this->createTestCrawler();
$this->assertNotSame($crawler, $crawler->selectButton('FooValue'), '->selectButton() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->selectButton() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->selectButton('FooValue'), '->selectButton() returns a new instance of a crawler');

$this->assertEquals(1, $crawler->selectButton('FooValue')->count(), '->selectButton() selects buttons');
$this->assertEquals(1, $crawler->selectButton('FooName')->count(), '->selectButton() selects buttons');
Expand Down Expand Up @@ -807,7 +807,7 @@ public function testLinks()

$this->assertCount(4, $crawler->links(), '->links() returns an array');
$links = $crawler->links();
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Link', $links[0], '->links() returns an array of Link instances');
$this->assertContainsOnlyInstancesOf('Symfony\\Component\\DomCrawler\\Link', $links, '->links() returns an array of Link instances');

$this->assertEquals([], $this->createTestCrawler()->filterXPath('//ol')->links(), '->links() returns an empty array if the node selection is empty');
}
Expand All @@ -819,7 +819,7 @@ public function testImages()

$this->assertCount(4, $crawler->images(), '->images() returns an array');
$images = $crawler->images();
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Image', $images[0], '->images() returns an array of Image instances');
$this->assertContainsOnlyInstancesOf('Symfony\\Component\\DomCrawler\\Image', $images, '->images() returns an array of Image instances');

$this->assertEquals([], $this->createTestCrawler()->filterXPath('//ol')->links(), '->links() returns an empty array if the node selection is empty');
}
Expand Down Expand Up @@ -858,7 +858,7 @@ public function testLast()
{
$crawler = $this->createTestCrawler()->filterXPath('//ul[1]/li');
$this->assertNotSame($crawler, $crawler->last(), '->last() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->last() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->last(), '->last() returns a new instance of a crawler');

$this->assertEquals('Three', $crawler->last()->text());
}
Expand All @@ -867,7 +867,7 @@ public function testFirst()
{
$crawler = $this->createTestCrawler()->filterXPath('//li');
$this->assertNotSame($crawler, $crawler->first(), '->first() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->first() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->first(), '->first() returns a new instance of a crawler');

$this->assertEquals('One', $crawler->first()->text());
}
Expand All @@ -876,7 +876,7 @@ 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');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->siblings(), '->siblings() returns a new instance of a crawler');

$nodes = $crawler->siblings();
$this->assertEquals(2, $nodes->count());
Expand Down Expand Up @@ -999,7 +999,7 @@ public function testNextAll()
{
$crawler = $this->createTestCrawler()->filterXPath('//li')->eq(1);
$this->assertNotSame($crawler, $crawler->nextAll(), '->nextAll() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->nextAll() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->nextAll(), '->nextAll() returns a new instance of a crawler');

$nodes = $crawler->nextAll();
$this->assertEquals(1, $nodes->count());
Expand All @@ -1017,7 +1017,7 @@ public function testPreviousAll()
{
$crawler = $this->createTestCrawler()->filterXPath('//li')->eq(2);
$this->assertNotSame($crawler, $crawler->previousAll(), '->previousAll() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->previousAll() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->previousAll(), '->previousAll() returns a new instance of a crawler');

$nodes = $crawler->previousAll();
$this->assertEquals(2, $nodes->count());
Expand All @@ -1035,7 +1035,7 @@ public function testChildren()
{
$crawler = $this->createTestCrawler()->filterXPath('//ul');
$this->assertNotSame($crawler, $crawler->children(), '->children() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->children() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->children(), '->children() returns a new instance of a crawler');

$nodes = $crawler->children();
$this->assertEquals(3, $nodes->count());
Expand Down Expand Up @@ -1095,7 +1095,7 @@ public function testParents()
{
$crawler = $this->createTestCrawler()->filterXPath('//li[1]');
$this->assertNotSame($crawler, $crawler->parents(), '->parents() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->parents() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler->parents(), '->parents() returns a new instance of a crawler');

$nodes = $crawler->parents();
$this->assertEquals(3, $nodes->count());
Expand Down