You are here

public function EntityUnitTest::testAccess in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testAccess()

@covers ::access

File

core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php, line 195

Class

EntityUnitTest
@coversDefaultClass \Drupal\Core\Entity\EntityBase @group Entity @group Access

Namespace

Drupal\Tests\Core\Entity

Code

public function testAccess() {
  $access = $this
    ->createMock('\\Drupal\\Core\\Entity\\EntityAccessControlHandlerInterface');
  $operation = $this
    ->randomMachineName();
  $access
    ->expects($this
    ->once())
    ->method('access')
    ->with($this->entity, $operation)
    ->will($this
    ->returnValue(AccessResult::allowed()));
  $access
    ->expects($this
    ->once())
    ->method('createAccess')
    ->will($this
    ->returnValue(AccessResult::allowed()));
  $this->entityTypeManager
    ->expects($this
    ->exactly(2))
    ->method('getAccessControlHandler')
    ->will($this
    ->returnValue($access));
  $this
    ->assertEquals(AccessResult::allowed(), $this->entity
    ->access($operation));
  $this
    ->assertEquals(AccessResult::allowed(), $this->entity
    ->access('create'));
}