Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Add assertSeeText() and assertDontSeeText() to TestResponse #18690

Merged
merged 2 commits into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Illuminate/Foundation/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/Foundation/FoundationTestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => 'foo<strong>bar</strong>',
]));
});

$response = TestResponse::fromBaseResponse($baseResponse);

$response->assertSeeText('foobar');
}

public function testAssertJsonWithArray()
{
$response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceStub));
Expand Down