diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-09-27 14:25:47 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-09-27 14:25:47 +0200 |
commit | 687ba053b7055900dc938da5b82b6d391b0b4318 (patch) | |
tree | 34e893923186c3373e85fb84e621b93f49dbf562 /tests | |
parent | 469b309b21b6634b275c485fb09aa5d8d69fe33c (diff) | |
parent | 735608f51323218a098137a4992aeafff5806f5c (diff) | |
download | nextcloud-server-687ba053b7055900dc938da5b82b6d391b0b4318.tar.gz nextcloud-server-687ba053b7055900dc938da5b82b6d391b0b4318.zip |
Merge branch 'master' into appframework-master
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bootstrap.php | 2 | ||||
-rw-r--r-- | tests/lib/user.php | 43 | ||||
-rw-r--r-- | tests/lib/user/manager.php | 45 | ||||
-rw-r--r-- | tests/lib/user/session.php | 32 | ||||
-rw-r--r-- | tests/lib/user/user.php | 40 |
5 files changed, 98 insertions, 64 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php index fb667263e45..581cfcff9f3 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,7 +1,5 @@ <?php -global $RUNTIME_NOAPPS; -$RUNTIME_NOAPPS = true; define('PHPUNIT_RUN', 1); diff --git a/tests/lib/user.php b/tests/lib/user.php new file mode 100644 index 00000000000..66c7f3f0d74 --- /dev/null +++ b/tests/lib/user.php @@ -0,0 +1,43 @@ +<?php + +/** + * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test; + +use OC\Hooks\PublicEmitter; + +class User extends \PHPUnit_Framework_TestCase { + + 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('foo')); + + $backend->expects($this->any()) + ->method('implementsActions') + ->will($this->returnCallback(function ($actions) { + if ($actions === \OC_USER_BACKEND_CHECK_PASSWORD) { + return true; + } else { + return false; + } + })); + + $manager = \OC_User::getManager(); + $manager->registerBackend($backend); + + $uid = \OC_User::checkPassword('foo', 'bar'); + $this->assertEquals($uid, 'foo'); + } + +}
\ No newline at end of file diff --git a/tests/lib/user/manager.php b/tests/lib/user/manager.php index bc49f6db4b2..00901dd4115 100644 --- a/tests/lib/user/manager.php +++ b/tests/lib/user/manager.php @@ -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 diff --git a/tests/lib/user/session.php b/tests/lib/user/session.php index 274e9e2831e..e457a7bda30 100644 --- a/tests/lib/user/session.php +++ b/tests/lib/user/session.php @@ -62,10 +62,6 @@ class Session extends \PHPUnit_Framework_TestCase { $user = $this->getMock('\OC\User\User', array(), array('foo', $backend)); $user->expects($this->once()) - ->method('checkPassword') - ->with('bar') - ->will($this->returnValue(true)); - $user->expects($this->once()) ->method('isEnabled') ->will($this->returnValue(true)); $user->expects($this->any()) @@ -73,8 +69,8 @@ class Session extends \PHPUnit_Framework_TestCase { ->will($this->returnValue('foo')); $manager->expects($this->once()) - ->method('get') - ->with('foo') + ->method('checkPassword') + ->with('foo', 'bar') ->will($this->returnValue($user)); $userSession = new \OC\User\Session($manager, $session); @@ -93,16 +89,12 @@ class Session extends \PHPUnit_Framework_TestCase { $user = $this->getMock('\OC\User\User', array(), array('foo', $backend)); $user->expects($this->once()) - ->method('checkPassword') - ->with('bar') - ->will($this->returnValue(true)); - $user->expects($this->once()) ->method('isEnabled') ->will($this->returnValue(false)); $manager->expects($this->once()) - ->method('get') - ->with('foo') + ->method('checkPassword') + ->with('foo', 'bar') ->will($this->returnValue($user)); $userSession = new \OC\User\Session($manager, $session); @@ -119,17 +111,13 @@ class Session extends \PHPUnit_Framework_TestCase { $backend = $this->getMock('OC_User_Dummy'); $user = $this->getMock('\OC\User\User', array(), array('foo', $backend)); - $user->expects($this->once()) - ->method('checkPassword') - ->with('bar') - ->will($this->returnValue(false)); $user->expects($this->never()) ->method('isEnabled'); $manager->expects($this->once()) - ->method('get') - ->with('foo') - ->will($this->returnValue($user)); + ->method('checkPassword') + ->with('foo', 'bar') + ->will($this->returnValue(false)); $userSession = new \OC\User\Session($manager, $session); $userSession->login('foo', 'bar'); @@ -145,9 +133,9 @@ class Session extends \PHPUnit_Framework_TestCase { $backend = $this->getMock('OC_User_Dummy'); $manager->expects($this->once()) - ->method('get') - ->with('foo') - ->will($this->returnValue(null)); + ->method('checkPassword') + ->with('foo', 'bar') + ->will($this->returnValue(false)); $userSession = new \OC\User\Session($manager, $session); $userSession->login('foo', 'bar'); diff --git a/tests/lib/user/user.php b/tests/lib/user/user.php index b0d170cbfc5..de5ccbf38c1 100644 --- a/tests/lib/user/user.php +++ b/tests/lib/user/user.php @@ -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 |