class EntityAccessCheckTest

Tests the entity access controller.

@group Entity

Hierarchy

Expanded class hierarchy of EntityAccessCheckTest

File

drupal/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php, line 20
Contains \Drupal\Tests\Core\Entity\EntityAccessCheckTest.

Namespace

Drupal\Tests\Core\Entity
View source
class EntityAccessCheckTest extends UnitTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Entity access check test',
      'description' => 'Unit test of entity access checking system.',
      'group' => 'Entity',
    );
  }

  /**
   * Tests the method for checking if the access check applies to a route.
   */
  public function testApplies() {
    $applies_check = new EntityAccessCheck();
    $route = $this
      ->getMockBuilder('Symfony\\Component\\Routing\\Route')
      ->disableOriginalConstructor()
      ->getMock();
    $route
      ->expects($this
      ->any())
      ->method('getRequirements')
      ->will($this
      ->returnValue(array(
      '_entity_access' => '',
    )));
    $res = $applies_check
      ->applies($route);
    $this
      ->assertEquals(TRUE, $res);
    $route = $this
      ->getMockBuilder('Symfony\\Component\\Routing\\Route')
      ->disableOriginalConstructor()
      ->getMock();
    $route
      ->expects($this
      ->any())
      ->method('getRequirements')
      ->will($this
      ->returnValue(array()));
    $res = $applies_check
      ->applies($route);
    $this
      ->assertEquals(FALSE, $res);
  }

  /**
   * Tests the method for checking access to routes.
   */
  public function testAccess() {
    $route = new Route('/foo', array(), array(
      '_entity_access' => 'node.update',
    ));
    $request = new Request();
    $node = $this
      ->getMockBuilder('Drupal\\node\\Plugin\\Core\\Entity\\Node')
      ->disableOriginalConstructor()
      ->getMock();
    $node
      ->expects($this
      ->any())
      ->method('access')
      ->will($this
      ->returnValue(TRUE));
    $access_check = new EntityAccessCheck();
    $request->attributes
      ->set('node', $node);
    $access = $access_check
      ->access($route, $request);
    $this
      ->assertEquals(TRUE, $access);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityAccessCheckTest::getInfo public static function This method exists to support the simpletest UI runner. Overrides UnitTestCase::getInfo
EntityAccessCheckTest::testAccess public function Tests the method for checking access to routes.
EntityAccessCheckTest::testApplies public function Tests the method for checking if the access check applies to a route.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::randomName public static function Generates a random string containing letters and numbers.