Skip to content

Commit

Permalink
Fix Apostrophe Handling in SeeInOrder.php and Enhance Test Coverage (#…
Browse files Browse the repository at this point in the history
…52627)

* Update SeeInOrder.php

The issue is happening when in the in order array, one of the string has apostrophe on it. So this PR will resolve that issue.

* Update MailMailableAssertionsTest.php

Updated tests for apostrophe

* Update SeeInOrder.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
nomitoor and taylorotwell authored Sep 3, 2024
1 parent 57249c3 commit 4153267
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Illuminate/Testing/Constraints/SeeInOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,26 @@ public function __construct($content)
*/
public function matches($values): bool
{
$decodedContent = html_entity_decode($this->content, ENT_QUOTES, 'UTF-8');

$position = 0;

foreach ($values as $value) {
if (empty($value)) {
continue;
}

$valuePosition = mb_strpos($this->content, $value, $position);
$decodedValue = html_entity_decode($value, ENT_QUOTES, 'UTF-8');

$valuePosition = mb_strpos($decodedContent, $decodedValue, $position);

if ($valuePosition === false || $valuePosition < $position) {
$this->failedValue = $value;

return false;
}

$position = $valuePosition + mb_strlen($value);
$position = $valuePosition + mb_strlen($decodedValue);
}

return true;
Expand Down
88 changes: 88 additions & 0 deletions tests/Mail/MailMailableAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,92 @@ public function testMailableAssertInOrderHtmlFailsWhenAbsentInOrder()
'<li>Third Item</li>',
]);
}

public function testMailableAssertSeeInTextWithApostrophePassesWhenPresent()
{
$mailable = new MailableAssertionsStub;

$mailable->assertSeeInText("It's a wonderful day");
}

public function testMailableAssertSeeInTextWithApostropheFailsWhenAbsent()
{
$mailable = new MailableAssertionsStub;

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

$mailable->assertSeeInText("It's not a wonderful day");
}

public function testMailableAssertDontSeeInTextWithApostrophePassesWhenAbsent()
{
$mailable = new MailableAssertionsStub;

$mailable->assertDontSeeInText("It's not a wonderful day");
}

public function testMailableAssertDontSeeInTextWithApostropheFailsWhenPresent()
{
$mailable = new MailableAssertionsStub;

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

$mailable->assertDontSeeInText("It's a wonderful day");
}

public function testMailableAssertSeeInHtmlWithApostropheFailsWhenAbsent()
{
$mailable = new MailableAssertionsStub;

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

$mailable->assertSeeInHtml("<li>It's not a wonderful day</li>");
}

public function testMailableAssertDontSeeInHtmlWithApostrophePassesWhenAbsent()
{
$mailable = new MailableAssertionsStub;

$mailable->assertDontSeeInHtml("<li>It's not a wonderful day</li>");
}

public function testMailableAssertDontSeeInHtmlWithApostropheFailsWhenPresent()
{
$mailable = new MailableAssertionsStub;

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

$mailable->assertDontSeeInHtml("<li>It's a wonderful day</li>", false);
}

public function testMailableAssertSeeInOrderInHtmlWithApostrophePassesWhenPresentInOrder()
{
$mailable = new MailableAssertionsStub;

$mailable->assertSeeInOrderInHtml([
'First Item',
'Sixth Item',
'It\'s a wonderful day',
]);

$mailable->assertSeeInOrderInHtml([
'<li>First Item</li>',
'<li>It\'s a wonderful day</li>',
], false);
}

public function testMailableAssertSeeInOrderInHtmlWithApostropheFailsWhenAbsentInOrder()
{
$mailable = new MailableAssertionsStub;

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

$mailable->assertSeeInOrderInHtml([
'It\'s a wonderful day',
'First Item',
'Sixth Item',
]);
}
}

class MailableAssertionsStub extends Mailable
Expand All @@ -149,6 +235,7 @@ protected function renderForAssertions()
- Third Item
- Fourth & Fifth Item
- Sixth Item
- It's a wonderful day
EOD;

$html = <<<'EOD'
Expand All @@ -167,6 +254,7 @@ protected function renderForAssertions()
<li>Third Item</li>
<li>Fourth &amp; Fifth Item</li>
<li>Sixth Item</li>
<li>It's a wonderful day</li>
</ul>
</body>
</html>
Expand Down

0 comments on commit 4153267

Please sign in to comment.