Networking\InitCmsBundle\Tests\Controller\FrontendPageControllerTest::testLiveAction PHP Метод

testLiveAction() публичный Метод

public testLiveAction ( )
    public function testLiveAction()
    {
        // MOCKS
        $mockPage = $this->getMock('Networking\\InitCmsBundle\\Model\\Page');
        $mockPage->expects($this->once())->method('getVisibility')->will($this->returnValue(PageInterface::VISIBILITY_PUBLIC));
        $mockPage->expects($this->once())->method('isActive')->will($this->returnValue(true));
        $mockSnapshot = $this->getMockBuilder('Networking\\InitCmsBundle\\Entity\\PageSnapshot')->disableOriginalConstructor()->getMock();
        $mockHelper = $this->getMockBuilder('Networking\\InitCmsBundle\\Helper\\PageHelper')->disableOriginalConstructor()->getMock();
        $mockHelper->expects($this->once())->method('unserializePageSnapshotData')->will($this->returnValue($mockPage));
        //cache class
        $mockCacheClass = $this->getMockBuilder('Networking\\InitCmsBundle\\Lib\\PhpCache')->disableOriginalConstructor()->getMock();
        //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));
        //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
        $mockRequest = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
        $mockRequest->expects($this->at(0))->method('get')->with('_content')->will($this->returnValue($mockSnapshot));
        $mockRequest->expects($this->at(1))->method('get')->with('_template');
        $mockRequest->expects($this->at(2))->method('get')->with('_content')->will($this->returnValue($mockSnapshot));
        //Container
        $mockContainer = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container')->disableOriginalConstructor()->getMock();
        $mockContainer->expects($this->at(0))->method('get')->with('networking_init_cms.lib.php_cache')->will($this->returnValue($mockCacheClass));
        $mockContainer->expects($this->at(1))->method('has')->with('security.token_storage')->will($this->returnValue(true));
        $mockContainer->expects($this->at(2))->method('get')->with('security.token_storage')->will($this->returnValue($mockTokenStorage));
        $mockContainer->expects($this->at(3))->method('get')->with('networking_init_cms.helper.page_helper')->will($this->returnValue($mockHelper));
        $mockContainer->expects($this->at(4))->method('get')->with('security.token_storage')->will($this->returnValue($mockTokenStorage));
        $mockContainer->expects($this->at(5))->method('has')->with('templating')->will($this->returnValue(true));
        $mockContainer->expects($this->at(6))->method('get')->with('templating')->will($this->returnValue($mockTemplating));
        // controller
        $controller = new FrontendPageController();
        $controller->setContainer($mockContainer);
        $response = $controller->indexAction($mockRequest);
        $this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\Response', $response, 'response object returned');
    }