/** * Builds a ContentView object from $viewConfig. * * @param array $viewConfig * * @return ContentView */ protected function buildContentView(array $viewConfig) { $view = new ContentView(); $view->setConfigHash($viewConfig); if (isset($viewConfig['template'])) { $view->setTemplateIdentifier($viewConfig['template']); } if (isset($viewConfig['controller'])) { $view->setControllerReference(new ControllerReference($viewConfig['controller'])); } return $view; }
public function testGetControllerMatchedView() { $id = 123; $viewType = 'full'; $templateIdentifier = 'FooBundle:full:template.twig.html'; $customController = 'FooBundle::bar'; $this->request->attributes->add(array('_controller' => 'ez_content:viewLocation', 'locationId' => $id, 'viewType' => $viewType)); $this->viewBuilderRegistry->expects($this->once())->method('getFromRegistry')->will($this->returnValue($this->viewBuilderMock)); $viewObject = new ContentView($templateIdentifier); $viewObject->setControllerReference(new ControllerReference($customController)); $this->viewBuilderMock->expects($this->once())->method('buildView')->will($this->returnValue($viewObject)); $this->event->expects($this->once())->method('setController'); $this->controllerResolver->expects($this->once())->method('getController')->will($this->returnValue(function () { })); $this->controllerListener->getController($this->event); $this->assertEquals($customController, $this->request->attributes->get('_controller')); $expectedView = new ContentView(); $expectedView->setTemplateIdentifier($templateIdentifier); $expectedView->setControllerReference(new ControllerReference($customController)); $this->assertEquals($expectedView, $this->request->attributes->get('view')); }