NoopScannerTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. class NoopScannerTest extends \Test\TestCase {
  14. /** @var \OC\Files\Storage\Storage $storage */
  15. private $storage;
  16. /** @var \OC\Files\ObjectStore\NoopScanner $scanner */
  17. private $scanner;
  18. protected function setUp(): void {
  19. parent::setUp();
  20. $this->storage = new \OC\Files\Storage\Temporary([]);
  21. $this->scanner = new \OC\Files\ObjectStore\NoopScanner($this->storage);
  22. }
  23. public function testFile() {
  24. $data = "dummy file data\n";
  25. $this->storage->file_put_contents('foo.txt', $data);
  26. $this->assertEquals(
  27. [],
  28. $this->scanner->scanFile('foo.txt'),
  29. 'Asserting that no error occurred while scanFile()'
  30. );
  31. }
  32. private function fillTestFolders() {
  33. $textData = "dummy file data\n";
  34. $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png');
  35. $this->storage->mkdir('folder');
  36. $this->storage->file_put_contents('foo.txt', $textData);
  37. $this->storage->file_put_contents('foo.png', $imgData);
  38. $this->storage->file_put_contents('folder/bar.txt', $textData);
  39. }
  40. public function testFolder() {
  41. $this->fillTestFolders();
  42. $this->assertEquals(
  43. [],
  44. $this->scanner->scan(''),
  45. 'Asserting that no error occurred while scan()'
  46. );
  47. }
  48. public function testBackgroundScan() {
  49. $this->fillTestFolders();
  50. $this->storage->mkdir('folder2');
  51. $this->storage->file_put_contents('folder2/bar.txt', 'foobar');
  52. $this->assertEquals(
  53. [],
  54. $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW),
  55. 'Asserting that no error occurred while scan(SCAN_SHALLOW)'
  56. );
  57. $this->scanner->backgroundScan();
  58. $this->assertTrue(
  59. true,
  60. 'Asserting that no error occurred while backgroundScan()'
  61. );
  62. }
  63. }