mirror of
https://github.com/dwaxweiler/connector-mobilizon
synced 2025-06-05 21:59:25 +02:00
fix require, add mock
This commit is contained in:
@ -18,7 +18,8 @@ require_once __DIR__ . '/includes/EventsCache.php';
|
|||||||
require_once __DIR__ . '/includes/Settings.php';
|
require_once __DIR__ . '/includes/Settings.php';
|
||||||
require_once __DIR__ . '/includes/SiteSettings.php';
|
require_once __DIR__ . '/includes/SiteSettings.php';
|
||||||
require_once __DIR__ . '/includes/LocalDateTime.php';
|
require_once __DIR__ . '/includes/LocalDateTime.php';
|
||||||
require_once __DIR__ . '/includes/Formatter.php';
|
require_once __DIR__ . '/includes/LocalDateTimeFormatter.php';
|
||||||
|
require_once __DIR__ . '/includes/LineFormatter.php';
|
||||||
require_once __DIR__ . '/includes/GraphQlClient.php';
|
require_once __DIR__ . '/includes/GraphQlClient.php';
|
||||||
require_once __DIR__ . '/includes/EventsListBlock.php';
|
require_once __DIR__ . '/includes/EventsListBlock.php';
|
||||||
require_once __DIR__ . '/includes/EventsListShortcut.php';
|
require_once __DIR__ . '/includes/EventsListShortcut.php';
|
||||||
|
@ -5,17 +5,22 @@ final class LineFormatter
|
|||||||
{
|
{
|
||||||
public static function format_date_time(\DateTimeZone $timeZone, string $dateFormat, string $timeFormat, string $start, ?string $end): string {
|
public static function format_date_time(\DateTimeZone $timeZone, string $dateFormat, string $timeFormat, string $start, ?string $end): string {
|
||||||
$startDateTime = new LocalDateTime($start, $timeZone);
|
$startDateTime = new LocalDateTime($start, $timeZone);
|
||||||
$dateText = LocalDateTimeFormatter::format($startDateTime, $dateFormat);
|
$startDate = LocalDateTimeFormatter::format($startDateTime, $dateFormat);
|
||||||
$dateText .= ' ' . LocalDateTimeFormatter::format($startDateTime, $timeFormat);
|
$startTime = LocalDateTimeFormatter::format($startDateTime, $timeFormat);
|
||||||
|
|
||||||
|
$dateText = $startDate . ' ' . $startTime;
|
||||||
if ($end) {
|
if ($end) {
|
||||||
$endDateTime = new LocalDateTime($end, $timeZone);
|
$endDateTime = new LocalDateTime($end, $timeZone);
|
||||||
if (LocalDateTimeFormatter::format($startDateTime, $dateFormat) != LocalDateTimeFormatter::format($endDateTime, $dateFormat)) {
|
$endDate = LocalDateTimeFormatter::format($endDateTime, $dateFormat);
|
||||||
|
$endTime = LocalDateTimeFormatter::format($endDateTime, $timeFormat);
|
||||||
|
|
||||||
|
if ($startDate != $endDate) {
|
||||||
$dateText .= ' - ';
|
$dateText .= ' - ';
|
||||||
$dateText .= LocalDateTimeFormatter::format($endDateTime, $dateFormat) . ' ';
|
$dateText .= $endDate . ' ';
|
||||||
} else {
|
} else {
|
||||||
$dateText .= ' - ';
|
$dateText .= ' - ';
|
||||||
}
|
}
|
||||||
$dateText .= LocalDateTimeFormatter::format($endDateTime, $timeFormat);
|
$dateText .= $endTime;
|
||||||
}
|
}
|
||||||
return $dateText;
|
return $dateText;
|
||||||
}
|
}
|
||||||
|
@ -4,34 +4,36 @@ declare(strict_types=1);
|
|||||||
use MobilizonConnector\LineFormatter;
|
use MobilizonConnector\LineFormatter;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
function date_i18n(string $format, int $timestamp) {
|
||||||
|
// Mock WordPress function.
|
||||||
|
if ($format == 'H:i') {
|
||||||
|
if ($timestamp == 1618482600) {
|
||||||
|
return '10:30';
|
||||||
|
} else if ($timestamp == 1618500600 || $timestamp == 1618587000) {
|
||||||
|
return '15:30';
|
||||||
|
}
|
||||||
|
} else if ($format == 'd/m/Y') {
|
||||||
|
if ($timestamp == 1618482600 || $timestamp == 1618500600) {
|
||||||
|
return '15/04/2021';
|
||||||
|
} else if ($timestamp == 1618587000) {
|
||||||
|
return '16/04/2021';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
final class LineFormatterTest extends TestCase
|
final class LineFormatterTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testCanDateFormatOneDate(): void {
|
public function testCanDateFormatOneDate(): void {
|
||||||
$this->assertSame('15/04/2021 10:30 - 15:30', LineFormatter::format_date_time(new \DateTimeZone('UTC'), '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z', false));
|
$this->assertSame('15/04/2021 10:30 - 15:30', LineFormatter::format_date_time(new \DateTimeZone('UTC'), 'd/m/Y', 'H:i', '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z'));
|
||||||
}
|
|
||||||
|
|
||||||
public function testCanDateFormatOneDateWithOffset(): void {
|
|
||||||
$this->assertSame('15/04/2021 10:30 - 15:30 (UTC)', LineFormatter::format_date_time(new \DateTimeZone('UTC'), '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z', true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCanDateFormatOneDateWithTimeZoneOffset(): void {
|
|
||||||
$this->assertSame('15/04/2021 11:30 - 16:30', LineFormatter::format_date_time(new \DateTimeZone('+01:00'), '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z', false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanDateFormatTwoDates(): void {
|
public function testCanDateFormatTwoDates(): void {
|
||||||
$this->assertSame('15/04/2021 10:30 - 16/04/2021 15:30', LineFormatter::format_date_time(new \DateTimeZone('UTC'), '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z', false));
|
$this->assertSame('15/04/2021 10:30 - 16/04/2021 15:30', LineFormatter::format_date_time(new \DateTimeZone('UTC'), 'd/m/Y', 'H:i', '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z'));
|
||||||
}
|
|
||||||
|
|
||||||
public function testCanDateFormatTwoDatesWithOffset(): void {
|
|
||||||
$this->assertSame('15/04/2021 10:30 - 16/04/2021 15:30 (UTC)', LineFormatter::format_date_time(new \DateTimeZone('UTC'), '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z', true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanDateFormatWhenSecondDateIsNull(): void {
|
public function testCanDateFormatWhenSecondDateIsNull(): void {
|
||||||
$this->assertSame('15/04/2021 10:30', LineFormatter::format_date_time(new \DateTimeZone('UTC'), '2021-04-15T10:30:00Z', null, false));
|
$this->assertSame('15/04/2021 10:30', LineFormatter::format_date_time(new \DateTimeZone('UTC'), 'd/m/Y', 'H:i', '2021-04-15T10:30:00Z', null));
|
||||||
}
|
|
||||||
|
|
||||||
public function testCanDateFormatWhenSecondDateIsNullWithOffset(): void {
|
|
||||||
$this->assertSame('15/04/2021 10:30 (UTC)', LineFormatter::format_date_time(new \DateTimeZone('UTC'), '2021-04-15T10:30:00Z', null, true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanLocationFormatBothParameters(): void {
|
public function testCanLocationFormatBothParameters(): void {
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
use MobilizonConnector\LocalDateTime;
|
|
||||||
use MobilizonConnector\LocalDateTimeFormatter;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
final class LocalDateTimeFormatterTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testCanFormatDate(): void {
|
|
||||||
$this->assertSame('15 April 2021', LocalDateTimeFormatter::format(new LocalDateTime('2021-04-15T10:30:00Z', new DateTimeZone("utc")), 'j F Y'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCanFormatTime(): void {
|
|
||||||
$this->assertSame('10:30', LocalDateTimeFormatter::format(new LocalDateTime('2021-04-15T10:30:00Z', new DateTimeZone("utc")), 'H:i'));
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user