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;
return $this->crawlerInstance;
}
+ /**
+ * Get the HTML of the first element at the given selector.
+ */
+ public function getElementHtml(string $selector): string
+ {
+ return $this->crawler()->filter($selector)->first()->outerHtml();
+ }
+
/**
* Assert the response contains the specified element.
*
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.
*