All W&K configuration moves from tl_calendar into the new table tl_wk_config (one entry per calendar), edited under W&K-Tools → Einstellungen. The backend group now has separate entries for import, inbox, bookings, inquiries, exports, categories, settings and log. Notification selects show the notification ID. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
93 lines
4.0 KiB
PHP
93 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Mummert\ContaoWkSyncBundle\Tests\Booking;
|
|
|
|
use Mummert\ContaoWkSyncBundle\Booking\BookingEvent;
|
|
use Mummert\ContaoWkSyncBundle\Booking\NotificationRouter;
|
|
use Mummert\ContaoWkSyncBundle\Category\CategoryKind;
|
|
use Mummert\ContaoWkSyncBundle\Sync\CalendarConfig;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class NotificationRouterTest extends TestCase
|
|
{
|
|
private function calendar(): CalendarConfig
|
|
{
|
|
$row = ['id' => 1, 'calendar' => 1, 'notificationDefault' => 99];
|
|
|
|
foreach (NotificationRouter::CONDITIONS as $c) {
|
|
$row['notification'.$c] = 100 + $c;
|
|
}
|
|
|
|
return CalendarConfig::fromRow($row);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $overrides
|
|
*/
|
|
private function event(CategoryKind $kind, bool $singleDay, array $overrides = []): BookingEvent
|
|
{
|
|
$start = mktime(0, 0, 0, 9, 29, 2026);
|
|
|
|
return BookingEvent::fromRow([
|
|
'id' => 1, 'pid' => 1, 'title' => 'Test', 'published' => 1,
|
|
'startDate' => $start, 'endDate' => $singleDay ? $start : $start + 86400,
|
|
'startTime' => $start, 'endTime' => $start + 3600,
|
|
'location' => 'TPI Moritzburg', 'wkInternalEventNumber' => 'EXTP00001', 'wkNotification' => 0,
|
|
...$overrides,
|
|
], $kind);
|
|
}
|
|
|
|
/**
|
|
* @return iterable<string, array{CategoryKind, bool, array<string, mixed>, int}>
|
|
*/
|
|
public static function conditions(): iterable
|
|
{
|
|
yield 'online' => [CategoryKind::Elementary, true, ['location' => 'Online'], 1];
|
|
yield 'single school extp' => [CategoryKind::School, true, [], 2];
|
|
yield 'single school without extp falls back to default' => [CategoryKind::School, true, ['wkInternalEventNumber' => ''], 99];
|
|
yield 'single community' => [CategoryKind::Community, true, [], 3];
|
|
yield 'single conference' => [CategoryKind::Conference, true, [], 3];
|
|
yield 'single children service' => [CategoryKind::ChildrenService, true, [], 3];
|
|
yield 'single elementary' => [CategoryKind::Elementary, true, [], 4];
|
|
yield 'multi school extp' => [CategoryKind::School, false, [], 5];
|
|
yield 'multi elementary' => [CategoryKind::Elementary, false, [], 6];
|
|
yield 'multi community' => [CategoryKind::Community, false, [], 7];
|
|
yield 'single evangelical' => [CategoryKind::EvangelicalSchool, true, [], 8];
|
|
yield 'multi evangelical' => [CategoryKind::EvangelicalSchool, false, [], 9];
|
|
yield 'single mentoring' => [CategoryKind::Mentoring, true, [], 10];
|
|
yield 'multi mentoring' => [CategoryKind::Mentoring, false, [], 11];
|
|
yield 'multi training' => [CategoryKind::Training, false, [], 12];
|
|
yield 'other kind uses default' => [CategoryKind::Other, false, [], 99];
|
|
yield 'event override wins' => [CategoryKind::Community, true, ['wkNotification' => 7], 7];
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $overrides
|
|
*/
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('conditions')]
|
|
public function testRouting(CategoryKind $kind, bool $singleDay, array $overrides, int $expected): void
|
|
{
|
|
$result = (new NotificationRouter())->resolve($this->event($kind, $singleDay, $overrides), $this->calendar());
|
|
$expectedId = $expected < 13 && 7 !== $expected ? 100 + $expected : $expected;
|
|
|
|
if (7 === $expected && isset($overrides['wkNotification'])) {
|
|
$expectedId = 7;
|
|
} elseif (7 === $expected) {
|
|
$expectedId = 107;
|
|
}
|
|
|
|
self::assertSame($expectedId, $result['notification']);
|
|
}
|
|
|
|
public function testFallsThroughToNextConditionWhenNotificationMissing(): void
|
|
{
|
|
$calendar = CalendarConfig::fromRow(['id' => 1, 'calendar' => 1, 'notification1' => 0, 'notification4' => 104]);
|
|
$result = (new NotificationRouter())->resolve($this->event(CategoryKind::Elementary, true, ['location' => 'Online']), $calendar);
|
|
|
|
self::assertSame([1, 4], $result['conditions']);
|
|
self::assertSame(104, $result['notification']);
|
|
}
|
|
}
|