X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/83c8f731424a317c0f3debcd9eac2cdf2d13cad2..refs/pull/3069/head:/tests/TestResponse.php diff --git a/tests/TestResponse.php b/tests/TestResponse.php index 79f173c9b..4e53aa020 100644 --- a/tests/TestResponse.php +++ b/tests/TestResponse.php @@ -2,7 +2,7 @@ namespace Tests; -use Illuminate\Foundation\Testing\TestResponse as BaseTestResponse; +use Illuminate\Testing\TestResponse as BaseTestResponse; use PHPUnit\Framework\Assert as PHPUnit; use Symfony\Component\DomCrawler\Crawler; @@ -53,6 +53,26 @@ class TestResponse extends BaseTestResponse return $this; } + /** + * Assert the response contains the given count of elements + * that match the given css selector. + * + * @return $this + */ + public function assertElementCount(string $selector, int $count) + { + $elements = $this->crawler()->filter($selector); + PHPUnit::assertTrue( + $elements->count() === $count, + 'Unable to ' . $count . ' element(s) matching the selector: ' . PHP_EOL . PHP_EOL . + "[{$selector}]" . PHP_EOL . PHP_EOL . + 'found ' . $elements->count() . ' within' . PHP_EOL . PHP_EOL . + "[{$this->getContent()}]." + ); + + return $this; + } + /** * Assert the response does not contain the specified element. *