Skip to content

Commit

Permalink
Be more precise when refuse to expire
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Nov 23, 2017
1 parent d2beef5 commit 98986a5
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/files_trashbin/lib/Command/ExpireTrash.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {

$maxAge = $this->expiration->getMaxAgeAsTimestamp();
if (!$maxAge) {
$output->writeln("No expiry configured.");
$output->writeln("Auto expiration is configured - expiration will be handled automatically.");
return;
}

Expand Down
63 changes: 63 additions & 0 deletions apps/files_trashbin/tests/Command/ExpireTrashTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* @author Viktar Dubiniuk <dubiniuk@owncloud.com>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Files_Trashbin\Tests\Command;

use OCA\Files_Trashbin\Command\ExpireTrash;
use OCA\Files_Trashbin\Expiration;
use OCP\IUserManager;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;


/**
* Class ExpireTrashTest
*
* @group DB
*
* @package OCA\Files_Trashbin\Tests\Command
*/
class ExpireTrashTest extends TestCase {

/** @var CommandTester */
private $commandTester;

private $userManager;

private $expiration;

public function setUp() {
parent::setUp();

$this->userManager = $this->createMock(IUserManager::class);
$this->expiration = $this->createMock(Expiration::class);
$command = new ExpireTrash($this->userManager, $this->expiration);
$this->commandTester = new CommandTester($command);
}

public function testExpireNoMaxRetention() {
$this->expiration->expects($this->any())->method('getMaxAgeAsTimestamp')
->willReturn(false);
$this->commandTester->execute([]);
$output = $this->commandTester->getDisplay();
$this->assertContains('Auto expiration is configured', $output);
}
}
2 changes: 1 addition & 1 deletion apps/files_versions/lib/Command/ExpireVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {

$maxAge = $this->expiration->getMaxAgeAsTimestamp();
if (!$maxAge) {
$output->writeln("No expiry configured.");
$output->writeln("Auto expiration is configured - expiration will be handled automatically.");
return;
}

Expand Down
63 changes: 63 additions & 0 deletions apps/files_versions/tests/Command/ExpireVersionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* @author Viktar Dubiniuk <dubiniuk@owncloud.com>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Files_Versions\Tests\Command;

use OCA\Files_Versions\Command\ExpireVersions;
use OCA\Files_Versions\Expiration;
use OCP\IUserManager;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;


/**
* Class ExpireVersionsTest
*
* @group DB
*
* @package OCA\Files_Versions\Tests\Command
*/
class ExpireVersionsTest extends TestCase {

/** @var CommandTester */
private $commandTester;

private $userManager;

private $expiration;

public function setUp() {
parent::setUp();

$this->userManager = $this->createMock(IUserManager::class);
$this->expiration = $this->createMock(Expiration::class);
$command = new ExpireVersions($this->userManager, $this->expiration);
$this->commandTester = new CommandTester($command);
}

public function testExpireNoMaxRetention() {
$this->expiration->expects($this->any())->method('getMaxAgeAsTimestamp')
->willReturn(false);
$this->commandTester->execute([]);
$output = $this->commandTester->getDisplay();
$this->assertContains('Auto expiration is configured', $output);
}
}

0 comments on commit 98986a5

Please sign in to comment.