You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CleanPreviewsTest.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  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
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Repair\Owncloud;
  24. use OC\Repair\Owncloud\CleanPreviews;
  25. use OC\Repair\Owncloud\CleanPreviewsBackgroundJob;
  26. use OCP\BackgroundJob\IJobList;
  27. use OCP\IConfig;
  28. use OCP\IUser;
  29. use OCP\IUserManager;
  30. use OCP\Migration\IOutput;
  31. use Test\TestCase;
  32. class CleanPreviewsTest extends TestCase {
  33. /** @var IJobList|\PHPUnit_Framework_MockObject_MockObject */
  34. private $jobList;
  35. /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
  36. private $userManager;
  37. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  38. private $config;
  39. /** @var CleanPreviews */
  40. private $repair;
  41. public function setUp(): void {
  42. parent::setUp();
  43. $this->jobList = $this->createMock(IJobList::class);
  44. $this->userManager = $this->createMock(IUserManager::class);
  45. $this->config = $this->createMock(IConfig::class);
  46. $this->repair = new CleanPreviews(
  47. $this->jobList,
  48. $this->userManager,
  49. $this->config
  50. );
  51. }
  52. public function testGetName() {
  53. $this->assertSame('Add preview cleanup background jobs', $this->repair->getName());
  54. }
  55. public function testRun() {
  56. $user1 = $this->createMock(IUser::class);
  57. $user1->method('getUID')
  58. ->willReturn('user1');
  59. $user2 = $this->createMock(IUser::class);
  60. $user2->method('getUID')
  61. ->willReturn('user2');
  62. $this->userManager->expects($this->once())
  63. ->method('callForSeenUsers')
  64. ->will($this->returnCallback(function (\Closure $function) use ($user1, $user2) {
  65. $function($user1);
  66. $function($user2);
  67. }));
  68. $this->jobList->expects($this->exactly(2))
  69. ->method('add')
  70. ->withConsecutive(
  71. [
  72. $this->equalTo(CleanPreviewsBackgroundJob::class),
  73. $this->equalTo(['uid' => 'user1'])
  74. ],
  75. [
  76. $this->equalTo(CleanPreviewsBackgroundJob::class),
  77. $this->equalTo(['uid' => 'user2'])
  78. ],
  79. );
  80. $this->config->expects($this->once())
  81. ->method('getAppValue')
  82. ->with(
  83. $this->equalTo('core'),
  84. $this->equalTo('previewsCleanedUp'),
  85. $this->equalTo(false)
  86. )->willReturn(false);
  87. $this->config->expects($this->once())
  88. ->method('setAppValue')
  89. ->with(
  90. $this->equalTo('core'),
  91. $this->equalTo('previewsCleanedUp'),
  92. $this->equalTo(1)
  93. );
  94. $this->repair->run($this->createMock(IOutput::class));
  95. }
  96. public function testRunAlreadyDoone() {
  97. $this->userManager->expects($this->never())
  98. ->method($this->anything());
  99. $this->jobList->expects($this->never())
  100. ->method($this->anything());
  101. $this->config->expects($this->once())
  102. ->method('getAppValue')
  103. ->with(
  104. $this->equalTo('core'),
  105. $this->equalTo('previewsCleanedUp'),
  106. $this->equalTo(false)
  107. )->willReturn('1');
  108. $this->config->expects($this->never())
  109. ->method('setAppValue');
  110. $this->repair->run($this->createMock(IOutput::class));
  111. }
  112. }