Skip to content

Commit e926b9d

Browse files
nfebeAndyScherzinger
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> Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent 780c99c commit e926b9d

6 files changed

Lines changed: 54 additions & 38 deletions

File tree

apps/files_sharing/tests/ApiTest.php

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

10931093
// date should be changed
1094-
$dateWithinRange->setTime(0, 0, 0);
1094+
$dateWithinRange->setTime(23, 59, 59);
10951095
$dateWithinRange->setTimezone(new \DateTimeZone(date_default_timezone_get()));
10961096
$this->assertEquals($dateWithinRange, $share1->getExpirationDate());
10971097

@@ -1306,7 +1306,7 @@ public function testShareStorageMountPoint(): void {
13061306

13071307
public static function datesProvider() {
13081308
$date = new \DateTime();
1309-
$date->setTime(0, 0);
1309+
$date->setTime(23, 59, 59);
13101310
$date->add(new \DateInterval('P5D'));
13111311
$date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
13121312

@@ -1371,14 +1371,14 @@ public function testCreatePublicLinkExpireDateValid(): void {
13711371

13721372
$data = $result->getData();
13731373
$this->assertTrue(is_string($data['token']));
1374-
$this->assertEquals($date->format('Y-m-d 00:00:00'), $data['expiration']);
1374+
$this->assertEquals($date->format('Y-m-d 23:59:59'), $data['expiration']);
13751375

13761376
// check for correct link
13771377
$url = Server::get(IURLGenerator::class)->getAbsoluteURL('/index.php/s/' . $data['token']);
13781378
$this->assertEquals($url, $data['url']);
13791379

13801380
$share = $this->shareManager->getShareById('ocinternal:' . $data['id']);
1381-
$date->setTime(0, 0, 0);
1381+
$date->setTime(23, 59, 59);
13821382
$this->assertEquals($date, $share->getExpirationDate());
13831383

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

apps/files_sharing/tests/Controller/ShareAPIControllerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,9 @@ public function dataGetShare() {
774774
$data[] = [$share, $expected];
775775

776776
// File shared by link with Expire
777-
$expire = \DateTime::createFromFormat('Y-m-d h:i:s', '2000-01-02 01:02:03');
778-
$share = $this->createShare(
779-
101,
777+
$expire = \DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 23:59:59');
778+
$share = [
779+
'101',
780780
IShare::TYPE_LINK,
781781
null,
782782
'initiatorId',
@@ -808,7 +808,7 @@ public function dataGetShare() {
808808
'file_target' => 'target',
809809
'file_parent' => 3,
810810
'token' => 'token',
811-
'expiration' => '2000-01-02 00:00:00',
811+
'expiration' => '2000-01-02 23:59:59',
812812
'permissions' => 4,
813813
'attributes' => null,
814814
'stime' => 5,
@@ -4481,7 +4481,7 @@ public function dataFormatShare() {
44814481
'permissions' => 1,
44824482
'stime' => 946684862,
44834483
'parent' => null,
4484-
'expiration' => '2001-02-03 00:00:00',
4484+
'expiration' => '2001-02-03 04:05:06',
44854485
'token' => null,
44864486
'uid_file_owner' => 'owner',
44874487
'displayname_file_owner' => 'owner',
@@ -4535,7 +4535,7 @@ public function dataFormatShare() {
45354535
'permissions' => 1,
45364536
'stime' => 946684862,
45374537
'parent' => null,
4538-
'expiration' => '2001-02-03 00:00:00',
4538+
'expiration' => '2001-02-03 04:05:06',
45394539
'token' => null,
45404540
'uid_file_owner' => 'owner',
45414541
'displayname_file_owner' => 'owner',

apps/files_sharing/tests/SharesReminderJobTest.php

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

autotest.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function execute_tests {
309309
if [ ! -z "$USEDOCKER" ] ; then
310310
echo "Fire up the postgres docker"
311311
DOCKER_CONTAINER_ID=$(docker run -e POSTGRES_DB="$DATABASENAME" -e POSTGRES_USER="$DATABASEUSER" -e POSTGRES_PASSWORD=owncloud -d postgres)
312-
DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID")
312+
DATABASEHOST=$(docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" "$DOCKER_CONTAINER_ID")
313313

314314
echo "Waiting for Postgres initialisation ..."
315315

build/integration/features/bootstrap/Sharing.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public function isFieldInResponse($field, $contentExpected) {
318318
$data = simplexml_load_string($this->response->getBody())->data[0];
319319
if ((string)$field == 'expiration') {
320320
if (!empty($contentExpected)) {
321-
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
321+
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 23:59:59';
322322
}
323323
}
324324
if (count($data->element) > 0) {
@@ -619,7 +619,7 @@ private function assertFieldIsInReturnedShare(string $field, string $contentExpe
619619
}
620620

621621
if ($field === 'expiration' && !empty($contentExpected)) {
622-
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
622+
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 23:59:59';
623623
}
624624

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

tests/lib/Share20/ManagerTest.php

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ public function testValidateExpirationDateInternalEnforceButNotSetNewShare($shar
12931293
}
12941294

12951295
$expected = new \DateTime('now', $this->timezone);
1296-
$expected->setTime(0, 0, 0);
1296+
$expected->setTime(23, 59, 59);
12971297
$expected->add(new \DateInterval('P3D'));
12981298

12991299
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
@@ -1326,7 +1326,7 @@ public function testValidateExpirationDateInternalEnforceRelaxedDefaultButNotSet
13261326
}
13271327

13281328
$expected = new \DateTime('now', $this->timezone);
1329-
$expected->setTime(0, 0, 0);
1329+
$expected->setTime(23, 59, 59);
13301330
$expected->add(new \DateInterval('P1D'));
13311331

13321332
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
@@ -1373,7 +1373,7 @@ public function testValidateExpirationDateInternalEnforceValid($shareType): void
13731373
$future->setTime(1, 2, 3);
13741374

13751375
$expected = clone $future;
1376-
$expected->setTime(0, 0, 0);
1376+
$expected->setTime(23, 59, 59);
13771377

13781378
$share = $this->manager->newShare();
13791379
$share->setShareType($shareType);
@@ -1413,7 +1413,7 @@ public function testValidateExpirationDateInternalNoDefault($shareType): void {
14131413
$date->setTime(1, 2, 3);
14141414

14151415
$expected = clone $date;
1416-
$expected->setTime(0, 0, 0);
1416+
$expected->setTime(23, 59, 59);
14171417

14181418
$share = $this->manager->newShare();
14191419
$share->setShareType($shareType);
@@ -1453,7 +1453,7 @@ public function testValidateExpirationDateInternalNoDateDefault($shareType): voi
14531453
$share->setShareType($shareType);
14541454

14551455
$expected = new \DateTime('now', $this->timezone);
1456-
$expected->setTime(0, 0);
1456+
$expected->setTime(23, 59, 59);
14571457
$expected->add(new \DateInterval('P3D'));
14581458
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
14591459

@@ -1491,7 +1491,7 @@ public function testValidateExpirationDateInternalDefault($shareType): void {
14911491
$future->setTime(1, 2, 3);
14921492

14931493
$expected = clone $future;
1494-
$expected->setTime(0, 0);
1494+
$expected->setTime(23, 59, 59);
14951495

14961496
$share = $this->manager->newShare();
14971497
$share->setShareType($shareType);
@@ -1528,7 +1528,7 @@ public function testValidateExpirationDateInternalDefault($shareType): void {
15281528
public function testValidateExpirationDateInternalHookModification($shareType): void {
15291529
$nextWeek = new \DateTime('now', $this->timezone);
15301530
$nextWeek->add(new \DateInterval('P7D'));
1531-
$nextWeek->setTime(0, 0, 0);
1531+
$nextWeek->setTime(23, 59, 59);
15321532

15331533
$save = clone $nextWeek;
15341534

@@ -1555,7 +1555,7 @@ public function testValidateExpirationDateInternalHookException($shareType): voi
15551555

15561556
$nextWeek = new \DateTime();
15571557
$nextWeek->add(new \DateInterval('P7D'));
1558-
$nextWeek->setTime(0, 0, 0);
1558+
$nextWeek->setTime(23, 59, 59);
15591559

15601560
$share = $this->manager->newShare();
15611561
$share->setShareType($shareType);
@@ -1656,7 +1656,7 @@ public function testValidateExpirationDateEnforceButNotSetNewShare(): void {
16561656
]);
16571657

16581658
$expected = new \DateTime('now', $this->timezone);
1659-
$expected->setTime(0, 0, 0);
1659+
$expected->setTime(23, 59, 59);
16601660
$expected->add(new \DateInterval('P3D'));
16611661

16621662
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]);
@@ -1681,7 +1681,7 @@ public function testValidateExpirationDateEnforceRelaxedDefaultButNotSetNewShare
16811681
]);
16821682

16831683
$expected = new \DateTime('now', $this->timezone);
1684-
$expected->setTime(0, 0, 0);
1684+
$expected->setTime(23, 59, 59);
16851685
$expected->add(new \DateInterval('P1D'));
16861686

16871687
self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]);
@@ -1720,7 +1720,7 @@ public function testValidateExpirationDateEnforceValid(): void {
17201720
$future->setTime(1, 2, 3);
17211721

17221722
$expected = clone $future;
1723-
$expected->setTime(0, 0, 0);
1723+
$expected->setTime(23, 59, 59);
17241724

17251725
$share = $this->manager->newShare();
17261726
$share->setExpirationDate($future);
@@ -1753,7 +1753,7 @@ public function testValidateExpirationDateNoDefault(): void {
17531753
$date->setTime(1, 2, 3);
17541754

17551755
$expected = clone $date;
1756-
$expected->setTime(0, 0);
1756+
$expected->setTime(23, 59, 59);
17571757
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
17581758

17591759
$share = $this->manager->newShare();
@@ -1790,7 +1790,7 @@ public function testValidateExpirationDateNoDateDefault(): void {
17901790

17911791
$expected = new \DateTime('now', $this->timezone);
17921792
$expected->add(new \DateInterval('P3D'));
1793-
$expected->setTime(0, 0);
1793+
$expected->setTime(23, 59, 59);
17941794
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
17951795

17961796
$this->config->method('getAppValue')
@@ -1822,7 +1822,7 @@ public function testValidateExpirationDateDefault(): void {
18221822
$future->setTime(1, 2, 3);
18231823

18241824
$expected = clone $future;
1825-
$expected->setTime(0, 0);
1825+
$expected->setTime(23, 59, 59);
18261826
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
18271827

18281828
$share = $this->manager->newShare();
@@ -1858,7 +1858,7 @@ public function testValidateExpirationNegativeOffsetTimezone(): void {
18581858

18591859
$expected = clone $future;
18601860
$expected->setTimezone($this->timezone);
1861-
$expected->setTime(0, 0);
1861+
$expected->setTime(23, 59, 59);
18621862
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
18631863

18641864
$share = $this->manager->newShare();
@@ -1892,7 +1892,7 @@ public function testValidateExpirationDateHookModification(): void {
18921892
$nextWeek->add(new \DateInterval('P7D'));
18931893

18941894
$save = clone $nextWeek;
1895-
$save->setTime(0, 0);
1895+
$save->setTime(23, 59, 59);
18961896
$save->sub(new \DateInterval('P2D'));
18971897
$save->setTimezone(new \DateTimeZone(date_default_timezone_get()));
18981898

@@ -1916,7 +1916,7 @@ public function testValidateExpirationDateHookException(): void {
19161916

19171917
$nextWeek = new \DateTime();
19181918
$nextWeek->add(new \DateInterval('P7D'));
1919-
$nextWeek->setTime(0, 0, 0);
1919+
$nextWeek->setTime(23, 59, 59);
19201920

19211921
$share = $this->manager->newShare();
19221922
$share->setExpirationDate($nextWeek);
@@ -2580,7 +2580,7 @@ public function testCanShare($expected, $sharingEnabled, $disabledForUser): void
25802580
public function testCreateShareUser(): void {
25812581
/** @var Manager&MockObject $manager */
25822582
$manager = $this->createManagerMock()
2583-
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
2583+
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
25842584
->getMock();
25852585

25862586
$shareOwner = $this->createMock(IUser::class);
@@ -2616,6 +2616,10 @@ public function testCreateShareUser(): void {
26162616
$manager->expects($this->once())
26172617
->method('pathCreateChecks')
26182618
->with($path);
2619+
$manager->expects($this->once())
2620+
->method('validateExpirationDateInternal')
2621+
->with($share)
2622+
->willReturnArgument(0);
26192623

26202624
$this->defaultProvider
26212625
->expects($this->once())
@@ -2635,7 +2639,7 @@ public function testCreateShareUser(): void {
26352639

26362640
public function testCreateShareGroup(): void {
26372641
$manager = $this->createManagerMock()
2638-
->onlyMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks'])
2642+
->onlyMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
26392643
->getMock();
26402644

26412645
$shareOwner = $this->createMock(IUser::class);
@@ -2671,6 +2675,10 @@ public function testCreateShareGroup(): void {
26712675
$manager->expects($this->once())
26722676
->method('pathCreateChecks')
26732677
->with($path);
2678+
$manager->expects($this->once())
2679+
->method('validateExpirationDateInternal')
2680+
->with($share)
2681+
->willReturnArgument(0);
26742682

26752683
$this->defaultProvider
26762684
->expects($this->once())
@@ -2904,6 +2912,7 @@ public function testCreateShareHookError(): void {
29042912
'generalCreateChecks',
29052913
'userCreateChecks',
29062914
'pathCreateChecks',
2915+
'validateExpirationDateInternal',
29072916
])
29082917
->getMock();
29092918

@@ -2940,6 +2949,10 @@ public function testCreateShareHookError(): void {
29402949
$manager->expects($this->once())
29412950
->method('pathCreateChecks')
29422951
->with($path);
2952+
$manager->expects($this->once())
2953+
->method('validateExpirationDateInternal')
2954+
->with($share)
2955+
->willReturnArgument(0);
29432956

29442957
$share->expects($this->once())
29452958
->method('setShareOwner')
@@ -2964,7 +2977,7 @@ public function testCreateShareHookError(): void {
29642977

29652978
public function testCreateShareOfIncomingFederatedShare(): void {
29662979
$manager = $this->createManagerMock()
2967-
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
2980+
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
29682981
->getMock();
29692982

29702983
$shareOwner = $this->createMock(IUser::class);
@@ -3019,6 +3032,10 @@ public function testCreateShareOfIncomingFederatedShare(): void {
30193032
$manager->expects($this->once())
30203033
->method('pathCreateChecks')
30213034
->with($path);
3035+
$manager->expects($this->once())
3036+
->method('validateExpirationDateInternal')
3037+
->with($share)
3038+
->willReturnArgument(0);
30223039

30233040
$this->defaultProvider
30243041
->expects($this->once())

0 commit comments

Comments
 (0)