|
3 | 3 | namespace Behat\Mink\Tests;
|
4 | 4 |
|
5 | 5 | use Behat\Mink\Exception\ExpectationException;
|
| 6 | +use Behat\Mink\Tests\Helper\Stringer; |
6 | 7 | use Behat\Mink\WebAssert;
|
7 | 8 | use PHPUnit\Framework\TestCase;
|
8 | 9 |
|
@@ -285,6 +286,50 @@ public function testResponseHeaderNotContains()
|
285 | 286 | );
|
286 | 287 | }
|
287 | 288 |
|
| 289 | + public function testResponseHeaderContainsObjectWithToString() |
| 290 | + { |
| 291 | + $this->session |
| 292 | + ->expects($this->any()) |
| 293 | + ->method('getResponseHeader') |
| 294 | + ->will($this->returnValueMap( |
| 295 | + array( |
| 296 | + array('foo', 'bar'), |
| 297 | + array('bar', 'baz'), |
| 298 | + ) |
| 299 | + )); |
| 300 | + |
| 301 | + $this->assertCorrectAssertion('responseHeaderContains', array('foo', new Stringer('ba'))); |
| 302 | + $this->assertWrongAssertion( |
| 303 | + 'responseHeaderContains', |
| 304 | + array('bar', 'bz'), |
| 305 | + 'Behat\\Mink\\Exception\\ExpectationException', |
| 306 | + 'The text "bz" was not found anywhere in the "bar" response header.' |
| 307 | + ); |
| 308 | + } |
| 309 | + |
| 310 | + public function testResponseHeaderNotContainsObjectWithToString() |
| 311 | + { |
| 312 | + $this->session |
| 313 | + ->expects($this->any()) |
| 314 | + ->method('getResponseHeader') |
| 315 | + ->will( |
| 316 | + $this->returnValueMap( |
| 317 | + array( |
| 318 | + array('foo', 'bar'), |
| 319 | + array('bar', 'baz'), |
| 320 | + ) |
| 321 | + ) |
| 322 | + ); |
| 323 | + |
| 324 | + $this->assertCorrectAssertion('responseHeaderNotContains', array('foo', new Stringer('bz'))); |
| 325 | + $this->assertWrongAssertion( |
| 326 | + 'responseHeaderNotContains', |
| 327 | + array('bar', 'ba'), |
| 328 | + 'Behat\\Mink\\Exception\\ExpectationException', |
| 329 | + 'The text "ba" was found in the "bar" response header, but it should not.' |
| 330 | + ); |
| 331 | + } |
| 332 | + |
288 | 333 | public function testResponseHeaderMatches()
|
289 | 334 | {
|
290 | 335 | $this->session
|
@@ -495,6 +540,62 @@ public function testResponseNotContains()
|
495 | 540 | );
|
496 | 541 | }
|
497 | 542 |
|
| 543 | + public function testResponseContainsObjectWithToString() |
| 544 | + { |
| 545 | + $page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement') |
| 546 | + ->disableOriginalConstructor() |
| 547 | + ->getMock() |
| 548 | + ; |
| 549 | + |
| 550 | + $this->session |
| 551 | + ->expects($this->exactly(2)) |
| 552 | + ->method('getPage') |
| 553 | + ->will($this->returnValue($page)) |
| 554 | + ; |
| 555 | + |
| 556 | + $page |
| 557 | + ->expects($this->exactly(2)) |
| 558 | + ->method('getContent') |
| 559 | + ->will($this->returnValue('Some page text')) |
| 560 | + ; |
| 561 | + |
| 562 | + $this->assertCorrectAssertion('responseContains', array(new Stringer('PAGE text'))); |
| 563 | + $this->assertWrongAssertion( |
| 564 | + 'responseContains', |
| 565 | + array('html text'), |
| 566 | + 'Behat\\Mink\\Exception\\ExpectationException', |
| 567 | + 'The string "html text" was not found anywhere in the HTML response of the current page.' |
| 568 | + ); |
| 569 | + } |
| 570 | + |
| 571 | + public function testResponseNotContainsObjectWithToString() |
| 572 | + { |
| 573 | + $page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement') |
| 574 | + ->disableOriginalConstructor() |
| 575 | + ->getMock() |
| 576 | + ; |
| 577 | + |
| 578 | + $this->session |
| 579 | + ->expects($this->exactly(2)) |
| 580 | + ->method('getPage') |
| 581 | + ->will($this->returnValue($page)) |
| 582 | + ; |
| 583 | + |
| 584 | + $page |
| 585 | + ->expects($this->exactly(2)) |
| 586 | + ->method('getContent') |
| 587 | + ->will($this->returnValue('Some html text')) |
| 588 | + ; |
| 589 | + |
| 590 | + $this->assertCorrectAssertion('responseNotContains', array(new Stringer('PAGE text'))); |
| 591 | + $this->assertWrongAssertion( |
| 592 | + 'responseNotContains', |
| 593 | + array('HTML text'), |
| 594 | + 'Behat\\Mink\\Exception\\ExpectationException', |
| 595 | + 'The string "HTML text" appears in the HTML response of this page, but it should not.' |
| 596 | + ); |
| 597 | + } |
| 598 | + |
498 | 599 | public function testResponseMatches()
|
499 | 600 | {
|
500 | 601 | $page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement')
|
|
0 commit comments