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:
nfebe 2026-02-06 00:46:22 +01:00 committed by backportbot[bot]
parent b601b03084
commit 6df78fad3d
5 changed files with 51 additions and 35 deletions

View file

@ -1050,7 +1050,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());
@ -1261,7 +1261,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()));
@ -1323,14 +1323,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);

View file

@ -774,7 +774,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,
@ -808,7 +808,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,
@ -4505,7 +4505,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',
@ -4555,7 +4555,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',

View file

@ -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;

View file

@ -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') {

View file

@ -1185,7 +1185,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]);
@ -1218,7 +1218,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]);
@ -1265,7 +1265,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);
@ -1305,7 +1305,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);
@ -1345,7 +1345,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()));
@ -1383,7 +1383,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);
@ -1420,7 +1420,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;
@ -1447,7 +1447,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);
@ -1548,7 +1548,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]);
@ -1573,7 +1573,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]);
@ -1612,7 +1612,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);
@ -1645,7 +1645,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();
@ -1682,7 +1682,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')
@ -1714,7 +1714,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();
@ -1750,7 +1750,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();
@ -1784,7 +1784,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()));
@ -1808,7 +1808,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);
@ -2472,7 +2472,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);
@ -2507,6 +2507,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())
@ -2526,7 +2530,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);
@ -2561,6 +2565,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())
@ -2792,6 +2800,7 @@ class ManagerTest extends \Test\TestCase {
'generalCreateChecks',
'userCreateChecks',
'pathCreateChecks',
'validateExpirationDateInternal',
])
->getMock();
@ -2827,6 +2836,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')
@ -2851,7 +2864,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);
@ -2905,6 +2918,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())