Skip to content

Commit

Permalink
[DomCrawler] removed the isEmpty() method
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 25, 2010
1 parent 898adc6 commit a26bdb7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
12 changes: 1 addition & 11 deletions src/Symfony/Components/DomCrawler/Crawler.php
Expand Up @@ -173,16 +173,6 @@ public function addNode(\DOMNode $node)
}
}

/**
* Returns true if the list of nodes is empty.
*
* @return Boolean true if the list of nodes is empty, false otherwise
*/
public function isEmpty()
{
return $this->count() < 1;
}

/**
* Returns a node given its position in the node list.
*
Expand Down Expand Up @@ -265,7 +255,7 @@ public function first()
*/
public function last()
{
return $this->eq($this->count() - 1);
return $this->eq(count($this) - 1);
}

/**
Expand Down
32 changes: 12 additions & 20 deletions tests/Symfony/Tests/Components/DomCrawler/CrawlerTest.php
Expand Up @@ -94,7 +94,7 @@ public function testAddContent()

$crawler = new Crawler();
$crawler->addContent('foo bar', 'text/plain');
$this->assertEquals(0, $crawler->count(), '->addContent() does nothing if the type is not (x|ht)ml');
$this->assertEquals(0, count($crawler), '->addContent() does nothing if the type is not (x|ht)ml');
}

/**
Expand Down Expand Up @@ -152,22 +152,14 @@ public function testClear()
$this->assertEquals(0, count($crawler), '->clear() removes all the nodes from the crawler');
}

public function testIsEmpty()
{
$crawler = new Crawler(new \DOMNode());
$this->assertFalse($crawler->isEmpty(), '->isEmpty() returns false if the crawler node list is not empty');
$crawler->clear();
$this->assertTrue($crawler->isEmpty(), '->isEmpty() returns true if the crawler node list is empty');
}

public function testEq()
{
$crawler = $this->createTestCrawler()->filter('li');
$this->assertNotSame($crawler, $crawler->eq(0), '->eq() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->eq() returns a new instance of a crawler');

$this->assertEquals('Two', $crawler->eq(1)->text(), '->eq() returns the nth node of the list');
$this->assertTrue($crawler->eq(100)->isEmpty(), '->eq() returns an empty crawler if the nth node does not exist');
$this->assertEquals(0, count($crawler->eq(100)), '->eq() returns an empty crawler if the nth node does not exist');
}

public function testEach()
Expand Down Expand Up @@ -238,7 +230,7 @@ public function testFilterXPath()

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

$this->assertEquals(6, $crawler->filterXPath('//li')->count(), '->filterXPath() filters the node list with the XPath expression');
$this->assertEquals(6, count($crawler->filterXPath('//li')), '->filterXPath() filters the node list with the XPath expression');
}

/**
Expand All @@ -252,7 +244,7 @@ public function testFilter()

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

$this->assertEquals(6, $crawler->filter('li')->count(), '->filter() filters the node list with the CSS selector');
$this->assertEquals(6, count($crawler->filter('li')), '->filter() filters the node list with the CSS selector');
}

public function testSelectLink()
Expand All @@ -261,17 +253,17 @@ public function testSelectLink()
$this->assertNotSame($crawler, $crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler');
$this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->selectLink() returns a new instance of a crawler');

$this->assertEquals(1, $crawler->selectLink('Fabien\'s Foo')->count(), '->selectLink() selects links by the node values');
$this->assertEquals(1, $crawler->selectLink('Fabien\'s Bar')->count(), '->selectLink() selects links by the alt attribute of a clickable image');
$this->assertEquals(1, count($crawler->selectLink('Fabien\'s Foo')), '->selectLink() selects links by the node values');
$this->assertEquals(1, count($crawler->selectLink('Fabien\'s Bar')), '->selectLink() selects links by the alt attribute of a clickable image');

$this->assertEquals(2, $crawler->selectLink('Fabien"s Foo')->count(), '->selectLink() selects links by the node values');
$this->assertEquals(2, $crawler->selectLink('Fabien"s Bar')->count(), '->selectLink() selects links by the alt attribute of a clickable image');
$this->assertEquals(2, count($crawler->selectLink('Fabien"s Foo')), '->selectLink() selects links by the node values');
$this->assertEquals(2, count($crawler->selectLink('Fabien"s Bar')), '->selectLink() selects links by the alt attribute of a clickable image');

$this->assertEquals(1, $crawler->selectLink('\' Fabien"s Foo')->count(), '->selectLink() selects links by the node values');
$this->assertEquals(1, $crawler->selectLink('\' Fabien"s Bar')->count(), '->selectLink() selects links by the alt attribute of a clickable image');
$this->assertEquals(1, count($crawler->selectLink('\' Fabien"s Foo')), '->selectLink() selects links by the node values');
$this->assertEquals(1, count($crawler->selectLink('\' Fabien"s Bar')), '->selectLink() selects links by the alt attribute of a clickable image');

$this->assertEquals(4, $crawler->selectLink('Foo')->count(), '->selectLink() selects links by the node values');
$this->assertEquals(4, $crawler->selectLink('Bar')->count(), '->selectLink() selects links by the node values');
$this->assertEquals(4, count($crawler->selectLink('Foo')), '->selectLink() selects links by the node values');
$this->assertEquals(4, count($crawler->selectLink('Bar')), '->selectLink() selects links by the node values');
}

public function testSelectButton()
Expand Down

0 comments on commit a26bdb7

Please sign in to comment.