Skip to content

Commit d312540

Browse files
committed
test(sharing): resolve sharing timestamp issues in tests
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 5158b43 commit d312540

5 files changed

Lines changed: 52 additions & 36 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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ public function dataGetShare() {
765765
$data[] = [$share, $expected];
766766

767767
// File shared by link with Expire
768-
$expire = \DateTime::createFromFormat('Y-m-d h:i:s', '2000-01-02 01:02:03');
768+
$expire = \DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 23:59:59');
769769
$share = $this->createShare(
770770
101,
771771
IShare::TYPE_LINK,
@@ -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,
@@ -2089,7 +2089,7 @@ public function testCreateShareLinkPublicUploadFile(): void {
20892089
$file = $this->createMock(File::class);
20902090
$file->method('getId')->willReturn(42);
20912091
$file->method('getStorage')->willReturn($storage);
2092-
2092+
20932093
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
20942094
$this->rootFolder->method('get')->with('valid-path')->willReturn($file);
20952095
$this->rootFolder->method('getById')
@@ -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: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ public function testValidateExpirationDateInternalEnforceButNotSetNewShare($shar
11531153
}
11541154

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

11591159
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
@@ -1188,7 +1188,7 @@ public function testValidateExpirationDateInternalEnforceRelaxedDefaultButNotSet
11881188
}
11891189

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

11941194
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
@@ -1239,7 +1239,7 @@ public function testValidateExpirationDateInternalEnforceValid($shareType): void
12391239
$future->setTime(1, 2, 3);
12401240

12411241
$expected = clone $future;
1242-
$expected->setTime(0, 0, 0);
1242+
$expected->setTime(23, 59, 59);
12431243

12441244
$share = $this->manager->newShare();
12451245
$share->setShareType($shareType);
@@ -1281,7 +1281,7 @@ public function testValidateExpirationDateInternalNoDefault($shareType): void {
12811281
$date->setTime(1, 2, 3);
12821282

12831283
$expected = clone $date;
1284-
$expected->setTime(0, 0, 0);
1284+
$expected->setTime(23, 59, 59);
12851285

12861286
$share = $this->manager->newShare();
12871287
$share->setShareType($shareType);
@@ -1325,7 +1325,7 @@ public function testValidateExpirationDateInternalNoDateDefault($shareType): voi
13251325
$share->setShareType($shareType);
13261326

13271327
$expected = new \DateTime('now', $this->timezone);
1328-
$expected->setTime(0, 0);
1328+
$expected->setTime(23, 59, 59);
13291329
$expected->add(new \DateInterval('P3D'));
13301330
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
13311331

@@ -1365,7 +1365,7 @@ public function testValidateExpirationDateInternalDefault($shareType): void {
13651365
$future->setTime(1, 2, 3);
13661366

13671367
$expected = clone $future;
1368-
$expected->setTime(0, 0);
1368+
$expected->setTime(23, 59, 59);
13691369

13701370
$share = $this->manager->newShare();
13711371
$share->setShareType($shareType);
@@ -1404,7 +1404,7 @@ public function testValidateExpirationDateInternalDefault($shareType): void {
14041404
public function testValidateExpirationDateInternalHookModification($shareType): void {
14051405
$nextWeek = new \DateTime('now', $this->timezone);
14061406
$nextWeek->add(new \DateInterval('P7D'));
1407-
$nextWeek->setTime(0, 0, 0);
1407+
$nextWeek->setTime(23, 59, 59);
14081408

14091409
$save = clone $nextWeek;
14101410

@@ -1433,7 +1433,7 @@ public function testValidateExpirationDateInternalHookException($shareType): voi
14331433

14341434
$nextWeek = new \DateTime();
14351435
$nextWeek->add(new \DateInterval('P7D'));
1436-
$nextWeek->setTime(0, 0, 0);
1436+
$nextWeek->setTime(23, 59, 59);
14371437

14381438
$share = $this->manager->newShare();
14391439
$share->setShareType($shareType);
@@ -1532,7 +1532,7 @@ public function testValidateExpirationDateEnforceButNotSetNewShare(): void {
15321532
]);
15331533

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

15381538
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]);
@@ -1553,7 +1553,7 @@ public function testValidateExpirationDateEnforceRelaxedDefaultButNotSetNewShare
15531553
]);
15541554

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

15591559
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]);
@@ -1588,7 +1588,7 @@ public function testValidateExpirationDateEnforceValid(): void {
15881588
$future->setTime(1, 2, 3);
15891589

15901590
$expected = clone $future;
1591-
$expected->setTime(0, 0, 0);
1591+
$expected->setTime(23, 59, 59);
15921592

15931593
$share = $this->manager->newShare();
15941594
$share->setExpirationDate($future);
@@ -1617,7 +1617,7 @@ public function testValidateExpirationDateNoDefault(): void {
16171617
$date->setTime(1, 2, 3);
16181618

16191619
$expected = clone $date;
1620-
$expected->setTime(0, 0);
1620+
$expected->setTime(23, 59, 59);
16211621
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
16221622

16231623
$share = $this->manager->newShare();
@@ -1654,7 +1654,7 @@ public function testValidateExpirationDateNoDateDefault(): void {
16541654

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

16601660
$this->config->method('getAppValue')
@@ -1681,7 +1681,7 @@ public function testValidateExpirationDateDefault(): void {
16811681
$future->setTime(1, 2, 3);
16821682

16831683
$expected = clone $future;
1684-
$expected->setTime(0, 0);
1684+
$expected->setTime(23, 59, 59);
16851685
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
16861686

16871687
$share = $this->manager->newShare();
@@ -1712,7 +1712,7 @@ public function testValidateExpirationNegativeOffsetTimezone(): void {
17121712

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

17181718
$share = $this->manager->newShare();
@@ -1741,7 +1741,7 @@ public function testValidateExpirationDateHookModification(): void {
17411741
$nextWeek->add(new \DateInterval('P7D'));
17421742

17431743
$save = clone $nextWeek;
1744-
$save->setTime(0, 0);
1744+
$save->setTime(23, 59, 59);
17451745
$save->sub(new \DateInterval('P2D'));
17461746
$save->setTimezone(new \DateTimeZone(date_default_timezone_get()));
17471747

@@ -1765,7 +1765,7 @@ public function testValidateExpirationDateHookException(): void {
17651765

17661766
$nextWeek = new \DateTime();
17671767
$nextWeek->add(new \DateInterval('P7D'));
1768-
$nextWeek->setTime(0, 0, 0);
1768+
$nextWeek->setTime(23, 59, 59);
17691769

17701770
$share = $this->manager->newShare();
17711771
$share->setExpirationDate($nextWeek);
@@ -2425,7 +2425,7 @@ public function testCanShare($expected, $sharingEnabled, $disabledForUser): void
24252425
public function testCreateShareUser(): void {
24262426
/** @var Manager&MockObject $manager */
24272427
$manager = $this->createManagerMock()
2428-
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
2428+
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
24292429
->getMock();
24302430

24312431
$shareOwner = $this->createMock(IUser::class);
@@ -2461,6 +2461,10 @@ public function testCreateShareUser(): void {
24612461
$manager->expects($this->once())
24622462
->method('pathCreateChecks')
24632463
->with($path);
2464+
$manager->expects($this->once())
2465+
->method('validateExpirationDateInternal')
2466+
->with($share)
2467+
->willReturnArgument(0);
24642468

24652469
$this->defaultProvider
24662470
->expects($this->once())
@@ -2480,7 +2484,7 @@ public function testCreateShareUser(): void {
24802484

24812485
public function testCreateShareGroup(): void {
24822486
$manager = $this->createManagerMock()
2483-
->setMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks'])
2487+
->setMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
24842488
->getMock();
24852489

24862490
$shareOwner = $this->createMock(IUser::class);
@@ -2516,6 +2520,10 @@ public function testCreateShareGroup(): void {
25162520
$manager->expects($this->once())
25172521
->method('pathCreateChecks')
25182522
->with($path);
2523+
$manager->expects($this->once())
2524+
->method('validateExpirationDateInternal')
2525+
->with($share)
2526+
->willReturnArgument(0);
25192527

25202528
$this->defaultProvider
25212529
->expects($this->once())
@@ -2767,6 +2775,7 @@ public function testCreateShareHookError(): void {
27672775
'generalCreateChecks',
27682776
'userCreateChecks',
27692777
'pathCreateChecks',
2778+
'validateExpirationDateInternal',
27702779
])
27712780
->getMock();
27722781

@@ -2803,6 +2812,10 @@ public function testCreateShareHookError(): void {
28032812
$manager->expects($this->once())
28042813
->method('pathCreateChecks')
28052814
->with($path);
2815+
$manager->expects($this->once())
2816+
->method('validateExpirationDateInternal')
2817+
->with($share)
2818+
->willReturnArgument(0);
28062819

28072820
$share->expects($this->once())
28082821
->method('setShareOwner')
@@ -2827,7 +2840,7 @@ public function testCreateShareHookError(): void {
28272840

28282841
public function testCreateShareOfIncomingFederatedShare(): void {
28292842
$manager = $this->createManagerMock()
2830-
->setMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
2843+
->setMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
28312844
->getMock();
28322845

28332846
$shareOwner = $this->createMock(IUser::class);
@@ -2882,6 +2895,10 @@ public function testCreateShareOfIncomingFederatedShare(): void {
28822895
$manager->expects($this->once())
28832896
->method('pathCreateChecks')
28842897
->with($path);
2898+
$manager->expects($this->once())
2899+
->method('validateExpirationDateInternal')
2900+
->with($share)
2901+
->willReturnArgument(0);
28852902

28862903
$this->defaultProvider
28872904
->expects($this->once())

0 commit comments

Comments
 (0)