Merge pull request 'Default lessons to a week view on the booking page and in wp-admin' (#80) from fix/week-view-default into main
CI / Tests (PHP 8.2) (push) Successful in 38s
CI / Tests (PHP 8.1) (push) Successful in 43s
CI / No Debug Code (push) Successful in 2s
CI / Coding Standards (push) Successful in 2m52s
CI / PHPStan (push) Successful in 2m53s
CI / Tests (PHP 8.3) (push) Successful in 2m42s
CI / Build Plugin Zip (push) Successful in 2m46s
CI / Tests (PHP 8.2) (push) Successful in 38s
CI / Tests (PHP 8.1) (push) Successful in 43s
CI / No Debug Code (push) Successful in 2s
CI / Coding Standards (push) Successful in 2m52s
CI / PHPStan (push) Successful in 2m53s
CI / Tests (PHP 8.3) (push) Successful in 2m42s
CI / Build Plugin Zip (push) Successful in 2m46s
Reviewed-on: #80
This commit was merged in pull request #80.
This commit is contained in:
@@ -63,4 +63,30 @@ class WeekCalendarTest extends TestCase
|
||||
self::assertSame('2026-06-29', $days[0]['date']);
|
||||
self::assertSame('2026-07-05', $days[6]['date']);
|
||||
}
|
||||
|
||||
public function testBucketGroupsItemsByExtractedDay(): void
|
||||
{
|
||||
$items = [
|
||||
['day' => '2026-07-06', 'label' => 'a'],
|
||||
['day' => '2026-07-06', 'label' => 'b'],
|
||||
['day' => '2026-07-09', 'label' => 'c'],
|
||||
['day' => '2026-07-13', 'label' => 'outside'],
|
||||
['day' => '', 'label' => 'dayless'],
|
||||
];
|
||||
|
||||
$days = WeekCalendar::bucket('2026-07-06', $items, static fn (array $i): string => $i['day']);
|
||||
|
||||
self::assertCount(7, $days);
|
||||
self::assertSame('2026-07-06', $days[0]['date']);
|
||||
self::assertSame('2026-07-12', $days[6]['date']);
|
||||
|
||||
self::assertSame(['a', 'b'], array_column($days[0]['items'], 'label'));
|
||||
self::assertSame(['c'], array_column($days[3]['items'], 'label'));
|
||||
self::assertSame([], $days[1]['items']);
|
||||
|
||||
// Items outside the week (or with no day) are not bucketed anywhere.
|
||||
$labels = array_merge(...array_column($days, 'items'));
|
||||
self::assertNotContains('outside', array_column($labels, 'label'));
|
||||
self::assertNotContains('dayless', array_column($labels, 'label'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,16 +30,26 @@ class LessonControllerTest extends TestCase
|
||||
$this->controller = new LessonController($this->bookings, $this->payments, $this->availability);
|
||||
|
||||
$_POST = [];
|
||||
$_GET = [];
|
||||
|
||||
Functions\when('current_user_can')->justReturn(true);
|
||||
Functions\when('get_userdata')->justReturn(false);
|
||||
Functions\when('mysql2date')->alias(
|
||||
static fn (string $format, string $date) => date($format, (int) strtotime($date))
|
||||
);
|
||||
Functions\when('wp_unslash')->returnArg();
|
||||
Functions\when('sanitize_text_field')->returnArg();
|
||||
Functions\when('sanitize_key')->alias(static fn ($v) => strtolower((string) $v));
|
||||
Functions\when('get_option')->justReturn(1);
|
||||
Functions\when('current_time')->justReturn('2026-07-06');
|
||||
Functions\when('admin_url')->alias(static fn (string $path) => 'https://example.test/wp-admin/' . $path);
|
||||
Functions\when('add_query_arg')->alias(static fn ($key, $value, $url) => $url . '&' . $key . '=' . $value);
|
||||
}
|
||||
|
||||
public function testAdminDashboardShowsSlotDateTimeInsteadOfSlotId(): void
|
||||
{
|
||||
$_GET['usc_view'] = 'list';
|
||||
|
||||
$lesson = new Lesson(slotId: 10, studentId: 5, instructorId: 3, id: 1);
|
||||
$slot = new AvailabilitySlot(
|
||||
instructorId: 3,
|
||||
@@ -60,6 +70,8 @@ class LessonControllerTest extends TestCase
|
||||
|
||||
public function testSlotCrossingMidnightRepeatsTheDateOnTheEndTime(): void
|
||||
{
|
||||
$_GET['usc_view'] = 'list';
|
||||
|
||||
$lesson = new Lesson(slotId: 11, studentId: 5, instructorId: 3, id: 2);
|
||||
$slot = new AvailabilitySlot(
|
||||
instructorId: 3,
|
||||
@@ -90,6 +102,7 @@ class LessonControllerTest extends TestCase
|
||||
|
||||
public function testInstructorLessonsShowSlotDateTime(): void
|
||||
{
|
||||
$_GET['usc_view'] = 'list';
|
||||
Functions\when('get_current_user_id')->justReturn(3);
|
||||
|
||||
$lesson = new Lesson(slotId: 12, studentId: 5, instructorId: 3, id: 4);
|
||||
@@ -110,6 +123,59 @@ class LessonControllerTest extends TestCase
|
||||
self::assertStringContainsString('Aug 1, 2026 2:00 PM–3:00 PM', $html);
|
||||
}
|
||||
|
||||
public function testDefaultsToWeekViewWithLessonInItsDay(): void
|
||||
{
|
||||
$lesson = new Lesson(slotId: 10, studentId: 5, instructorId: 3, id: 1);
|
||||
$slot = new AvailabilitySlot(
|
||||
instructorId: 3,
|
||||
startDt: '2026-07-08 09:00:00',
|
||||
endDt: '2026-07-08 10:00:00',
|
||||
id: 10
|
||||
);
|
||||
|
||||
$this->bookings->shouldReceive('findAllUpcoming')->once()->andReturn([$lesson]);
|
||||
$this->availability->shouldReceive('findById')->once()->with(10)->andReturn($slot);
|
||||
|
||||
$html = $this->render();
|
||||
|
||||
// Week of Monday 2026-07-06 (start_of_week = 1, today = 2026-07-06).
|
||||
self::assertStringContainsString('Week of Jul 6, 2026', $html);
|
||||
self::assertStringContainsString('Wed Jul 8', $html);
|
||||
self::assertStringContainsString('9:00 AM', $html);
|
||||
// The list table is not rendered in week view.
|
||||
self::assertStringNotContainsString('Date/Time', $html);
|
||||
}
|
||||
|
||||
public function testWeekViewHonoursRequestedWeek(): void
|
||||
{
|
||||
$_GET['usc_week'] = '2026-08-01';
|
||||
|
||||
$this->bookings->shouldReceive('findAllUpcoming')->once()->andReturn([]);
|
||||
|
||||
$html = $this->render();
|
||||
|
||||
// 2026-08-01 is a Saturday; its Monday-start week begins 2026-07-27.
|
||||
self::assertStringContainsString('Week of Jul 27, 2026', $html);
|
||||
}
|
||||
|
||||
public function testLessonOutsideDisplayedWeekIsNotShown(): void
|
||||
{
|
||||
$lesson = new Lesson(slotId: 10, studentId: 5, instructorId: 3, id: 1);
|
||||
$slot = new AvailabilitySlot(
|
||||
instructorId: 3,
|
||||
startDt: '2026-09-01 09:00:00',
|
||||
endDt: '2026-09-01 10:00:00',
|
||||
id: 10
|
||||
);
|
||||
|
||||
$this->bookings->shouldReceive('findAllUpcoming')->once()->andReturn([$lesson]);
|
||||
$this->availability->shouldReceive('findById')->once()->with(10)->andReturn($slot);
|
||||
|
||||
$html = $this->render();
|
||||
|
||||
self::assertStringNotContainsString('9:00 AM', $html);
|
||||
}
|
||||
|
||||
private function render(): string
|
||||
{
|
||||
ob_start();
|
||||
|
||||
Reference in New Issue
Block a user