0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-01-31 06:43:12 +00:00
nextcloud_server/apps/user_ldap/tests/Service/BirthdateParserServiceTest.php
Jake Nabasny f863290572
feat(ldap): sync additional properties to profile and SAB
Synced from LDAP to profile:
- Date of birth

Synced from LDAP to SAB (via the profile):
- Biography
- Date of birth

Original code by Jake Nabasny (GitHub: @slapcat)

Co-authored-by: Jake Nabasny <jake@nabasny.com>
Co-authored-by: Richard Steinmetz <richard@steinmetz.cloud>
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
2024-05-30 12:01:13 +02:00

52 lines
1.4 KiB
PHP

<?php
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\user_ldap\tests\Service;
use DateTimeImmutable;
use OCA\User_LDAP\Service\BirthdateParserService;
use PHPUnit\Framework\TestCase;
class BirthdateParserServiceTest extends TestCase {
private BirthdateParserService $service;
protected function setUp(): void {
parent::setUp();
$this->service = new BirthdateParserService();
}
public function parseBirthdateDataProvider(): array {
return [
['2024-01-01', new DateTimeImmutable('2024-01-01'), false],
['20240101', new DateTimeImmutable('2024-01-01'), false],
['199412161032Z', new DateTimeImmutable('1994-12-16'), false], // LDAP generalized time
['199412160532-0500', new DateTimeImmutable('1994-12-16'), false], // LDAP generalized time
['2023-07-31T00:60:59.000Z', null, true],
['01.01.2024', null, true],
['01/01/2024', null, true],
['01 01 2024', null, true],
['foobar', null, true],
];
}
/**
* @dataProvider parseBirthdateDataProvider
*/
public function testParseBirthdate(
string $value,
?DateTimeImmutable $expected,
bool $shouldThrow,
): void {
if ($shouldThrow) {
$this->expectException(\InvalidArgumentException::class);
}
$actual = $this->service->parseBirthdate($value);
$this->assertEquals($expected, $actual);
}
}