drupalextension
drupalextension copied to clipboard
Given :name create(s) a/an :type (content ) with the title :title
The lovely new UserManager service enables the following step. Is it worth including in DrupalContext?
/**
* Creates content of the given type.
*
* @Given :name create(s) a/an :type (content ) with the title :title
* @Given I am viewing a/an :type (content )(created )by :name with the title :title
* @Given a/an :type (content )(created )by :name with the title :title
*/
public function userCreatesNode($type, $title, $name) {
if ($name === 'me' || $name === 'I') {
$uid = $this->getUserManager()->getCurrentUser()->uid;
}
else {
$uid = $this->getUserManager()->getUser($name)->uid;
}
$node = (object) array(
'title' => $title,
'type' => $type,
'uid' => $uid,
);
$saved = $this->nodeCreate($node);
// Set internal page on the new node.
$this->getSession()->visit($this->locatePath('/node/' . $saved->nid));
}
I haven't tried, but I think this could be combined with the existing createNode step definition, so it doesn't bloat the number of step definitions being maintained.
Makes sense to me!