Skip to content

Commit e041c98

Browse files
nfebebackportbot[bot]
authored andcommitted
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> [skip ci]
1 parent 941ff54 commit e041c98

5 files changed

Lines changed: 48 additions & 32 deletions

File tree

‎apps/files_sharing/tests/ApiTest.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ public function testUpdateShareExpireDate(): void {
10651065
$share1 = $this->shareManager->getShareById($share1->getFullId());
10661066

10671067
// date should be changed
1068-
$dateWithinRange->setTime(0, 0, 0);
1068+
$dateWithinRange->setTime(23, 59, 59);
10691069
$dateWithinRange->setTimezone(new \DateTimeZone(date_default_timezone_get()));
10701070
$this->assertEquals($dateWithinRange, $share1->getExpirationDate());
10711071

@@ -1280,7 +1280,7 @@ public function testShareStorageMountPoint(): void {
12801280

12811281
public function datesProvider() {
12821282
$date = new \DateTime();
1283-
$date->setTime(0, 0);
1283+
$date->setTime(23, 59, 59);
12841284
$date->add(new \DateInterval('P5D'));
12851285
$date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
12861286

@@ -1345,14 +1345,14 @@ public function testCreatePublicLinkExpireDateValid(): void {
13451345

13461346
$data = $result->getData();
13471347
$this->assertTrue(is_string($data['token']));
1348-
$this->assertEquals($date->format('Y-m-d 00:00:00'), $data['expiration']);
1348+
$this->assertEquals($date->format('Y-m-d 23:59:59'), $data['expiration']);
13491349

13501350
// check for correct link
13511351
$url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']);
13521352
$this->assertEquals($url, $data['url']);
13531353

13541354
$share = $this->shareManager->getShareById('ocinternal:' . $data['id']);
1355-
$date->setTime(0, 0, 0);
1355+
$date->setTime(23, 59, 59);
13561356
$this->assertEquals($date, $share->getExpirationDate());
13571357

13581358
$this->shareManager->deleteShare($share);

‎apps/files_sharing/tests/Controller/ShareAPIControllerTest.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ public function dataGetShare() {
799799
'file_target' => 'target',
800800
'file_parent' => 3,
801801
'token' => 'token',
802-
'expiration' => '2000-01-02 00:00:00',
802+
'expiration' => '2000-01-02 23:59:59',
803803
'permissions' => 4,
804804
'attributes' => null,
805805
'stime' => 5,
@@ -4430,7 +4430,7 @@ public function dataFormatShare() {
44304430
'permissions' => 1,
44314431
'stime' => 946684862,
44324432
'parent' => null,
4433-
'expiration' => '2001-02-03 00:00:00',
4433+
'expiration' => '2001-02-03 04:05:06',
44344434
'token' => null,
44354435
'uid_file_owner' => 'owner',
44364436
'displayname_file_owner' => 'owner',
@@ -4484,7 +4484,7 @@ public function dataFormatShare() {
44844484
'permissions' => 1,
44854485
'stime' => 946684862,
44864486
'parent' => null,
4487-
'expiration' => '2001-02-03 00:00:00',
4487+
'expiration' => '2001-02-03 04:05:06',
44884488
'token' => null,
44894489
'uid_file_owner' => 'owner',
44904490
'displayname_file_owner' => 'owner',

‎apps/files_sharing/tests/SharesReminderJobTest.php‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,11 @@ public function dataSharesReminder() {
9898
$someMail = 'test@test.com';
9999
$noExpirationDate = null;
100100
$today = new \DateTime();
101-
// For expiration dates, the time is always automatically set to zero by ShareAPIController
102-
$today->setTime(0, 0);
103-
$nearFuture = new \DateTime();
104-
$nearFuture->setTimestamp($today->getTimestamp() + 86400 * 1);
101+
// Expiration dates are set to end of day (23:59:59) by the Share Manager
102+
$today->setTime(23, 59, 59);
103+
$nearFuture = clone $today;
105104
$farFuture = new \DateTime();
106-
$farFuture->setTimestamp($today->getTimestamp() + 86400 * 2);
105+
$farFuture->setTimestamp($today->getTimestamp() + 86400 * 1);
107106
$permissionRead = Constants::PERMISSION_READ;
108107
$permissionCreate = $permissionRead | Constants::PERMISSION_CREATE;
109108
$permissionUpdate = $permissionRead | Constants::PERMISSION_UPDATE;

‎build/integration/features/bootstrap/Sharing.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public function isFieldInResponse($field, $contentExpected) {
308308
$data = simplexml_load_string($this->response->getBody())->data[0];
309309
if ((string)$field == 'expiration') {
310310
if (!empty($contentExpected)) {
311-
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
311+
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 23:59:59';
312312
}
313313
}
314314
if (count($data->element) > 0) {
@@ -607,7 +607,7 @@ private function assertFieldIsInReturnedShare(string $field, string $contentExpe
607607
}
608608

609609
if ($field === 'expiration' && !empty($contentExpected)) {
610-
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
610+
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 23:59:59';
611611
}
612612

613613
if ($contentExpected === 'A_NUMBER') {

‎tests/lib/Share20/ManagerTest.php‎

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ public function testValidateExpirationDateInternalEnforceButNotSetNewShare($shar
11561156
}
11571157

11581158
$expected = new \DateTime('now', $this->timezone);
1159-
$expected->setTime(0, 0, 0);
1159+
$expected->setTime(23, 59, 59);
11601160
$expected->add(new \DateInterval('P3D'));
11611161

11621162
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
@@ -1191,7 +1191,7 @@ public function testValidateExpirationDateInternalEnforceRelaxedDefaultButNotSet
11911191
}
11921192

11931193
$expected = new \DateTime('now', $this->timezone);
1194-
$expected->setTime(0, 0, 0);
1194+
$expected->setTime(23, 59, 59);
11951195
$expected->add(new \DateInterval('P1D'));
11961196

11971197
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
@@ -1242,7 +1242,7 @@ public function testValidateExpirationDateInternalEnforceValid($shareType): void
12421242
$future->setTime(1, 2, 3);
12431243

12441244
$expected = clone $future;
1245-
$expected->setTime(0, 0, 0);
1245+
$expected->setTime(23, 59, 59);
12461246

12471247
$share = $this->manager->newShare();
12481248
$share->setShareType($shareType);
@@ -1284,7 +1284,7 @@ public function testValidateExpirationDateInternalNoDefault($shareType): void {
12841284
$date->setTime(1, 2, 3);
12851285

12861286
$expected = clone $date;
1287-
$expected->setTime(0, 0, 0);
1287+
$expected->setTime(23, 59, 59);
12881288

12891289
$share = $this->manager->newShare();
12901290
$share->setShareType($shareType);
@@ -1328,7 +1328,7 @@ public function testValidateExpirationDateInternalNoDateDefault($shareType): voi
13281328
$share->setShareType($shareType);
13291329

13301330
$expected = new \DateTime('now', $this->timezone);
1331-
$expected->setTime(0, 0);
1331+
$expected->setTime(23, 59, 59);
13321332
$expected->add(new \DateInterval('P3D'));
13331333
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
13341334

@@ -1368,7 +1368,7 @@ public function testValidateExpirationDateInternalDefault($shareType): void {
13681368
$future->setTime(1, 2, 3);
13691369

13701370
$expected = clone $future;
1371-
$expected->setTime(0, 0);
1371+
$expected->setTime(23, 59, 59);
13721372

13731373
$share = $this->manager->newShare();
13741374
$share->setShareType($shareType);
@@ -1407,7 +1407,7 @@ public function testValidateExpirationDateInternalDefault($shareType): void {
14071407
public function testValidateExpirationDateInternalHookModification($shareType): void {
14081408
$nextWeek = new \DateTime('now', $this->timezone);
14091409
$nextWeek->add(new \DateInterval('P7D'));
1410-
$nextWeek->setTime(0, 0, 0);
1410+
$nextWeek->setTime(23, 59, 59);
14111411

14121412
$save = clone $nextWeek;
14131413

@@ -1436,7 +1436,7 @@ public function testValidateExpirationDateInternalHookException($shareType): voi
14361436

14371437
$nextWeek = new \DateTime();
14381438
$nextWeek->add(new \DateInterval('P7D'));
1439-
$nextWeek->setTime(0, 0, 0);
1439+
$nextWeek->setTime(23, 59, 59);
14401440

14411441
$share = $this->manager->newShare();
14421442
$share->setShareType($shareType);
@@ -1535,7 +1535,7 @@ public function testValidateExpirationDateEnforceButNotSetNewShare(): void {
15351535
]);
15361536

15371537
$expected = new \DateTime('now', $this->timezone);
1538-
$expected->setTime(0, 0, 0);
1538+
$expected->setTime(23, 59, 59);
15391539
$expected->add(new \DateInterval('P3D'));
15401540

15411541
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]);
@@ -1556,7 +1556,7 @@ public function testValidateExpirationDateEnforceRelaxedDefaultButNotSetNewShare
15561556
]);
15571557

15581558
$expected = new \DateTime('now', $this->timezone);
1559-
$expected->setTime(0, 0, 0);
1559+
$expected->setTime(23, 59, 59);
15601560
$expected->add(new \DateInterval('P1D'));
15611561

15621562
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]);
@@ -1591,7 +1591,7 @@ public function testValidateExpirationDateEnforceValid(): void {
15911591
$future->setTime(1, 2, 3);
15921592

15931593
$expected = clone $future;
1594-
$expected->setTime(0, 0, 0);
1594+
$expected->setTime(23, 59, 59);
15951595

15961596
$share = $this->manager->newShare();
15971597
$share->setExpirationDate($future);
@@ -1620,7 +1620,7 @@ public function testValidateExpirationDateNoDefault(): void {
16201620
$date->setTime(1, 2, 3);
16211621

16221622
$expected = clone $date;
1623-
$expected->setTime(0, 0);
1623+
$expected->setTime(23, 59, 59);
16241624
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
16251625

16261626
$share = $this->manager->newShare();
@@ -1657,7 +1657,7 @@ public function testValidateExpirationDateNoDateDefault(): void {
16571657

16581658
$expected = new \DateTime('now', $this->timezone);
16591659
$expected->add(new \DateInterval('P3D'));
1660-
$expected->setTime(0, 0);
1660+
$expected->setTime(23, 59, 59);
16611661
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
16621662

16631663
$this->config->method('getAppValue')
@@ -1684,7 +1684,7 @@ public function testValidateExpirationDateDefault(): void {
16841684
$future->setTime(1, 2, 3);
16851685

16861686
$expected = clone $future;
1687-
$expected->setTime(0, 0);
1687+
$expected->setTime(23, 59, 59);
16881688
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
16891689

16901690
$share = $this->manager->newShare();
@@ -1715,7 +1715,7 @@ public function testValidateExpirationNegativeOffsetTimezone(): void {
17151715

17161716
$expected = clone $future;
17171717
$expected->setTimezone($this->timezone);
1718-
$expected->setTime(0, 0);
1718+
$expected->setTime(23, 59, 59);
17191719
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
17201720

17211721
$share = $this->manager->newShare();
@@ -1744,7 +1744,7 @@ public function testValidateExpirationDateHookModification(): void {
17441744
$nextWeek->add(new \DateInterval('P7D'));
17451745

17461746
$save = clone $nextWeek;
1747-
$save->setTime(0, 0);
1747+
$save->setTime(23, 59, 59);
17481748
$save->sub(new \DateInterval('P2D'));
17491749
$save->setTimezone(new \DateTimeZone(date_default_timezone_get()));
17501750

@@ -1768,7 +1768,7 @@ public function testValidateExpirationDateHookException(): void {
17681768

17691769
$nextWeek = new \DateTime();
17701770
$nextWeek->add(new \DateInterval('P7D'));
1771-
$nextWeek->setTime(0, 0, 0);
1771+
$nextWeek->setTime(23, 59, 59);
17721772

17731773
$share = $this->manager->newShare();
17741774
$share->setExpirationDate($nextWeek);
@@ -2428,7 +2428,7 @@ public function testCanShare($expected, $sharingEnabled, $disabledForUser): void
24282428
public function testCreateShareUser(): void {
24292429
/** @var Manager&MockObject $manager */
24302430
$manager = $this->createManagerMock()
2431-
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
2431+
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
24322432
->getMock();
24332433

24342434
$shareOwner = $this->createMock(IUser::class);
@@ -2464,6 +2464,10 @@ public function testCreateShareUser(): void {
24642464
$manager->expects($this->once())
24652465
->method('pathCreateChecks')
24662466
->with($path);
2467+
$manager->expects($this->once())
2468+
->method('validateExpirationDateInternal')
2469+
->with($share)
2470+
->willReturnArgument(0);
24672471

24682472
$this->defaultProvider
24692473
->expects($this->once())
@@ -2519,6 +2523,10 @@ public function testCreateShareGroup(): void {
25192523
$manager->expects($this->once())
25202524
->method('pathCreateChecks')
25212525
->with($path);
2526+
$manager->expects($this->once())
2527+
->method('validateExpirationDateInternal')
2528+
->with($share)
2529+
->willReturnArgument(0);
25222530

25232531
$this->defaultProvider
25242532
->expects($this->once())
@@ -2770,6 +2778,7 @@ public function testCreateShareHookError(): void {
27702778
'generalCreateChecks',
27712779
'userCreateChecks',
27722780
'pathCreateChecks',
2781+
'validateExpirationDateInternal',
27732782
])
27742783
->getMock();
27752784

@@ -2806,6 +2815,10 @@ public function testCreateShareHookError(): void {
28062815
$manager->expects($this->once())
28072816
->method('pathCreateChecks')
28082817
->with($path);
2818+
$manager->expects($this->once())
2819+
->method('validateExpirationDateInternal')
2820+
->with($share)
2821+
->willReturnArgument(0);
28092822

28102823
$share->expects($this->once())
28112824
->method('setShareOwner')
@@ -2885,6 +2898,10 @@ public function testCreateShareOfIncomingFederatedShare(): void {
28852898
$manager->expects($this->once())
28862899
->method('pathCreateChecks')
28872900
->with($path);
2901+
$manager->expects($this->once())
2902+
->method('validateExpirationDateInternal')
2903+
->with($share)
2904+
->willReturnArgument(0);
28882905

28892906
$this->defaultProvider
28902907
->expects($this->once())

0 commit comments

Comments
 (0)