You are here

protected function EntityReferenceFieldTest::assertUserRoleAutocreate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityReferenceFieldTest.php \Drupal\system\Tests\Entity\EntityReferenceFieldTest::assertUserRoleAutocreate()

Asserts that the setter callback performs autocreation for user roles.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The referencing entity.

$setter_callback: A callback setting the target entity on the referencing entity.

Return value

bool TRUE if the user was autocreated, FALSE otherwise.

1 call to EntityReferenceFieldTest::assertUserRoleAutocreate()
EntityReferenceFieldTest::testAutocreateApi in core/modules/system/src/Tests/Entity/EntityReferenceFieldTest.php
Tests all the possible ways to autocreate an entity via the API.

File

core/modules/system/src/Tests/Entity/EntityReferenceFieldTest.php, line 347
Contains \Drupal\system\Tests\Entity\EntityReferenceFieldTest.

Class

EntityReferenceFieldTest
Tests for the entity reference field.

Namespace

Drupal\system\Tests\Entity

Code

protected function assertUserRoleAutocreate(EntityInterface $entity, $setter_callback) {
  $storage = $this->entityManager
    ->getStorage('user_role');
  $role_id = $this
    ->generateRandomEntityId(TRUE);
  $role = $storage
    ->create(array(
    'id' => $role_id,
    'label' => $this
      ->randomString(),
  ));
  $setter_callback($entity, $role);
  $entity
    ->save();
  $storage
    ->resetCache();
  $role = Role::load($role_id);
  return $this
    ->assertEqual($entity->user_role->target_id, $role
    ->id());
}