protected function EntityAccessControlHandlerTest::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 EntityAccessControlHandlerTest::buildMockEntity()
- EntityAccessControlHandlerTest::accessProvider in tests/
src/ Unit/ EntityAccessControlHandlerTest.php - Data provider for testAccess().
File
- tests/
src/ Unit/ EntityAccessControlHandlerTest.php, line 201
Class
- EntityAccessControlHandlerTest
- @coversDefaultClass \Drupal\entity\EntityAccessControlHandler @group entity
Namespace
Drupal\Tests\entity\UnitCode
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;
}