I would like to create a Behat rule that allows me to find text with wildcards, since I couldn't find anything close to it.
I sometimes have to create some contents in Drupal projects, but the title isn't defined by the user so I can't know before running the test what the title will be when saved. I.E., in my situation, I would like to check if I can see the following text in the page
The content 'N° 1', of type 'ISAI', has been created.
Here, I would like to put N°1
in a wildcard, so I only have to look for
"The content '/^[A-Z]{1}°[0-9]+$/', of type 'ISAI', has been created."
I started to create a function that looks like the following:
And I should see the text "The content 'WILDCARD', of type 'ISAI', has been created" with wildcard matching "/[a-zA-Z °]+$/"
/**
* @Then I should see the text :arg1 with wildcard matching :arg2
*/
public function iShouldSeeTheTextWithWildcardMatching($text, $regex){
$string = str_replace('WILDCARD', $regex, $text);
$result = $this->getSession()->getPage()->find('css', sprintf('div.alert-success:contains("%s")', $string));
echo $result; // is null
}
However, it fails because the selector can't find anything with "/" (since it's a regex).
My question is: is it possible to find some text with a regex, and what should I do to make my method work?