CacheJailTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\CacheTest;
  10. /**
  11. * Class CacheJail
  12. *
  13. * @group DB
  14. *
  15. * @package Test\Files\Cache\Wrapper
  16. */
  17. class CacheJailTest extends CacheTest {
  18. /**
  19. * @var \OC\Files\Cache\Cache $sourceCache
  20. */
  21. protected $sourceCache;
  22. public function setUp() {
  23. parent::setUp();
  24. $this->storage->mkdir('foo');
  25. $this->sourceCache = $this->cache;
  26. $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, 'foo');
  27. }
  28. function testSearchOutsideJail() {
  29. $file1 = 'foo/foobar';
  30. $file2 = 'folder/foobar';
  31. $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
  32. $this->sourceCache->put($file1, $data1);
  33. $this->sourceCache->put($file2, $data1);
  34. $this->assertCount(2, $this->sourceCache->search('%foobar'));
  35. $result = $this->cache->search('%foobar%');
  36. $this->assertCount(1, $result);
  37. $this->assertEquals('foobar', $result[0]['path']);
  38. }
  39. function testClearKeepEntriesOutsideJail() {
  40. $file1 = 'foo/foobar';
  41. $file2 = 'foo/foobar/asd';
  42. $file3 = 'folder/foobar';
  43. $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
  44. $this->sourceCache->put('foo', $data1);
  45. $this->sourceCache->put($file1, $data1);
  46. $this->sourceCache->put($file2, $data1);
  47. $this->sourceCache->put($file3, $data1);
  48. $this->cache->clear();
  49. $this->assertFalse($this->cache->inCache('foobar'));
  50. $this->assertTrue($this->sourceCache->inCache('folder/foobar'));
  51. }
  52. function testGetById() {
  53. $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
  54. $id = $this->sourceCache->put('foo/bar', $data1);
  55. // path from jailed foo of foo/bar is bar
  56. $path = $this->cache->getPathById($id);
  57. $this->assertEquals('bar', $path);
  58. // path from jailed '' of foo/bar is foo/bar
  59. $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, '');
  60. $path = $this->cache->getPathById($id);
  61. $this->assertEquals('foo/bar', $path);
  62. }
  63. function testGetIncomplete() {
  64. //not supported
  65. $this->assertTrue(true);
  66. }
  67. }