/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // TODO: Change the autogenerated stub $condition_plugin_manager = $this->getMock('Drupal\\Core\\Executable\\ExecutableManagerInterface'); $condition_plugin_manager->expects($this->any())->method('getDefinitions')->will($this->returnValue(array())); $container = new ContainerBuilder(); $container->set('plugin.manager.condition', $condition_plugin_manager); \Drupal::setContainer($container); $this->executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->setMethods(['buildRenderable', 'setDisplay', 'setItemsPerPage'])->getMock(); $this->executable->expects($this->any())->method('setDisplay')->with('block_1')->will($this->returnValue(TRUE)); $this->executable->expects($this->any())->method('getShowAdminLinks')->willReturn(FALSE); $this->executable->display_handler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\Block')->disableOriginalConstructor()->setMethods(NULL)->getMock(); $this->view = $this->getMockBuilder('Drupal\\views\\Entity\\View')->disableOriginalConstructor()->getMock(); $this->view->expects($this->any())->method('id')->willReturn('test_view'); $this->executable->storage = $this->view; $this->executableFactory = $this->getMockBuilder('Drupal\\views\\ViewExecutableFactory')->disableOriginalConstructor()->getMock(); $this->executableFactory->expects($this->any())->method('get')->with($this->view)->will($this->returnValue($this->executable)); $this->displayHandler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\Block')->disableOriginalConstructor()->getMock(); $this->displayHandler->expects($this->any())->method('blockSettings')->willReturn([]); $this->displayHandler->expects($this->any())->method('getPluginId')->willReturn('block'); $this->executable->display_handler = $this->displayHandler; $this->storage = $this->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->disableOriginalConstructor()->getMock(); $this->storage->expects($this->any())->method('load')->with('test_view')->will($this->returnValue($this->view)); $this->account = $this->getMock('Drupal\\Core\\Session\\AccountInterface'); }
/** * 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); }
/** * Sets up a bunch of valid mocks like the view entity and executable. */ protected function setupValidMocks() { $view = $this->getMockBuilder('Drupal\\views\\Entity\\View')->disableOriginalConstructor()->getMock(); $this->viewStorage->expects($this->once())->method('load')->with('test_view')->will($this->returnValue($view)); $executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->getMock(); $executable->expects($this->once())->method('access')->will($this->returnValue(TRUE)); $executable->expects($this->once())->method('preview')->will($this->returnValue(array('#markup' => 'View result'))); $this->executableFactory->expects($this->once())->method('get')->with($view)->will($this->returnValue($executable)); return array($view, $executable); }
/** * @covers ::attachDisplays */ public function testAttachDisplays() { /** @var \Drupal\views\ViewExecutable|\PHPUnit_Framework_MockObject_MockObject $view */ /** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit_Framework_MockObject_MockObject $display */ list($view, $display) = $this->setupBaseViewAndDisplay(); $display->expects($this->atLeastOnce())->method('acceptAttachments')->willReturn(TRUE); $display->expects($this->atLeastOnce())->method('getAttachedDisplays')->willReturn(['page_1']); $cloned_view = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->getMock(); $this->viewExecutableFactory->expects($this->atLeastOnce())->method('get')->willReturn($cloned_view); $page_display = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')->disableOriginalConstructor()->getMock(); $page_display->expects($this->atLeastOnce())->method('isEnabled')->willReturn(TRUE); $display_collection = $this->getMockBuilder('Drupal\\views\\DisplayPluginCollection')->disableOriginalConstructor()->getMock(); $display_collection->expects($this->atLeastOnce())->method('get')->with('page_1')->willReturn($page_display); $view->displayHandlers = $display_collection; // Setup the expectations. $page_display->expects($this->once())->method('attachTo')->with($cloned_view, 'default', $view->element); $view->attachDisplays(); }
/** * 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); }