diff options
Diffstat (limited to 'apps/files_trashbin/tests/ExpirationTest.php')
-rw-r--r-- | apps/files_trashbin/tests/ExpirationTest.php | 77 |
1 files changed, 23 insertions, 54 deletions
diff --git a/apps/files_trashbin/tests/ExpirationTest.php b/apps/files_trashbin/tests/ExpirationTest.php index adef194f34f..3348edc4016 100644 --- a/apps/files_trashbin/tests/ExpirationTest.php +++ b/apps/files_trashbin/tests/ExpirationTest.php @@ -1,28 +1,12 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Victor Dubiniuk <dubiniuk@owncloud.com> - * - * @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/> - * + * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ +namespace OCA\Files_Trashbin\Tests; use OCA\Files_Trashbin\Expiration; use OCP\AppFramework\Utility\ITimeFactory; @@ -34,7 +18,7 @@ class ExpirationTest extends \Test\TestCase { public const FAKE_TIME_NOW = 1000000; - public function expirationData() { + public static function expirationData(): array { $today = 100 * self::SECONDS_PER_DAY; $back10Days = (100 - 10) * self::SECONDS_PER_DAY; $back20Days = (100 - 20) * self::SECONDS_PER_DAY; @@ -98,16 +82,8 @@ class ExpirationTest extends \Test\TestCase { ]; } - /** - * @dataProvider expirationData - * - * @param string $retentionObligation - * @param int $timeNow - * @param int $timestamp - * @param bool $quotaExceeded - * @param string $expectedResult - */ - public function testExpiration($retentionObligation, $timeNow, $timestamp, $quotaExceeded, $expectedResult) { + #[\PHPUnit\Framework\Attributes\DataProvider('expirationData')] + public function testExpiration(string $retentionObligation, int $timeNow, int $timestamp, bool $quotaExceeded, bool $expectedResult): void { $mockedConfig = $this->getMockedConfig($retentionObligation); $mockedTimeFactory = $this->getMockedTimeFactory($timeNow); @@ -118,30 +94,25 @@ class ExpirationTest extends \Test\TestCase { } - public function configData() { + public static function timestampTestData(): array { return [ - [ 'disabled', null, null, null], - [ 'auto', Expiration::DEFAULT_RETENTION_OBLIGATION, Expiration::NO_OBLIGATION, true ], - [ 'auto,auto', Expiration::DEFAULT_RETENTION_OBLIGATION, Expiration::NO_OBLIGATION, true ], - [ 'auto, auto', Expiration::DEFAULT_RETENTION_OBLIGATION, Expiration::NO_OBLIGATION, true ], - [ 'auto, 3', Expiration::NO_OBLIGATION, 3, true ], - [ '5, auto', 5, Expiration::NO_OBLIGATION, true ], - [ '3, 5', 3, 5, false ], - [ '10, 3', 10, 10, false ], + [ 'disabled', false], + [ 'auto', false ], + [ 'auto,auto', false ], + [ 'auto, auto', false ], + [ 'auto, 3', self::FAKE_TIME_NOW - (3 * self::SECONDS_PER_DAY) ], + [ '5, auto', false ], + [ '3, 5', self::FAKE_TIME_NOW - (5 * self::SECONDS_PER_DAY) ], + [ '10, 3', self::FAKE_TIME_NOW - (10 * self::SECONDS_PER_DAY) ], ]; } - /** - * @dataProvider timestampTestData - * - * @param string $configValue - * @param int $expectedMaxAgeTimestamp - */ - public function testGetMaxAgeAsTimestamp($configValue, $expectedMaxAgeTimestamp) { + #[\PHPUnit\Framework\Attributes\DataProvider('timestampTestData')] + public function testGetMaxAgeAsTimestamp(string $configValue, bool|int $expectedMaxAgeTimestamp): void { $mockedConfig = $this->getMockedConfig($configValue); $mockedTimeFactory = $this->getMockedTimeFactory( - self::FAKE_TIME_NOW + self::FAKE_TIME_NOW ); $expiration = new Expiration($mockedConfig, $mockedTimeFactory); @@ -150,10 +121,9 @@ class ExpirationTest extends \Test\TestCase { } /** - * @param int $time * @return ITimeFactory|MockObject */ - private function getMockedTimeFactory($time) { + private function getMockedTimeFactory(int $time) { $mockedTimeFactory = $this->createMock(ITimeFactory::class); $mockedTimeFactory->expects($this->any()) ->method('getTime') @@ -163,10 +133,9 @@ class ExpirationTest extends \Test\TestCase { } /** - * @param string $returnValue * @return IConfig|MockObject */ - private function getMockedConfig($returnValue) { + private function getMockedConfig(string $returnValue) { $mockedConfig = $this->createMock(IConfig::class); $mockedConfig->expects($this->any()) ->method('getSystemValue') |