diff options
author | Joas Schilling <coding@schilljs.com> | 2017-01-05 18:32:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-05 18:32:42 +0300 |
commit | 48d439074f53fd30ef588164c84bce1ce5ae4b7b (patch) | |
tree | 6afdb821330fc01d7cca424f2720bac060116452 | |
parent | 61d0a9c8aea62e45e05e6b32088befe642864f4b (diff) | |
parent | bf1ebab6acfd8961b435e0614dc334659716930a (diff) |
Merge pull request #18 from nextcloud/stable11_17v11.0.4RC1v11.0.4v11.0.3RC2v11.0.3RC1v11.0.3v11.0.2RC1v11.0.2v11.0.1RC1v11.0.1
[stable11] Delete job if tag not found
-rw-r--r-- | lib/BackgroundJob/RetentionJob.php | 5 | ||||
-rw-r--r-- | tests/lib/BackgroundJob/RetentionJobTest.php | 20 |
2 files changed, 22 insertions, 3 deletions
diff --git a/lib/BackgroundJob/RetentionJob.php b/lib/BackgroundJob/RetentionJob.php index 497ef1b..a5d4c45 100644 --- a/lib/BackgroundJob/RetentionJob.php +++ b/lib/BackgroundJob/RetentionJob.php @@ -33,6 +33,7 @@ use OCP\Files\NotPermittedException; use OCP\Files\IRootFolder; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagObjectMapper; +use OCP\SystemTag\TagNotFoundException; class RetentionJob extends TimedJob { /** @var ISystemTagManager */ @@ -92,6 +93,10 @@ class RetentionJob extends TimedJob { try { $this->tagManager->getTagsByIds($tag); } catch (\InvalidArgumentException $e) { + // tag is invalid remove backgroundjob and exit + $this->jobList->remove($this, $argument); + return; + } catch (TagNotFoundException $e) { // tag no longer exists remove backgroundjob and exit $this->jobList->remove($this, $argument); return; diff --git a/tests/lib/BackgroundJob/RetentionJobTest.php b/tests/lib/BackgroundJob/RetentionJobTest.php index 83a317d..3c32a61 100644 --- a/tests/lib/BackgroundJob/RetentionJobTest.php +++ b/tests/lib/BackgroundJob/RetentionJobTest.php @@ -19,7 +19,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -namespace OCA\Files_Retention\Tests\BackgroundJob\RententionJobTest; +namespace OCA\Files_Retention\Tests\BackgroundJob; use OCA\Files_Retention\BackgroundJob\RetentionJob; use OCA\Files_Retention\Constants; @@ -35,11 +35,13 @@ use OCP\Files\IRootFolder; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagObjectMapper; use OCP\IUser; +use OCP\SystemTag\TagNotFoundException; +use Test\TestCase; /** * @group DB */ -class RetentionJobTest extends \Test\TestCase { +class RetentionJobTest extends TestCase { /** @var ISystemTagManager|\PHPUnit_Framework_MockObject_MockObject */ private $tagManager; @@ -202,7 +204,7 @@ class RetentionJobTest extends \Test\TestCase { $this->retentionJob->run(['tag' => 42]); } - public function testNoSuchTag() { + public function testInvalidTag() { $this->tagManager->expects($this->once()) ->method('getTagsByIds') ->will($this->throwException(new \InvalidArgumentException())); @@ -214,6 +216,18 @@ class RetentionJobTest extends \Test\TestCase { $this->retentionJob->run(['tag' => 42]); } + public function testNoSuchTag() { + $this->tagManager->expects($this->once()) + ->method('getTagsByIds') + ->will($this->throwException(new TagNotFoundException())); + + $this->jobList->expects($this->once()) + ->method('remove') + ->with($this->equalTo($this->retentionJob), $this->equalTo(['tag' => 42])); + + $this->retentionJob->run(['tag' => 42]); + } + public function testNoSuchRetention() { // Tag exists $this->tagManager->expects($this->once()) |