Split availability windows into bookable lesson-length slots with weekly calendar views
CI / Build Plugin Zip (pull_request) Has been skipped
CI / Tests (PHP 8.2) (pull_request) Successful in 45s
CI / PHPStan (pull_request) Successful in 2m48s
CI / Tests (PHP 8.1) (pull_request) Successful in 41s
CI / No Debug Code (pull_request) Failing after 2s
CI / Coding Standards (pull_request) Successful in 52s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m36s
CI / Build Plugin Zip (pull_request) Has been skipped
CI / Tests (PHP 8.2) (pull_request) Successful in 45s
CI / PHPStan (pull_request) Successful in 2m48s
CI / Tests (PHP 8.1) (pull_request) Successful in 41s
CI / No Debug Code (pull_request) Failing after 2s
CI / Coding Standards (pull_request) Successful in 52s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m36s
Availability windows were stored and served as a single bookable row, so a 9:00 AM-4:00 PM window showed to students as one giant slot and booking it consumed the whole day; past and multi-day windows also leaked into the booking page as nonsense entries. - Split windows into consecutive lesson-length slots on save (REST and admin form); each chunk is independently bookable and weekly recurrence creates a series per chunk so "reserve this time weekly" holds the same hour each week - Reject windows spanning multiple days or shorter than the lesson length (400 invalid_window) - Never return slots whose start has passed from GET /availability - Migrate pre-split rows: Plugin::boot re-runs the Installer on version change and AvailabilityRepository::splitOversizedWindows() rewrites unbooked same-day oversized windows in place - Display all times in 12-hour AM/PM form (booking page, wp-admin lists, editor previews) - Add a List | Week view toggle to the student booking page and the instructor availability page, with previous/next-week navigation honouring the site's start_of_week option (new WeekCalendar helper) Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Unsupervised\Schedular\Tests\Unit\Availability;
|
||||
|
||||
use Unsupervised\Schedular\Availability\AvailabilitySlot;
|
||||
use Unsupervised\Schedular\Availability\WeekCalendar;
|
||||
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
||||
|
||||
class WeekCalendarTest extends TestCase
|
||||
{
|
||||
public function testWeekStartShiftsBackToConfiguredStartOfWeek(): void
|
||||
{
|
||||
// 2026-07-08 is a Wednesday; with Monday (1) starts, the week begins Jul 6.
|
||||
self::assertSame('2026-07-06', WeekCalendar::weekStart('2026-07-08', 1, '2026-01-01'));
|
||||
|
||||
// With Sunday (0) starts, the same Wednesday's week begins Jul 5.
|
||||
self::assertSame('2026-07-05', WeekCalendar::weekStart('2026-07-08', 0, '2026-01-01'));
|
||||
}
|
||||
|
||||
public function testWeekStartIsIdempotentWhenAnchorIsAlreadyTheStart(): void
|
||||
{
|
||||
self::assertSame('2026-07-06', WeekCalendar::weekStart('2026-07-06', 1, '2026-01-01'));
|
||||
}
|
||||
|
||||
public function testWeekStartFallsBackToTodayForInvalidInput(): void
|
||||
{
|
||||
// 2026-07-05 is a Sunday; with Monday starts, its week began Jun 29.
|
||||
self::assertSame('2026-06-29', WeekCalendar::weekStart('', 1, '2026-07-05'));
|
||||
self::assertSame('2026-06-29', WeekCalendar::weekStart('not-a-date', 1, '2026-07-05'));
|
||||
self::assertSame('2026-06-29', WeekCalendar::weekStart('2026-13-40', 1, '2026-07-05'));
|
||||
}
|
||||
|
||||
public function testDaysReturnsSevenBucketsWithSlotsOnTheirDates(): void
|
||||
{
|
||||
$monday = new AvailabilitySlot(5, '2026-07-06 09:00:00', '2026-07-06 10:00:00', 60, null, false, null, 1);
|
||||
$mondayTwo = new AvailabilitySlot(5, '2026-07-06 10:00:00', '2026-07-06 11:00:00', 60, null, false, null, 2);
|
||||
$thursday = new AvailabilitySlot(5, '2026-07-09 14:00:00', '2026-07-09 15:00:00', 60, null, false, null, 3);
|
||||
$nextWeek = new AvailabilitySlot(5, '2026-07-13 09:00:00', '2026-07-13 10:00:00', 60, null, false, null, 4);
|
||||
|
||||
$days = WeekCalendar::days('2026-07-06', [$monday, $mondayTwo, $thursday, $nextWeek]);
|
||||
|
||||
self::assertCount(7, $days);
|
||||
self::assertSame('2026-07-06', $days[0]['date']);
|
||||
self::assertSame('2026-07-12', $days[6]['date']);
|
||||
|
||||
self::assertCount(2, $days[0]['slots']);
|
||||
self::assertSame(3, $days[3]['slots'][0]->id);
|
||||
self::assertSame([], $days[1]['slots']);
|
||||
|
||||
// A slot outside the week is not bucketed anywhere.
|
||||
$ids = array_merge(...array_map(
|
||||
static fn (array $day): array => array_map(static fn (AvailabilitySlot $s): ?int => $s->id, $day['slots']),
|
||||
$days
|
||||
));
|
||||
self::assertNotContains(4, $ids);
|
||||
}
|
||||
|
||||
public function testDaysCrossesMonthBoundary(): void
|
||||
{
|
||||
$days = WeekCalendar::days('2026-06-29', []);
|
||||
|
||||
self::assertSame('2026-06-29', $days[0]['date']);
|
||||
self::assertSame('2026-07-05', $days[6]['date']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user