Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Commit

Permalink
Enhancement: Assert listModule plugin is called in index action
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Feb 4, 2015
1 parent 557e7da commit 099812e
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 099812e

Please sign in to comment.