NoopScannerTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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() {
  19. parent::setUp();
  20. $this->storage = new \OC\Files\Storage\Temporary(array());
  21. $this->scanner = new \OC\Files\ObjectStore\NoopScanner($this->storage);
  22. }
  23. 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. function testFolder() {
  41. $this->fillTestFolders();
  42. $this->assertEquals(
  43. [],
  44. $this->scanner->scan(''),
  45. 'Asserting that no error occurred while scan()'
  46. );
  47. }
  48. 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. }