@@ -20,7 +20,10 @@ public function testConstructor()
20
20
$ crawler = new Crawler ();
21
21
$ this ->assertCount (0 , $ crawler , '__construct() returns an empty crawler ' );
22
22
23
- $ crawler = new Crawler (new \DOMNode ());
23
+ $ doc = new \DOMDocument ();
24
+ $ node = $ doc ->createElement ('test ' );
25
+
26
+ $ crawler = new Crawler ($ node );
24
27
$ this ->assertCount (1 , $ crawler , '__construct() takes a node as a first argument ' );
25
28
}
26
29
@@ -37,6 +40,7 @@ public function testAdd()
37
40
$ crawler ->add ($ this ->createNodeList ());
38
41
$ this ->assertEquals ('foo ' , $ crawler ->filterXPath ('//div ' )->attr ('class ' ), '->add() adds nodes from a \DOMNodeList ' );
39
42
43
+ $ list = array ();
40
44
foreach ($ this ->createNodeList () as $ node ) {
41
45
$ list [] = $ node ;
42
46
}
@@ -56,12 +60,22 @@ public function testAdd()
56
60
/**
57
61
* @expectedException \InvalidArgumentException
58
62
*/
59
- public function testAddInvalidNode ()
63
+ public function testAddInvalidType ()
60
64
{
61
65
$ crawler = new Crawler ();
62
66
$ crawler ->add (1 );
63
67
}
64
68
69
+ /**
70
+ * @expectedException \InvalidArgumentException
71
+ * @expectedExceptionMessage Nodes set in a Crawler must be DOMElement or DOMDocument instances, "DOMNode" given.
72
+ */
73
+ public function testAddInvalidNode ()
74
+ {
75
+ $ crawler = new Crawler ();
76
+ $ crawler ->add (new \DOMNode ());
77
+ }
78
+
65
79
/**
66
80
* @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent
67
81
*/
@@ -267,6 +281,7 @@ public function testAddNodeList()
267
281
*/
268
282
public function testAddNodes ()
269
283
{
284
+ $ list = array ();
270
285
foreach ($ this ->createNodeList () as $ node ) {
271
286
$ list [] = $ node ;
272
287
}
@@ -290,7 +305,10 @@ public function testAddNode()
290
305
291
306
public function testClear ()
292
307
{
293
- $ crawler = new Crawler (new \DOMNode ());
308
+ $ doc = new \DOMDocument ();
309
+ $ node = $ doc ->createElement ('test ' );
310
+
311
+ $ crawler = new Crawler ($ node );
294
312
$ crawler ->clear ();
295
313
$ this ->assertCount (0 , $ crawler , '->clear() removes all the nodes from the crawler ' );
296
314
}
@@ -526,7 +544,7 @@ public function testFilterXPathWithAttributeAxis()
526
544
527
545
public function testFilterXPathWithAttributeAxisAfterElementAxis ()
528
546
{
529
- $ this ->assertCount (3 , $ this ->createTestCrawler ()->filterXPath ('//form/button/attribute::* ' ), '->filterXPath() handles attribute axes properly when they are preceded by an element filtering axis ' );
547
+ $ this ->assertCount (0 , $ this ->createTestCrawler ()->filterXPath ('//form/button/attribute::* ' ), '->filterXPath() handles attribute axes properly when they are preceded by an element filtering axis ' );
530
548
}
531
549
532
550
public function testFilterXPathWithChildAxis ()
0 commit comments