From 8a88e52b368a2231e2d7a87e73db23bd8a815860 Mon Sep 17 00:00:00 2001 From: Stidges Date: Thu, 6 Apr 2017 12:31:21 +0200 Subject: [PATCH 1/2] Add assertSeeText() and assertDontSeeText() to TestResponse --- .../Foundation/Testing/TestResponse.php | 26 +++++++++++++++++++ .../Foundation/FoundationTestResponseTest.php | 13 ++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/Illuminate/Foundation/Testing/TestResponse.php b/src/Illuminate/Foundation/Testing/TestResponse.php index c36d5d871946..369b00ac5dca 100644 --- a/src/Illuminate/Foundation/Testing/TestResponse.php +++ b/src/Illuminate/Foundation/Testing/TestResponse.php @@ -197,6 +197,19 @@ public function assertSee($value) return $this; } + /** + * Assert that the given string is contained within the response text. + * + * @param string $value + * @return $this + */ + public function assertSeeText($value) + { + PHPUnit::assertContains($value, strip_tags($this->getContent())); + + return $this; + } + /** * Assert that the given string is not contained within the response. * @@ -210,6 +223,19 @@ public function assertDontSee($value) return $this; } + /** + * Assert that the given string is not contained within the response text. + * + * @param string $value + * @return $this + */ + public function assertDontSeeText($value) + { + PHPUnit::assertNotContains($value, strip_tags($this->getContent())); + + return $this; + } + /** * Assert that the response is a superset of the given JSON. * diff --git a/tests/Foundation/FoundationTestResponseTest.php b/tests/Foundation/FoundationTestResponseTest.php index 475e4afc46f7..953839f88c5a 100644 --- a/tests/Foundation/FoundationTestResponseTest.php +++ b/tests/Foundation/FoundationTestResponseTest.php @@ -26,6 +26,19 @@ public function testAssertViewHas() $response->assertViewHas('foo'); } + public function testAssertSeeText() + { + $baseResponse = tap(new Response, function ($response) { + $response->setContent(\Mockery::mock(View::class, [ + 'render' => 'foobar' + ])); + }); + + $response = TestResponse::fromBaseResponse($baseResponse); + + $response->assertSeeText('foobar'); + } + public function testAssertJsonWithArray() { $response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceStub)); From 869aa53add0ae38c040d502d577725a537f12027 Mon Sep 17 00:00:00 2001 From: Stidges Date: Thu, 6 Apr 2017 12:49:50 +0200 Subject: [PATCH 2/2] Fix style --- tests/Foundation/FoundationTestResponseTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Foundation/FoundationTestResponseTest.php b/tests/Foundation/FoundationTestResponseTest.php index 953839f88c5a..289664890ae2 100644 --- a/tests/Foundation/FoundationTestResponseTest.php +++ b/tests/Foundation/FoundationTestResponseTest.php @@ -30,7 +30,7 @@ public function testAssertSeeText() { $baseResponse = tap(new Response, function ($response) { $response->setContent(\Mockery::mock(View::class, [ - 'render' => 'foobar' + 'render' => 'foobar', ])); });