diff --git a/module/User/test/UserTest/Integration/Controller/UserControllerTest.php b/module/User/test/UserTest/Integration/Controller/UserControllerTest.php index c6c19810..8e22253d 100644 --- a/module/User/test/UserTest/Integration/Controller/UserControllerTest.php +++ b/module/User/test/UserTest/Integration/Controller/UserControllerTest.php @@ -3,9 +3,14 @@ namespace UserTest\Integration\Controller; use ApplicationTest\Integration\Util\Bootstrap; +use User\Controller; +use User\Entity\User; use Zend\Authentication\AuthenticationService; use Zend\Http; +use Zend\Mvc; use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase; +use ZfModule\Entity\Module; +use ZfModule\Mvc\Controller\Plugin\ListModule; /** * @coversNothing @@ -47,4 +52,67 @@ public function testIndexActionRedirectsIfNotAuthenticated() $this->assertRedirectTo('/user/login'); } + + public function testIndexActionSetsModulesIfAuthenticated() + { + $authenticationService = $this->getMockBuilder(AuthenticationService::class) + ->disableOriginalConstructor() + ->getMock() + ; + + $authenticationService + ->expects($this->any()) + ->method('hasIdentity') + ->willReturn(true) + ; + + $authenticationService + ->expects($this->any()) + ->method('getIdentity') + ->willReturn(new User()) + ; + + $serviceManager = $this->getApplicationServiceLocator(); + + $serviceManager + ->setAllowOverride(true) + ->setService( + 'zfcuser_auth_service', + $authenticationService + ) + ; + + $listModule = $this->getMockBuilder(ListModule::class) + ->disableOriginalConstructor() + ->getMock() + ; + + $listModule + ->expects($this->once()) + ->method('__invoke') + ->with($this->equalTo([ + 'user' => true, + ])) + ->willReturn([ + new Module(), + ]) + ; + + /* @var Mvc\Controller\PluginManager $controllerPluginManager */ + $controllerPluginManager = $serviceManager->get('ControllerPluginManager'); + + $controllerPluginManager + ->setAllowOverride(true) + ->setService( + 'listModule', + $listModule + ) + ; + + $this->dispatch('/user'); + + $this->assertControllerName('zfcuser'); + $this->assertActionName('index'); + $this->assertResponseStatusCode(Http\Response::STATUS_CODE_200); + } }