permissions.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. use OC\Files\Storage\Temporary;
  10. class Permissions extends \PHPUnit_Framework_TestCase {
  11. /***
  12. * @var \OC\Files\Cache\Permissions $permissionsCache
  13. */
  14. private $permissionsCache;
  15. function setUp() {
  16. $this->permissionsCache = new \OC\Files\Cache\Permissions('dummy');
  17. }
  18. function testSimple() {
  19. $ids = range(1, 10);
  20. $user = uniqid();
  21. $this->assertEquals(-1, $this->permissionsCache->get(1, $user));
  22. $this->assertNotContains($user, $this->permissionsCache->getUsers(1));
  23. $this->permissionsCache->set(1, $user, 1);
  24. $this->assertEquals(1, $this->permissionsCache->get(1, $user));
  25. $this->assertContains($user, $this->permissionsCache->getUsers(1));
  26. $this->assertEquals(-1, $this->permissionsCache->get(2, $user));
  27. $this->assertEquals(-1, $this->permissionsCache->get(1, $user . '2'));
  28. $this->permissionsCache->set(1, $user, 2);
  29. $this->assertEquals(2, $this->permissionsCache->get(1, $user));
  30. $this->permissionsCache->set(2, $user, 1);
  31. $this->assertEquals(1, $this->permissionsCache->get(2, $user));
  32. $this->permissionsCache->remove(1, $user);
  33. $this->assertEquals(-1, $this->permissionsCache->get(1, $user));
  34. $this->permissionsCache->remove(1, $user . '2');
  35. $this->assertEquals(1, $this->permissionsCache->get(2, $user));
  36. $expected = array();
  37. foreach ($ids as $id) {
  38. $this->permissionsCache->set($id, $user, 10 + $id);
  39. $expected[$id] = 10 + $id;
  40. }
  41. $this->assertEquals($expected, $this->permissionsCache->getMultiple($ids, $user));
  42. $this->permissionsCache->removeMultiple(array(10, 9), $user);
  43. unset($expected[9]);
  44. unset($expected[10]);
  45. $this->assertEquals($expected, $this->permissionsCache->getMultiple($ids, $user));
  46. $this->permissionsCache->removeMultiple($ids, $user);
  47. }
  48. public function testUpdatePermissionsOnRescan() {
  49. $storage = new Temporary(array());
  50. $scanner = $storage->getScanner();
  51. $cache = $storage->getCache();
  52. $permissionsCache = $storage->getPermissionsCache();
  53. $storage->file_put_contents('foo.txt', 'bar');
  54. $scanner->scan('');
  55. $id = $cache->getId('foo.txt');
  56. $permissionsCache->set($id, 'test', 1);
  57. $scanner->scan('');
  58. $this->assertEquals(-1, $permissionsCache->get($id, 'test'));
  59. }
  60. }