I'm writing some functional tests and i want to verify that the Edit link exists on the page if the user is logged in.
The link is a simple <a href="/profile/22/edit">Edit</a>
.
How can I filter it using the Crawler component of Symfony?
One solution is this:
$this->assertEquals(1, $crawler->filter('html:contains("<a href="/profile/22/edit">")')->count());
But I'd like to use, instead, the tag selection, so how can I do this?
You can use Crawler::filterXPath() to check for the presence or even absence of html elements matching all sorts of criteria. To check for the presence of a link I prefer to use the element id as that is most likely to remain constant. For example, if you modify your link as follows:
Then you can check the link exists like this:
Here are some good examples of the sort of filters you can use with XPath.