CrawlerTest.php 23 KB

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