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

Commit

Permalink
Enhancement: Assert redirect of authentication service has no identity
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Feb 4, 2015
1 parent b8410f0 commit 1dab7d0
Showing 1 changed file with 50 additions and 0 deletions.
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');
}
}

0 comments on commit 1dab7d0

Please sign in to comment.