public function ContentEntityBaseUnitTest::testAccess in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest::testAccess()
@covers ::access
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ ContentEntityBaseUnitTest.php, line 426
Class
- ContentEntityBaseUnitTest
- @coversDefaultClass \Drupal\Core\Entity\ContentEntityBase @group Entity @group Access
Namespace
Drupal\Tests\Core\EntityCode
public function testAccess() {
$access = $this
->createMock('\\Drupal\\Core\\Entity\\EntityAccessControlHandlerInterface');
$operation = $this
->randomMachineName();
$access
->expects($this
->exactly(2))
->method('access')
->with($this->entity, $operation)
->willReturnOnConsecutiveCalls(TRUE, AccessResult::allowed());
$access
->expects($this
->exactly(2))
->method('createAccess')
->willReturnOnConsecutiveCalls(TRUE, AccessResult::allowed());
$this->entityTypeManager
->expects($this
->exactly(4))
->method('getAccessControlHandler')
->will($this
->returnValue($access));
$this
->assertTrue($this->entity
->access($operation));
$this
->assertEquals(AccessResult::allowed(), $this->entity
->access($operation, NULL, TRUE));
$this
->assertTrue($this->entity
->access('create'));
$this
->assertEquals(AccessResult::allowed(), $this->entity
->access('create', NULL, TRUE));
}