permissions.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright (c) 2012 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\Files\Cache;
  9. class Permissions extends \PHPUnit_Framework_TestCase {
  10. /***
  11. * @var \OC\Files\Cache\Permissions $permissionsCache
  12. */
  13. private $permissionsCache;
  14. function setUp() {
  15. $this->permissionsCache = new \OC\Files\Cache\Permissions('dummy');
  16. }
  17. function testSimple() {
  18. $ids = range(1, 10);
  19. $user = uniqid();
  20. $this->assertEquals(-1, $this->permissionsCache->get(1, $user));
  21. $this->assertNotContains($user, $this->permissionsCache->getUsers(1));
  22. $this->permissionsCache->set(1, $user, 1);
  23. $this->assertEquals(1, $this->permissionsCache->get(1, $user));
  24. $this->assertContains($user, $this->permissionsCache->getUsers(1));
  25. $this->assertEquals(-1, $this->permissionsCache->get(2, $user));
  26. $this->assertEquals(-1, $this->permissionsCache->get(1, $user . '2'));
  27. $this->permissionsCache->set(1, $user, 2);
  28. $this->assertEquals(2, $this->permissionsCache->get(1, $user));
  29. $this->permissionsCache->set(2, $user, 1);
  30. $this->assertEquals(1, $this->permissionsCache->get(2, $user));
  31. $this->permissionsCache->remove(1, $user);
  32. $this->assertEquals(-1, $this->permissionsCache->get(1, $user));
  33. $this->permissionsCache->remove(1, $user . '2');
  34. $this->assertEquals(1, $this->permissionsCache->get(2, $user));
  35. $expected = array();
  36. foreach ($ids as $id) {
  37. $this->permissionsCache->set($id, $user, 10 + $id);
  38. $expected[$id] = 10 + $id;
  39. }
  40. $this->assertEquals($expected, $this->permissionsCache->getMultiple($ids, $user));
  41. $this->permissionsCache->removeMultiple(array(10, 9), $user);
  42. unset($expected[9]);
  43. unset($expected[10]);
  44. $this->assertEquals($expected, $this->permissionsCache->getMultiple($ids, $user));
  45. $this->permissionsCache->removeMultiple($ids, $user);
  46. }
  47. }