function EntityUnitTest::testAccess

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testAccess()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testAccess()
  3. 11.x 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)
        ->willReturn(AccessResult::allowed());
    $access->expects($this->once())
        ->method('createAccess')
        ->willReturn(AccessResult::allowed());
    $this->entityTypeManager
        ->expects($this->exactly(2))
        ->method('getAccessControlHandler')
        ->willReturn($access);
    $this->assertEquals(AccessResult::allowed(), $this->entity
        ->access($operation));
    $this->assertEquals(AccessResult::allowed(), $this->entity
        ->access('create'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.