You are here

public function TestSubContext::assertEntityReferenceFieldContains in Panopoly 8.2

Checks, that entity reference field has specified value.

Entity references have the entity ID appended to the title. This step allows asserting the main text value without needing to know the entity ID.

@Then /^the entity reference "(?P<field>(?:[^"]|\\")*)" field should contain "(?P<value>(?:[^"]|\\")*)"$/

File

modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc, line 1054
Provide Behat step-definitions for generic Panopoly tests.

Class

TestSubContext
Behat sub-context for Panopoly.

Code

public function assertEntityReferenceFieldContains($field, $value) {
  $node = $this
    ->assertSession()
    ->fieldExists($field);
  $actual = $node
    ->getValue();
  $regex = '/^' . preg_quote($value, '/') . ' \\(.\\d*\\)$/ui';
  $message = sprintf('The field "%s" value is "%s", but "%s" (%s) expected.', $field, $actual, $value, $regex);
  if (preg_match($regex, $actual) !== 1) {
    throw new ExpectationException($message, $this
      ->getSession()
      ->getDriver());
  }
}