diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php new file mode 100644 index 0000000..3478cc6 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php @@ -0,0 +1,72 @@ + 'Entity access check test', + 'description' => 'Unit test of entity access checking system.', + 'group' => 'Entity' + ); + } + + /** + * Test the method for determining if the access check applies to a specific + * route or not + */ + 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('_access_entity' => ''))); + $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); + } + + + /** + * Test the method for checking access to routes. + */ + public function testAccess() { + $args = array('/foo', array(), array("_access_entity: 'node.update'")); + $route = $this->getMockBuilder('Symfony\Component\Routing\Route') + ->setConstructorArgs($args) + ->getMock(); + $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') + ->disableOriginalConstructor() + ->getMock(); + $access_check = new EntityAccessCheck(); + $operation = $access_check->access($route, $request); + $this->assertEquals('node.update', $operation); + } +} +