mirror of
https://github.com/nextcloud/server.git
synced 2026-05-19 08:25:56 -04:00
test(share): Update expiration date tests for end-of-day time
Update expected values in ManagerTest to reflect the new behavior where share expiration dates are set to 23:59:59 instead of 00:00:00. Signed-off-by: nfebe <fenn25.fn@gmail.com>
This commit is contained in:
parent
2d20ee2e4e
commit
ce0d97b6e5
5 changed files with 51 additions and 35 deletions
|
|
@ -1052,7 +1052,7 @@ class ApiTest extends TestCase {
|
|||
$share1 = $this->shareManager->getShareById($share1->getFullId());
|
||||
|
||||
// date should be changed
|
||||
$dateWithinRange->setTime(0, 0, 0);
|
||||
$dateWithinRange->setTime(23, 59, 59);
|
||||
$dateWithinRange->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
$this->assertEquals($dateWithinRange, $share1->getExpirationDate());
|
||||
|
||||
|
|
@ -1263,7 +1263,7 @@ class ApiTest extends TestCase {
|
|||
|
||||
public static function datesProvider() {
|
||||
$date = new \DateTime();
|
||||
$date->setTime(0, 0);
|
||||
$date->setTime(23, 59, 59);
|
||||
$date->add(new \DateInterval('P5D'));
|
||||
$date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
|
||||
|
|
@ -1325,14 +1325,14 @@ class ApiTest extends TestCase {
|
|||
|
||||
$data = $result->getData();
|
||||
$this->assertTrue(is_string($data['token']));
|
||||
$this->assertEquals($date->format('Y-m-d 00:00:00'), $data['expiration']);
|
||||
$this->assertEquals($date->format('Y-m-d 23:59:59'), $data['expiration']);
|
||||
|
||||
// check for correct link
|
||||
$url = Server::get(IURLGenerator::class)->getAbsoluteURL('/index.php/s/' . $data['token']);
|
||||
$this->assertEquals($url, $data['url']);
|
||||
|
||||
$share = $this->shareManager->getShareById('ocinternal:' . $data['id']);
|
||||
$date->setTime(0, 0, 0);
|
||||
$date->setTime(23, 59, 59);
|
||||
$this->assertEquals($date, $share->getExpirationDate());
|
||||
|
||||
$this->shareManager->deleteShare($share);
|
||||
|
|
|
|||
|
|
@ -773,7 +773,7 @@ class ShareAPIControllerTest extends TestCase {
|
|||
$data['Folder shared with group'] = [$share, $expected, true];
|
||||
|
||||
// File shared by link with Expire
|
||||
$expire = \DateTime::createFromFormat('Y-m-d h:i:s', '2000-01-02 01:02:03');
|
||||
$expire = \DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 23:59:59');
|
||||
$share = [
|
||||
'101',
|
||||
IShare::TYPE_LINK,
|
||||
|
|
@ -807,7 +807,7 @@ class ShareAPIControllerTest extends TestCase {
|
|||
'file_target' => 'target',
|
||||
'file_parent' => 3,
|
||||
'token' => 'token',
|
||||
'expiration' => '2000-01-02 00:00:00',
|
||||
'expiration' => '2000-01-02 23:59:59',
|
||||
'permissions' => 4,
|
||||
'attributes' => null,
|
||||
'stime' => 5,
|
||||
|
|
@ -4504,7 +4504,7 @@ class ShareAPIControllerTest extends TestCase {
|
|||
'permissions' => 1,
|
||||
'stime' => 946684862,
|
||||
'parent' => null,
|
||||
'expiration' => '2001-02-03 00:00:00',
|
||||
'expiration' => '2001-02-03 04:05:06',
|
||||
'token' => null,
|
||||
'uid_file_owner' => 'owner',
|
||||
'displayname_file_owner' => 'owner',
|
||||
|
|
@ -4554,7 +4554,7 @@ class ShareAPIControllerTest extends TestCase {
|
|||
'permissions' => 1,
|
||||
'stime' => 946684862,
|
||||
'parent' => null,
|
||||
'expiration' => '2001-02-03 00:00:00',
|
||||
'expiration' => '2001-02-03 04:05:06',
|
||||
'token' => null,
|
||||
'uid_file_owner' => 'owner',
|
||||
'displayname_file_owner' => 'owner',
|
||||
|
|
|
|||
|
|
@ -99,12 +99,11 @@ class SharesReminderJobTest extends \Test\TestCase {
|
|||
$someMail = 'test@test.com';
|
||||
$noExpirationDate = null;
|
||||
$today = new \DateTime();
|
||||
// For expiration dates, the time is always automatically set to zero by ShareAPIController
|
||||
$today->setTime(0, 0);
|
||||
$nearFuture = new \DateTime();
|
||||
$nearFuture->setTimestamp($today->getTimestamp() + 86400 * 1);
|
||||
// Expiration dates are set to end of day (23:59:59) by the Share Manager
|
||||
$today->setTime(23, 59, 59);
|
||||
$nearFuture = clone $today;
|
||||
$farFuture = new \DateTime();
|
||||
$farFuture->setTimestamp($today->getTimestamp() + 86400 * 2);
|
||||
$farFuture->setTimestamp($today->getTimestamp() + 86400 * 1);
|
||||
$permissionRead = Constants::PERMISSION_READ;
|
||||
$permissionCreate = $permissionRead | Constants::PERMISSION_CREATE;
|
||||
$permissionUpdate = $permissionRead | Constants::PERMISSION_UPDATE;
|
||||
|
|
|
|||
|
|
@ -310,7 +310,7 @@ trait Sharing {
|
|||
$data = simplexml_load_string($this->response->getBody())->data[0];
|
||||
if ((string)$field == 'expiration') {
|
||||
if (!empty($contentExpected)) {
|
||||
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
|
||||
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 23:59:59';
|
||||
}
|
||||
}
|
||||
if (count($data->element) > 0) {
|
||||
|
|
@ -611,7 +611,7 @@ trait Sharing {
|
|||
}
|
||||
|
||||
if ($field === 'expiration' && !empty($contentExpected)) {
|
||||
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
|
||||
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 23:59:59';
|
||||
}
|
||||
|
||||
if ($contentExpected === 'A_NUMBER') {
|
||||
|
|
|
|||
|
|
@ -1199,7 +1199,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
$expected = new \DateTime('now', $this->timezone);
|
||||
$expected->setTime(0, 0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
$expected->add(new \DateInterval('P3D'));
|
||||
|
||||
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
|
||||
|
|
@ -1232,7 +1232,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
$expected = new \DateTime('now', $this->timezone);
|
||||
$expected->setTime(0, 0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
$expected->add(new \DateInterval('P1D'));
|
||||
|
||||
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
|
||||
|
|
@ -1279,7 +1279,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$future->setTime(1, 2, 3);
|
||||
|
||||
$expected = clone $future;
|
||||
$expected->setTime(0, 0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
$share->setShareType($shareType);
|
||||
|
|
@ -1319,7 +1319,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$date->setTime(1, 2, 3);
|
||||
|
||||
$expected = clone $date;
|
||||
$expected->setTime(0, 0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
$share->setShareType($shareType);
|
||||
|
|
@ -1359,7 +1359,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$share->setShareType($shareType);
|
||||
|
||||
$expected = new \DateTime('now', $this->timezone);
|
||||
$expected->setTime(0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
$expected->add(new \DateInterval('P3D'));
|
||||
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
|
||||
|
|
@ -1397,7 +1397,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$future->setTime(1, 2, 3);
|
||||
|
||||
$expected = clone $future;
|
||||
$expected->setTime(0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
$share->setShareType($shareType);
|
||||
|
|
@ -1434,7 +1434,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
public function testValidateExpirationDateInternalHookModification($shareType): void {
|
||||
$nextWeek = new \DateTime('now', $this->timezone);
|
||||
$nextWeek->add(new \DateInterval('P7D'));
|
||||
$nextWeek->setTime(0, 0, 0);
|
||||
$nextWeek->setTime(23, 59, 59);
|
||||
|
||||
$save = clone $nextWeek;
|
||||
|
||||
|
|
@ -1461,7 +1461,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
$nextWeek = new \DateTime();
|
||||
$nextWeek->add(new \DateInterval('P7D'));
|
||||
$nextWeek->setTime(0, 0, 0);
|
||||
$nextWeek->setTime(23, 59, 59);
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
$share->setShareType($shareType);
|
||||
|
|
@ -1562,7 +1562,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
]);
|
||||
|
||||
$expected = new \DateTime('now', $this->timezone);
|
||||
$expected->setTime(0, 0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
$expected->add(new \DateInterval('P3D'));
|
||||
|
||||
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]);
|
||||
|
|
@ -1587,7 +1587,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
]);
|
||||
|
||||
$expected = new \DateTime('now', $this->timezone);
|
||||
$expected->setTime(0, 0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
$expected->add(new \DateInterval('P1D'));
|
||||
|
||||
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]);
|
||||
|
|
@ -1626,7 +1626,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$future->setTime(1, 2, 3);
|
||||
|
||||
$expected = clone $future;
|
||||
$expected->setTime(0, 0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
$share->setExpirationDate($future);
|
||||
|
|
@ -1659,7 +1659,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$date->setTime(1, 2, 3);
|
||||
|
||||
$expected = clone $date;
|
||||
$expected->setTime(0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
|
|
@ -1696,7 +1696,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
$expected = new \DateTime('now', $this->timezone);
|
||||
$expected->add(new \DateInterval('P3D'));
|
||||
$expected->setTime(0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
|
||||
$this->config->method('getAppValue')
|
||||
|
|
@ -1728,7 +1728,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$future->setTime(1, 2, 3);
|
||||
|
||||
$expected = clone $future;
|
||||
$expected->setTime(0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
|
|
@ -1764,7 +1764,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
$expected = clone $future;
|
||||
$expected->setTimezone($this->timezone);
|
||||
$expected->setTime(0, 0);
|
||||
$expected->setTime(23, 59, 59);
|
||||
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
|
|
@ -1798,7 +1798,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$nextWeek->add(new \DateInterval('P7D'));
|
||||
|
||||
$save = clone $nextWeek;
|
||||
$save->setTime(0, 0);
|
||||
$save->setTime(23, 59, 59);
|
||||
$save->sub(new \DateInterval('P2D'));
|
||||
$save->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
|
||||
|
|
@ -1822,7 +1822,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
$nextWeek = new \DateTime();
|
||||
$nextWeek->add(new \DateInterval('P7D'));
|
||||
$nextWeek->setTime(0, 0, 0);
|
||||
$nextWeek->setTime(23, 59, 59);
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
$share->setExpirationDate($nextWeek);
|
||||
|
|
@ -2486,7 +2486,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
public function testCreateShareUser(): void {
|
||||
/** @var Manager&MockObject $manager */
|
||||
$manager = $this->createManagerMock()
|
||||
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
|
||||
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
|
||||
->getMock();
|
||||
|
||||
$shareOwner = $this->createMock(IUser::class);
|
||||
|
|
@ -2521,6 +2521,10 @@ class ManagerTest extends \Test\TestCase {
|
|||
$manager->expects($this->once())
|
||||
->method('pathCreateChecks')
|
||||
->with($path);
|
||||
$manager->expects($this->once())
|
||||
->method('validateExpirationDateInternal')
|
||||
->with($share)
|
||||
->willReturnArgument(0);
|
||||
|
||||
$this->defaultProvider
|
||||
->expects($this->once())
|
||||
|
|
@ -2540,7 +2544,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
public function testCreateShareGroup(): void {
|
||||
$manager = $this->createManagerMock()
|
||||
->onlyMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks'])
|
||||
->onlyMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
|
||||
->getMock();
|
||||
|
||||
$shareOwner = $this->createMock(IUser::class);
|
||||
|
|
@ -2575,6 +2579,10 @@ class ManagerTest extends \Test\TestCase {
|
|||
$manager->expects($this->once())
|
||||
->method('pathCreateChecks')
|
||||
->with($path);
|
||||
$manager->expects($this->once())
|
||||
->method('validateExpirationDateInternal')
|
||||
->with($share)
|
||||
->willReturnArgument(0);
|
||||
|
||||
$this->defaultProvider
|
||||
->expects($this->once())
|
||||
|
|
@ -2806,6 +2814,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
'generalCreateChecks',
|
||||
'userCreateChecks',
|
||||
'pathCreateChecks',
|
||||
'validateExpirationDateInternal',
|
||||
])
|
||||
->getMock();
|
||||
|
||||
|
|
@ -2841,6 +2850,10 @@ class ManagerTest extends \Test\TestCase {
|
|||
$manager->expects($this->once())
|
||||
->method('pathCreateChecks')
|
||||
->with($path);
|
||||
$manager->expects($this->once())
|
||||
->method('validateExpirationDateInternal')
|
||||
->with($share)
|
||||
->willReturnArgument(0);
|
||||
|
||||
$share->expects($this->once())
|
||||
->method('setShareOwner')
|
||||
|
|
@ -2865,7 +2878,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
public function testCreateShareOfIncomingFederatedShare(): void {
|
||||
$manager = $this->createManagerMock()
|
||||
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
|
||||
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
|
||||
->getMock();
|
||||
|
||||
$shareOwner = $this->createMock(IUser::class);
|
||||
|
|
@ -2919,6 +2932,10 @@ class ManagerTest extends \Test\TestCase {
|
|||
$manager->expects($this->once())
|
||||
->method('pathCreateChecks')
|
||||
->with($path);
|
||||
$manager->expects($this->once())
|
||||
->method('validateExpirationDateInternal')
|
||||
->with($share)
|
||||
->willReturnArgument(0);
|
||||
|
||||
$this->defaultProvider
|
||||
->expects($this->once())
|
||||
|
|
|
|||
Loading…
Reference in a new issue