Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 99f389a

Browse filesBrowse files
committed
Escape asserted value by default before checking for it's presence in HTML
1 parent 8a6ab91 commit 99f389a
Copy full SHA for 99f389a

File tree

Expand file treeCollapse file tree

2 files changed

+37
-7
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+37
-7
lines changed

‎src/Illuminate/Mail/Mailable.php

Copy file name to clipboardExpand all lines: src/Illuminate/Mail/Mailable.php
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -976,10 +976,13 @@ public function metadata($key, $value)
976976
* Assert that the given text is present in the HTML email body.
977977
*
978978
* @param string $string
979+
* @param bool $escape
979980
* @return $this
980981
*/
981-
public function assertSeeInHtml($string)
982+
public function assertSeeInHtml($string, $escape = true)
982983
{
984+
$string = $escape ? e($string) : $string;
985+
983986
[$html, $text] = $this->renderForAssertions();
984987

985988
PHPUnit::assertTrue(
@@ -994,10 +997,13 @@ public function assertSeeInHtml($string)
994997
* Assert that the given text is not present in the HTML email body.
995998
*
996999
* @param string $string
1000+
* @param bool $escape
9971001
* @return $this
9981002
*/
999-
public function assertDontSeeInHtml($string)
1003+
public function assertDontSeeInHtml($string, $escape = true)
10001004
{
1005+
$string = $escape ? e($string) : $string;
1006+
10011007
[$html, $text] = $this->renderForAssertions();
10021008

10031009
PHPUnit::assertFalse(
@@ -1012,10 +1018,13 @@ public function assertDontSeeInHtml($string)
10121018
* Assert that the given text strings are present in order in the HTML email body.
10131019
*
10141020
* @param array $strings
1021+
* @param bool $escape
10151022
* @return $this
10161023
*/
1017-
public function assertSeeInOrderInHtml($strings)
1024+
public function assertSeeInOrderInHtml($strings, $escape = true)
10181025
{
1026+
$strings = $escape ? array_map('e', ($strings)) : $strings;
1027+
10191028
[$html, $text] = $this->renderForAssertions();
10201029

10211030
PHPUnit::assertThat($strings, new SeeInOrder($html));

‎tests/Mail/MailMailableAssertionsTest.php

Copy file name to clipboardExpand all lines: tests/Mail/MailMailableAssertionsTest.php
+25-4Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public function testMailableAssertSeeInHtmlPassesWhenPresent()
4444
{
4545
$mailable = new MailableAssertionsStub;
4646

47-
$mailable->assertSeeInHtml('<li>First Item</li>');
47+
$mailable->assertSeeInHtml('Fourth & Fifth Item');
48+
49+
$mailable->assertSeeInHtml('<li>First Item</li>', false);
4850
}
4951

5052
public function testMailableAssertSeeInHtmlFailsWhenAbsent()
@@ -63,13 +65,22 @@ public function testMailableAssertDontSeeInHtmlPassesWhenAbsent()
6365
$mailable->assertDontSeeInHtml('<li>Fourth Item</li>');
6466
}
6567

66-
public function testMailableAssertDontSeeInHtmlFailsWhenPresent()
68+
public function testMailableAssertDontSeeInHtmlEscapedFailsWhenPresent()
6769
{
6870
$mailable = new MailableAssertionsStub;
6971

7072
$this->expectException(AssertionFailedError::class);
7173

72-
$mailable->assertDontSeeInHtml('<li>First Item</li>');
74+
$mailable->assertDontSeeInHtml('Fourth & Fifth Item');
75+
}
76+
77+
public function testMailableAssertDontSeeInHtmlUnescapedFailsWhenPresent()
78+
{
79+
$mailable = new MailableAssertionsStub;
80+
81+
$this->expectException(AssertionFailedError::class);
82+
83+
$mailable->assertDontSeeInHtml('<li>First Item</li>', false);
7384
}
7485

7586
public function testMailableAssertSeeInOrderTextPassesWhenPresentInOrder()
@@ -100,11 +111,17 @@ public function testMailableAssertInOrderHtmlPassesWhenPresentInOrder()
100111
{
101112
$mailable = new MailableAssertionsStub;
102113

114+
$mailable->assertSeeInOrderInHtml([
115+
'Third Item',
116+
'Fourth & Fifth Item',
117+
'Sixth Item',
118+
]);
119+
103120
$mailable->assertSeeInOrderInHtml([
104121
'<li>First Item</li>',
105122
'<li>Second Item</li>',
106123
'<li>Third Item</li>',
107-
]);
124+
], false);
108125
}
109126

110127
public function testMailableAssertInOrderHtmlFailsWhenAbsentInOrder()
@@ -130,6 +147,8 @@ protected function renderForAssertions()
130147
- First Item
131148
- Second Item
132149
- Third Item
150+
- Fourth & Fifth Item
151+
- Sixth Item
133152
EOD;
134153

135154
$html = <<<'EOD'
@@ -146,6 +165,8 @@ protected function renderForAssertions()
146165
<li>First Item</li>
147166
<li>Second Item</li>
148167
<li>Third Item</li>
168+
<li>Fourth &amp; Fifth Item</li>
169+
<li>Sixth Item</li>
149170
</ul>
150171
</body>
151172
</html>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.