You are here

protected function GroupBehaviorInvocationTest::createEntity in Rabbit Hole 8

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

Creates new entity.

Parameters

string $action: Rabbit Hole action.

Return value

\Drupal\Core\Entity\EntityInterface Created entity.

Overrides RabbitHoleBehaviorInvocationTestBase::createEntity

File

modules/rh_group/tests/src/Functional/GroupBehaviorInvocationTest.php, line 58

Class

GroupBehaviorInvocationTest
Test that rabbit hole behaviors are invoked correctly for groups.

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->groupType
      ->id(),
    'label' => $this
      ->randomString(),
  ]);
  $group
    ->enforceIsNew();
  $storage
    ->save($group);
  return $group;
}