Skip to content

Commit

Permalink
Add test if repair step is already done
Browse files Browse the repository at this point in the history
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed Nov 19, 2016
1 parent ccb05db commit 78a318d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/private/Repair.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public static function getRepairSteps() {
),
new CleanPreviews(
\OC::$server->getJobList(),
\OC::$server->getUserManager()
\OC::$server->getUserManager(),
\OC::$server->getConfig()
),
];
}
Expand Down
18 changes: 14 additions & 4 deletions lib/private/Repair/NC11/CleanPreviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OC\Repair\NC11;

use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Migration\IOutput;
Expand All @@ -36,16 +37,22 @@ class CleanPreviews implements IRepairStep {
/** @var IUserManager */
private $userManager;

/** @var IConfig */
private $config;

/**
* MoveAvatars constructor.
*
* @param IJobList $jobList
* @param IUserManager $userManager
* @param IConfig $config
*/
public function __construct(IJobList $jobList,
IUserManager $userManager) {
IUserManager $userManager,
IConfig $config) {
$this->jobList = $jobList;
$this->userManager = $userManager;
$this->config = $config;
}

/**
Expand All @@ -56,8 +63,11 @@ public function getName() {
}

public function run(IOutput $output) {
$this->userManager->callForSeenUsers(function(IUser $user) {
$this->jobList->add(CleanPreviewsBackgroundJob::class, ['uid' => $user->getUID()]);
});
if (!$this->config->getAppValue('core', 'previewsCleanedUp', false)) {
$this->userManager->callForSeenUsers(function (IUser $user) {
$this->jobList->add(CleanPreviewsBackgroundJob::class, ['uid' => $user->getUID()]);
});
$this->config->setAppValue('core', 'previewsCleanedUp', 1);
}
}
}
44 changes: 43 additions & 1 deletion tests/lib/Repair/NC11/CleanPreviewsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OC\Repair\NC11\CleanPreviews;
use OC\Repair\NC11\CleanPreviewsBackgroundJob;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Migration\IOutput;
Expand All @@ -39,6 +40,9 @@ class CleanPreviewsTest extends TestCase {
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;

/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;

/** @var CleanPreviews */
private $repair;

Expand All @@ -47,10 +51,12 @@ public function setUp() {

$this->jobList = $this->createMock(IJobList::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->config = $this->createMock(IConfig::class);

$this->repair = new CleanPreviews(
$this->jobList,
$this->userManager
$this->userManager,
$this->config
);
}

Expand Down Expand Up @@ -87,6 +93,42 @@ public function testRun() {
$this->equalTo(['uid' => 'user2'])
);

$this->config->expects($this->once())
->method('getAppValue')
->with(
$this->equalTo('core'),
$this->equalTo('previewsCleanedUp'),
$this->equalTo(false)
)->willReturn(false);
$this->config->expects($this->once())
->method('setAppValue')
->with(
$this->equalTo('core'),
$this->equalTo('previewsCleanedUp'),
$this->equalTo(1)
);

$this->repair->run($this->createMock(IOutput::class));
}


public function testRunAlreadyDoone() {
$this->userManager->expects($this->never())
->method($this->anything());

$this->jobList->expects($this->never())
->method($this->anything());

$this->config->expects($this->once())
->method('getAppValue')
->with(
$this->equalTo('core'),
$this->equalTo('previewsCleanedUp'),
$this->equalTo(false)
)->willReturn('1');
$this->config->expects($this->never())
->method('setAppValue');

$this->repair->run($this->createMock(IOutput::class));
}

Expand Down

0 comments on commit 78a318d

Please sign in to comment.