function ContentEntityBaseUnitTest::testAccess

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest::testAccess()
  2. 10 core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest::testAccess()
  3. 11.x 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 449

Class

ContentEntityBaseUnitTest
@coversDefaultClass \Drupal\Core\Entity\ContentEntityBase @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->at(0))
        ->method('access')
        ->with($this->entity, $operation)
        ->will($this->returnValue(TRUE));
    $access->expects($this->at(1))
        ->method('access')
        ->with($this->entity, $operation)
        ->will($this->returnValue(AccessResult::allowed()));
    $access->expects($this->at(2))
        ->method('createAccess')
        ->will($this->returnValue(TRUE));
    $access->expects($this->at(3))
        ->method('createAccess')
        ->will($this->returnValue(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));
}

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