/** * Tests the page controller with arguments of a overridden page view. * * This test care about upcasted values and ensures that the raw variables * are pulled in. */ public function testHandleWithArgumentsOnOverriddenRouteWithUpcasting() { $view = $this->getMock('Drupal\\views\\ViewEntityInterface'); $this->storage->expects($this->once())->method('load')->with('test_page_view')->will($this->returnValue($view)); $executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->getMock(); $executable->expects($this->once())->method('setDisplay')->with('page_1'); $executable->expects($this->once())->method('initHandlers'); $views_display = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')->disableOriginalConstructor()->getMock(); $views_display->expects($this->any())->method('getDefinition')->willReturn([]); $executable->display_handler = $views_display; // Manually setup a argument handler. $argument = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\argument\\ArgumentPluginBase')->disableOriginalConstructor()->getMock(); $executable->argument['test_id'] = $argument; $executable->expects($this->once())->method('buildRenderable')->with('page_1', array('example_id')); $this->executableFactory->expects($this->any())->method('get')->with($view)->will($this->returnValue($executable)); $request = new Request(); $request->attributes->set('view_id', 'test_page_view'); $request->attributes->set('display_id', 'page_1'); // Add the argument to the request. $request->attributes->set('test_entity', $this->getMock('Drupal\\Core\\Entity\\EntityInterface')); $raw_variables = new ParameterBag(array('test_entity' => 'example_id')); $request->attributes->set('_raw_variables', $raw_variables); $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/test/{test_entity}', ['view_id' => 'test_page_view', 'display_id' => 'default'], [], ['_view_argument_map' => ['arg_0' => 'test_entity']])); $route_match = RouteMatch::createFromRequest($request); $this->pageController->handle($route_match->getParameter('view_id'), $route_match->getParameter('display_id'), $request, $route_match); }
/** * Tests the page controller with arguments of a overridden page view. * * This test care about upcasted values and ensures that the raw variables * are pulled in. */ public function testHandleWithArgumentsOnOverriddenRouteWithUpcasting() { $this->storage->expects($this->never())->method('load'); $request = new Request(); $request->attributes->set('view_id', 'test_page_view'); $request->attributes->set('display_id', 'page_1'); // Add the argument to the request. $request->attributes->set('test_entity', $this->getMock('Drupal\\Core\\Entity\\EntityInterface')); $raw_variables = new ParameterBag(array('test_entity' => 'example_id')); $request->attributes->set('_raw_variables', $raw_variables); $options = ['_view_argument_map' => ['arg_0' => 'test_entity'], '_view_display_plugin_class' => '\\Drupal\\views\\Plugin\\views\\display\\Page']; $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/test/{test_entity}', ['view_id' => 'test_page_view', 'display_id' => 'default'], [], $options)); $route_match = RouteMatch::createFromRequest($request); $result = $this->pageController->handle($route_match->getParameter('view_id'), $route_match->getParameter('display_id'), $route_match); $build = ['#type' => 'view', '#name' => 'test_page_view', '#display_id' => 'page_1', '#embed' => FALSE, '#arguments' => ['example_id'], '#cache' => ['keys' => ['view', 'test_page_view', 'display', 'page_1', 'args', 'example_id']]] + $this->defaultRenderArray; $this->assertEquals($build, $result); }
/** * Sets up mocks of Views objects needed for testing. * * @return array * An array of Views mocks, including the executable, the view entity, and * two display plugins. */ protected function setupMocks() { $executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->getMock(); $view = $this->getMockBuilder('Drupal\\views\\Entity\\View')->disableOriginalConstructor()->getMock(); $this->viewStorage->expects($this->any())->method('load')->will($this->returnValue($view)); $view->expects($this->any())->method('getExecutable')->will($this->returnValue($executable)); $view->expects($this->any())->method('id')->will($this->returnValue('test_id')); $executable->storage = $view; $executable->expects($this->any())->method('setDisplay')->will($this->returnValueMap(array(array('page_1', TRUE), array('page_2', TRUE), array('page_3', FALSE)))); // Ensure that only the first two displays are actually called. $display_1 = $this->getMock('Drupal\\views\\Plugin\\views\\display\\DisplayRouterInterface'); $display_2 = $this->getMock('Drupal\\views\\Plugin\\views\\display\\DisplayRouterInterface'); $display_collection = $this->getMockBuilder('Drupal\\views\\DisplayPluginCollection')->disableOriginalConstructor()->getMock(); $display_collection->expects($this->any())->method('get')->will($this->returnValueMap(array(array('page_1', $display_1), array('page_2', $display_2)))); $executable->displayHandlers = $display_collection; $this->routeSubscriber->applicableViews = array(); $this->routeSubscriber->applicableViews[] = array($executable, 'page_1'); $this->routeSubscriber->applicableViews[] = array($executable, 'page_2'); $this->routeSubscriber->applicableViews[] = array($executable, 'page_3'); return array($executable, $view, $display_1, $display_2); }
/** * Tests the page controller with arguments of a overridden page view. * * This test care about upcasted values and ensures that the raw variables * are pulled in. */ public function testHandleWithArgumentsOnOveriddenRouteWithUpcasting() { $view = $this->getMock('Drupal\\views\\ViewStorageInterface'); $this->storage->expects($this->once())->method('load')->with('test_page_view')->will($this->returnValue($view)); $executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->getMock(); $executable->expects($this->once())->method('setDisplay')->with('page_1'); $executable->expects($this->once())->method('initHandlers'); // Manually setup a argument handler. $argument = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\argument\\ArgumentPluginBase')->disableOriginalConstructor()->getMock(); $executable->argument['test_id'] = $argument; $executable->expects($this->once())->method('executeDisplay')->with('page_1', array('example_id')); $this->executableFactory->expects($this->any())->method('get')->with($view)->will($this->returnValue($executable)); $request = new Request(); $request->attributes->set('view_id', 'test_page_view'); $request->attributes->set('display_id', 'page_1'); // Add the argument to the request. $request->attributes->set('test_entity', $this->getMock('Drupal\\Core\\Entity\\EntityInterface')); $raw_variables = new ParameterBag(array('test_entity' => 'example_id')); $request->attributes->set('_raw_variables', $raw_variables); $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('', array(), array(), array('_view_argument_map' => array('arg_0' => 'test_entity')))); $this->pageController->handle($request); }