public function TestSubContext::assertFieldContains in Panopoly 8.2
Verifies that a field has expected placeholder text.
@Then /^the "(?P<field>(?:[^"]|\\")*)" field placeholder should contain "(?P<value>(?:[^"]|\\")*)"$/
File
- modules/
panopoly/ panopoly_test/ behat/ steps/ panopoly_test.behat.inc, line 1213 - Provide Behat step-definitions for generic Panopoly tests.
Class
- TestSubContext
- Behat sub-context for Panopoly.
Code
public function assertFieldContains($field, $value) {
$node = $this
->assertSession()
->fieldExists($field);
$actual = $node
->getAttribute('placeholder');
$regex = '/^' . preg_quote($value, '/') . '$/ui';
$message = sprintf('The field "%s" value is "%s", but "%s" expected.', $field, $actual, $value);
$result = (bool) preg_match($regex, $actual);
if (!$result) {
throw new ExpectationException($message, $this
->getSession()
->getDriver());
}
}