当前位置: 首页>>代码示例>>PHP>>正文


PHP ControllerResolverInterface::expects方法代码示例

本文整理汇总了PHP中Drupal\Core\Controller\ControllerResolverInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP ControllerResolverInterface::expects方法的具体用法?PHP ControllerResolverInterface::expects怎么用?PHP ControllerResolverInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Controller\ControllerResolverInterface的用法示例。


在下文中一共展示了ControllerResolverInterface::expects方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testRebuildWithProviderBasedRoutes

 /**
  * Tests the rebuild with routes provided by a callback.
  *
  * @see \Drupal\Core\Routing\RouteBuilder::rebuild()
  */
 public function testRebuildWithProviderBasedRoutes()
 {
     $this->lock->expects($this->once())->method('acquire')->with('router_rebuild')->will($this->returnValue(TRUE));
     $this->yamlDiscovery->expects($this->once())->method('findAll')->will($this->returnValue(array('test_module' => array('route_callbacks' => array('\\Drupal\\Tests\\Core\\Routing\\TestRouteSubscriber::routesFromArray', 'test_module.route_service:routesFromCollection')))));
     $container = new ContainerBuilder();
     $container->set('test_module.route_service', new TestRouteSubscriber());
     $this->controllerResolver->expects($this->any())->method('getControllerFromDefinition')->will($this->returnCallback(function ($controller) use($container) {
         $count = substr_count($controller, ':');
         if ($count == 1) {
             list($service, $method) = explode(':', $controller, 2);
             $object = $container->get($service);
         } else {
             list($class, $method) = explode('::', $controller, 2);
             $object = new $class();
         }
         return array($object, $method);
     }));
     $route_collection_filled = new RouteCollection();
     $route_collection_filled->add('test_route.1', new Route('/test-route/1'));
     $route_collection_filled->add('test_route.2', new Route('/test-route/2'));
     $route_build_event = new RouteBuildEvent($route_collection_filled);
     // Ensure that the alter routes events are fired.
     $this->dispatcher->expects($this->at(0))->method('dispatch')->with(RoutingEvents::DYNAMIC, $route_build_event);
     $this->dispatcher->expects($this->at(1))->method('dispatch')->with(RoutingEvents::ALTER, $route_build_event);
     // Ensure that the routes are set to the dumper and dumped.
     $this->dumper->expects($this->at(0))->method('addRoutes')->with($route_collection_filled);
     $this->dumper->expects($this->at(1))->method('dump');
     $this->assertTrue($this->routeBuilder->rebuild());
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:34,代码来源:RouteBuilderTest.php

示例2: testPermissionsYamlStaticAndCallback

 /**
  * Tests a YAML file containing both static permissions and a callback.
  */
 public function testPermissionsYamlStaticAndCallback()
 {
     vfsStreamWrapper::register();
     $root = new vfsStreamDirectory('modules');
     vfsStreamWrapper::setRoot($root);
     $this->moduleHandler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->moduleHandler->expects($this->once())->method('getModuleDirectories')->willReturn(array('module_a' => vfsStream::url('modules/module_a')));
     $url = vfsStream::url('modules');
     mkdir($url . '/module_a');
     file_put_contents($url . '/module_a/module_a.permissions.yml', "'access module a':\n  title: 'Access A'\n  description: 'bla bla'\npermission_callbacks:\n  - 'Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescription'\n");
     $modules = array('module_a');
     $extensions = array('module_a' => $this->mockModuleExtension('module_a', 'Module a'));
     $this->moduleHandler->expects($this->any())->method('getImplementations')->with('permission')->willReturn(array());
     $this->moduleHandler->expects($this->any())->method('getModuleList')->willReturn(array_flip($modules));
     $this->controllerResolver->expects($this->once())->method('getControllerFromDefinition')->with('Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescription')->willReturn(array(new TestPermissionCallbacks(), 'titleDescription'));
     $this->permissionHandler = new TestPermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver);
     // Setup system_rebuild_module_data().
     $this->permissionHandler->setSystemRebuildModuleData($extensions);
     $actual_permissions = $this->permissionHandler->getPermissions();
     $this->assertCount(2, $actual_permissions);
     $this->assertEquals($actual_permissions['access module a']['title'], 'Access A');
     $this->assertEquals($actual_permissions['access module a']['provider'], 'module_a');
     $this->assertEquals($actual_permissions['access module a']['description'], 'bla bla');
     $this->assertEquals($actual_permissions['access module b']['title'], 'Access B');
     $this->assertEquals($actual_permissions['access module b']['provider'], 'module_a');
     $this->assertEquals($actual_permissions['access module b']['description'], 'bla bla');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:30,代码来源:PermissionHandlerTest.php

示例3: testAccess

 /**
  * 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));
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:20,代码来源:CustomAccessCheckTest.php

示例4: testDynamicTitle

 /**
  * Tests a dynamic title.
  *
  * @see \Drupal\Core\Controller\TitleResolver::getTitle()
  */
 public function testDynamicTitle()
 {
     $request = new Request();
     $route = new Route('/test-route', array('_title' => 'static title', '_title_callback' => 'Drupal\\Tests\\Core\\Controller\\TitleCallback::example'));
     $callable = array(new TitleCallback(), 'example');
     $this->controllerResolver->expects($this->once())->method('getControllerFromDefinition')->with('Drupal\\Tests\\Core\\Controller\\TitleCallback::example')->will($this->returnValue($callable));
     $this->controllerResolver->expects($this->once())->method('getArguments')->with($request, $callable)->will($this->returnValue(array('example')));
     $this->assertEquals('test example', $this->titleResolver->getTitle($request, $route));
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:14,代码来源:TitleResolverTest.php

示例5: testAccess

 /**
  * 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));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:26,代码来源:CustomAccessCheckTest.php

示例6: testGetActionsForRoute

 /**
  * @covers \Drupal\Core\Menu\LocalActionManager::getActionsForRoute()
  *
  * @dataProvider getActionsForRouteProvider
  */
 public function testGetActionsForRoute($route_appears, array $plugin_definitions, array $expected_actions)
 {
     $this->discovery->expects($this->any())->method('getDefinitions')->will($this->returnValue($plugin_definitions));
     $map = array();
     foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
         $plugin = $this->getMock('Drupal\\Core\\Menu\\LocalActionInterface');
         $plugin->expects($this->any())->method('getRouteName')->will($this->returnValue($plugin_definition['route_name']));
         $plugin->expects($this->any())->method('getRouteParameters')->will($this->returnValue(isset($plugin_definition['route_parameters']) ? $plugin_definition['route_parameters'] : array()));
         $plugin->expects($this->any())->method('getTitle')->will($this->returnValue($plugin_definition['title']));
         $this->controllerResolver->expects($this->any())->method('getArguments')->with($this->request, array($plugin, 'getTitle'))->will($this->returnValue(array()));
         $plugin->expects($this->any())->method('getWeight')->will($this->returnValue($plugin_definition['weight']));
         $this->controllerResolver->expects($this->any())->method('getArguments')->with($this->request, array($plugin, 'getTitle'))->will($this->returnValue(array()));
         $map[] = array($plugin_id, array(), $plugin);
     }
     $this->factory->expects($this->any())->method('createInstance')->will($this->returnValueMap($map));
     $this->assertEquals($expected_actions, $this->localActionManager->getActionsForRoute($route_appears));
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:22,代码来源:LocalActionManagerTest.php

示例7: setupControllerResolver

 /**
  * Setups the controller resolver to return the given controller definition.
  *
  * @param string $controller_definition
  *   The definition of a controller
  */
 protected function setupControllerResolver($controller_definition)
 {
     $controller = $controller_definition;
     list($class, $method) = explode('::', $controller);
     $this->controllerResolver->expects($this->atLeastOnce())->method('getControllerFromDefinition')->with($controller_definition)->will($this->returnValue(array(new $class(), $method)));
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:12,代码来源:EntityResolverManagerTest.php


注:本文中的Drupal\Core\Controller\ControllerResolverInterface::expects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。