user.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test;
  9. class User extends TestCase {
  10. /**
  11. * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
  12. */
  13. private $backend;
  14. protected function setUp(){
  15. parent::setUp();
  16. $this->backend = $this->getMock('\OC_User_Dummy');
  17. $manager = \OC_User::getManager();
  18. $manager->registerBackend($this->backend);
  19. }
  20. public function testCheckPassword() {
  21. $this->backend->expects($this->once())
  22. ->method('checkPassword')
  23. ->with($this->equalTo('foo'), $this->equalTo('bar'))
  24. ->will($this->returnValue('foo'))
  25. ;
  26. $this->backend->expects($this->any())
  27. ->method('implementsActions')
  28. ->will($this->returnCallback(function ($actions) {
  29. if ($actions === \OC_USER_BACKEND_CHECK_PASSWORD) {
  30. return true;
  31. } else {
  32. return false;
  33. }
  34. }));
  35. $uid = \OC_User::checkPassword('foo', 'bar');
  36. $this->assertEquals($uid, 'foo');
  37. }
  38. public function testDeleteUser() {
  39. $fail = \OC_User::deleteUser('victim');
  40. $this->assertFalse($fail);
  41. $success = \OC_User::createUser('victim', 'password');
  42. $success = \OC_User::deleteUser('victim');
  43. $this->assertTrue($success);
  44. }
  45. public function testCreateUser(){
  46. $this->backend->expects($this->any())
  47. ->method('implementsActions')
  48. ->will($this->returnCallback(function ($actions) {
  49. if ($actions === \OC_USER_BACKEND_CREATE_USER) {
  50. return true;
  51. } else {
  52. return false;
  53. }
  54. }));
  55. $user = \OC_User::createUser('newuser', 'newpassword');
  56. $this->assertEquals('newuser', $user->getUid());
  57. }
  58. }