diff options
author | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2015-08-05 01:00:42 +0300 |
---|---|---|
committer | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2015-08-10 23:54:44 +0300 |
commit | 33c29d3da75447da6a659239e8a2b60c72230588 (patch) | |
tree | 00fc25a66474e67b305f14c8f1d118c4c7a1f504 /apps/files_trashbin/tests | |
parent | 4ef26157880f5cd5d5bd27abe0a6991d7c8a415a (diff) | |
download | nextcloud-server-33c29d3da75447da6a659239e8a2b60c72230588.tar.gz nextcloud-server-33c29d3da75447da6a659239e8a2b60c72230588.zip |
Migrate settings
Diffstat (limited to 'apps/files_trashbin/tests')
-rw-r--r-- | apps/files_trashbin/tests/expiration.php | 87 |
1 files changed, 71 insertions, 16 deletions
diff --git a/apps/files_trashbin/tests/expiration.php b/apps/files_trashbin/tests/expiration.php index 68fd32c911b..7bd51dccddd 100644 --- a/apps/files_trashbin/tests/expiration.php +++ b/apps/files_trashbin/tests/expiration.php @@ -98,11 +98,78 @@ class Expiration_Test extends \PHPUnit_Framework_TestCase { * @param string $expectedResult */ public function testExpiration($retentionObligation, $timeNow, $timestamp, $quotaExceeded, $expectedResult){ + $mockedConfig = $this->getMockedConfig($retentionObligation); + $mockedTimeFactory = $this->getMockedTimeFactory($timeNow); + + $expiration = new Expiration($mockedConfig, $mockedTimeFactory); + $actualResult = $expiration->isExpired($timestamp, $quotaExceeded); + + $this->assertEquals($expectedResult, $actualResult); + } + + + public function configData(){ + 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 ], + ]; + } + + + /** + * @dataProvider configData + * + * @param string $configValue + * @param int $expectedMinAge + * @param int $expectedMaxAge + * @param bool $expectedCanPurgeToSaveSpace + */ + public function testParseRetentionObligation($configValue, $expectedMinAge, $expectedMaxAge, $expectedCanPurgeToSaveSpace){ + $mockedConfig = $this->getMockedConfig($configValue); + $mockedTimeFactory = $this->getMockedTimeFactory( + time() + ); + + $expiration = new Expiration($mockedConfig, $mockedTimeFactory); + $this->assertAttributeEquals($expectedMinAge, 'minAge', $expiration); + $this->assertAttributeEquals($expectedMaxAge, 'maxAge', $expiration); + $this->assertAttributeEquals($expectedCanPurgeToSaveSpace, 'canPurgeToSaveSpace', $expiration); + } + + /** + * + * @param int $time + * @return \OCP\AppFramework\Utility\ITimeFactory + */ + private function getMockedTimeFactory($time){ + $mockedTimeFactory = $this->getMockBuilder('\OCP\AppFramework\Utility\ITimeFactory') + ->disableOriginalConstructor() + ->setMethods(['getTime']) + ->getMock() + ; + $mockedTimeFactory->expects($this->any())->method('getTime')->will( + $this->returnValue($time) + ); + + return $mockedTimeFactory; + } + + /** + * + * @param string $returnValue + * @return \OCP\IConfig + */ + private function getMockedConfig($returnValue){ $mockedConfig = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor() ->setMethods( [ - 'getValue', 'setSystemValues', 'setSystemValue', 'getSystemValue', @@ -124,22 +191,10 @@ class Expiration_Test extends \PHPUnit_Framework_TestCase { ) ->getMock() ; - $mockedConfig->expects($this->any())->method('getValue')->will( - $this->returnValue($retentionObligation) + $mockedConfig->expects($this->any())->method('getSystemValue')->will( + $this->returnValue($returnValue) ); - $mockedTimeFactory = $this->getMockBuilder('\OCP\AppFramework\Utility\ITimeFactory') - ->disableOriginalConstructor() - ->setMethods(['getTime']) - ->getMock() - ; - $mockedTimeFactory->expects($this->any())->method('getTime')->will( - $this->returnValue($timeNow) - ); - - $expiration = new Expiration($mockedConfig, $mockedTimeFactory); - $actualResult = $expiration->isExpired($timestamp, $quotaExceeded); - - $this->assertEquals($expectedResult, $actualResult); + return $mockedConfig; } } |