CrawlerTest.php 23 KB

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