Skip to content

Commit 0535b10

Browse files
nfebeCarlSchwan
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 f91bc05 commit 0535b10

File tree

6 files changed

+54
-38
lines changed

6 files changed

+54
-38
lines changed

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
@@ -309,7 +309,7 @@ public function isFieldInResponse($field, $contentExpected) {
309309
$data = simplexml_load_string($this->response->getBody())->data[0];
310310
if ((string)$field == 'expiration') {
311311
if (!empty($contentExpected)) {
312-
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
312+
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 23:59:59';
313313
}
314314
}
315315
if (count($data->element) > 0) {
@@ -610,7 +610,7 @@ private function assertFieldIsInReturnedShare(string $field, string $contentExpe
610610
}
611611

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

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

tests/lib/Share20/ManagerTest.php

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

11671167
$expected = new \DateTime('now', $this->timezone);
1168-
$expected->setTime(0, 0, 0);
1168+
$expected->setTime(23, 59, 59);
11691169
$expected->add(new \DateInterval('P3D'));
11701170

11711171
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
@@ -1198,7 +1198,7 @@ public function testValidateExpirationDateInternalEnforceRelaxedDefaultButNotSet
11981198
}
11991199

12001200
$expected = new \DateTime('now', $this->timezone);
1201-
$expected->setTime(0, 0, 0);
1201+
$expected->setTime(23, 59, 59);
12021202
$expected->add(new \DateInterval('P1D'));
12031203

12041204
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
@@ -1245,7 +1245,7 @@ public function testValidateExpirationDateInternalEnforceValid($shareType): void
12451245
$future->setTime(1, 2, 3);
12461246

12471247
$expected = clone $future;
1248-
$expected->setTime(0, 0, 0);
1248+
$expected->setTime(23, 59, 59);
12491249

12501250
$share = $this->manager->newShare();
12511251
$share->setShareType($shareType);
@@ -1285,7 +1285,7 @@ public function testValidateExpirationDateInternalNoDefault($shareType): void {
12851285
$date->setTime(1, 2, 3);
12861286

12871287
$expected = clone $date;
1288-
$expected->setTime(0, 0, 0);
1288+
$expected->setTime(23, 59, 59);
12891289

12901290
$share = $this->manager->newShare();
12911291
$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

@@ -1363,7 +1363,7 @@ public function testValidateExpirationDateInternalDefault($shareType): void {
13631363
$future->setTime(1, 2, 3);
13641364

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

13681368
$share = $this->manager->newShare();
13691369
$share->setShareType($shareType);
@@ -1400,7 +1400,7 @@ public function testValidateExpirationDateInternalDefault($shareType): void {
14001400
public function testValidateExpirationDateInternalHookModification($shareType): void {
14011401
$nextWeek = new \DateTime('now', $this->timezone);
14021402
$nextWeek->add(new \DateInterval('P7D'));
1403-
$nextWeek->setTime(0, 0, 0);
1403+
$nextWeek->setTime(23, 59, 59);
14041404

14051405
$save = clone $nextWeek;
14061406

@@ -1427,7 +1427,7 @@ public function testValidateExpirationDateInternalHookException($shareType): voi
14271427

14281428
$nextWeek = new \DateTime();
14291429
$nextWeek->add(new \DateInterval('P7D'));
1430-
$nextWeek->setTime(0, 0, 0);
1430+
$nextWeek->setTime(23, 59, 59);
14311431

14321432
$share = $this->manager->newShare();
14331433
$share->setShareType($shareType);
@@ -1528,7 +1528,7 @@ public function testValidateExpirationDateEnforceButNotSetNewShare(): void {
15281528
]);
15291529

15301530
$expected = new \DateTime('now', $this->timezone);
1531-
$expected->setTime(0, 0, 0);
1531+
$expected->setTime(23, 59, 59);
15321532
$expected->add(new \DateInterval('P3D'));
15331533

15341534
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]);
@@ -1592,7 +1592,7 @@ public function testValidateExpirationDateEnforceValid(): void {
15921592
$future->setTime(1, 2, 3);
15931593

15941594
$expected = clone $future;
1595-
$expected->setTime(0, 0, 0);
1595+
$expected->setTime(23, 59, 59);
15961596

15971597
$share = $this->manager->newShare();
15981598
$share->setExpirationDate($future);
@@ -1625,7 +1625,7 @@ public function testValidateExpirationDateNoDefault(): void {
16251625
$date->setTime(1, 2, 3);
16261626

16271627
$expected = clone $date;
1628-
$expected->setTime(0, 0);
1628+
$expected->setTime(23, 59, 59);
16291629
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
16301630

16311631
$share = $this->manager->newShare();
@@ -1662,7 +1662,7 @@ public function testValidateExpirationDateNoDateDefault(): void {
16621662

16631663
$expected = new \DateTime('now', $this->timezone);
16641664
$expected->add(new \DateInterval('P3D'));
1665-
$expected->setTime(0, 0);
1665+
$expected->setTime(23, 59, 59);
16661666
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
16671667

16681668
$this->config->method('getAppValue')
@@ -1694,7 +1694,7 @@ public function testValidateExpirationDateDefault(): void {
16941694
$future->setTime(1, 2, 3);
16951695

16961696
$expected = clone $future;
1697-
$expected->setTime(0, 0);
1697+
$expected->setTime(23, 59, 59);
16981698
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
16991699

17001700
$share = $this->manager->newShare();
@@ -1730,7 +1730,7 @@ public function testValidateExpirationNegativeOffsetTimezone(): void {
17301730

17311731
$expected = clone $future;
17321732
$expected->setTimezone($this->timezone);
1733-
$expected->setTime(0, 0);
1733+
$expected->setTime(23, 59, 59);
17341734
$expected->setTimezone(new \DateTimeZone(date_default_timezone_get()));
17351735

17361736
$share = $this->manager->newShare();
@@ -1764,7 +1764,7 @@ public function testValidateExpirationDateHookModification(): void {
17641764
$nextWeek->add(new \DateInterval('P7D'));
17651765

17661766
$save = clone $nextWeek;
1767-
$save->setTime(0, 0);
1767+
$save->setTime(23, 59, 59);
17681768
$save->sub(new \DateInterval('P2D'));
17691769
$save->setTimezone(new \DateTimeZone(date_default_timezone_get()));
17701770

@@ -1788,7 +1788,7 @@ public function testValidateExpirationDateHookException(): void {
17881788

17891789
$nextWeek = new \DateTime();
17901790
$nextWeek->add(new \DateInterval('P7D'));
1791-
$nextWeek->setTime(0, 0, 0);
1791+
$nextWeek->setTime(23, 59, 59);
17921792

17931793
$share = $this->manager->newShare();
17941794
$share->setExpirationDate($nextWeek);
@@ -2452,7 +2452,7 @@ public function testCanShare($expected, $sharingEnabled, $disabledForUser): void
24522452
public function testCreateShareUser(): void {
24532453
/** @var Manager&MockObject $manager */
24542454
$manager = $this->createManagerMock()
2455-
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
2455+
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
24562456
->getMock();
24572457

24582458
$shareOwner = $this->createMock(IUser::class);
@@ -2488,6 +2488,10 @@ public function testCreateShareUser(): void {
24882488
$manager->expects($this->once())
24892489
->method('pathCreateChecks')
24902490
->with($path);
2491+
$manager->expects($this->once())
2492+
->method('validateExpirationDateInternal')
2493+
->with($share)
2494+
->willReturnArgument(0);
24912495

24922496
$this->defaultProvider
24932497
->expects($this->once())
@@ -2507,7 +2511,7 @@ public function testCreateShareUser(): void {
25072511

25082512
public function testCreateShareGroup(): void {
25092513
$manager = $this->createManagerMock()
2510-
->onlyMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks'])
2514+
->onlyMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
25112515
->getMock();
25122516

25132517
$shareOwner = $this->createMock(IUser::class);
@@ -2543,6 +2547,10 @@ public function testCreateShareGroup(): void {
25432547
$manager->expects($this->once())
25442548
->method('pathCreateChecks')
25452549
->with($path);
2550+
$manager->expects($this->once())
2551+
->method('validateExpirationDateInternal')
2552+
->with($share)
2553+
->willReturnArgument(0);
25462554

25472555
$this->defaultProvider
25482556
->expects($this->once())
@@ -2776,6 +2784,7 @@ public function testCreateShareHookError(): void {
27762784
'generalCreateChecks',
27772785
'userCreateChecks',
27782786
'pathCreateChecks',
2787+
'validateExpirationDateInternal',
27792788
])
27802789
->getMock();
27812790

@@ -2812,6 +2821,10 @@ public function testCreateShareHookError(): void {
28122821
$manager->expects($this->once())
28132822
->method('pathCreateChecks')
28142823
->with($path);
2824+
$manager->expects($this->once())
2825+
->method('validateExpirationDateInternal')
2826+
->with($share)
2827+
->willReturnArgument(0);
28152828

28162829
$share->expects($this->once())
28172830
->method('setShareOwner')
@@ -2836,7 +2849,7 @@ public function testCreateShareHookError(): void {
28362849

28372850
public function testCreateShareOfIncomingFederatedShare(): void {
28382851
$manager = $this->createManagerMock()
2839-
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
2852+
->onlyMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks', 'validateExpirationDateInternal'])
28402853
->getMock();
28412854

28422855
$shareOwner = $this->createMock(IUser::class);
@@ -2891,6 +2904,10 @@ public function testCreateShareOfIncomingFederatedShare(): void {
28912904
$manager->expects($this->once())
28922905
->method('pathCreateChecks')
28932906
->with($path);
2907+
$manager->expects($this->once())
2908+
->method('validateExpirationDateInternal')
2909+
->with($share)
2910+
->willReturnArgument(0);
28942911

28952912
$this->defaultProvider
28962913
->expects($this->once())

0 commit comments

Comments
 (0)