|
23 | 23 | use Symfony\Component\BrowserKit\CookieJar;
|
24 | 24 | use Symfony\Component\BrowserKit\History;
|
25 | 25 | use Symfony\Component\DomCrawler\Crawler;
|
| 26 | +use Symfony\Component\DomCrawler\DomCrawler; |
26 | 27 | use Symfony\Component\HttpFoundation\Cookie as HttpFoundationCookie;
|
27 | 28 | use Symfony\Component\HttpFoundation\Request;
|
28 | 29 | use Symfony\Component\HttpFoundation\Response;
|
@@ -231,126 +232,156 @@ public function testAssertBrowserHistoryIsNotOnLastPage()
|
231 | 232 |
|
232 | 233 | public function testAssertSelectorExists()
|
233 | 234 | {
|
234 |
| - $this->getCrawlerTester(new Crawler('<html><body><h1>'))->assertSelectorExists('body > h1'); |
| 235 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 236 | + |
| 237 | + $this->getCrawlerTester(new $crawler('<html><body><h1>'))->assertSelectorExists('body > h1'); |
235 | 238 | $this->expectException(AssertionFailedError::class);
|
236 | 239 | $this->expectExceptionMessage('matches selector "body > h1".');
|
237 |
| - $this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertSelectorExists('body > h1'); |
| 240 | + $this->getCrawlerTester(new $crawler('<html><head><title>Foo'))->assertSelectorExists('body > h1'); |
238 | 241 | }
|
239 | 242 |
|
240 | 243 | public function testAssertSelectorNotExists()
|
241 | 244 | {
|
242 |
| - $this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertSelectorNotExists('body > h1'); |
| 245 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 246 | + |
| 247 | + $this->getCrawlerTester(new $crawler('<html><head><title>Foo'))->assertSelectorNotExists('body > h1'); |
243 | 248 | $this->expectException(AssertionFailedError::class);
|
244 | 249 | $this->expectExceptionMessage('does not match selector "body > h1".');
|
245 |
| - $this->getCrawlerTester(new Crawler('<html><body><h1>'))->assertSelectorNotExists('body > h1'); |
| 250 | + $this->getCrawlerTester(new $crawler('<html><body><h1>'))->assertSelectorNotExists('body > h1'); |
246 | 251 | }
|
247 | 252 |
|
248 | 253 | public function testAssertSelectorCount()
|
249 | 254 | {
|
250 |
| - $this->getCrawlerTester(new Crawler('<html><body><p>Hello</p></body></html>'))->assertSelectorCount(1, 'p'); |
251 |
| - $this->getCrawlerTester(new Crawler('<html><body><p>Hello</p><p>Foo</p></body></html>'))->assertSelectorCount(2, 'p'); |
252 |
| - $this->getCrawlerTester(new Crawler('<html><body><h1>This is not a paragraph.</h1></body></html>'))->assertSelectorCount(0, 'p'); |
| 255 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 256 | + |
| 257 | + $this->getCrawlerTester(new $crawler('<html><body><p>Hello</p></body></html>'))->assertSelectorCount(1, 'p'); |
| 258 | + $this->getCrawlerTester(new $crawler('<html><body><p>Hello</p><p>Foo</p></body></html>'))->assertSelectorCount(2, 'p'); |
| 259 | + $this->getCrawlerTester(new $crawler('<html><body><h1>This is not a paragraph.</h1></body></html>'))->assertSelectorCount(0, 'p'); |
253 | 260 | $this->expectException(AssertionFailedError::class);
|
254 | 261 | $this->expectExceptionMessage('Failed asserting that the Crawler selector "p" was expected to be found 0 time(s) but was found 1 time(s).');
|
255 |
| - $this->getCrawlerTester(new Crawler('<html><body><p>Hello</p></body></html>'))->assertSelectorCount(0, 'p'); |
| 262 | + $this->getCrawlerTester(new $crawler('<html><body><p>Hello</p></body></html>'))->assertSelectorCount(0, 'p'); |
256 | 263 | }
|
257 | 264 |
|
258 | 265 | public function testAssertSelectorTextNotContains()
|
259 | 266 | {
|
260 |
| - $this->getCrawlerTester(new Crawler('<html><body><h1>Foo'))->assertSelectorTextNotContains('body > h1', 'Bar'); |
| 267 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 268 | + |
| 269 | + $this->getCrawlerTester(new $crawler('<html><body><h1>Foo'))->assertSelectorTextNotContains('body > h1', 'Bar'); |
261 | 270 | $this->expectException(AssertionFailedError::class);
|
262 | 271 | $this->expectExceptionMessage('matches selector "body > h1" and the text "Foo" of the node matching selector "body > h1" does not contain "Foo".');
|
263 |
| - $this->getCrawlerTester(new Crawler('<html><body><h1>Foo'))->assertSelectorTextNotContains('body > h1', 'Foo'); |
| 272 | + $this->getCrawlerTester(new $crawler('<html><body><h1>Foo'))->assertSelectorTextNotContains('body > h1', 'Foo'); |
264 | 273 | }
|
265 | 274 |
|
266 | 275 | public function testAssertAnySelectorTextContains()
|
267 | 276 | {
|
268 |
| - $this->getCrawlerTester(new Crawler('<ul><li>Bar</li><li>Foo Baz'))->assertAnySelectorTextContains('ul li', 'Foo'); |
| 277 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 278 | + |
| 279 | + $this->getCrawlerTester(new $crawler('<ul><li>Bar</li><li>Foo Baz'))->assertAnySelectorTextContains('ul li', 'Foo'); |
269 | 280 | $this->expectException(AssertionFailedError::class);
|
270 | 281 | $this->expectExceptionMessage('matches selector "ul li" and the text of any node matching selector "ul li" contains "Foo".');
|
271 |
| - $this->getCrawlerTester(new Crawler('<ul><li>Bar</li><li>Baz'))->assertAnySelectorTextContains('ul li', 'Foo'); |
| 282 | + $this->getCrawlerTester(new $crawler('<ul><li>Bar</li><li>Baz'))->assertAnySelectorTextContains('ul li', 'Foo'); |
272 | 283 | }
|
273 | 284 |
|
274 | 285 | public function testAssertAnySelectorTextSame()
|
275 | 286 | {
|
276 |
| - $this->getCrawlerTester(new Crawler('<ul><li>Bar</li><li>Foo'))->assertAnySelectorTextSame('ul li', 'Foo'); |
| 287 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 288 | + |
| 289 | + $this->getCrawlerTester(new $crawler('<ul><li>Bar</li><li>Foo'))->assertAnySelectorTextSame('ul li', 'Foo'); |
277 | 290 | $this->expectException(AssertionFailedError::class);
|
278 | 291 | $this->expectExceptionMessage('matches selector "ul li" and has at least a node matching selector "ul li" with content "Foo".');
|
279 |
| - $this->getCrawlerTester(new Crawler('<ul><li>Bar</li><li>Baz'))->assertAnySelectorTextSame('ul li', 'Foo'); |
| 292 | + $this->getCrawlerTester(new $crawler('<ul><li>Bar</li><li>Baz'))->assertAnySelectorTextSame('ul li', 'Foo'); |
280 | 293 | }
|
281 | 294 |
|
282 | 295 | public function testAssertAnySelectorTextNotContains()
|
283 | 296 | {
|
284 |
| - $this->getCrawlerTester(new Crawler('<ul><li>Bar</li><li>Baz'))->assertAnySelectorTextNotContains('ul li', 'Foo'); |
| 297 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 298 | + |
| 299 | + $this->getCrawlerTester(new $crawler('<ul><li>Bar</li><li>Baz'))->assertAnySelectorTextNotContains('ul li', 'Foo'); |
285 | 300 | $this->expectException(AssertionFailedError::class);
|
286 | 301 | $this->expectExceptionMessage('matches selector "ul li" and the text of any node matching selector "ul li" does not contain "Foo".');
|
287 |
| - $this->getCrawlerTester(new Crawler('<ul><li>Bar</li><li>Foo'))->assertAnySelectorTextNotContains('ul li', 'Foo'); |
| 302 | + $this->getCrawlerTester(new $crawler('<ul><li>Bar</li><li>Foo'))->assertAnySelectorTextNotContains('ul li', 'Foo'); |
288 | 303 | }
|
289 | 304 |
|
290 | 305 | public function testAssertPageTitleSame()
|
291 | 306 | {
|
292 |
| - $this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertPageTitleSame('Foo'); |
| 307 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 308 | + |
| 309 | + $this->getCrawlerTester(new $crawler('<html><head><title>Foo'))->assertPageTitleSame('Foo'); |
293 | 310 | $this->expectException(AssertionFailedError::class);
|
294 | 311 | $this->expectExceptionMessage('matches selector "title" and has a node matching selector "title" with content "Bar".');
|
295 |
| - $this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertPageTitleSame('Bar'); |
| 312 | + $this->getCrawlerTester(new $crawler('<html><head><title>Foo'))->assertPageTitleSame('Bar'); |
296 | 313 | }
|
297 | 314 |
|
298 | 315 | public function testAssertPageTitleContains()
|
299 | 316 | {
|
300 |
| - $this->getCrawlerTester(new Crawler('<html><head><title>Foobar'))->assertPageTitleContains('Foo'); |
| 317 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 318 | + |
| 319 | + $this->getCrawlerTester(new $crawler('<html><head><title>Foobar'))->assertPageTitleContains('Foo'); |
301 | 320 | $this->expectException(AssertionFailedError::class);
|
302 | 321 | $this->expectExceptionMessage('matches selector "title" and the text "Foo" of the node matching selector "title" contains "Bar".');
|
303 |
| - $this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertPageTitleContains('Bar'); |
| 322 | + $this->getCrawlerTester(new $crawler('<html><head><title>Foo'))->assertPageTitleContains('Bar'); |
304 | 323 | }
|
305 | 324 |
|
306 | 325 | public function testAssertInputValueSame()
|
307 | 326 | {
|
308 |
| - $this->getCrawlerTester(new Crawler('<html><body><form><input type="text" name="username" value="Fabien">'))->assertInputValueSame('username', 'Fabien'); |
| 327 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 328 | + |
| 329 | + $this->getCrawlerTester(new $crawler('<html><body><form><input type="text" name="username" value="Fabien">'))->assertInputValueSame('username', 'Fabien'); |
309 | 330 | $this->expectException(AssertionFailedError::class);
|
310 | 331 | $this->expectExceptionMessage('matches selector "input[name="password"]" and has a node matching selector "input[name="password"]" with attribute "value" of value "pa$$".');
|
311 |
| - $this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertInputValueSame('password', 'pa$$'); |
| 332 | + $this->getCrawlerTester(new $crawler('<html><head><title>Foo'))->assertInputValueSame('password', 'pa$$'); |
312 | 333 | }
|
313 | 334 |
|
314 | 335 | public function testAssertInputValueNotSame()
|
315 | 336 | {
|
316 |
| - $this->getCrawlerTester(new Crawler('<html><body><input type="text" name="username" value="Helene">'))->assertInputValueNotSame('username', 'Fabien'); |
| 337 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 338 | + |
| 339 | + $this->getCrawlerTester(new $crawler('<html><body><input type="text" name="username" value="Helene">'))->assertInputValueNotSame('username', 'Fabien'); |
317 | 340 | $this->expectException(AssertionFailedError::class);
|
318 | 341 | $this->expectExceptionMessage('matches selector "input[name="password"]" and does not have a node matching selector "input[name="password"]" with attribute "value" of value "pa$$".');
|
319 |
| - $this->getCrawlerTester(new Crawler('<html><body><form><input type="text" name="password" value="pa$$">'))->assertInputValueNotSame('password', 'pa$$'); |
| 342 | + $this->getCrawlerTester(new $crawler('<html><body><form><input type="text" name="password" value="pa$$">'))->assertInputValueNotSame('password', 'pa$$'); |
320 | 343 | }
|
321 | 344 |
|
322 | 345 | public function testAssertCheckboxChecked()
|
323 | 346 | {
|
324 |
| - $this->getCrawlerTester(new Crawler('<html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxChecked('rememberMe'); |
325 |
| - $this->getCrawlerTester(new Crawler('<!DOCTYPE html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxChecked('rememberMe'); |
| 347 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 348 | + |
| 349 | + $this->getCrawlerTester(new $crawler('<html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxChecked('rememberMe'); |
| 350 | + $this->getCrawlerTester(new $crawler('<!DOCTYPE html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxChecked('rememberMe'); |
326 | 351 | $this->expectException(AssertionFailedError::class);
|
327 | 352 | $this->expectExceptionMessage('matches selector "input[name="rememberMe"]:checked".');
|
328 |
| - $this->getCrawlerTester(new Crawler('<html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxChecked('rememberMe'); |
| 353 | + $this->getCrawlerTester(new $crawler('<html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxChecked('rememberMe'); |
329 | 354 | }
|
330 | 355 |
|
331 | 356 | public function testAssertCheckboxNotChecked()
|
332 | 357 | {
|
333 |
| - $this->getCrawlerTester(new Crawler('<html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxNotChecked('rememberMe'); |
334 |
| - $this->getCrawlerTester(new Crawler('<!DOCTYPE html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxNotChecked('rememberMe'); |
| 358 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 359 | + |
| 360 | + $this->getCrawlerTester(new $crawler('<html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxNotChecked('rememberMe'); |
| 361 | + $this->getCrawlerTester(new $crawler('<!DOCTYPE html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxNotChecked('rememberMe'); |
335 | 362 | $this->expectException(AssertionFailedError::class);
|
336 | 363 | $this->expectExceptionMessage('does not match selector "input[name="rememberMe"]:checked".');
|
337 |
| - $this->getCrawlerTester(new Crawler('<html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxNotChecked('rememberMe'); |
| 364 | + $this->getCrawlerTester(new $crawler('<html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxNotChecked('rememberMe'); |
338 | 365 | }
|
339 | 366 |
|
340 | 367 | public function testAssertFormValue()
|
341 | 368 | {
|
342 |
| - $this->getCrawlerTester(new Crawler('<html><body><form id="form"><input type="text" name="username" value="Fabien">', 'http://localhost'))->assertFormValue('#form', 'username', 'Fabien'); |
| 369 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 370 | + |
| 371 | + $this->getCrawlerTester(new $crawler('<html><body><form id="form"><input type="text" name="username" value="Fabien">', 'http://localhost'))->assertFormValue('#form', 'username', 'Fabien'); |
343 | 372 | $this->expectException(AssertionFailedError::class);
|
344 | 373 | $this->expectExceptionMessage('Failed asserting that two strings are identical.');
|
345 |
| - $this->getCrawlerTester(new Crawler('<html><body><form id="form"><input type="text" name="username" value="Fabien">', 'http://localhost'))->assertFormValue('#form', 'username', 'Jane'); |
| 374 | + $this->getCrawlerTester(new $crawler('<html><body><form id="form"><input type="text" name="username" value="Fabien">', 'http://localhost'))->assertFormValue('#form', 'username', 'Jane'); |
346 | 375 | }
|
347 | 376 |
|
348 | 377 | public function testAssertNoFormValue()
|
349 | 378 | {
|
350 |
| - $this->getCrawlerTester(new Crawler('<html><body><form id="form"><input type="checkbox" name="rememberMe">', 'http://localhost'))->assertNoFormValue('#form', 'rememberMe'); |
| 379 | + $crawler = \PHP_VERSION_ID >= 80400 && class_exists(DomCrawler::class) ? DomCrawler::class : Crawler::class; |
| 380 | + |
| 381 | + $this->getCrawlerTester(new $crawler('<html><body><form id="form"><input type="checkbox" name="rememberMe">', 'http://localhost'))->assertNoFormValue('#form', 'rememberMe'); |
351 | 382 | $this->expectException(AssertionFailedError::class);
|
352 | 383 | $this->expectExceptionMessage('Field "rememberMe" has a value in form "#form".');
|
353 |
| - $this->getCrawlerTester(new Crawler('<html><body><form id="form"><input type="checkbox" name="rememberMe" checked>', 'http://localhost'))->assertNoFormValue('#form', 'rememberMe'); |
| 384 | + $this->getCrawlerTester(new $crawler('<html><body><form id="form"><input type="checkbox" name="rememberMe" checked>', 'http://localhost'))->assertNoFormValue('#form', 'rememberMe'); |
354 | 385 | }
|
355 | 386 |
|
356 | 387 | public function testAssertRequestAttributeValueSame()
|
|
0 commit comments