You are here

protected function GroupBehaviorSettingsFormTest::createEntity in Rabbit Hole 2.x

Same name and namespace in other branches
  1. 8 modules/rh_group/tests/src/Functional/GroupBehaviorSettingsFormTest.php \Drupal\Tests\rh_group\Functional\GroupBehaviorSettingsFormTest::createEntity()

Creates new entity.

Parameters

string $action: Rabbit Hole action.

Return value

int ID of the created entity.

Overrides RabbitHoleBehaviorSettingsFormTestBase::createEntity

File

modules/rh_group/tests/src/Functional/GroupBehaviorSettingsFormTest.php, line 80

Class

GroupBehaviorSettingsFormTest
Test the functionality of the rabbit hole form additions to the Group.

Namespace

Drupal\Tests\rh_group\Functional

Code

protected function createEntity($action = NULL) {
  $values = [];
  if (isset($action)) {
    $values['rh_action'] = $action;
  }

  // TODO: Switch to trait when/if the patch is committed and released.
  // See: https://www.drupal.org/project/group/issues/3177542
  $storage = \Drupal::entityTypeManager()
    ->getStorage('group');
  $group = $storage
    ->create($values + [
    'type' => $this->bundle
      ->id(),
    'label' => $this
      ->randomString(),
  ]);
  $group
    ->enforceIsNew();
  $storage
    ->save($group);
  return $group
    ->id();
}