public function testIndexActionWithAccessDeniedException()
{
// because no user is authenticated: a AuthenticationCredentialsNotFoundException
$this->setExpectedException('Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException');
//Mocks
$mockPage = $this->getMockBuilder('\\Networking\\InitCmsBundle\\Model\\Page')->disableOriginalConstructor()->getMock();
$mockPage->expects($this->once())->method('getVisibility')->will($this->returnValue(PageInterface::VISIBILITY_PROTECTED));
$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));
$mockTokenStorage = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorage')->disableOriginalConstructor()->getMock();
$mockAccessDecisionManager = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authorization\\AccessDecisionManager')->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);
$property = new \ReflectionProperty('Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationChecker', 'accessDecisionManager');
$property->setAccessible(true);
$property->setValue($mockAuthorizationChecker, $mockAccessDecisionManager);
$mockTokenStorage->expects($this->any())->method('getToken')->will($this->returnValue(new AnonymousToken('anon', 'anon')));
$mockAccessDecisionManager->expects($this->any())->method('decide')->willReturn(false);
$mockAuthorizationChecker->expects($this->any())->method('isGranted')->with('ROLE_USER')->will($this->returnValue(false));
$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.authorization_checker')->will($this->returnValue($mockAuthorizationChecker));
// Controller
$controller = new FrontendPageController();
$controller->setContainer($mockContainer);
$this->assertInstanceOf('Networking\\InitCmsBundle\\Controller\\FrontendPageController', $controller, 'Controller ist a DefaultController');
$controller->indexAction($mockRequest);
}