CI / Tests (PHP 8.2) (pull_request) Successful in 45s
CI / Tests (PHP 8.1) (pull_request) Successful in 48s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 1m14s
CI / PHPStan (pull_request) Successful in 1m16s
CI / Tests (PHP 8.3) (pull_request) Successful in 37s
CI / Build Plugin Zip (pull_request) Has been skipped
Group class offerings now carry real dates: the add/edit form takes a start date plus a sessions control (one-off, or weekly for N sessions; the end date is computed as start + (N-1) weeks via Offering::weeklyTermEnd). Dates are validated strictly (Y-m-d) and shown in the offerings list and on the student-facing class card, including the weekly session count. [us_group_classes offering="<id>"] (block attribute offeringId, chosen from a dropdown of active classes fetched from the public offerings endpoint) restricts the page to a single class so the enrolment flow can be embedded on a page dedicated to that class; a pinned class that is no longer offered reports itself closed instead of falling back to the catalog. Offerings are now editable from the admin screen: an Edit button prefills the shared add/edit form and saving posts usc_action=update. Updates always preserve the original owner and currency, and non-admin instructors can only load and update their own offerings. The form also gains the previously missing description field and an Active toggle (the admin-UI counterpart of the REST is_active flag) so an edit cannot wipe data the form never collected. Closes #59 Co-Authored-By: Claude Fable 5 <[email protected]>
134 lines
5.1 KiB
PHP
134 lines
5.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Tests\Unit\Offering;
|
|
|
|
use Unsupervised\Schedular\Offering\Offering;
|
|
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
|
|
|
class OfferingTest extends TestCase
|
|
{
|
|
public function testConstructorAndProperties(): void
|
|
{
|
|
$offering = new Offering(
|
|
instructorId: 5,
|
|
kind: Offering::KIND_PRIVATE_LESSON,
|
|
title: '30-min Piano',
|
|
price: 35.00,
|
|
billingMode: Offering::BILLING_ONE_TIME,
|
|
durationMinutes: 30,
|
|
id: 42,
|
|
);
|
|
|
|
self::assertSame(5, $offering->instructorId);
|
|
self::assertSame(Offering::KIND_PRIVATE_LESSON, $offering->kind);
|
|
self::assertSame('30-min Piano', $offering->title);
|
|
self::assertSame(35.00, $offering->price);
|
|
self::assertSame(30, $offering->durationMinutes);
|
|
self::assertSame(42, $offering->id);
|
|
}
|
|
|
|
public function testNormalizeDateAcceptsRealDates(): void
|
|
{
|
|
self::assertSame('2026-09-08', Offering::normalizeDate('2026-09-08'));
|
|
}
|
|
|
|
public function testNormalizeDateRejectsGarbage(): void
|
|
{
|
|
self::assertNull(Offering::normalizeDate(''));
|
|
self::assertNull(Offering::normalizeDate('not-a-date'));
|
|
self::assertNull(Offering::normalizeDate('2026-02-30'));
|
|
self::assertNull(Offering::normalizeDate('2026-09-08 10:00'));
|
|
}
|
|
|
|
public function testWeeklyTermEndAddsOneWeekPerExtraSession(): void
|
|
{
|
|
self::assertSame('2026-11-10', Offering::weeklyTermEnd('2026-09-08', 10));
|
|
}
|
|
|
|
public function testWeeklyTermEndOfSingleSessionIsTheStartDate(): void
|
|
{
|
|
self::assertSame('2026-09-08', Offering::weeklyTermEnd('2026-09-08', 1));
|
|
self::assertSame('2026-09-08', Offering::weeklyTermEnd('2026-09-08', 0));
|
|
}
|
|
|
|
public function testDefaults(): void
|
|
{
|
|
$offering = new Offering(1, Offering::KIND_GROUP_CLASS, 'Choir');
|
|
|
|
self::assertSame(0.0, $offering->price);
|
|
self::assertSame('CAD', $offering->currency);
|
|
self::assertSame(Offering::BILLING_ONE_TIME, $offering->billingMode);
|
|
self::assertNull($offering->durationMinutes);
|
|
self::assertFalse($offering->allowWeekly);
|
|
self::assertNull($offering->capacity);
|
|
self::assertTrue($offering->isActive);
|
|
self::assertNull($offering->id);
|
|
}
|
|
|
|
public function testFromRowMapsCorrectlyAndCastsNullables(): void
|
|
{
|
|
$row = (object) [
|
|
'id' => '7',
|
|
'instructor_id' => '3',
|
|
'kind' => Offering::KIND_GROUP_CLASS,
|
|
'title' => 'Year Choir',
|
|
'description' => 'Weekly choir',
|
|
'duration_minutes' => null,
|
|
'price' => '120.00',
|
|
'currency' => 'CAD',
|
|
'billing_mode' => Offering::BILLING_FULL_TERM,
|
|
'allow_weekly' => '0',
|
|
'capacity' => '20',
|
|
'term_start' => '2026-09-01',
|
|
'term_end' => '2027-06-30',
|
|
'schedule_note' => 'Tuesdays 4:00pm',
|
|
'etransfer_email' => null,
|
|
'is_active' => '1',
|
|
];
|
|
|
|
$offering = Offering::fromRow($row);
|
|
|
|
self::assertSame(7, $offering->id);
|
|
self::assertSame(3, $offering->instructorId);
|
|
self::assertNull($offering->durationMinutes);
|
|
self::assertSame(120.00, $offering->price);
|
|
self::assertSame(20, $offering->capacity);
|
|
self::assertSame(Offering::BILLING_FULL_TERM, $offering->billingMode);
|
|
self::assertTrue($offering->isActive);
|
|
}
|
|
|
|
public function testToArrayContainsExpectedKeys(): void
|
|
{
|
|
$offering = new Offering(1, Offering::KIND_PRIVATE_LESSON, 'Lesson', id: 10);
|
|
$arr = $offering->toArray();
|
|
|
|
foreach (['id', 'instructor_id', 'kind', 'title', 'price', 'billing_mode', 'is_active'] as $key) {
|
|
self::assertArrayHasKey($key, $arr);
|
|
}
|
|
}
|
|
|
|
public function testToArrayIncludesEtransferEmailByDefault(): void
|
|
{
|
|
$offering = new Offering(1, Offering::KIND_PRIVATE_LESSON, 'Lesson', etransferEmail: '[email protected]', id: 10);
|
|
|
|
self::assertArrayHasKey('etransfer_email', $offering->toArray());
|
|
self::assertSame('[email protected]', $offering->toArray()['etransfer_email']);
|
|
}
|
|
|
|
public function testToArrayOmitsEtransferEmailWhenExcluded(): void
|
|
{
|
|
$offering = new Offering(1, Offering::KIND_PRIVATE_LESSON, 'Lesson', etransferEmail: '[email protected]', id: 10);
|
|
|
|
self::assertArrayNotHasKey('etransfer_email', $offering->toArray(includeEtransferEmail: false));
|
|
}
|
|
|
|
public function testValidKindAndBillingConstants(): void
|
|
{
|
|
self::assertContains(Offering::KIND_PRIVATE_LESSON, Offering::VALID_KINDS);
|
|
self::assertContains(Offering::KIND_GROUP_CLASS, Offering::VALID_KINDS);
|
|
self::assertContains(Offering::BILLING_ONE_TIME, Offering::VALID_BILLING_MODES);
|
|
self::assertContains(Offering::BILLING_FULL_TERM, Offering::VALID_BILLING_MODES);
|
|
}
|
|
}
|