CrawlerTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Components\DomCrawler;
  11. use Symfony\Components\DomCrawler\Crawler;
  12. class CrawlerTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testConstructor()
  15. {
  16. $crawler = new Crawler();
  17. $this->assertEquals(0, count($crawler), '__construct() returns an empty crawler');
  18. $crawler = new Crawler(new \DOMNode());
  19. $this->assertEquals(1, count($crawler), '__construct() takes a node as a first argument');
  20. }
  21. /**
  22. * @covers Symfony\Components\DomCrawler\Crawler::add
  23. */
  24. public function testAdd()
  25. {
  26. $crawler = new Crawler();
  27. $crawler->add($this->createDomDocument());
  28. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->add() adds nodes from a \DOMDocument');
  29. $crawler = new Crawler();
  30. $crawler->add($this->createNodeList());
  31. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->add() adds nodes from a \DOMNodeList');
  32. foreach ($this->createNodeList() as $node)
  33. {
  34. $list[] = $node;
  35. }
  36. $crawler = new Crawler();
  37. $crawler->add($list);
  38. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->add() adds nodes from an array of nodes');
  39. $crawler = new Crawler();
  40. $crawler->add($this->createNodeList()->item(0));
  41. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->add() adds nodes from an \DOMNode');
  42. }
  43. /**
  44. * @covers Symfony\Components\DomCrawler\Crawler::addHtmlContent
  45. */
  46. public function testAddHtmlContent()
  47. {
  48. $crawler = new Crawler();
  49. $crawler->addHtmlContent('<html><div class="foo"></html>', 'UTF-8');
  50. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addHtmlContent() adds nodes from an HTML string');
  51. }
  52. /**
  53. * @covers Symfony\Components\DomCrawler\Crawler::addXmlContent
  54. */
  55. public function testAddXmlContent()
  56. {
  57. $crawler = new Crawler();
  58. $crawler->addXmlContent('<html><div class="foo"></div></html>', 'UTF-8');
  59. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addXmlContent() adds nodes from an XML string');
  60. }
  61. /**
  62. * @covers Symfony\Components\DomCrawler\Crawler::addContent
  63. */
  64. public function testAddContent()
  65. {
  66. $crawler = new Crawler();
  67. $crawler->addContent('<html><div class="foo"></html>', 'text/html; charset=UTF-8');
  68. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addContent() adds nodes from an HTML string');
  69. $crawler = new Crawler();
  70. $crawler->addContent('<html><div class="foo"></html>');
  71. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addContent() uses text/html as the default type');
  72. $crawler = new Crawler();
  73. $crawler->addContent('<html><div class="foo"></div></html>', 'text/xml; charset=UTF-8');
  74. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addContent() adds nodes from an XML string');
  75. $crawler = new Crawler();
  76. $crawler->addContent('<html><div class="foo"></div></html>', 'text/xml');
  77. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addContent() adds nodes from an XML string');
  78. $crawler = new Crawler();
  79. $crawler->addContent('foo bar', 'text/plain');
  80. $this->assertEquals(0, $crawler->count(), '->addContent() does nothing if the type is not (x|ht)ml');
  81. }
  82. /**
  83. * @covers Symfony\Components\DomCrawler\Crawler::addDocument
  84. */
  85. public function testAddDocument()
  86. {
  87. $crawler = new Crawler();
  88. $crawler->addDocument($this->createDomDocument());
  89. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addDocument() adds nodes from a \DOMDocument');
  90. }
  91. /**
  92. * @covers Symfony\Components\DomCrawler\Crawler::addNodeList
  93. */
  94. public function testAddNodeList()
  95. {
  96. $crawler = new Crawler();
  97. $crawler->addNodeList($this->createNodeList());
  98. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addNodeList() adds nodes from a \DOMNodeList');
  99. }
  100. /**
  101. * @covers Symfony\Components\DomCrawler\Crawler::addNodes
  102. */
  103. public function testAddNodes()
  104. {
  105. foreach ($this->createNodeList() as $node)
  106. {
  107. $list[] = $node;
  108. }
  109. $crawler = new Crawler();
  110. $crawler->addNodes($list);
  111. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addNodes() adds nodes from an array of nodes');
  112. }
  113. /**
  114. * @covers Symfony\Components\DomCrawler\Crawler::addNode
  115. */
  116. public function testAddNode()
  117. {
  118. $crawler = new Crawler();
  119. $crawler->addNode($this->createNodeList()->item(0));
  120. $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addNode() adds nodes from an \DOMNode');
  121. }
  122. public function testClear()
  123. {
  124. $crawler = new Crawler(new \DOMNode());
  125. $crawler->clear();
  126. $this->assertEquals(0, count($crawler), '->clear() removes all the nodes from the crawler');
  127. }
  128. public function testIsEmpty()
  129. {
  130. $crawler = new Crawler(new \DOMNode());
  131. $this->assertFalse($crawler->isEmpty(), '->isEmpty() returns false if the crawler node list is not empty');
  132. $crawler->clear();
  133. $this->assertTrue($crawler->isEmpty(), '->isEmpty() returns true if the crawler node list is empty');
  134. }
  135. public function testEq()
  136. {
  137. $crawler = $this->createTestCrawler()->filter('li');
  138. $this->assertNotSame($crawler, $crawler->eq(0), '->eq() returns a new instance of a crawler');
  139. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->eq() returns a new instance of a crawler');
  140. $this->assertEquals('Two', $crawler->eq(1)->text(), '->eq() returns the nth node of the list');
  141. $this->assertTrue($crawler->eq(100)->isEmpty(), '->eq() returns an empty crawler if the nth node does not exist');
  142. }
  143. public function testEach()
  144. {
  145. $data = $this->createTestCrawler()->filter('ul.first li')->each(function ($node, $i)
  146. {
  147. return $i.'-'.$node->nodeValue;
  148. });
  149. $this->assertEquals(array('0-One', '1-Two', '2-Three'), $data, '->each() executes an anonymous function on each node of the list');
  150. }
  151. public function testReduce()
  152. {
  153. $crawler = $this->createTestCrawler()->filter('ul.first li');
  154. $nodes = $crawler->reduce(function ($node, $i)
  155. {
  156. return $i == 1 ? false : true;
  157. });
  158. $this->assertNotSame($nodes, $crawler, '->reduce() returns a new instance of a crawler');
  159. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $nodes, '->reduce() returns a new instance of a crawler');
  160. $this->assertEquals(2, count($nodes), '->reduce() filters the nodes in the list');
  161. }
  162. public function testAttr()
  163. {
  164. $this->assertEquals('first', $this->createTestCrawler()->filter('li')->attr('class'), '->attr() returns the attribute of the first element of the node list');
  165. try
  166. {
  167. $this->createTestCrawler()->filter('ol')->attr('class');
  168. $this->fail('->attr() throws an \InvalidArgumentException if the node list is empty');
  169. }
  170. catch (\InvalidArgumentException $e)
  171. {
  172. $this->assertTrue(true, '->attr() throws an \InvalidArgumentException if the node list is empty');
  173. }
  174. }
  175. public function testText()
  176. {
  177. $this->assertEquals('One', $this->createTestCrawler()->filter('li')->text(), '->text() returns the node value of the first element of the node list');
  178. try
  179. {
  180. $this->createTestCrawler()->filter('ol')->text();
  181. $this->fail('->text() throws an \InvalidArgumentException if the node list is empty');
  182. }
  183. catch (\InvalidArgumentException $e)
  184. {
  185. $this->assertTrue(true, '->text() throws an \InvalidArgumentException if the node list is empty');
  186. }
  187. }
  188. public function testExtract()
  189. {
  190. $crawler = $this->createTestCrawler()->filter('ul.first li');
  191. $this->assertEquals(array('One', 'Two', 'Three'), $crawler->extract('_text'), '->extract() returns an array of extracted data from the node list');
  192. $this->assertEquals(array(array('One', 'first'), array('Two', ''), array('Three', '')), $crawler->extract(array('_text', 'class')), '->extract() returns an array of extracted data from the node list');
  193. $this->assertEquals(array(), $this->createTestCrawler()->filter('lo')->extract('_text'), '->extract() returns an empty array if the node list is empty');
  194. }
  195. /**
  196. * @covers Symfony\Components\DomCrawler\Crawler::filterXPath
  197. */
  198. public function testFilterXPath()
  199. {
  200. $crawler = $this->createTestCrawler();
  201. $this->assertNotSame($crawler, $crawler->filterXPath('//li'), '->filterXPath() returns a new instance of a crawler');
  202. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->filterXPath() returns a new instance of a crawler');
  203. $crawler = $this->createTestCrawler()->filter('ul');
  204. $this->assertEquals(6, $crawler->filterXPath('//li')->count(), '->filterXPath() filters the node list with the XPath expression');
  205. }
  206. /**
  207. * @covers Symfony\Components\DomCrawler\Crawler::filter
  208. */
  209. public function testFilter()
  210. {
  211. $crawler = $this->createTestCrawler();
  212. $this->assertNotSame($crawler, $crawler->filter('li'), '->filter() returns a new instance of a crawler');
  213. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->filter() returns a new instance of a crawler');
  214. $crawler = $this->createTestCrawler()->filter('ul');
  215. $this->assertEquals(6, $crawler->filter('li')->count(), '->filter() filters the node list with the CSS selector');
  216. }
  217. public function testSelectLink()
  218. {
  219. $crawler = $this->createTestCrawler();
  220. $this->assertNotSame($crawler, $crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler');
  221. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->selectLink() returns a new instance of a crawler');
  222. $this->assertEquals(1, $crawler->selectLink('Fabien\'s Foo')->count(), '->selectLink() selects links by the node values');
  223. $this->assertEquals(1, $crawler->selectLink('Fabien\'s Bar')->count(), '->selectLink() selects links by the alt attribute of a clickable image');
  224. $this->assertEquals(2, $crawler->selectLink('Fabien"s Foo')->count(), '->selectLink() selects links by the node values');
  225. $this->assertEquals(2, $crawler->selectLink('Fabien"s Bar')->count(), '->selectLink() selects links by the alt attribute of a clickable image');
  226. $this->assertEquals(1, $crawler->selectLink('\' Fabien"s Foo')->count(), '->selectLink() selects links by the node values');
  227. $this->assertEquals(1, $crawler->selectLink('\' Fabien"s Bar')->count(), '->selectLink() selects links by the alt attribute of a clickable image');
  228. $this->assertEquals(4, $crawler->selectLink('Foo')->count(), '->selectLink() selects links by the node values');
  229. $this->assertEquals(4, $crawler->selectLink('Bar')->count(), '->selectLink() selects links by the node values');
  230. }
  231. public function testSelectButton()
  232. {
  233. $crawler = $this->createTestCrawler();
  234. $this->assertNotSame($crawler, $crawler->selectButton('FooValue'), '->selectButton() returns a new instance of a crawler');
  235. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->selectButton() returns a new instance of a crawler');
  236. $this->assertEquals(1, $crawler->selectButton('FooValue')->count(), '->selectButton() selects buttons');
  237. $this->assertEquals(1, $crawler->selectButton('FooName')->count(), '->selectButton() selects buttons');
  238. $this->assertEquals(1, $crawler->selectButton('FooId')->count(), '->selectButton() selects buttons');
  239. $this->assertEquals(1, $crawler->selectButton('BarValue')->count(), '->selectButton() selects buttons');
  240. $this->assertEquals(1, $crawler->selectButton('BarName')->count(), '->selectButton() selects buttons');
  241. $this->assertEquals(1, $crawler->selectButton('BarId')->count(), '->selectButton() selects buttons');
  242. }
  243. public function testLink()
  244. {
  245. $crawler = $this->createTestCrawler()->selectLink('Foo');
  246. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Link', $crawler->link(), '->link() returns a Link instance');
  247. $this->assertEquals('/foo', $crawler->link()->getUri(), '->link() returns a Link instance');
  248. $this->assertEquals('post', $crawler->link('post')->getMethod(), '->link() takes a method as its argument');
  249. $crawler = $this->createTestCrawler('http://example.com/bar/')->selectLink('Foo');
  250. $this->assertEquals('http://example.com/bar/foo', $crawler->link()->getUri(), '->link() returns a Link instance');
  251. $crawler = $this->createTestCrawler('http://example.com/bar')->selectLink('Foo');
  252. $this->assertEquals('http://example.com/foo', $crawler->link()->getUri(), '->form() linketurns a Link instance');
  253. try
  254. {
  255. $this->createTestCrawler()->filter('ol')->link();
  256. $this->fail('->link() throws an \InvalidArgumentException if the node list is empty');
  257. }
  258. catch (\InvalidArgumentException $e)
  259. {
  260. $this->assertTrue(true, '->link() throws an \InvalidArgumentException if the node list is empty');
  261. }
  262. }
  263. public function testLinks()
  264. {
  265. $crawler = $this->createTestCrawler()->selectLink('Foo');
  266. $this->assertType('array', $crawler->links(), '->links() returns an array');
  267. $this->assertEquals(4, count($crawler->links()), '->links() returns an array');
  268. $links = $crawler->links();
  269. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Link', $links[0], '->links() returns an array of Link instances');
  270. $this->assertEquals(array(), $this->createTestCrawler()->filter('ol')->links(), '->links() returns an empty array if the node selection is empty');
  271. }
  272. public function testForm()
  273. {
  274. $crawler = $this->createTestCrawler()->selectButton('FooValue');
  275. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Form', $crawler->form(), '->form() returns a Form instance');
  276. $this->assertEquals('/foo?FooName=FooValue', $crawler->form()->getUri(), '->form() returns a Form instance');
  277. $this->assertEquals(array('FooName' => 'FooBar'), $crawler->form(array('FooName' => 'FooBar'))->getValues(), '->form() takes an array of values to submit as its first argument');
  278. $crawler = $this->createTestCrawler('http://example.com/bar/')->selectButton('FooValue');
  279. $this->assertEquals('http://example.com/bar/foo?FooName=FooValue', $crawler->form()->getUri(), '->form() returns a Form instance');
  280. $crawler = $this->createTestCrawler('http://example.com/bar')->selectButton('FooValue');
  281. $this->assertEquals('http://example.com/foo?FooName=FooValue', $crawler->form()->getUri(), '->form() returns a Form instance');
  282. try
  283. {
  284. $this->createTestCrawler()->filter('ol')->form();
  285. $this->fail('->form() throws an \InvalidArgumentException if the node list is empty');
  286. }
  287. catch (\InvalidArgumentException $e)
  288. {
  289. $this->assertTrue(true, '->form() throws an \InvalidArgumentException if the node list is empty');
  290. }
  291. }
  292. public function testLast()
  293. {
  294. $crawler = $this->createTestCrawler()->filter('ul.first li');
  295. $this->assertNotSame($crawler, $crawler->last(), '->last() returns a new instance of a crawler');
  296. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->last() returns a new instance of a crawler');
  297. $this->assertEquals('Three', $crawler->last()->text());
  298. }
  299. public function testFirst()
  300. {
  301. $crawler = $this->createTestCrawler()->filter('li');
  302. $this->assertNotSame($crawler, $crawler->first(), '->first() returns a new instance of a crawler');
  303. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->first() returns a new instance of a crawler');
  304. $this->assertEquals('One', $crawler->first()->text());
  305. }
  306. public function testSiblings()
  307. {
  308. $crawler = $this->createTestCrawler()->filter('li')->eq(1);
  309. $this->assertNotSame($crawler, $crawler->siblings(), '->siblings() returns a new instance of a crawler');
  310. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->siblings() returns a new instance of a crawler');
  311. $nodes = $crawler->siblings();
  312. $this->assertEquals(2, $nodes->count());
  313. $this->assertEquals('One', $nodes->eq(0)->text());
  314. $this->assertEquals('Three', $nodes->eq(1)->text());
  315. $nodes = $this->createTestCrawler()->filter('li')->eq(0)->siblings();
  316. $this->assertEquals(2, $nodes->count());
  317. $this->assertEquals('Two', $nodes->eq(0)->text());
  318. $this->assertEquals('Three', $nodes->eq(1)->text());
  319. try
  320. {
  321. $this->createTestCrawler()->filter('ol')->siblings();
  322. $this->fail('->siblings() throws an \InvalidArgumentException if the node list is empty');
  323. }
  324. catch (\InvalidArgumentException $e)
  325. {
  326. $this->assertTrue(true, '->siblings() throws an \InvalidArgumentException if the node list is empty');
  327. }
  328. }
  329. public function testNextAll()
  330. {
  331. $crawler = $this->createTestCrawler()->filter('li')->eq(1);
  332. $this->assertNotSame($crawler, $crawler->nextAll(), '->nextAll() returns a new instance of a crawler');
  333. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->nextAll() returns a new instance of a crawler');
  334. $nodes = $crawler->nextAll();
  335. $this->assertEquals(1, $nodes->count());
  336. $this->assertEquals('Three', $nodes->eq(0)->text());
  337. try
  338. {
  339. $this->createTestCrawler()->filter('ol')->nextAll();
  340. $this->fail('->nextAll() throws an \InvalidArgumentException if the node list is empty');
  341. }
  342. catch (\InvalidArgumentException $e)
  343. {
  344. $this->assertTrue(true, '->nextAll() throws an \InvalidArgumentException if the node list is empty');
  345. }
  346. }
  347. public function testPreviousAll()
  348. {
  349. $crawler = $this->createTestCrawler()->filter('li')->eq(2);
  350. $this->assertNotSame($crawler, $crawler->previousAll(), '->previousAll() returns a new instance of a crawler');
  351. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->previousAll() returns a new instance of a crawler');
  352. $nodes = $crawler->previousAll();
  353. $this->assertEquals(2, $nodes->count());
  354. $this->assertEquals('Two', $nodes->eq(0)->text());
  355. try
  356. {
  357. $this->createTestCrawler()->filter('ol')->previousAll();
  358. $this->fail('->previousAll() throws an \InvalidArgumentException if the node list is empty');
  359. }
  360. catch (\InvalidArgumentException $e)
  361. {
  362. $this->assertTrue(true, '->previousAll() throws an \InvalidArgumentException if the node list is empty');
  363. }
  364. }
  365. public function testChildren()
  366. {
  367. $crawler = $this->createTestCrawler()->filter('ul');
  368. $this->assertNotSame($crawler, $crawler->children(), '->children() returns a new instance of a crawler');
  369. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->children() returns a new instance of a crawler');
  370. $nodes = $crawler->children();
  371. $this->assertEquals(3, $nodes->count());
  372. $this->assertEquals('One', $nodes->eq(0)->text());
  373. $this->assertEquals('Two', $nodes->eq(1)->text());
  374. $this->assertEquals('Three', $nodes->eq(2)->text());
  375. try
  376. {
  377. $this->createTestCrawler()->filter('ol')->children();
  378. $this->fail('->children() throws an \InvalidArgumentException if the node list is empty');
  379. }
  380. catch (\InvalidArgumentException $e)
  381. {
  382. $this->assertTrue(true, '->children() throws an \InvalidArgumentException if the node list is empty');
  383. }
  384. }
  385. public function testParents()
  386. {
  387. $crawler = $this->createTestCrawler()->filter('li:first-child');
  388. $this->assertNotSame($crawler, $crawler->parents(), '->parents() returns a new instance of a crawler');
  389. $this->assertInstanceOf('Symfony\\Components\\DomCrawler\\Crawler', $crawler, '->parents() returns a new instance of a crawler');
  390. $nodes = $crawler->parents();
  391. $this->assertEquals(3, $nodes->count());
  392. $nodes = $this->createTestCrawler()->filter('html')->parents();
  393. $this->assertEquals(0, $nodes->count());
  394. try
  395. {
  396. $this->createTestCrawler()->filter('ol')->parents();
  397. $this->fail('->parents() throws an \InvalidArgumentException if the node list is empty');
  398. }
  399. catch (\InvalidArgumentException $e)
  400. {
  401. $this->assertTrue(true, '->parents() throws an \InvalidArgumentException if the node list is empty');
  402. }
  403. }
  404. public function createTestCrawler($uri = null)
  405. {
  406. $dom = new \DOMDocument();
  407. $dom->loadHTML('
  408. <html>
  409. <body>
  410. <a href="foo">Foo</a>
  411. <a href="/foo"> Fabien\'s Foo </a>
  412. <a href="/foo">Fabien"s Foo</a>
  413. <a href="/foo">\' Fabien"s Foo</a>
  414. <a href="/bar"><img alt="Bar"/></a>
  415. <a href="/bar"><img alt=" Fabien\'s Bar "/></a>
  416. <a href="/bar"><img alt="Fabien&quot;s Bar"/></a>
  417. <a href="/bar"><img alt="\' Fabien&quot;s Bar"/></a>
  418. <form action="foo">
  419. <input type="submit" value="FooValue" name="FooName" id="FooId" />
  420. <input type="button" value="BarValue" name="BarName" id="BarId" />
  421. <button value="ButtonValue" name="ButtonName" id="ButtonId" />
  422. </form>
  423. <ul class="first">
  424. <li class="first">One</li>
  425. <li>Two</li>
  426. <li>Three</li>
  427. </ul>
  428. <ul>
  429. <li>One Bis</li>
  430. <li>Two Bis</li>
  431. <li>Three Bis</li>
  432. </ul>
  433. </body>
  434. </html>
  435. ');
  436. return new Crawler($dom, $uri);
  437. }
  438. protected function createDomDocument()
  439. {
  440. $dom = new \DOMDocument();
  441. $dom->loadXML('<html><div class="foo"></div></html>');
  442. return $dom;
  443. }
  444. protected function createNodeList()
  445. {
  446. $dom = new \DOMDocument();
  447. $dom->loadXML('<html><div class="foo"></div></html>');
  448. $domxpath = new \DOMXPath($dom);
  449. return $domxpath->query('//div');
  450. }
  451. }