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

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

    public function testIndexActionWithNotFoundHttpException()
    {
        $this->setExpectedException('\\Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException');
        //Mocks
        // page
        $mockPage = $this->getMockBuilder('\\Networking\\InitCmsBundle\\Model\\Page')->disableOriginalConstructor()->getMock();
        $mockPage->expects($this->once())->method('getVisibility')->will($this->returnValue(Page::VISIBILITY_PUBLIC));
        $mockPage->expects($this->exactly(2))->method('getStatus')->will($this->returnValue(Page::STATUS_DRAFT));
        // request
        $mockRequest = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
        $mockRequest->expects($this->at(0))->method('get')->with('_content')->will($this->returnValue($mockPage));
        $mockRequest->expects($this->at(1))->method('get')->with('_template');
        $mockRequest->expects($this->at(2))->method('get')->with('_content')->will($this->returnValue($mockPage));
        //security context
        $mockTokenStorage = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorage')->disableOriginalConstructor()->getMock();
        $mockAuthorizationChecker = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationChecker')->disableOriginalConstructor()->getMock();
        $property = new \ReflectionProperty('Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationChecker', 'tokenStorage');
        $property->setAccessible(true);
        $property->setValue($mockAuthorizationChecker, $mockTokenStorage);
        $mockTokenStorage->expects($this->any())->method('getToken')->will($this->returnValue(null));
        $mockAuthorizationChecker->expects($this->any())->method('isGranted')->with('ROLE_SONATA_ADMIN')->will($this->returnValue(false));
        //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.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('security.token_storage')->will($this->returnValue($mockTokenStorage));
        // Controller
        $controller = new FrontendPageController();
        $controller->setContainer($mockContainer);
        $this->assertInstanceOf('Networking\\InitCmsBundle\\Controller\\FrontendPageController', $controller, 'Controller ist a DefaultController');
        $controller->indexAction($mockRequest);
    }