]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix unit test for verifying enforced expire date too far in the future
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Wed, 11 Nov 2020 19:50:23 +0000 (20:50 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Mon, 16 Nov 2020 13:16:49 +0000 (13:16 +0000)
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>
tests/lib/Share20/ManagerTest.php

index ee5b8bc68bf202048af25f1765067348e646ef94..f242e1cd5e241e30b973f7a89a98da2b19a3ec1a 100644 (file)
@@ -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() {