This repository has been archived by the owner on May 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Assert redirect of authentication service has no identity
- Loading branch information
1 parent
b8410f0
commit 1dab7d0
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
module/User/test/UserTest/Integration/Controller/UserControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace UserTest\Integration\Controller; | ||
|
||
use User\Controller; | ||
use ApplicationTest\Integration\Util\Bootstrap; | ||
use Zend\Authentication\AuthenticationService; | ||
use Zend\Http; | ||
use Zend\Mvc; | ||
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase; | ||
use ZfcUser\Controller\Plugin; | ||
|
||
class UserControllerTest extends AbstractHttpControllerTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setApplicationConfig(Bootstrap::getConfig()); | ||
} | ||
|
||
public function testIndexActionRedirectsIfNotAuthenticated() | ||
{ | ||
$authenticationService = $this->getMockBuilder(AuthenticationService::class)->getMock(); | ||
|
||
$authenticationService | ||
->expects($this->once()) | ||
->method('hasIdentity') | ||
->willReturn(false) | ||
; | ||
|
||
$serviceManager = $this->getApplicationServiceLocator(); | ||
|
||
$serviceManager | ||
->setAllowOverride(true) | ||
->setService( | ||
'zfcuser_auth_service', | ||
$authenticationService | ||
) | ||
; | ||
|
||
$this->dispatch('/user'); | ||
|
||
$this->assertControllerName('zfcuser'); | ||
$this->assertActionName('index'); | ||
$this->assertResponseStatusCode(Http\Response::STATUS_CODE_302); | ||
|
||
$this->assertRedirectTo('/user/login'); | ||
} | ||
} |