You are here

public function SocialDrupalContext::createTopics in Open Social 10.2.x

Same name and namespace in other branches
  1. 10.3.x tests/behat/features/bootstrap/SocialDrupalContext.php \Drupal\social\Behat\SocialDrupalContext::createTopics()
  2. 10.0.x tests/behat/features/bootstrap/SocialDrupalContext.php \Drupal\social\Behat\SocialDrupalContext::createTopics()
  3. 10.1.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\Behat

Code

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);
  }
}