/** * home */ public function testHomeAction() { $mockPage = $this->getMock('\\Networking\\InitCmsBundle\\Model\\Page'); $mockSnapshot = $this->getMockForAbstractClass('\\Networking\\InitCmsBundle\\Model\\PageSnapshot', array($mockPage)); $mockPage->expects($this->once())->method('getVisibility')->will($this->returnValue(PageInterface::VISIBILITY_PUBLIC)); $mockPage->expects($this->once())->method('isActive')->will($this->returnValue(true)); $pageHelper = new \Networking\InitCmsBundle\Helper\PageHelper(); $mockSerializer = $this->getMockBuilder('\\JMS\\Serializer\\SerializerInterface')->disableOriginalConstructor()->getMock(); $mockSerializer->expects($this->once())->method('deserialize')->willReturn($mockPage); //security context $mockTokenStorage = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorage')->disableOriginalConstructor()->getMock(); $mockTokenStorage->expects($this->any())->method('isGranted')->with('ROLE_USER')->will($this->returnValue(true)); $_SERVER = array('PATH_INFO' => '/', 'SCRIPT_NAME' => 'app.php'); $templateParams = array('template' => 'DemoInitCmsBundle:Default:one_column.html.twig', 'engine' => 'twig', 'vars' => array(), 'isStreamable' => false); $template = new Template($templateParams); $requestParams = array('_content' => $mockSnapshot, '_template' => $template); //templating $mockTemplating = $this->getMockBuilder('\\Symfony\\Bundle\\TwigBundle\\Debug\\TimedTwigEngine')->disableOriginalConstructor()->getMock(); $mockResponse = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Response')->getMock(); $mockTemplating->expects($this->once())->method('render')->will($this->returnValue($mockResponse)); //request $request = new Request(array(), array(), array(), array(), array(), $_SERVER); $request->attributes->set('_route', 'networking_init_cms_default'); $request->attributes->set('_locale', 'en'); //dynamic router $mockDynamicRouter = $this->getMockBuilder('\\Symfony\\Cmf\\Component\\Routing\\DynamicRouter')->disableOriginalConstructor()->getMock(); $mockDynamicRouter->expects($this->once())->method('matchRequest')->with($request)->willReturn($requestParams); //container $mockContainer = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container')->disableOriginalConstructor()->getMock(); //cache class $mockCacheClass = $this->getMockBuilder('Networking\\InitCmsBundle\\Lib\\PhpCache')->disableOriginalConstructor()->getMock(); $mockContainer->expects($this->at(0))->method('get')->with('networking_init_cms.helper.page_helper')->will($this->returnValue($pageHelper)); $mockContainer->expects($this->at(1))->method('get')->with('networking_init_cms.cms_router')->will($this->returnValue($mockDynamicRouter)); $mockContainer->expects($this->at(2))->method('get')->with('networking_init_cms.lib.php_cache')->will($this->returnValue($mockCacheClass)); $mockContainer->expects($this->at(3))->method('has')->with('security.token_storage')->will($this->returnValue(true)); $mockContainer->expects($this->at(4))->method('get')->with('security.token_storage')->will($this->returnValue($mockTokenStorage)); $mockContainer->expects($this->at(5))->method('get')->with('networking_init_cms.helper.page_helper')->will($this->returnValue($pageHelper)); $mockContainer->expects($this->at(6))->method('get')->with('serializer')->willReturn($mockSerializer); $mockContainer->expects($this->at(7))->method('get')->with('security.token_storage')->will($this->returnValue($mockTokenStorage)); $mockContainer->expects($this->at(8))->method('has')->with('templating')->will($this->returnValue(true)); $mockContainer->expects($this->at(9))->method('get')->with('templating')->will($this->returnValue($mockTemplating)); $requestAfter = clone $request; $requestAfter->attributes->add($requestParams); unset($requestParams['_route']); unset($requestParams['_controller']); $requestAfter->attributes->set('_route_params', $requestParams); $configuration = $requestAfter->attributes->get('_template'); $requestAfter->attributes->set('_template', $configuration->getTemplate()); $requestAfter->attributes->set('_template_vars', $configuration->getVars()); $requestAfter->attributes->set('_template_streamable', $configuration->isStreamable()); $pageHelper->setContainer($mockContainer); $controller = new FrontendPageController(); $controller->setContainer($mockContainer); $response = $controller->homeAction($request); $this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\Response', $response, 'response object returned'); }