diff --git a/src/Illuminate/Foundation/Testing/TestResponse.php b/src/Illuminate/Foundation/Testing/TestResponse.php index 1f77c47d443b..776aececcb0c 100644 --- a/src/Illuminate/Foundation/Testing/TestResponse.php +++ b/src/Illuminate/Foundation/Testing/TestResponse.php @@ -253,6 +253,32 @@ public function assertSee($value) return $this; } + /** + * Assert that the given strings are contained in order within the response. + * + * @param array $values + * @return $this + */ + public function assertSeeInOrder(array $values) + { + $position = -1; + + foreach ($values as $value) { + $valuePosition = mb_strpos($this->getContent(), $value); + + if ($valuePosition === false || $valuePosition < $position) { + PHPUnit::fail( + 'Failed asserting that \''.$this->getContent(). + '\' contains "'.$value.'" in specified order.' + ); + } + + $position = $valuePosition; + } + + return $this; + } + /** * Assert that the given string is contained within the response text. * @@ -266,6 +292,32 @@ public function assertSeeText($value) return $this; } + /** + * Assert that the given strings are contained in order within the response text. + * + * @param array $values + * @return $this + */ + public function assertSeeTextInOrder(array $values) + { + $position = -1; + + foreach ($values as $value) { + $valuePosition = mb_strpos(strip_tags($this->getContent()), $value); + + if ($valuePosition === false || $valuePosition < $position) { + PHPUnit::fail( + 'Failed asserting that \''.strip_tags($this->getContent()). + '\' contains "'.$value.'" in specified order.' + ); + } + + $position = $valuePosition; + } + + return $this; + } + /** * Assert that the given string is not contained within the response. * diff --git a/tests/Foundation/FoundationTestResponseTest.php b/tests/Foundation/FoundationTestResponseTest.php index d04b4ac2f41a..bdece6dfe012 100644 --- a/tests/Foundation/FoundationTestResponseTest.php +++ b/tests/Foundation/FoundationTestResponseTest.php @@ -41,6 +41,28 @@ public function testAssertViewHas() $response->assertViewHas('foo'); } + public function testAssertSeeInOrder() + { + $baseResponse = tap(new Response, function ($response) { + $response->setContent(\Mockery::mock(View::class, [ + 'render' => '