summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2020-11-11 20:50:23 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2020-11-16 13:19:53 +0000
commit42782ceeba97e0953e2d62a4eb68238203ccd3d6 (patch)
treef47d7036725b536e7d9694ccb0d1c8227c923c43
parent94648f1ecdc567b3ed2a09299d69c487c65811c4 (diff)
downloadnextcloud-server-42782ceeba97e0953e2d62a4eb68238203ccd3d6.tar.gz
nextcloud-server-42782ceeba97e0953e2d62a4eb68238203ccd3d6.zip
Fix unit test for verifying enforced expire date too far in the future
The test should fail if no exception was thrown, and no exception was thrown due to a missing configuration parameter. However, the use of "addToAssertionCount(1)" made the test pass even if no exception was thrown and, therefore, to silently fail. Now the missing configuration parameter was added and the test will fail if the expected exception is not thrown. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
-rw-r--r--tests/lib/Share20/ManagerTest.php13
1 files changed, 5 insertions, 8 deletions
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index aa3f1e93ff0..6a7d6290866 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -852,6 +852,9 @@ class ManagerTest extends \Test\TestCase {
}
public function testValidateExpirationDateEnforceTooFarIntoFuture() {
+ $this->expectException(\OCP\Share\Exceptions\GenericShareException::class);
+ $this->expectExceptionMessage('Can’t set expiration date more than 3 days in the future');
+
$future = new \DateTime();
$future->add(new \DateInterval('P7D'));
@@ -862,16 +865,10 @@ class ManagerTest extends \Test\TestCase {
->willReturnMap([
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '3'],
+ ['core', 'shareapi_default_expire_date', 'no', 'yes'],
]);
- try {
- self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
- $this->addToAssertionCount(1);
- } catch (\OCP\Share\Exceptions\GenericShareException $e) {
- $this->assertEquals('Cannot set expiration date more than 3 days in the future', $e->getMessage());
- $this->assertEquals('Cannot set expiration date more than 3 days in the future', $e->getHint());
- $this->assertEquals(404, $e->getCode());
- }
+ self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
}
public function testValidateExpirationDateEnforceValid() {