Skip to content

Commit 5baa538

Browse files
authored
[11.x] assertSeeHtml, assertDontSeeHtml and assertSeeHtmlInOrder testing methods (#52285)
* assertSeeHtml and assertSeeHtmlInOrder * assertDontSeeHtml
1 parent 440ccb0 commit 5baa538

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

src/Illuminate/Testing/TestResponse.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,17 @@ public function assertSee($value, $escape = true)
571571
return $this;
572572
}
573573

574+
/**
575+
* Assert that the given HTML string or array of HTML strings are contained within the response.
576+
*
577+
* @param string|array $value
578+
* @return $this
579+
*/
580+
public function assertSeeHtml($value)
581+
{
582+
return $this->assertSee($value, false);
583+
}
584+
574585
/**
575586
* Assert that the given strings are contained in order within the response.
576587
*
@@ -587,6 +598,17 @@ public function assertSeeInOrder(array $values, $escape = true)
587598
return $this;
588599
}
589600

601+
/**
602+
* Assert that the given HTML strings are contained in order within the response.
603+
*
604+
* @param array $values
605+
* @return $this
606+
*/
607+
public function assertSeeHtmlInOrder(array $values)
608+
{
609+
return $this->assertSeeInOrder($values, false);
610+
}
611+
590612
/**
591613
* Assert that the given string or array of strings are contained within the response text.
592614
*
@@ -645,6 +667,17 @@ public function assertDontSee($value, $escape = true)
645667
return $this;
646668
}
647669

670+
/**
671+
* Assert that the given HTML string or array of HTML strings are not contained within the response.
672+
*
673+
* @param string|array $value
674+
* @return $this
675+
*/
676+
public function assertDontSeeHtml($value)
677+
{
678+
return $this->assertDontSee($value, false);
679+
}
680+
648681
/**
649682
* Assert that the given string or array of strings are not contained within the response text.
650683
*

tests/Testing/TestResponseTest.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,28 @@ public function testAssertSeeEscapedCanFail()
376376
$response->assertSee(['bar & baz', 'baz & qux']);
377377
}
378378

379+
public function testAssertSeeHtml()
380+
{
381+
$response = $this->makeMockResponse([
382+
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
383+
]);
384+
385+
$response->assertSeeHtml('<li>foo</li>');
386+
$response->assertSeeHtml(['<li>baz</li>', '<li>bar</li>']);
387+
}
388+
389+
public function testAssertSeeHtmlCanFail()
390+
{
391+
$this->expectException(AssertionFailedError::class);
392+
393+
$response = $this->makeMockResponse([
394+
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
395+
]);
396+
397+
$response->assertSeeHtml('<li>item</li>');
398+
$response->assertSeeHtml(['<li>not</li>', '<li>found</li>']);
399+
}
400+
379401
public function testAssertSeeInOrder()
380402
{
381403
$response = $this->makeMockResponse([
@@ -409,6 +431,39 @@ public function testAssertSeeInOrderCanFail2()
409431
$response->assertSeeInOrder(['foo', 'qux', 'bar', 'baz']);
410432
}
411433

434+
public function testAssertSeeHtmlInOrder()
435+
{
436+
$response = $this->makeMockResponse([
437+
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
438+
]);
439+
440+
$response->assertSeeHtmlInOrder(['<li>foo</li>', '<li>bar</li>', '<li>baz</li>']);
441+
442+
$response->assertSeeHtmlInOrder(['<li>foo</li>', '<li>bar</li>', '<li>baz</li>', '<li>foo</li>']);
443+
}
444+
445+
public function testAssertSeeHtmlInOrderCanFail()
446+
{
447+
$this->expectException(AssertionFailedError::class);
448+
449+
$response = $this->makeMockResponse([
450+
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
451+
]);
452+
453+
$response->assertSeeHtmlInOrder(['<li>baz</li>', '<li>bar</li>', '<li>foo</li>']);
454+
}
455+
456+
public function testAssertSeeHtmlInOrderCanFail2()
457+
{
458+
$this->expectException(AssertionFailedError::class);
459+
460+
$response = $this->makeMockResponse([
461+
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
462+
]);
463+
464+
$response->assertSeeHtmlInOrder(['<li>foo</li>', '<li>qux</li>', '<li>bar</li>', '<li>baz</li>']);
465+
}
466+
412467
public function testAssertSeeText()
413468
{
414469
$response = $this->makeMockResponse([
@@ -539,6 +594,28 @@ public function testAssertDontSeeEscapedCanFail()
539594
$response->assertDontSee(['php & friends', 'laravel & php']);
540595
}
541596

597+
public function testAssertDontSeeHtml()
598+
{
599+
$response = $this->makeMockResponse([
600+
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
601+
]);
602+
603+
$response->assertDontSeeHtml('<li>laravel</li>');
604+
$response->assertDontSeeHtml(['<li>php</li>', '<li>friends</li>']);
605+
}
606+
607+
public function testAssertDontSeeHtmlCanFail()
608+
{
609+
$this->expectException(AssertionFailedError::class);
610+
611+
$response = $this->makeMockResponse([
612+
'render' => '<ul><li>foo</li><li>bar</li><li>baz</li><li>foo</li></ul>',
613+
]);
614+
615+
$response->assertDontSeeHtml('<li>foo</li>');
616+
$response->assertDontSeeHtml(['<li>baz</li>', '<li>bar</li>']);
617+
}
618+
542619
public function testAssertDontSeeText()
543620
{
544621
$response = $this->makeMockResponse([

0 commit comments

Comments
 (0)