2013-04-20 21:27:46 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\BackgroundJob;
|
|
|
|
|
2018-10-09 13:25:56 +00:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
|
2013-04-20 21:27:46 +00:00
|
|
|
class TestQueuedJob extends \OC\BackgroundJob\QueuedJob {
|
2018-10-09 13:25:56 +00:00
|
|
|
public $ran = false;
|
2013-12-04 15:28:27 +00:00
|
|
|
|
2018-10-09 13:25:56 +00:00
|
|
|
|
|
|
|
public function run($argument) {
|
|
|
|
$this->ran = true;
|
2013-12-04 15:28:27 +00:00
|
|
|
}
|
2018-10-09 13:25:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class TestQueuedJobNew extends \OCP\BackgroundJob\QueuedJob {
|
|
|
|
public $ran = false;
|
|
|
|
|
2013-12-04 15:28:27 +00:00
|
|
|
|
2013-04-20 21:51:58 +00:00
|
|
|
public function run($argument) {
|
2018-10-09 13:25:56 +00:00
|
|
|
$this->ran = true;
|
2013-04-20 21:27:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 13:38:20 +00:00
|
|
|
class QueuedJobTest extends \Test\TestCase {
|
2013-04-20 21:27:46 +00:00
|
|
|
/**
|
|
|
|
* @var DummyJobList $jobList
|
|
|
|
*/
|
|
|
|
private $jobList;
|
2013-12-04 15:28:27 +00:00
|
|
|
|
2014-11-10 22:30:38 +00:00
|
|
|
protected function setup() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2013-04-20 21:27:46 +00:00
|
|
|
$this->jobList = new DummyJobList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testJobShouldBeRemoved() {
|
2018-10-09 13:25:56 +00:00
|
|
|
$job = new TestQueuedJob();
|
|
|
|
$this->jobList->add($job);
|
|
|
|
|
|
|
|
$this->assertTrue($this->jobList->has($job, null));
|
|
|
|
$job->execute($this->jobList);
|
|
|
|
$this->assertTrue($job->ran);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testJobShouldBeRemovedNew() {
|
|
|
|
$job = new TestQueuedJobNew(\OC::$server->query(ITimeFactory::class));
|
|
|
|
$job->setId(42);
|
|
|
|
$this->jobList->add($job);
|
|
|
|
|
|
|
|
$this->assertTrue($this->jobList->has($job, null));
|
|
|
|
$job->execute($this->jobList);
|
|
|
|
$this->assertTrue($job->ran);
|
2013-04-20 21:27:46 +00:00
|
|
|
}
|
|
|
|
}
|