Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

homecache.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 DummyUser extends \OC\User\User {
  10. /**
  11. * @var string $home
  12. */
  13. private $home;
  14. /**
  15. * @var string $uid
  16. */
  17. private $uid;
  18. /**
  19. * @param string $uid
  20. * @param string $home
  21. */
  22. public function __construct($uid, $home) {
  23. $this->home = $home;
  24. $this->uid = $uid;
  25. }
  26. /**
  27. * @return string
  28. */
  29. public function getHome() {
  30. return $this->home;
  31. }
  32. /**
  33. * @return string
  34. */
  35. public function getUID() {
  36. return $this->uid;
  37. }
  38. }
  39. class HomeCache extends \Test\TestCase {
  40. /**
  41. * @var \OC\Files\Storage\Home $storage
  42. */
  43. private $storage;
  44. /**
  45. * @var \OC\Files\Cache\HomeCache $cache
  46. */
  47. private $cache;
  48. /**
  49. * @var \OC\User\User $user
  50. */
  51. private $user;
  52. protected function setUp() {
  53. parent::setUp();
  54. $this->user = new DummyUser('foo', \OC_Helper::tmpFolder());
  55. $this->storage = new \OC\Files\Storage\Home(array('user' => $this->user));
  56. $this->cache = $this->storage->getCache();
  57. }
  58. /**
  59. * Tests that the root and files folder size calculation ignores the subdirs
  60. * that have an unknown size. This makes sure that quota calculation still
  61. * works as it's based on the "files" folder size.
  62. */
  63. public function testRootFolderSizeIgnoresUnknownUpdate() {
  64. $dir1 = 'files/knownsize';
  65. $dir2 = 'files/unknownsize';
  66. $fileData = array();
  67. $fileData[''] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
  68. $fileData['files'] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
  69. $fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
  70. $fileData[$dir2] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory');
  71. $this->cache->put('', $fileData['']);
  72. $this->cache->put('files', $fileData['files']);
  73. $this->cache->put($dir1, $fileData[$dir1]);
  74. $this->cache->put($dir2, $fileData[$dir2]);
  75. $this->assertTrue($this->cache->inCache('files'));
  76. $this->assertTrue($this->cache->inCache($dir1));
  77. $this->assertTrue($this->cache->inCache($dir2));
  78. // check that files and root size ignored the unknown sizes
  79. $this->assertEquals(1000, $this->cache->calculateFolderSize('files'));
  80. // clean up
  81. $this->cache->remove('');
  82. $this->cache->remove('files');
  83. $this->cache->remove($dir1);
  84. $this->cache->remove($dir2);
  85. $this->assertFalse($this->cache->inCache('files'));
  86. $this->assertFalse($this->cache->inCache($dir1));
  87. $this->assertFalse($this->cache->inCache($dir2));
  88. }
  89. public function testRootFolderSizeIsFilesSize() {
  90. $dir1 = 'files';
  91. $afile = 'test.txt';
  92. $fileData = array();
  93. $fileData[''] = array('size' => 1500, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
  94. $fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
  95. $fileData[$afile] = array('size' => 500, 'mtime' => 20);
  96. $this->cache->put('', $fileData['']);
  97. $this->cache->put($dir1, $fileData[$dir1]);
  98. $this->assertTrue($this->cache->inCache($dir1));
  99. // check that root size ignored the unknown sizes
  100. $data = $this->cache->get('files');
  101. $this->assertEquals(1000, $data['size']);
  102. $data = $this->cache->get('');
  103. $this->assertEquals(1000, $data['size']);
  104. // clean up
  105. $this->cache->remove('');
  106. $this->cache->remove($dir1);
  107. $this->assertFalse($this->cache->inCache($dir1));
  108. }
  109. }