You are here

protected function CommerceAvailabilityExistingRightsTest::createEntity in Commerce License 8.2

Creates and saves a new entity.

Parameters

string $entity_type: The entity type to be created.

array $values: An array of settings. Example: 'id' => 'foo'.

Return value

\Drupal\Core\Entity\EntityInterface A new, saved entity.

1 call to CommerceAvailabilityExistingRightsTest::createEntity()
CommerceAvailabilityExistingRightsTest::setUp in tests/src/Kernel/CommerceAvailabilityExistingRightsTest.php

File

tests/src/Kernel/CommerceAvailabilityExistingRightsTest.php, line 163

Class

CommerceAvailabilityExistingRightsTest
Tests a product is not added to the cart when the user has existing rights.

Namespace

Drupal\Tests\commerce_license\Kernel

Code

protected function createEntity($entity_type, array $values) {

  /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
  $storage = \Drupal::service('entity_type.manager')
    ->getStorage($entity_type);
  $entity = $storage
    ->create($values);
  $status = $entity
    ->save();
  $this
    ->assertEquals(SAVED_NEW, $status, new FormattableMarkup('Created %label entity %type.', [
    '%label' => $entity
      ->getEntityType()
      ->getLabel(),
    '%type' => $entity
      ->id(),
  ]));

  // The newly saved entity isn't identical to a loaded one, and would fail
  // comparisons.
  $entity = $storage
    ->load($entity
    ->id());
  return $entity;
}