diff --git a/src/Illuminate/Testing/TestResponse.php b/src/Illuminate/Testing/TestResponse.php index 5272b17ccd83..316cc0f8ca44 100644 --- a/src/Illuminate/Testing/TestResponse.php +++ b/src/Illuminate/Testing/TestResponse.php @@ -571,6 +571,17 @@ public function assertSee($value, $escape = true) return $this; } + /** + * Assert that the given HTML string or array of HTML strings are contained within the response. + * + * @param string|array $value + * @return $this + */ + public function assertSeeHtml($value) + { + return $this->assertSee($value, false); + } + /** * Assert that the given strings are contained in order within the response. * @@ -587,6 +598,17 @@ public function assertSeeInOrder(array $values, $escape = true) return $this; } + /** + * Assert that the given HTML strings are contained in order within the response. + * + * @param array $values + * @return $this + */ + public function assertSeeHtmlInOrder(array $values) + { + return $this->assertSeeInOrder($values, false); + } + /** * Assert that the given string or array of strings are contained within the response text. * @@ -645,6 +667,17 @@ public function assertDontSee($value, $escape = true) return $this; } + /** + * Assert that the given HTML string or array of HTML strings are not contained within the response. + * + * @param string|array $value + * @return $this + */ + public function assertDontSeeHtml($value) + { + return $this->assertDontSee($value, false); + } + /** * Assert that the given string or array of strings are not contained within the response text. * diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index 9a4632954099..3bef1b9b71b4 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -376,6 +376,28 @@ public function testAssertSeeEscapedCanFail() $response->assertSee(['bar & baz', 'baz & qux']); } + public function testAssertSeeHtml() + { + $response = $this->makeMockResponse([ + 'render' => '', + ]); + + $response->assertSeeHtml('
  • foo
  • '); + $response->assertSeeHtml(['
  • baz
  • ', '
  • bar
  • ']); + } + + public function testAssertSeeHtmlCanFail() + { + $this->expectException(AssertionFailedError::class); + + $response = $this->makeMockResponse([ + 'render' => '', + ]); + + $response->assertSeeHtml('
  • item
  • '); + $response->assertSeeHtml(['
  • not
  • ', '
  • found
  • ']); + } + public function testAssertSeeInOrder() { $response = $this->makeMockResponse([ @@ -409,6 +431,39 @@ public function testAssertSeeInOrderCanFail2() $response->assertSeeInOrder(['foo', 'qux', 'bar', 'baz']); } + public function testAssertSeeHtmlInOrder() + { + $response = $this->makeMockResponse([ + 'render' => '', + ]); + + $response->assertSeeHtmlInOrder(['
  • foo
  • ', '
  • bar
  • ', '
  • baz
  • ']); + + $response->assertSeeHtmlInOrder(['
  • foo
  • ', '
  • bar
  • ', '
  • baz
  • ', '
  • foo
  • ']); + } + + public function testAssertSeeHtmlInOrderCanFail() + { + $this->expectException(AssertionFailedError::class); + + $response = $this->makeMockResponse([ + 'render' => '', + ]); + + $response->assertSeeHtmlInOrder(['
  • baz
  • ', '
  • bar
  • ', '
  • foo
  • ']); + } + + public function testAssertSeeHtmlInOrderCanFail2() + { + $this->expectException(AssertionFailedError::class); + + $response = $this->makeMockResponse([ + 'render' => '', + ]); + + $response->assertSeeHtmlInOrder(['
  • foo
  • ', '
  • qux
  • ', '
  • bar
  • ', '
  • baz
  • ']); + } + public function testAssertSeeText() { $response = $this->makeMockResponse([ @@ -539,6 +594,28 @@ public function testAssertDontSeeEscapedCanFail() $response->assertDontSee(['php & friends', 'laravel & php']); } + public function testAssertDontSeeHtml() + { + $response = $this->makeMockResponse([ + 'render' => '', + ]); + + $response->assertDontSeeHtml('
  • laravel
  • '); + $response->assertDontSeeHtml(['
  • php
  • ', '
  • friends
  • ']); + } + + public function testAssertDontSeeHtmlCanFail() + { + $this->expectException(AssertionFailedError::class); + + $response = $this->makeMockResponse([ + 'render' => '', + ]); + + $response->assertDontSeeHtml('
  • foo
  • '); + $response->assertDontSeeHtml(['
  • baz
  • ', '
  • bar
  • ']); + } + public function testAssertDontSeeText() { $response = $this->makeMockResponse([