2013-04-20 17:27:46 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2013-04-20 17:27:46 -04:00
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2013-04-20 17:27:46 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Test\BackgroundJob;
|
|
|
|
|
|
2018-10-09 09:25:56 -04:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2024-02-08 05:52:40 -05:00
|
|
|
use OCP\BackgroundJob\QueuedJob;
|
2025-06-12 12:31:58 -04:00
|
|
|
use OCP\Server;
|
2018-10-09 09:25:56 -04:00
|
|
|
|
2024-02-08 05:52:40 -05:00
|
|
|
class TestQueuedJobNew extends QueuedJob {
|
|
|
|
|
public bool $ran = false;
|
2013-12-04 10:28:27 -05:00
|
|
|
|
2013-04-20 17:51:58 -04:00
|
|
|
public function run($argument) {
|
2018-10-09 09:25:56 -04:00
|
|
|
$this->ran = true;
|
2013-04-20 17:27:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-20 09:38:20 -04:00
|
|
|
class QueuedJobTest extends \Test\TestCase {
|
2024-02-08 05:52:40 -05:00
|
|
|
private DummyJobList $jobList;
|
2013-12-04 10:28:27 -05:00
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2014-11-10 17:30:38 -05:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2013-04-20 17:27:46 -04:00
|
|
|
$this->jobList = new DummyJobList();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-09 09:25:56 -04:00
|
|
|
public function testJobShouldBeRemovedNew(): void {
|
2025-06-12 12:31:58 -04:00
|
|
|
$job = new TestQueuedJobNew(Server::get(ITimeFactory::class));
|
2018-10-09 09:25:56 -04:00
|
|
|
$job->setId(42);
|
|
|
|
|
$this->jobList->add($job);
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($this->jobList->has($job, null));
|
2024-02-08 05:52:40 -05:00
|
|
|
$job->start($this->jobList);
|
2018-10-09 09:25:56 -04:00
|
|
|
$this->assertTrue($job->ran);
|
2013-04-20 17:27:46 -04:00
|
|
|
}
|
|
|
|
|
}
|