@@ -348,12 +348,56 @@ public function testText()
348
348
$ this ->assertSame ('my value ' , $ this ->createTestCrawler (null )->filterXPath ('//ol ' )->text ('my value ' ));
349
349
}
350
350
351
- public function testInnerText ()
351
+ public function provideInnerTextExamples ()
352
352
{
353
- self ::assertCount (1 , $ crawler = $ this ->createTestCrawler ()->filterXPath ('//*[@id="complex-element"] ' ));
353
+ return [
354
+ [
355
+ '//*[@id="complex-elements"]/*[@class="one"] ' , // XPath query
356
+ 'Parent text Child text ' , // Result of Crawler::text()
357
+ 'Parent text ' , // Result of Crawler::innerText()
358
+ ' Parent text ' , // Result of Crawler::innerText(false)
359
+ ],
360
+ [
361
+ '//*[@id="complex-elements"]/*[@class="two"] ' ,
362
+ 'Child text Parent text ' ,
363
+ 'Parent text ' ,
364
+ ' ' ,
365
+ ],
366
+ [
367
+ '//*[@id="complex-elements"]/*[@class="three"] ' ,
368
+ 'Parent text Child text Parent text ' ,
369
+ 'Parent text ' ,
370
+ ' Parent text ' ,
371
+ ],
372
+ [
373
+ '//*[@id="complex-elements"]/*[@class="four"] ' ,
374
+ 'Child text ' ,
375
+ '' ,
376
+ ' ' ,
377
+ ],
378
+ [
379
+ '//*[@id="complex-elements"]/*[@class="five"] ' ,
380
+ 'Child text Another child ' ,
381
+ '' ,
382
+ ' ' ,
383
+ ],
384
+ ];
385
+ }
386
+
387
+ /**
388
+ * @dataProvider provideInnerTextExamples
389
+ */
390
+ public function testInnerText (
391
+ string $ xPathQuery ,
392
+ string $ expectedText ,
393
+ string $ expectedInnerText ,
394
+ string $ expectedInnerTextNormalizeWhitespaceFalse ,
395
+ ) {
396
+ self ::assertCount (1 , $ crawler = $ this ->createTestCrawler ()->filterXPath ($ xPathQuery ));
354
397
355
- self ::assertSame ('Parent text Child text ' , $ crawler ->text ());
356
- self ::assertSame ('Parent text ' , $ crawler ->innerText ());
398
+ self ::assertSame ($ expectedText , $ crawler ->text ());
399
+ self ::assertSame ($ expectedInnerText , $ crawler ->innerText ());
400
+ self ::assertSame ($ expectedInnerTextNormalizeWhitespaceFalse , $ crawler ->innerText (false ));
357
401
}
358
402
359
403
public function testHtml ()
@@ -1265,9 +1309,12 @@ public function createTestCrawler($uri = null)
1265
1309
<div id="child2" xmlns:foo="http://example.com"></div>
1266
1310
</div>
1267
1311
<div id="sibling"><img /></div>
1268
- <div id="complex-element">
1269
- Parent text
1270
- <span>Child text</span>
1312
+ <div id="complex-elements">
1313
+ <div class="one"> Parent text <span>Child text</span> </div>
1314
+ <div class="two"> <span>Child text</span> Parent text </div>
1315
+ <div class="three"> Parent text <span>Child text</span> Parent text </div>
1316
+ <div class="four"> <span>Child text</span> </div>
1317
+ <div class="five"><span>Child text</span> <span>Another child</span></div>
1271
1318
</div>
1272
1319
</body>
1273
1320
</html>
0 commit comments