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

[11.x] assertSeeHtml, assertDontSeeHtml and assertSeeHtmlInOrder testing methods #52285

Merged
merged 2 commits into from
Jul 29, 2024
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
33 changes: 33 additions & 0 deletions src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
77 changes: 77 additions & 0 deletions tests/Testing/TestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,28 @@ public function testAssertSeeEscapedCanFail()
$response->assertSee(['bar & baz', 'baz & qux']);
}

public function testAssertSeeHtml()
{
$response = $this->makeMockResponse([
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
]);

$response->assertSeeHtml('<li>foo</li>');
$response->assertSeeHtml(['<li>baz</li>', '<li>bar</li>']);
}

public function testAssertSeeHtmlCanFail()
{
$this->expectException(AssertionFailedError::class);

$response = $this->makeMockResponse([
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
]);

$response->assertSeeHtml('<li>item</li>');
$response->assertSeeHtml(['<li>not</li>', '<li>found</li>']);
}

public function testAssertSeeInOrder()
{
$response = $this->makeMockResponse([
Expand Down Expand Up @@ -409,6 +431,39 @@ public function testAssertSeeInOrderCanFail2()
$response->assertSeeInOrder(['foo', 'qux', 'bar', 'baz']);
}

public function testAssertSeeHtmlInOrder()
{
$response = $this->makeMockResponse([
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
]);

$response->assertSeeHtmlInOrder(['<li>foo</li>', '<li>bar</li>', '<li>baz</li>']);

$response->assertSeeHtmlInOrder(['<li>foo</li>', '<li>bar</li>', '<li>baz</li>', '<li>foo</li>']);
}

public function testAssertSeeHtmlInOrderCanFail()
{
$this->expectException(AssertionFailedError::class);

$response = $this->makeMockResponse([
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
]);

$response->assertSeeHtmlInOrder(['<li>baz</li>', '<li>bar</li>', '<li>foo</li>']);
}

public function testAssertSeeHtmlInOrderCanFail2()
{
$this->expectException(AssertionFailedError::class);

$response = $this->makeMockResponse([
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
]);

$response->assertSeeHtmlInOrder(['<li>foo</li>', '<li>qux</li>', '<li>bar</li>', '<li>baz</li>']);
}

public function testAssertSeeText()
{
$response = $this->makeMockResponse([
Expand Down Expand Up @@ -539,6 +594,28 @@ public function testAssertDontSeeEscapedCanFail()
$response->assertDontSee(['php & friends', 'laravel & php']);
}

public function testAssertDontSeeHtml()
{
$response = $this->makeMockResponse([
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
]);

$response->assertDontSeeHtml('<li>laravel</li>');
$response->assertDontSeeHtml(['<li>php</li>', '<li>friends</li>']);
}

public function testAssertDontSeeHtmlCanFail()
{
$this->expectException(AssertionFailedError::class);

$response = $this->makeMockResponse([
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
]);

$response->assertDontSeeHtml('<li>foo</li>');
$response->assertDontSeeHtml(['<li>baz</li>', '<li>bar</li>']);
}

public function testAssertDontSeeText()
{
$response = $this->makeMockResponse([
Expand Down