|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace UserTest\Integration\Controller; |
| 4 | + |
| 5 | +use ApplicationTest\Integration\Util\Bootstrap; |
| 6 | +use User\Entity\User as UserEntity; |
| 7 | +use Zend\Http\Response as HttpResponse; |
| 8 | +use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase; |
| 9 | + |
| 10 | +class IndexControllerTest extends AbstractHttpControllerTestCase |
| 11 | +{ |
| 12 | + protected $viewHelperManager; |
| 13 | + |
| 14 | + protected function setUp() |
| 15 | + { |
| 16 | + parent::setUp(); |
| 17 | + $this->setApplicationConfig(Bootstrap::getConfig()); |
| 18 | + $this->getApplicationServiceLocator()->setAllowOverride(true); |
| 19 | + |
| 20 | + $mockTotalModules = $this->getMockBuilder('ZfModule\View\Helper\TotalModules') |
| 21 | + ->disableOriginalConstructor() |
| 22 | + ->getMock(); |
| 23 | + |
| 24 | + $mockListModule = $this->getMockBuilder('ZfModule\View\Helper\ListModule') |
| 25 | + ->disableOriginalConstructor() |
| 26 | + ->getMock(); |
| 27 | + |
| 28 | + $this->viewHelperManager = $this->getApplicationServiceLocator()->get('ViewHelperManager'); |
| 29 | + $this->viewHelperManager->setService('totalModules', $mockTotalModules); |
| 30 | + $this->viewHelperManager->setService('listModule', $mockListModule); |
| 31 | + |
| 32 | + $mockAuthService = $this->getMockBuilder('Zend\Authentication\AuthenticationService') |
| 33 | + ->disableOriginalConstructor() |
| 34 | + ->getMock(); |
| 35 | + $mockAuthService->expects($this->any()) |
| 36 | + ->method('hasIdentity') |
| 37 | + ->will($this->returnValue(true)); |
| 38 | + $mockAuthService->expects($this->any()) |
| 39 | + ->method('getIdentity') |
| 40 | + ->will($this->returnValue(new UserEntity())); |
| 41 | + |
| 42 | + $this->getApplicationServiceLocator()->setService('zfcuser_auth_service', $mockAuthService); |
| 43 | + $this->viewHelperManager->get('zfcUserIdentity')->setAuthService($mockAuthService); |
| 44 | + } |
| 45 | + |
| 46 | + public function testIndexActionCanBeAccessed() |
| 47 | + { |
| 48 | + $mockListModule = $this->viewHelperManager->get('listModule'); |
| 49 | + $mockListModule->expects($this->once()) |
| 50 | + ->method('__invoke') |
| 51 | + ->will($this->returnValue([])); |
| 52 | + |
| 53 | + $this->dispatch('/user'); |
| 54 | + |
| 55 | + $this->assertControllerName('User\Controller\Index'); |
| 56 | + $this->assertActionName('index'); |
| 57 | + $this->assertTemplateName('user/index/index'); |
| 58 | + $this->assertResponseStatusCode(HttpResponse::STATUS_CODE_200); |
| 59 | + } |
| 60 | +} |
0 commit comments