Add student administration view (studio-admin)
CI / Tests (PHP 8.1) (pull_request) Successful in 43s
CI / Coding Standards (pull_request) Successful in 56s
CI / PHPStan (pull_request) Successful in 57s
CI / No Debug Code (pull_request) Successful in 2s
CI / Tests (PHP 8.2) (pull_request) Successful in 44s
CI / Tests (PHP 8.3) (pull_request) Successful in 48s
CI / Build Plugin Zip (pull_request) Has been skipped
CI / Tests (PHP 8.1) (pull_request) Successful in 43s
CI / Coding Standards (pull_request) Successful in 56s
CI / PHPStan (pull_request) Successful in 57s
CI / No Debug Code (pull_request) Successful in 2s
CI / Tests (PHP 8.2) (pull_request) Successful in 44s
CI / Tests (PHP 8.3) (pull_request) Successful in 48s
CI / Build Plugin Zip (pull_request) Has been skipped
Implements #22: a read-only Students area for studio admins. - StudentController (manage_students): a list of us_student users with upcoming-lesson and active-enrolment counts, each linking to a detail page showing account info, upcoming/past lessons (offering, instructor, status), and group-class enrolments. - StudentSchedule::partition() — pure, unit-tested upcoming/past split. - Repo counts: BookingRepository::countUpcomingForStudent and EnrollmentRepository::countActiveForStudent (single-query, tested). - Templates: templates/admin/students.php, student-detail.php. - Students admin menu wired in AdminMenu (no Plugin change — the repos were already available there). - Docs: README status flipped to implemented; feature spec updated. Payment history slots into the detail when Payments (#7) lands. Tests: StudentScheduleTest + the two repo count tests. composer test (127), cs, and PHPStan level 6 all pass. Refs #22 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Unsupervised\Schedular\Tests\Unit\Auth;
|
||||
|
||||
use Unsupervised\Schedular\Auth\StudentSchedule;
|
||||
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
||||
|
||||
class StudentScheduleTest extends TestCase
|
||||
{
|
||||
public function testPartitionSplitsByNow(): void
|
||||
{
|
||||
$rows = [
|
||||
['start_dt' => '2026-06-10 09:00:00', 'label' => 'future-a'],
|
||||
['start_dt' => '2026-06-01 09:00:00', 'label' => 'past-a'],
|
||||
['start_dt' => '2026-06-20 09:00:00', 'label' => 'future-b'],
|
||||
['start_dt' => '2026-05-15 09:00:00', 'label' => 'past-b'],
|
||||
];
|
||||
|
||||
$result = StudentSchedule::partition($rows, '2026-06-08 12:00:00');
|
||||
|
||||
self::assertSame(['future-a', 'future-b'], array_column($result['upcoming'], 'label'));
|
||||
self::assertSame(['past-a', 'past-b'], array_column($result['past'], 'label'));
|
||||
}
|
||||
|
||||
public function testUpcomingSortedAscendingAndPastDescending(): void
|
||||
{
|
||||
$rows = [
|
||||
['start_dt' => '2026-06-20 09:00:00'],
|
||||
['start_dt' => '2026-06-10 09:00:00'],
|
||||
['start_dt' => '2026-05-01 09:00:00'],
|
||||
['start_dt' => '2026-05-30 09:00:00'],
|
||||
];
|
||||
|
||||
$result = StudentSchedule::partition($rows, '2026-06-08 00:00:00');
|
||||
|
||||
self::assertSame(
|
||||
['2026-06-10 09:00:00', '2026-06-20 09:00:00'],
|
||||
array_column($result['upcoming'], 'start_dt')
|
||||
);
|
||||
self::assertSame(
|
||||
['2026-05-30 09:00:00', '2026-05-01 09:00:00'],
|
||||
array_column($result['past'], 'start_dt')
|
||||
);
|
||||
}
|
||||
|
||||
public function testRowsWithoutStartDateFallIntoPast(): void
|
||||
{
|
||||
$rows = [
|
||||
['start_dt' => '', 'label' => 'no-slot'],
|
||||
['start_dt' => '2026-06-10 09:00:00', 'label' => 'future'],
|
||||
];
|
||||
|
||||
$result = StudentSchedule::partition($rows, '2026-06-08 00:00:00');
|
||||
|
||||
self::assertSame(['future'], array_column($result['upcoming'], 'label'));
|
||||
self::assertSame(['no-slot'], array_column($result['past'], 'label'));
|
||||
}
|
||||
|
||||
public function testEmptyInput(): void
|
||||
{
|
||||
$result = StudentSchedule::partition([], '2026-06-08 00:00:00');
|
||||
|
||||
self::assertSame([], $result['upcoming']);
|
||||
self::assertSame([], $result['past']);
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,20 @@ class BookingRepositoryTest extends TestCase
|
||||
self::assertFalse($this->repo->updateStatus(1, Lesson::STATUS_CONFIRMED));
|
||||
}
|
||||
|
||||
public function testCountUpcomingForStudent(): void
|
||||
{
|
||||
Functions\when('current_time')->justReturn('2026-06-08 12:00:00');
|
||||
|
||||
$this->db->shouldReceive('prepare')
|
||||
->once()
|
||||
->with(Mockery::pattern('/COUNT\(\*\).*l.student_id = %d.*a.start_dt >= %s/s'), 5, Lesson::STATUS_CANCELLED, '2026-06-08 12:00:00')
|
||||
->andReturn('SELECT ...');
|
||||
|
||||
$this->db->shouldReceive('get_var')->andReturn('3');
|
||||
|
||||
self::assertSame(3, $this->repo->countUpcomingForStudent(5));
|
||||
}
|
||||
|
||||
public function testFindByStudentReturnsLessons(): void
|
||||
{
|
||||
$row = (object) [
|
||||
|
||||
@@ -56,6 +56,18 @@ class EnrollmentRepositoryTest extends TestCase
|
||||
self::assertSame(4, $this->repo->countActiveForOffering(7));
|
||||
}
|
||||
|
||||
public function testCountActiveForStudent(): void
|
||||
{
|
||||
$this->db->shouldReceive('prepare')
|
||||
->once()
|
||||
->with(Mockery::pattern('/student_id = %d AND status = %s/'), 5, Enrollment::STATUS_ACTIVE)
|
||||
->andReturn('SELECT ...');
|
||||
|
||||
$this->db->shouldReceive('get_var')->andReturn('2');
|
||||
|
||||
self::assertSame(2, $this->repo->countActiveForStudent(5));
|
||||
}
|
||||
|
||||
public function testHasActiveEnrollmentTrueWhenCountPositive(): void
|
||||
{
|
||||
$this->db->shouldReceive('prepare')
|
||||
|
||||
Reference in New Issue
Block a user