public function SocialDrupalContext::createTopics in Open Social 10.1.x
Same name and namespace in other branches
- 10.3.x tests/behat/features/bootstrap/SocialDrupalContext.php \Drupal\social\Behat\SocialDrupalContext::createTopics()
- 10.0.x tests/behat/features/bootstrap/SocialDrupalContext.php \Drupal\social\Behat\SocialDrupalContext::createTopics()
- 10.2.x tests/behat/features/bootstrap/SocialDrupalContext.php \Drupal\social\Behat\SocialDrupalContext::createTopics()
Creates topics.
@Given :count topics with title :title by :username
File
- tests/
behat/ features/ bootstrap/ SocialDrupalContext.php, line 162
Class
- SocialDrupalContext
- Provides pre-built step definitions for interacting with Open Social.
Namespace
Drupal\social\BehatCode
public function createTopics($count, $title, $username) {
/** @var \Drupal\user\UserInterface[] $accounts */
$accounts = \Drupal::entityTypeManager()
->getStorage('user')
->loadByProperties([
'name' => $username,
]);
if (!$accounts) {
return;
}
$account = reset($accounts);
for ($index = 1; $index <= $count; $index++) {
$node = (object) [
'type' => 'topic',
'title' => str_replace('[id]', $index, $title),
'uid' => $account
->id(),
];
$this
->nodeCreate($node);
}
}