ScanFilesTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\Files\Tests\BackgroundJob;
  24. use OCP\IUser;
  25. use Test\TestCase;
  26. use OCP\IConfig;
  27. use OCP\IUserManager;
  28. use OCA\Files\BackgroundJob\ScanFiles;
  29. /**
  30. * Class ScanFilesTest
  31. *
  32. * @package OCA\Files\Tests\BackgroundJob
  33. */
  34. class ScanFilesTest extends TestCase {
  35. /** @var IConfig */
  36. private $config;
  37. /** @var IUserManager */
  38. private $userManager;
  39. /** @var ScanFiles */
  40. private $scanFiles;
  41. public function setUp() {
  42. parent::setUp();
  43. $this->config = $this->createMock(IConfig::class);
  44. $this->userManager = $this->createMock(IUserManager::class);
  45. $this->scanFiles = $this->getMockBuilder('\OCA\Files\BackgroundJob\ScanFiles')
  46. ->setConstructorArgs([
  47. $this->config,
  48. $this->userManager,
  49. ])
  50. ->setMethods(['runScanner'])
  51. ->getMock();
  52. }
  53. public function testRunWithoutUsers() {
  54. $this->config
  55. ->expects($this->at(0))
  56. ->method('getAppValue')
  57. ->with('files', 'cronjob_scan_files', 0)
  58. ->will($this->returnValue(50));
  59. $this->userManager
  60. ->expects($this->at(0))
  61. ->method('search')
  62. ->with('', 500, 50)
  63. ->will($this->returnValue([]));
  64. $this->userManager
  65. ->expects($this->at(1))
  66. ->method('search')
  67. ->with('', 500)
  68. ->will($this->returnValue([]));
  69. $this->config
  70. ->expects($this->at(1))
  71. ->method('setAppValue')
  72. ->with('files', 'cronjob_scan_files', 500);
  73. $this->invokePrivate($this->scanFiles, 'run', [[]]);
  74. }
  75. public function testRunWithUsers() {
  76. $fakeUser = $this->createMock(IUser::class);
  77. $this->config
  78. ->expects($this->at(0))
  79. ->method('getAppValue')
  80. ->with('files', 'cronjob_scan_files', 0)
  81. ->will($this->returnValue(50));
  82. $this->userManager
  83. ->expects($this->at(0))
  84. ->method('search')
  85. ->with('', 500, 50)
  86. ->will($this->returnValue([
  87. $fakeUser
  88. ]));
  89. $this->config
  90. ->expects($this->at(1))
  91. ->method('setAppValue')
  92. ->with('files', 'cronjob_scan_files', 550);
  93. $this->scanFiles
  94. ->expects($this->once())
  95. ->method('runScanner')
  96. ->with($fakeUser);
  97. $this->invokePrivate($this->scanFiles, 'run', [[]]);
  98. }
  99. public function testRunWithUsersAndOffsetAtEndOfUserList() {
  100. $this->config
  101. ->expects($this->at(0))
  102. ->method('getAppValue')
  103. ->with('files', 'cronjob_scan_files', 0)
  104. ->will($this->returnValue(50));
  105. $this->userManager
  106. ->expects($this->at(0))
  107. ->method('search')
  108. ->with('', 500, 50)
  109. ->will($this->returnValue([]));
  110. $this->userManager
  111. ->expects($this->at(1))
  112. ->method('search')
  113. ->with('', 500)
  114. ->will($this->returnValue([]));
  115. $this->config
  116. ->expects($this->at(1))
  117. ->method('setAppValue')
  118. ->with('files', 'cronjob_scan_files', 500);
  119. $this->scanFiles
  120. ->expects($this->never())
  121. ->method('runScanner');
  122. $this->invokePrivate($this->scanFiles, 'run', [[]]);
  123. }
  124. }