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>
116 lines
5.0 KiB
PHP
116 lines
5.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Mummert\ContaoWkSyncBundle\Tests\Booking;
|
|
|
|
use Mummert\ContaoWkSyncBundle\Booking\BookingEvent;
|
|
use Mummert\ContaoWkSyncBundle\Booking\BookingFields;
|
|
use Mummert\ContaoWkSyncBundle\Booking\BookingRules;
|
|
use Mummert\ContaoWkSyncBundle\Category\CategoryKind;
|
|
use Mummert\ContaoWkSyncBundle\Sync\CalendarConfig;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class BookingRulesTest extends TestCase
|
|
{
|
|
private function calendar(): CalendarConfig
|
|
{
|
|
return CalendarConfig::fromRow(['id' => 1, 'calendar' => 1, 'ownVenues' => "TPI Moritzburg\nMoritzburg"]);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $overrides
|
|
*/
|
|
private function event(CategoryKind $kind, array $overrides = []): BookingEvent
|
|
{
|
|
$row = [
|
|
'id' => 1, 'pid' => 1, 'title' => 'Test', 'alias' => 'test', 'published' => 1,
|
|
'startDate' => mktime(0, 0, 0, 9, 29, 2026), 'endDate' => mktime(0, 0, 0, 9, 30, 2026),
|
|
'startTime' => mktime(9, 0, 0, 9, 29, 2026), 'endTime' => mktime(16, 0, 0, 9, 30, 2026),
|
|
'location' => 'TPI Moritzburg (barrierefrei)', 'wkInternalEventNumber' => 'EXTP00557',
|
|
...$overrides,
|
|
];
|
|
|
|
return BookingEvent::fromRow($row, $kind);
|
|
}
|
|
|
|
public function testTeacherFieldsOnlyForSchoolKinds(): void
|
|
{
|
|
$rules = new BookingRules();
|
|
|
|
self::assertFalse($rules->rulesFor($this->event(CategoryKind::School), $this->calendar())->isHidden('teacherPosition'));
|
|
self::assertFalse($rules->rulesFor($this->event(CategoryKind::EvangelicalSchool), $this->calendar())->isHidden('teacherPosition'));
|
|
self::assertTrue($rules->rulesFor($this->event(CategoryKind::Community), $this->calendar())->isHidden('teacherPosition'));
|
|
self::assertTrue($rules->rulesFor($this->event(CategoryKind::Community), $this->calendar())->isHidden('schoolName'));
|
|
}
|
|
|
|
public function testInvoiceAddressDependsOnTeacherPositionForSchoolCourses(): void
|
|
{
|
|
$rules = (new BookingRules())->rulesFor($this->event(CategoryKind::School), $this->calendar());
|
|
|
|
self::assertFalse($rules->isDependencyMet('addDifferentInvoiceAddress', ['teacherPosition' => 'state']));
|
|
self::assertTrue($rules->isDependencyMet('addDifferentInvoiceAddress', ['teacherPosition' => 'other']));
|
|
|
|
$community = (new BookingRules())->rulesFor($this->event(CategoryKind::Community), $this->calendar());
|
|
self::assertTrue($community->isDependencyMet('addDifferentInvoiceAddress', []));
|
|
}
|
|
|
|
public function testMultiDayExtpCourseAtOwnVenueShowsGuesthouseNoteInsteadOfOvernightStay(): void
|
|
{
|
|
$rules = (new BookingRules())->rulesFor($this->event(CategoryKind::School), $this->calendar());
|
|
|
|
self::assertTrue($rules->isHidden('overnightStay'));
|
|
self::assertTrue($rules->isHidden('vegetarian'));
|
|
self::assertContains(BookingFields::SLOT_NO_OVERNIGHT_STAY, $rules->activeSlots);
|
|
}
|
|
|
|
public function testMultiDayTeacherCourseAwayShowsOvernightStayAndVegetarian(): void
|
|
{
|
|
$rules = (new BookingRules())->rulesFor($this->event(CategoryKind::School, ['location' => 'Klosterhof St. Afra Meißen']), $this->calendar());
|
|
|
|
self::assertFalse($rules->isHidden('overnightStay'));
|
|
self::assertFalse($rules->isHidden('vegetarian'));
|
|
self::assertSame([], $rules->activeSlots);
|
|
}
|
|
|
|
public function testSingleDayHidesOvernightStayWithoutNote(): void
|
|
{
|
|
$rules = (new BookingRules())->rulesFor($this->event(CategoryKind::Community, ['endDate' => mktime(0, 0, 0, 9, 29, 2026)]), $this->calendar());
|
|
|
|
self::assertTrue($rules->isHidden('overnightStay'));
|
|
self::assertSame([], $rules->activeSlots);
|
|
self::assertFalse($rules->isHidden('vegetarian'));
|
|
}
|
|
|
|
public function testOnlineCourseHidesVegetarian(): void
|
|
{
|
|
$rules = (new BookingRules())->rulesFor($this->event(CategoryKind::Community, ['location' => 'Online', 'wkInternalEventNumber' => 'keine']), $this->calendar());
|
|
|
|
self::assertTrue($rules->isHidden('vegetarian'));
|
|
}
|
|
|
|
public function testConferenceKeepsOvernightStayAndVegetarian(): void
|
|
{
|
|
$rules = (new BookingRules())->rulesFor($this->event(CategoryKind::Conference), $this->calendar());
|
|
|
|
self::assertFalse($rules->isHidden('overnightStay'));
|
|
self::assertFalse($rules->isHidden('vegetarian'));
|
|
}
|
|
|
|
public function testElementaryMultiDayHidesVegetarianAndShowsNote(): void
|
|
{
|
|
$rules = (new BookingRules())->rulesFor($this->event(CategoryKind::Elementary, ['wkInternalEventNumber' => '']), $this->calendar());
|
|
|
|
self::assertTrue($rules->isHidden('vegetarian'));
|
|
self::assertTrue($rules->isHidden('overnightStay'));
|
|
self::assertContains(BookingFields::SLOT_NO_OVERNIGHT_STAY, $rules->activeSlots);
|
|
}
|
|
|
|
public function testDependentFieldIsHiddenWhenControllerIsHidden(): void
|
|
{
|
|
$rules = (new BookingRules())->rulesFor($this->event(CategoryKind::Community), $this->calendar());
|
|
|
|
self::assertFalse($rules->isDependencyMet('schoolName', ['teacherPosition' => 'state']));
|
|
}
|
|
}
|