You are here

protected function UncacheableEntityAccessControlHandlerTest::buildMockEntity in Entity API 8

Builds a mock entity.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.

string $owner_id: The owner ID.

string $bundle: The bundle.

bool $published: Whether the entity is published.

Return value

\Prophecy\Prophecy\ObjectProphecy The entity mock.

1 call to UncacheableEntityAccessControlHandlerTest::buildMockEntity()
UncacheableEntityAccessControlHandlerTest::accessProvider in tests/src/Unit/UncacheableEntityAccessControlHandlerTest.php
Data provider for testAccess().

File

tests/src/Unit/UncacheableEntityAccessControlHandlerTest.php, line 203

Class

UncacheableEntityAccessControlHandlerTest
@coversDefaultClass \Drupal\entity\UncacheableEntityAccessControlHandler @group entity

Namespace

Drupal\Tests\entity\Unit

Code

protected function buildMockEntity(EntityTypeInterface $entity_type, $owner_id = NULL, $bundle = NULL, $published = NULL) {
  $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED;
  $entity = $this
    ->prophesize(ContentEntityInterface::class);
  if (isset($published)) {
    $entity
      ->willImplement(EntityPublishedInterface::class);
  }
  if ($owner_id) {
    $entity
      ->willImplement(EntityOwnerInterface::class);
  }
  if (isset($published)) {
    $entity
      ->isPublished()
      ->willReturn($published);
  }
  if ($owner_id) {
    $entity
      ->getOwnerId()
      ->willReturn($owner_id);
  }
  $entity
    ->bundle()
    ->willReturn($bundle ?: $entity_type
    ->id());
  $entity
    ->isNew()
    ->willReturn(FALSE);
  $entity
    ->uuid()
    ->willReturn('fake uuid');
  $entity
    ->id()
    ->willReturn('fake id');
  $entity
    ->getRevisionId()
    ->willReturn(NULL);
  $entity
    ->language()
    ->willReturn(new Language([
    'id' => $langcode,
  ]));
  $entity
    ->getEntityTypeId()
    ->willReturn($entity_type
    ->id());
  $entity
    ->getEntityType()
    ->willReturn($entity_type);
  $entity
    ->getCacheContexts()
    ->willReturn([]);
  $entity
    ->getCacheTags()
    ->willReturn([]);
  $entity
    ->getCacheMaxAge()
    ->willReturn(Cache::PERMANENT);
  return $entity;
}