ObjectStoreScannerTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Joas Schilling
  6. * @copyright 2015 Joas Schilling nickvergessen@owncloud.com
  7. *
  8. * This file is licensed under the Affero General Public License version 3 or
  9. * later.
  10. * See the COPYING-README file.
  11. */
  12. namespace Test\Files\ObjectStore;
  13. use OC\Files\Cache\Scanner;
  14. use OC\Files\ObjectStore\ObjectStoreScanner;
  15. use OC\Files\Storage\Temporary;
  16. use OCP\Files\Cache\ICache;
  17. use OCP\Files\Storage\IStorage;
  18. use Test\TestCase;
  19. /**
  20. * @group DB
  21. */
  22. class ObjectStoreScannerTest extends TestCase {
  23. private IStorage $storage;
  24. private ICache $cache;
  25. private ObjectStoreScanner $scanner;
  26. private Scanner $realScanner;
  27. protected function setUp(): void {
  28. parent::setUp();
  29. $this->storage = new Temporary([]);
  30. $this->cache = $this->storage->getCache();
  31. $this->scanner = new ObjectStoreScanner($this->storage);
  32. $this->realScanner = new Scanner($this->storage);
  33. }
  34. public function testFile() {
  35. $data = "dummy file data\n";
  36. $this->storage->file_put_contents('foo.txt', $data);
  37. $this->assertEquals(
  38. [],
  39. $this->scanner->scanFile('foo.txt'),
  40. 'Asserting that no error occurred while scanFile()'
  41. );
  42. }
  43. private function fillTestFolders() {
  44. $textData = "dummy file data\n";
  45. $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png');
  46. $this->storage->mkdir('folder');
  47. $this->storage->file_put_contents('foo.txt', $textData);
  48. $this->storage->file_put_contents('foo.png', $imgData);
  49. $this->storage->file_put_contents('folder/bar.txt', $textData);
  50. }
  51. public function testFolder() {
  52. $this->fillTestFolders();
  53. $this->assertEquals(
  54. [],
  55. $this->scanner->scan(''),
  56. 'Asserting that no error occurred while scan()'
  57. );
  58. }
  59. public function testBackgroundScan() {
  60. $this->fillTestFolders();
  61. $this->storage->mkdir('folder2');
  62. $this->storage->file_put_contents('folder2/bar.txt', 'foobar');
  63. $this->realScanner->scan('');
  64. $this->assertEquals(6, $this->cache->get('folder2')->getSize());
  65. $this->cache->put('folder2', ['size' => -1]);
  66. $this->assertEquals(-1, $this->cache->get('folder2')->getSize());
  67. $this->scanner->backgroundScan();
  68. $this->assertEquals(6, $this->cache->get('folder2')->getSize());
  69. }
  70. }