本文整理汇总了PHP中Drupal\Core\Routing\RouteProviderInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP RouteProviderInterface::expects方法的具体用法?PHP RouteProviderInterface::expects怎么用?PHP RouteProviderInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Routing\RouteProviderInterface
的用法示例。
在下文中一共展示了RouteProviderInterface::expects方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->entityManager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$this->entity = $this->getMock('Drupal\\Core\\Entity\\EntityInterface');
$this->routeProvider = $this->getMock('Drupal\\Core\\Routing\\RouteProviderInterface');
$this->routeProvider->expects($this->any())->method('getRouteByName')->with('entity.language_entity.edit_form')->will($this->returnValue(new Route('/admin/config/regional/language/edit/{language_entity}')));
$definition = array('class' => '\\Drupal\\config_translation\\ConfigEntityMapper', 'base_route_name' => 'entity.language_entity.edit_form', 'title' => '!label language', 'names' => array(), 'entity_type' => 'language_entity', 'route_name' => 'config_translation.item.overview.entity.language_entity.edit_form');
$typed_config_manager = $this->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface');
$locale_config_manager = $this->getMockBuilder('Drupal\\locale\\LocaleConfigManager')->disableOriginalConstructor()->getMock();
$this->configEntityMapper = new ConfigEntityMapper('language_entity', $definition, $this->getConfigFactoryStub(), $typed_config_manager, $locale_config_manager, $this->getMock('Drupal\\config_translation\\ConfigMapperManagerInterface'), $this->routeProvider, $this->getStringTranslationStub(), $this->entityManager);
}
示例2: setUp
public function setUp()
{
$this->routeProvider = $this->getMock('Drupal\\Core\\Routing\\RouteProviderInterface');
$this->pluginDefinition = array('class' => '\\Drupal\\config_translation\\ConfigNamesMapper', 'base_route_name' => 'system.site_information_settings', 'title' => 'System information', 'names' => array('system.site'), 'weight' => 42);
$this->typedConfigManager = $this->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface');
$this->localeConfigManager = $this->getMockBuilder('Drupal\\locale\\LocaleConfigManager')->disableOriginalConstructor()->getMock();
$this->configMapperManager = $this->getMock('Drupal\\config_translation\\ConfigMapperManagerInterface');
$this->baseRoute = new Route('/admin/config/system/site-information');
$this->routeProvider->expects($this->any())->method('getRouteByName')->with('system.site_information_settings')->will($this->returnValue($this->baseRoute));
$this->configNamesMapper = new TestConfigNamesMapper('system.site_information_settings', $this->pluginDefinition, $this->getConfigFactoryStub(), $this->typedConfigManager, $this->localeConfigManager, $this->configMapperManager, $this->routeProvider, $this->getStringTranslationStub());
}
示例3: testGetRouteParametersForDynamicRouteWithUpcastedParameters
/**
* Tests the getRouteParameters method for a route with upcasted parameters.
*
* @covers ::getRouteParameters
*/
public function testGetRouteParametersForDynamicRouteWithUpcastedParameters()
{
$this->pluginDefinition = array('route_name' => 'test_route');
$route = new Route('/test-route/{parameter}');
$this->routeProvider->expects($this->once())->method('getRouteByName')->with('test_route')->will($this->returnValue($route));
$this->setupLocalTaskDefault();
$route_match = new RouteMatch('', $route, array('parameter' => (object) 'example2'), array('parameter' => 'example'));
$this->assertEquals(array('parameter' => 'example'), $this->localTaskBase->getRouteParameters($route_match));
}
示例4: testOnRequestOnHtml
/**
* Tests onRequest on a html request.
*/
public function testOnRequestOnHtml()
{
$event = $this->getMockBuilder('\\Symfony\\Component\\HttpKernel\\Event\\KernelEvent')->disableOriginalConstructor()->getMock();
$request = new Request();
$request->setRequestFormat('html');
$event->expects($this->any())->method('getRequest')->will($this->returnValue($request));
$this->routeProvider->expects($this->once())->method('preLoadRoutes')->with(['test2']);
$this->state->expects($this->once())->method('get')->with('routing.non_admin_routes')->will($this->returnValue(array('test2')));
$this->preloader->onRequest($event);
}
示例5: testGetRouteParametersForDynamicRouteWithUpcastedParameters
/**
* Tests the getRouteParameters method for a route with upcasted parameters.
*
* @see \Drupal\Core\Menu\LocalTaskDefault::getRouteParameters()
*/
public function testGetRouteParametersForDynamicRouteWithUpcastedParameters()
{
$this->pluginDefinition = array('route_name' => 'test_route');
$this->routeProvider->expects($this->once())->method('getRouteByName')->with('test_route')->will($this->returnValue(new Route('/test-route/{parameter}')));
$this->setupLocalTaskDefault();
$request = new Request();
$raw_variables = new ParameterBag();
$raw_variables->set('parameter', 'example');
$request->attributes->set('parameter', (object) array('example2'));
$request->attributes->set('_raw_variables', $raw_variables);
$this->assertEquals(array('parameter' => 'example'), $this->localTaskBase->getRouteParameters($request));
}
示例6: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$cache_contexts_manager = $this->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')->disableOriginalConstructor()->getMock();
$cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE);
$container = new ContainerBuilder();
$container->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($container);
$routes = new RouteCollection();
$first_route = new Route('/test/one');
$second_route = new Route('/test/two/{narf}');
$third_route = new Route('/test/two/');
$fourth_route = new Route('/test/four', [], [], [], '', ['https']);
$none_route = new Route('', [], [], ['_no_path' => TRUE]);
$routes->add('test_1', $first_route);
$routes->add('test_2', $second_route);
$routes->add('test_3', $third_route);
$routes->add('test_4', $fourth_route);
$routes->add('<none>', $none_route);
// Create a route provider stub.
$provider = $this->getMockBuilder('Drupal\\Core\\Routing\\RouteProvider')->disableOriginalConstructor()->getMock();
// We need to set up return value maps for both the getRouteByName() and the
// getRoutesByNames() method calls on the route provider. The parameters
// are not passed in and default to an empty array.
$route_name_return_map = $routes_names_return_map = array();
$return_map_values = array(['route_name' => 'test_1', 'return' => $first_route], ['route_name' => 'test_2', 'return' => $second_route], ['route_name' => 'test_3', 'return' => $third_route], ['route_name' => 'test_4', 'return' => $fourth_route], ['route_name' => '<none>', 'return' => $none_route]);
foreach ($return_map_values as $values) {
$route_name_return_map[] = array($values['route_name'], $values['return']);
$routes_names_return_map[] = array(array($values['route_name']), $values['return']);
}
$this->provider = $provider;
$this->provider->expects($this->any())->method('getRouteByName')->will($this->returnValueMap($route_name_return_map));
$provider->expects($this->any())->method('getRoutesByNames')->will($this->returnValueMap($routes_names_return_map));
// Create an alias manager stub.
$alias_manager = $this->getMockBuilder('Drupal\\Core\\Path\\AliasManager')->disableOriginalConstructor()->getMock();
$alias_manager->expects($this->any())->method('getAliasByPath')->will($this->returnCallback(array($this, 'aliasManagerCallback')));
$this->aliasManager = $alias_manager;
$this->requestStack = new RequestStack();
$request = Request::create('/some/path');
$this->requestStack->push($request);
$this->context = new RequestContext();
$this->context->fromRequestStack($this->requestStack);
$processor = new PathProcessorAlias($this->aliasManager);
$processor_manager = new PathProcessorManager();
$processor_manager->addOutbound($processor, 1000);
$this->routeProcessorManager = $this->getMockBuilder('Drupal\\Core\\RouteProcessor\\RouteProcessorManager')->disableOriginalConstructor()->getMock();
$generator = new UrlGenerator($this->provider, $processor_manager, $this->routeProcessorManager, $this->requestStack, ['http', 'https']);
$generator->setContext($this->context);
$this->generator = $generator;
}
示例7: testGetDerivativeDefinitionsWithExistingLocalTask
/**
* Tests fetching the derivatives on a view with a local task and a parent.
*
* The parent is defined by another module, not views.
*/
public function testGetDerivativeDefinitionsWithExistingLocalTask()
{
$executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->getMock();
$storage = $this->getMockBuilder('Drupal\\views\\Entity\\View')->disableOriginalConstructor()->getMock();
$storage->expects($this->any())->method('id')->will($this->returnValue('example_view'));
$storage->expects($this->any())->method('getExecutable')->willReturn($executable);
$executable->storage = $storage;
$this->viewStorage->expects($this->any())->method('load')->with('example_view')->willReturn($storage);
$display_plugin = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\PathPluginBase')->setMethods(array('getOption', 'getPath'))->disableOriginalConstructor()->getMockForAbstractClass();
$display_plugin->expects($this->exactly(2))->method('getOption')->with('menu')->will($this->returnValue(array('type' => 'tab', 'weight' => 12, 'title' => 'Example title')));
$display_plugin->expects($this->once())->method('getPath')->will($this->returnValue('path/example'));
$executable->display_handler = $display_plugin;
$result = [['example_view', 'page_1']];
$this->localTaskDerivative->setApplicableMenuViews($result);
// Mock the view route names state.
$view_route_names = array();
$view_route_names['example_view.page_1'] = 'view.example_view.page_1';
$this->state->expects($this->exactly(2))->method('get')->with('views.view_route_names')->will($this->returnValue($view_route_names));
// Mock the route provider.
$route_collection = new RouteCollection();
$route_collection->add('test_route', new Route('/path'));
$this->routeProvider->expects($this->any())->method('getRoutesByPattern')->with('/path')->will($this->returnValue($route_collection));
// Setup the existing local task of the test_route.
$definitions['test_route_tab'] = $other_tab = array('route_name' => 'test_route', 'title' => 'Test route', 'base_route' => 'test_route');
$definitions += $this->localTaskDerivative->getDerivativeDefinitions($this->baseDefinition);
// Setup the prefix of the derivative.
$definitions['views_view:view.example_view.page_1'] = $definitions['view.example_view.page_1'];
unset($definitions['view.example_view.page_1']);
$this->localTaskDerivative->alterLocalTasks($definitions);
$plugin = $definitions['views_view:view.example_view.page_1'];
$this->assertCount(2, $definitions);
// Ensure the other local task was not changed.
$this->assertEquals($other_tab, $definitions['test_route_tab']);
$this->assertEquals('view.example_view.page_1', $plugin['route_name']);
$this->assertEquals(12, $plugin['weight']);
$this->assertEquals('Example title', $plugin['title']);
$this->assertEquals($this->baseDefinition['class'], $plugin['class']);
$this->assertEquals('test_route', $plugin['base_route']);
}
示例8: testGetUrlWithPlaceholdersAndWithoutArgsAndExceptionValue
/**
* @covers ::getUrl
*/
public function testGetUrlWithPlaceholdersAndWithoutArgsAndExceptionValue()
{
$this->displayHandler->expects($this->any())->method('getRoutedDisplay')->willReturn($this->displayHandler);
$this->displayHandlers->expects($this->any())->method('get')->willReturn($this->displayHandler);
$this->displayHandler->expects($this->any())->method('getUrlInfo')->willReturn(Url::fromRoute('views.test.page_1'));
$this->displayHandler->expects($this->any())->method('getPath')->willReturn('test-path/%/%');
$route = new Route('/test-path/{arg_0}/{arg_1}');
$this->routeProvider->expects($this->any())->method('getRouteByName')->with('views.test.page_1')->willReturn($route);
$argument_handler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\argument\\ArgumentPluginBase')->disableOriginalConstructor()->getMock();
$argument_handler->options['exception']['value'] = 'exception_0';
$this->executable->argument['key_1'] = $argument_handler;
$argument_handler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\argument\\ArgumentPluginBase')->disableOriginalConstructor()->getMock();
$argument_handler->options['exception']['value'] = 'exception_1';
$this->executable->argument['key_2'] = $argument_handler;
$this->assertEquals(Url::fromRoute('views.test.page_1', ['arg_0' => 'exception_0', 'arg_1' => 'exception_1']), $this->executable->getUrl());
}