cachejail.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright (c) 2014 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\Wrapper;
  9. use Test\Files\Cache\Cache;
  10. class CacheJail extends Cache {
  11. /**
  12. * @var \OC\Files\Cache\Cache $sourceCache
  13. */
  14. protected $sourceCache;
  15. public function setUp() {
  16. parent::setUp();
  17. $this->storage->mkdir('foo');
  18. $this->sourceCache = $this->cache;
  19. $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, 'foo');
  20. }
  21. function testSearchOutsideJail() {
  22. $file1 = 'foo/foobar';
  23. $file2 = 'folder/foobar';
  24. $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
  25. $this->sourceCache->put($file1, $data1);
  26. $this->sourceCache->put($file2, $data1);
  27. $this->assertCount(2, $this->sourceCache->search('%foobar'));
  28. $result = $this->cache->search('%foobar%');
  29. $this->assertCount(1, $result);
  30. $this->assertEquals('foobar', $result[0]['path']);
  31. }
  32. function testClearKeepEntriesOutsideJail() {
  33. $file1 = 'foo/foobar';
  34. $file2 = 'foo/foobar/asd';
  35. $file3 = 'folder/foobar';
  36. $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
  37. $this->sourceCache->put('foo', $data1);
  38. $this->sourceCache->put($file1, $data1);
  39. $this->sourceCache->put($file2, $data1);
  40. $this->sourceCache->put($file3, $data1);
  41. $this->cache->clear();
  42. $this->assertFalse($this->cache->inCache('foobar'));
  43. $this->assertTrue($this->sourceCache->inCache('folder/foobar'));
  44. }
  45. function testGetById() {
  46. //not supported
  47. $this->assertTrue(true);
  48. }
  49. function testGetIncomplete() {
  50. //not supported
  51. $this->assertTrue(true);
  52. }
  53. }