/** * Test the access method. */ public function testAccess() { $request = new Request(array()); $this->controllerResolver->expects($this->at(0))->method('getControllerFromDefinition')->with('\\Drupal\\Tests\\Core\\Access\\TestController::accessDeny')->will($this->returnValue(array(new TestController(), 'accessDeny'))); $this->argumentsResolver->expects($this->at(0))->method('getArguments')->will($this->returnValue(array())); $this->controllerResolver->expects($this->at(1))->method('getControllerFromDefinition')->with('\\Drupal\\Tests\\Core\\Access\\TestController::accessAllow')->will($this->returnValue(array(new TestController(), 'accessAllow'))); $this->argumentsResolver->expects($this->at(1))->method('getArguments')->will($this->returnValue(array())); $this->controllerResolver->expects($this->at(2))->method('getControllerFromDefinition')->with('\\Drupal\\Tests\\Core\\Access\\TestController::accessParameter')->will($this->returnValue(array(new TestController(), 'accessParameter'))); $this->argumentsResolver->expects($this->at(2))->method('getArguments')->will($this->returnValue(array('parameter' => 'TRUE'))); $route = new Route('/test-route', array(), array('_custom_access' => '\\Drupal\\Tests\\Core\\Access\\TestController::accessDeny')); $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface'); $this->assertSame(AccessInterface::DENY, $this->accessChecker->access($route, $request, $account)); $route = new Route('/test-route', array(), array('_custom_access' => '\\Drupal\\Tests\\Core\\Access\\TestController::accessAllow')); $this->assertSame(AccessInterface::ALLOW, $this->accessChecker->access($route, $request, $account)); $route = new Route('/test-route', array('parameter' => 'TRUE'), array('_custom_access' => '\\Drupal\\Tests\\Core\\Access\\TestController::accessParameter')); $this->assertSame(AccessInterface::ALLOW, $this->accessChecker->access($route, $request, $account)); }
/** * Test the access method. */ public function testAccess() { $route_match = $this->getMock('Drupal\\Core\\Routing\\RouteMatchInterface'); $this->controllerResolver->expects($this->at(0))->method('getControllerFromDefinition')->with('\\Drupal\\Tests\\Core\\Access\\TestController::accessDeny')->will($this->returnValue(array(new TestController(), 'accessDeny'))); $resolver0 = $this->getMock('Drupal\\Component\\Utility\\ArgumentsResolverInterface'); $resolver0->expects($this->once())->method('getArguments')->will($this->returnValue(array())); $this->argumentsResolverFactory->expects($this->at(0))->method('getArgumentsResolver')->will($this->returnValue($resolver0)); $this->controllerResolver->expects($this->at(1))->method('getControllerFromDefinition')->with('\\Drupal\\Tests\\Core\\Access\\TestController::accessAllow')->will($this->returnValue(array(new TestController(), 'accessAllow'))); $resolver1 = $this->getMock('Drupal\\Component\\Utility\\ArgumentsResolverInterface'); $resolver1->expects($this->once())->method('getArguments')->will($this->returnValue(array())); $this->argumentsResolverFactory->expects($this->at(1))->method('getArgumentsResolver')->will($this->returnValue($resolver1)); $this->controllerResolver->expects($this->at(2))->method('getControllerFromDefinition')->with('\\Drupal\\Tests\\Core\\Access\\TestController::accessParameter')->will($this->returnValue(array(new TestController(), 'accessParameter'))); $resolver2 = $this->getMock('Drupal\\Component\\Utility\\ArgumentsResolverInterface'); $resolver2->expects($this->once())->method('getArguments')->will($this->returnValue(array('parameter' => 'TRUE'))); $this->argumentsResolverFactory->expects($this->at(2))->method('getArgumentsResolver')->will($this->returnValue($resolver2)); $route = new Route('/test-route', array(), array('_custom_access' => '\\Drupal\\Tests\\Core\\Access\\TestController::accessDeny')); $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface'); $this->assertEquals(AccessResult::neutral(), $this->accessChecker->access($route, $route_match, $account)); $route = new Route('/test-route', array(), array('_custom_access' => '\\Drupal\\Tests\\Core\\Access\\TestController::accessAllow')); $this->assertEquals(AccessResult::allowed(), $this->accessChecker->access($route, $route_match, $account)); $route = new Route('/test-route', array('parameter' => 'TRUE'), array('_custom_access' => '\\Drupal\\Tests\\Core\\Access\\TestController::accessParameter')); $this->assertEquals(AccessResult::allowed(), $this->accessChecker->access($route, $route_match, $account)); }