зеркало из https://github.com/nextcloud/server.git
Adjust Tests and satisfy them
This commit is contained in:
Родитель
63324e2347
Коммит
14a160e176
|
@ -127,12 +127,14 @@ class Manager extends PublicEmitter {
|
|||
*/
|
||||
public function checkPassword($loginname, $password) {
|
||||
foreach ($this->backends as $backend) {
|
||||
$uid = $backend->checkPassword($loginname, $password);
|
||||
if ($uid !== false) {
|
||||
return $this->getUserObject($uid, $backend);
|
||||
if($backend->implementsActions(\OC_USER_BACKEND_CHECK_PASSWORD)) {
|
||||
$uid = $backend->checkPassword($loginname, $password);
|
||||
if ($uid !== false) {
|
||||
return $this->getUserObject($uid, $backend);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -98,6 +98,51 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
|||
$this->assertTrue($manager->userExists('foo'));
|
||||
}
|
||||
|
||||
public function testCheckPassword() {
|
||||
/**
|
||||
* @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
|
||||
*/
|
||||
$backend = $this->getMock('\OC_User_Dummy');
|
||||
$backend->expects($this->once())
|
||||
->method('checkPassword')
|
||||
->with($this->equalTo('foo'), $this->equalTo('bar'))
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$backend->expects($this->any())
|
||||
->method('implementsActions')
|
||||
->will($this->returnCallback(function ($actions) {
|
||||
if ($actions === \OC_USER_BACKEND_CHECK_PASSWORD) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
|
||||
$manager = new \OC\User\Manager();
|
||||
$manager->registerBackend($backend);
|
||||
|
||||
$user = $manager->checkPassword('foo', 'bar');
|
||||
$this->assertTrue($user instanceof \OC\User\User);
|
||||
}
|
||||
|
||||
public function testCheckPasswordNotSupported() {
|
||||
/**
|
||||
* @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
|
||||
*/
|
||||
$backend = $this->getMock('\OC_User_Dummy');
|
||||
$backend->expects($this->never())
|
||||
->method('checkPassword');
|
||||
|
||||
$backend->expects($this->any())
|
||||
->method('implementsActions')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$manager = new \OC\User\Manager();
|
||||
$manager->registerBackend($backend);
|
||||
|
||||
$this->assertFalse($manager->checkPassword('foo', 'bar'));
|
||||
}
|
||||
|
||||
public function testGetOneBackendExists() {
|
||||
/**
|
||||
* @var \OC_User_Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
|
||||
|
|
|
@ -100,46 +100,6 @@ class User extends \PHPUnit_Framework_TestCase {
|
|||
$this->assertTrue($user->delete());
|
||||
}
|
||||
|
||||
public function testCheckPassword() {
|
||||
/**
|
||||
* @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
|
||||
*/
|
||||
$backend = $this->getMock('\OC_User_Dummy');
|
||||
$backend->expects($this->once())
|
||||
->method('checkPassword')
|
||||
->with($this->equalTo('foo'), $this->equalTo('bar'))
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$backend->expects($this->any())
|
||||
->method('implementsActions')
|
||||
->will($this->returnCallback(function ($actions) {
|
||||
if ($actions === \OC_USER_BACKEND_CHECK_PASSWORD) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
|
||||
$user = new \OC\User\User('foo', $backend);
|
||||
$this->assertTrue($user->checkPassword('bar'));
|
||||
}
|
||||
|
||||
public function testCheckPasswordNotSupported() {
|
||||
/**
|
||||
* @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
|
||||
*/
|
||||
$backend = $this->getMock('\OC_User_Dummy');
|
||||
$backend->expects($this->never())
|
||||
->method('checkPassword');
|
||||
|
||||
$backend->expects($this->any())
|
||||
->method('implementsActions')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$user = new \OC\User\User('foo', $backend);
|
||||
$this->assertFalse($user->checkPassword('bar'));
|
||||
}
|
||||
|
||||
public function testGetHome() {
|
||||
/**
|
||||
* @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
|
||||
|
|
Загрузка…
Ссылка в новой задаче