e61d99daed
CI / Coding Standards (pull_request) Successful in 51s
CI / PHPStan (pull_request) Successful in 1m0s
CI / Tests (PHP 8.1) (pull_request) Successful in 46s
CI / Tests (PHP 8.2) (pull_request) Successful in 48s
CI / Tests (PHP 8.3) (pull_request) Successful in 47s
CI / No Debug Code (pull_request) Successful in 3s
Implements #5: studio admin / instructors author intake questions scoped per offering; answers are stored against a lesson or group enrolment via a polymorphic registration reference. - src/Registration/: Question + Answer value objects, QuestionRepository and AnswerRepository, QuestionEndpoint (REST), QuestionController + templates/admin/questions.php (Offerings -> Questions submenu) - us_questions and us_question_answers tables in Schema.php - REST: public GET /offerings/{id}/questions; POST/PATCH/DELETE /questions gated by manage_questions + offering ownership (owner or studio admin) - Field types text/textarea/select/checkbox; select options stored as JSON - Wiring in Plugin, RestRegistrar, AdminMenu AnswerRepository is built now and consumed by the booking/enrolment flow in #3/#4. Tests: tests/Unit/Registration/ (19 tests). composer test (63 total), cs, and PHPStan level 6 all pass. Refs #5 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
84 lines
2.8 KiB
PHP
84 lines
2.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Tests\Unit\Registration;
|
|
|
|
use Unsupervised\Schedular\Registration\Question;
|
|
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
|
|
|
class QuestionTest extends TestCase
|
|
{
|
|
public function testConstructorAndDefaults(): void
|
|
{
|
|
$question = new Question(7, 'Your level?');
|
|
|
|
self::assertSame(7, $question->offeringId);
|
|
self::assertSame('Your level?', $question->label);
|
|
self::assertSame(Question::FIELD_TEXT, $question->fieldType);
|
|
self::assertNull($question->options);
|
|
self::assertFalse($question->isRequired);
|
|
self::assertSame(0, $question->sortOrder);
|
|
self::assertTrue($question->isActive);
|
|
self::assertNull($question->id);
|
|
}
|
|
|
|
public function testFromRowDecodesOptionsJson(): void
|
|
{
|
|
$row = (object) [
|
|
'id' => '3',
|
|
'offering_id' => '7',
|
|
'label' => 'Pick a level',
|
|
'field_type' => Question::FIELD_SELECT,
|
|
'options' => '["Beginner","Advanced"]',
|
|
'is_required' => '1',
|
|
'sort_order' => '2',
|
|
'is_active' => '1',
|
|
];
|
|
|
|
$question = Question::fromRow($row);
|
|
|
|
self::assertSame(3, $question->id);
|
|
self::assertSame(Question::FIELD_SELECT, $question->fieldType);
|
|
self::assertSame(['Beginner', 'Advanced'], $question->options);
|
|
self::assertTrue($question->isRequired);
|
|
self::assertSame(2, $question->sortOrder);
|
|
}
|
|
|
|
public function testFromRowHandlesNullOptions(): void
|
|
{
|
|
$row = (object) [
|
|
'id' => '4',
|
|
'offering_id' => '7',
|
|
'label' => 'Notes',
|
|
'field_type' => Question::FIELD_TEXTAREA,
|
|
'options' => null,
|
|
'is_required' => '0',
|
|
'sort_order' => '0',
|
|
'is_active' => '0',
|
|
];
|
|
|
|
$question = Question::fromRow($row);
|
|
|
|
self::assertNull($question->options);
|
|
self::assertFalse($question->isActive);
|
|
}
|
|
|
|
public function testToArrayContainsExpectedKeys(): void
|
|
{
|
|
$question = new Question(7, 'Label', Question::FIELD_TEXT, id: 9);
|
|
$arr = $question->toArray();
|
|
|
|
foreach (['id', 'offering_id', 'label', 'field_type', 'options', 'is_required', 'sort_order', 'is_active'] as $key) {
|
|
self::assertArrayHasKey($key, $arr);
|
|
}
|
|
}
|
|
|
|
public function testValidFieldTypeConstants(): void
|
|
{
|
|
self::assertContains(Question::FIELD_TEXT, Question::VALID_FIELD_TYPES);
|
|
self::assertContains(Question::FIELD_TEXTAREA, Question::VALID_FIELD_TYPES);
|
|
self::assertContains(Question::FIELD_SELECT, Question::VALID_FIELD_TYPES);
|
|
self::assertContains(Question::FIELD_CHECKBOX, Question::VALID_FIELD_TYPES);
|
|
}
|
|
}
|