diff --git a/tests/Helper/Stringer.php b/tests/Helper/Stringer.php new file mode 100644 index 000000000..b36330323 --- /dev/null +++ b/tests/Helper/Stringer.php @@ -0,0 +1,40 @@ +content = $content; + } + + /** + * Returns the wrapped string. + * + * @return string + */ + public function __toString() + { + return $this->content; + } + +} diff --git a/tests/WebAssertTest.php b/tests/WebAssertTest.php index 92f3a1e10..f9a52c6d8 100644 --- a/tests/WebAssertTest.php +++ b/tests/WebAssertTest.php @@ -3,7 +3,7 @@ namespace Behat\Mink\Tests; use Behat\Mink\Exception\ExpectationException; -use Behat\Mink\Tests\helpers\Stringer; +use Behat\Mink\Tests\Helper\Stringer; use Behat\Mink\WebAssert; use PHPUnit\Framework\TestCase; @@ -256,7 +256,7 @@ public function testResponseHeaderContains() ) )); - $this->assertCorrectAssertion('responseHeaderContains', array('foo', new Stringer('ba'))); + $this->assertCorrectAssertion('responseHeaderContains', array('foo', 'ba')); $this->assertWrongAssertion( 'responseHeaderContains', array('bar', 'bz'), @@ -277,6 +277,50 @@ public function testResponseHeaderNotContains() ) )); + $this->assertCorrectAssertion('responseHeaderNotContains', array('foo', 'bz')); + $this->assertWrongAssertion( + 'responseHeaderNotContains', + array('bar', 'ba'), + 'Behat\\Mink\\Exception\\ExpectationException', + 'The text "ba" was found in the "bar" response header, but it should not.' + ); + } + + public function testResponseHeaderContainsObjectWithToString() + { + $this->session + ->expects($this->any()) + ->method('getResponseHeader') + ->will($this->returnValueMap( + array( + array('foo', 'bar'), + array('bar', 'baz'), + ) + )); + + $this->assertCorrectAssertion('responseHeaderContains', array('foo', new Stringer('ba'))); + $this->assertWrongAssertion( + 'responseHeaderContains', + array('bar', 'bz'), + 'Behat\\Mink\\Exception\\ExpectationException', + 'The text "bz" was not found anywhere in the "bar" response header.' + ); + } + + public function testResponseHeaderNotContainsObjectWithToString() + { + $this->session + ->expects($this->any()) + ->method('getResponseHeader') + ->will( + $this->returnValueMap( + array( + array('foo', 'bar'), + array('bar', 'baz'), + ) + ) + ); + $this->assertCorrectAssertion('responseHeaderNotContains', array('foo', new Stringer('bz'))); $this->assertWrongAssertion( 'responseHeaderNotContains', @@ -459,7 +503,7 @@ public function testResponseContains() ->will($this->returnValue('Some page text')) ; - $this->assertCorrectAssertion('responseContains', array(new Stringer('PAGE text'))); + $this->assertCorrectAssertion('responseContains', array('PAGE text')); $this->assertWrongAssertion( 'responseContains', array('html text'), @@ -487,6 +531,62 @@ public function testResponseNotContains() ->will($this->returnValue('Some html text')) ; + $this->assertCorrectAssertion('responseNotContains', array('PAGE text')); + $this->assertWrongAssertion( + 'responseNotContains', + array('HTML text'), + 'Behat\\Mink\\Exception\\ExpectationException', + 'The string "HTML text" appears in the HTML response of this page, but it should not.' + ); + } + + public function testResponseContainsObjectWithToString() + { + $page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement') + ->disableOriginalConstructor() + ->getMock() + ; + + $this->session + ->expects($this->exactly(2)) + ->method('getPage') + ->will($this->returnValue($page)) + ; + + $page + ->expects($this->exactly(2)) + ->method('getContent') + ->will($this->returnValue('Some page text')) + ; + + $this->assertCorrectAssertion('responseContains', array(new Stringer('PAGE text'))); + $this->assertWrongAssertion( + 'responseContains', + array('html text'), + 'Behat\\Mink\\Exception\\ExpectationException', + 'The string "html text" was not found anywhere in the HTML response of the current page.' + ); + } + + public function testResponseNotContainsObjectWithToString() + { + $page = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement') + ->disableOriginalConstructor() + ->getMock() + ; + + $this->session + ->expects($this->exactly(2)) + ->method('getPage') + ->will($this->returnValue($page)) + ; + + $page + ->expects($this->exactly(2)) + ->method('getContent') + ->will($this->returnValue('Some html text')) + ; + $this->assertCorrectAssertion('responseNotContains', array(new Stringer('PAGE text'))); $this->assertWrongAssertion( 'responseNotContains', diff --git a/tests/helpers/Stringer.php b/tests/helpers/Stringer.php deleted file mode 100644 index 34eee5704..000000000 --- a/tests/helpers/Stringer.php +++ /dev/null @@ -1,42 +0,0 @@ -content = $content; - } - - /** - * Returns in the wrapped string. - * - * @return string - */ - public function __toString() - { - return $this->content; - } - -}