HomeCacheTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. /**
  40. * Class HomeCacheTest
  41. *
  42. * @group DB
  43. *
  44. * @package Test\Files\Cache
  45. */
  46. class HomeCacheTest extends \Test\TestCase {
  47. /**
  48. * @var \OC\Files\Storage\Home $storage
  49. */
  50. private $storage;
  51. /**
  52. * @var \OC\Files\Cache\HomeCache $cache
  53. */
  54. private $cache;
  55. /**
  56. * @var \OC\User\User $user
  57. */
  58. private $user;
  59. protected function setUp() {
  60. parent::setUp();
  61. $this->user = new DummyUser('foo', \OC::$server->getTempManager()->getTemporaryFolder());
  62. $this->storage = new \OC\Files\Storage\Home(array('user' => $this->user));
  63. $this->cache = $this->storage->getCache();
  64. }
  65. /**
  66. * Tests that the root and files folder size calculation ignores the subdirs
  67. * that have an unknown size. This makes sure that quota calculation still
  68. * works as it's based on the "files" folder size.
  69. */
  70. public function testRootFolderSizeIgnoresUnknownUpdate() {
  71. $dir1 = 'files/knownsize';
  72. $dir2 = 'files/unknownsize';
  73. $fileData = array();
  74. $fileData[''] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
  75. $fileData['files'] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
  76. $fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
  77. $fileData[$dir2] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory');
  78. $this->cache->put('', $fileData['']);
  79. $this->cache->put('files', $fileData['files']);
  80. $this->cache->put($dir1, $fileData[$dir1]);
  81. $this->cache->put($dir2, $fileData[$dir2]);
  82. $this->assertTrue($this->cache->inCache('files'));
  83. $this->assertTrue($this->cache->inCache($dir1));
  84. $this->assertTrue($this->cache->inCache($dir2));
  85. // check that files and root size ignored the unknown sizes
  86. $this->assertEquals(1000, $this->cache->calculateFolderSize('files'));
  87. // clean up
  88. $this->cache->remove('');
  89. $this->cache->remove('files');
  90. $this->cache->remove($dir1);
  91. $this->cache->remove($dir2);
  92. $this->assertFalse($this->cache->inCache('files'));
  93. $this->assertFalse($this->cache->inCache($dir1));
  94. $this->assertFalse($this->cache->inCache($dir2));
  95. }
  96. public function testRootFolderSizeIsFilesSize() {
  97. $dir1 = 'files';
  98. $afile = 'test.txt';
  99. $fileData = array();
  100. $fileData[''] = array('size' => 1500, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
  101. $fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
  102. $fileData[$afile] = array('size' => 500, 'mtime' => 20);
  103. $this->cache->put('', $fileData['']);
  104. $this->cache->put($dir1, $fileData[$dir1]);
  105. $this->assertTrue($this->cache->inCache($dir1));
  106. // check that root size ignored the unknown sizes
  107. $data = $this->cache->get('files');
  108. $this->assertEquals(1000, $data['size']);
  109. $data = $this->cache->get('');
  110. $this->assertEquals(1000, $data['size']);
  111. // clean up
  112. $this->cache->remove('');
  113. $this->cache->remove($dir1);
  114. $this->assertFalse($this->cache->inCache($dir1));
  115. }
  116. }