PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/lib/user/backend.php

https://github.com/sezuan/core
PHP | 99 lines | 47 code | 14 blank | 38 comment | 0 complexity | 252e4419388c1d2e8919874b4641533e MD5 | raw file
Possible License(s): AGPL-3.0, AGPL-1.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2012 Robin Appelman icewind@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Abstract class to provide the basis of backend-specific unit test classes.
  24. *
  25. * All subclasses MUST assign a backend property in setUp() which implements
  26. * user operations (add, remove, etc.). Test methods in this class will then be
  27. * run on each separate subclass and backend therein.
  28. *
  29. * For an example see /tests/lib/user/dummy.php
  30. */
  31. abstract class Test_User_Backend extends PHPUnit_Framework_TestCase {
  32. /**
  33. * @var OC_User_Backend $backend
  34. */
  35. protected $backend;
  36. /**
  37. * get a new unique user name
  38. * test cases can override this in order to clean up created user
  39. * @return array
  40. */
  41. public function getUser() {
  42. return uniqid('test_');
  43. }
  44. public function testAddRemove() {
  45. //get the number of groups we start with, in case there are exising groups
  46. $startCount=count($this->backend->getUsers());
  47. $name1=$this->getUser();
  48. $name2=$this->getUser();
  49. $this->backend->createUser($name1, '');
  50. $count=count($this->backend->getUsers())-$startCount;
  51. $this->assertEquals(1, $count);
  52. $this->assertTrue((array_search($name1, $this->backend->getUsers())!==false));
  53. $this->assertFalse((array_search($name2, $this->backend->getUsers())!==false));
  54. $this->backend->createUser($name2, '');
  55. $count=count($this->backend->getUsers())-$startCount;
  56. $this->assertEquals(2, $count);
  57. $this->assertTrue((array_search($name1, $this->backend->getUsers())!==false));
  58. $this->assertTrue((array_search($name2, $this->backend->getUsers())!==false));
  59. $this->backend->deleteUser($name2);
  60. $count=count($this->backend->getUsers())-$startCount;
  61. $this->assertEquals(1, $count);
  62. $this->assertTrue((array_search($name1, $this->backend->getUsers())!==false));
  63. $this->assertFalse((array_search($name2, $this->backend->getUsers())!==false));
  64. }
  65. public function testLogin() {
  66. $name1=$this->getUser();
  67. $name2=$this->getUser();
  68. $this->assertFalse($this->backend->userExists($name1));
  69. $this->assertFalse($this->backend->userExists($name2));
  70. $this->backend->createUser($name1, 'pass1');
  71. $this->backend->createUser($name2, 'pass2');
  72. $this->assertTrue($this->backend->userExists($name1));
  73. $this->assertTrue($this->backend->userExists($name2));
  74. $this->assertTrue($this->backend->checkPassword($name1, 'pass1'));
  75. $this->assertTrue($this->backend->checkPassword($name2, 'pass2'));
  76. $this->assertFalse($this->backend->checkPassword($name1, 'pass2'));
  77. $this->assertFalse($this->backend->checkPassword($name2, 'pass1'));
  78. $this->assertFalse($this->backend->checkPassword($name1, 'dummy'));
  79. $this->assertFalse($this->backend->checkPassword($name2, 'foobar'));
  80. $this->backend->setPassword($name1, 'newpass1');
  81. $this->assertFalse($this->backend->checkPassword($name1, 'pass1'));
  82. $this->assertTrue($this->backend->checkPassword($name1, 'newpass1'));
  83. $this->assertFalse($this->backend->checkPassword($name2, 'newpass1'));
  84. }
  85. }