public function FeatureContext::openNodeWithTitle in Open Social 8
Same name and namespace in other branches
- 8.2 tests/behat/features/bootstrap/FeatureContext.php \FeatureContext::openNodeWithTitle()
Opens specified node page of type and with title.
@Given /^(?:|I )open the "(?P<type>[^"]+)" node with title "(?P<title>[^"]+)"$/ @When /^(?:|I )go the "(?P<type>[^"]+)" node with title "(?P<title>[^"]+)"$/
File
- tests/
behat/ features/ bootstrap/ FeatureContext.php, line 566
Class
- FeatureContext
- Defines application features from the specific context.
Code
public function openNodeWithTitle($type, $title) {
$query = \Drupal::entityQuery('node')
->condition('type', $type)
->condition('title', $title, '=')
->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
$nids = $query
->execute();
if (!empty($nids) && count($nids) === 1) {
$nid = reset($nids);
$page = '/node/' . $nid;
$this
->visitPath($page);
}
else {
if (count($nids) > 1) {
throw new \Exception(sprintf("Multiple nodes of type '%s' with title '%s' found.", $type, $title));
}
else {
throw new \Exception(sprintf("Node of type '%s' with title '%s' does not exist.", $type, $title));
}
}
}