Файл: symfony-2.7/src/Symfony/Component/Security/Core/Tests/User/UserCheckerTest.php
Строк: 178
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SymfonyComponentSecurityCoreTestsUser;
use SymfonyComponentSecurityCoreUserUserChecker;
class UserCheckerTest extends PHPUnit_Framework_TestCase
{
public function testCheckPostAuthNotAdvancedUserInterface()
{
$checker = new UserChecker();
$this->assertNull($checker->checkPostAuth($this->getMock('SymfonyComponentSecurityCoreUserUserInterface')));
}
public function testCheckPostAuthPass()
{
$checker = new UserChecker();
$account = $this->getMock('SymfonyComponentSecurityCoreUserAdvancedUserInterface');
$account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(true));
$this->assertNull($checker->checkPostAuth($account));
}
/**
* @expectedException SymfonyComponentSecurityCoreExceptionCredentialsExpiredException
*/
public function testCheckPostAuthCredentialsExpired()
{
$checker = new UserChecker();
$account = $this->getMock('SymfonyComponentSecurityCoreUserAdvancedUserInterface');
$account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(false));
$checker->checkPostAuth($account);
}
public function testCheckPreAuthNotAdvancedUserInterface()
{
$checker = new UserChecker();
$this->assertNull($checker->checkPreAuth($this->getMock('SymfonyComponentSecurityCoreUserUserInterface')));
}
public function testCheckPreAuthPass()
{
$checker = new UserChecker();
$account = $this->getMock('SymfonyComponentSecurityCoreUserAdvancedUserInterface');
$account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(true));
$account->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
$account->expects($this->once())->method('isAccountNonExpired')->will($this->returnValue(true));
$this->assertNull($checker->checkPreAuth($account));
}
/**
* @expectedException SymfonyComponentSecurityCoreExceptionLockedException
*/
public function testCheckPreAuthAccountLocked()
{
$checker = new UserChecker();
$account = $this->getMock('SymfonyComponentSecurityCoreUserAdvancedUserInterface');
$account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(false));
$checker->checkPreAuth($account);
}
/**
* @expectedException SymfonyComponentSecurityCoreExceptionDisabledException
*/
public function testCheckPreAuthDisabled()
{
$checker = new UserChecker();
$account = $this->getMock('SymfonyComponentSecurityCoreUserAdvancedUserInterface');
$account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(true));
$account->expects($this->once())->method('isEnabled')->will($this->returnValue(false));
$checker->checkPreAuth($account);
}
/**
* @expectedException SymfonyComponentSecurityCoreExceptionAccountExpiredException
*/
public function testCheckPreAuthAccountExpired()
{
$checker = new UserChecker();
$account = $this->getMock('SymfonyComponentSecurityCoreUserAdvancedUserInterface');
$account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(true));
$account->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
$account->expects($this->once())->method('isAccountNonExpired')->will($this->returnValue(false));
$checker->checkPreAuth($account);
}
}