From 4153267b88a1e552001a0bde145526f9e561f3b9 Mon Sep 17 00:00:00 2001 From: Nauman Javed <63299036+nomitoor@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:30:38 +0500 Subject: [PATCH] Fix Apostrophe Handling in SeeInOrder.php and Enhance Test Coverage (#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 --- .../Testing/Constraints/SeeInOrder.php | 8 +- tests/Mail/MailMailableAssertionsTest.php | 88 +++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Testing/Constraints/SeeInOrder.php b/src/Illuminate/Testing/Constraints/SeeInOrder.php index 609f32d50b92..aba5c6bdac4c 100644 --- a/src/Illuminate/Testing/Constraints/SeeInOrder.php +++ b/src/Illuminate/Testing/Constraints/SeeInOrder.php @@ -40,6 +40,8 @@ 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) { @@ -47,7 +49,9 @@ public function matches($values): bool 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; @@ -55,7 +59,7 @@ public function matches($values): bool return false; } - $position = $valuePosition + mb_strlen($value); + $position = $valuePosition + mb_strlen($decodedValue); } return true; diff --git a/tests/Mail/MailMailableAssertionsTest.php b/tests/Mail/MailMailableAssertionsTest.php index 536a9953109b..1584fb84e6f5 100644 --- a/tests/Mail/MailMailableAssertionsTest.php +++ b/tests/Mail/MailMailableAssertionsTest.php @@ -136,6 +136,92 @@ public function testMailableAssertInOrderHtmlFailsWhenAbsentInOrder() '
  • Third Item
  • ', ]); } + + 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("
  • It's not a wonderful day
  • "); + } + + public function testMailableAssertDontSeeInHtmlWithApostrophePassesWhenAbsent() + { + $mailable = new MailableAssertionsStub; + + $mailable->assertDontSeeInHtml("
  • It's not a wonderful day
  • "); + } + + public function testMailableAssertDontSeeInHtmlWithApostropheFailsWhenPresent() + { + $mailable = new MailableAssertionsStub; + + $this->expectException(AssertionFailedError::class); + + $mailable->assertDontSeeInHtml("
  • It's a wonderful day
  • ", false); + } + + public function testMailableAssertSeeInOrderInHtmlWithApostrophePassesWhenPresentInOrder() + { + $mailable = new MailableAssertionsStub; + + $mailable->assertSeeInOrderInHtml([ + 'First Item', + 'Sixth Item', + 'It\'s a wonderful day', + ]); + + $mailable->assertSeeInOrderInHtml([ + '
  • First Item
  • ', + '
  • It\'s a wonderful day
  • ', + ], 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 @@ -149,6 +235,7 @@ protected function renderForAssertions() - Third Item - Fourth & Fifth Item - Sixth Item + - It's a wonderful day EOD; $html = <<<'EOD' @@ -167,6 +254,7 @@ protected function renderForAssertions()
  • Third Item
  • Fourth & Fifth Item
  • Sixth Item
  • +
  • It's a wonderful day