CI / Tests (PHP 8.2) (pull_request) Successful in 44s
CI / Tests (PHP 8.1) (pull_request) Successful in 45s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 2m46s
CI / PHPStan (pull_request) Successful in 2m58s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m41s
CI / Build Plugin Zip (pull_request) Skipped
Studio admins can now define registration questions that every new student answers as a required second step during signup, with each student's answers shown under a "Registration Information" section in the admin. Extends the existing Registration domain: us_questions gains a scope column (offering | account) and a nullable offering_id, and account answers reuse us_question_answers with registration_type = 'account'. Authoring reuses the Offerings -> Questions page via an "Account signup" scope (studio-admin only). The registration form becomes two steps (progressive enhancement via assets/js/register.js; works without JS); required answers are validated before the account is created and apply to all signup paths (invite, group link, self-approval). StudentHistory::registrationInfo() powers the admin section. Bumps the plugin version to 1.1.0 so dbDelta runs the schema migration. Closes #90 Co-Authored-By: Claude Opus 4.8 <[email protected]>
123 lines
4.2 KiB
PHP
123 lines
4.2 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::assertSame(Question::SCOPE_OFFERING, $question->scope);
|
|
self::assertNull($question->id);
|
|
}
|
|
|
|
public function testAccountScopeQuestionHasNoOffering(): void
|
|
{
|
|
$question = new Question(null, 'Emergency contact', scope: Question::SCOPE_ACCOUNT);
|
|
|
|
self::assertNull($question->offeringId);
|
|
self::assertSame(Question::SCOPE_ACCOUNT, $question->scope);
|
|
}
|
|
|
|
public function testFromRowDecodesOptionsJson(): void
|
|
{
|
|
$row = (object) [
|
|
'id' => '3',
|
|
'offering_id' => '7',
|
|
'scope' => Question::SCOPE_OFFERING,
|
|
'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);
|
|
self::assertSame(Question::SCOPE_OFFERING, $question->scope);
|
|
}
|
|
|
|
public function testFromRowHandlesNullOptions(): void
|
|
{
|
|
$row = (object) [
|
|
'id' => '4',
|
|
'offering_id' => '7',
|
|
'scope' => Question::SCOPE_OFFERING,
|
|
'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 testFromRowHandlesAccountScopeWithNullOffering(): void
|
|
{
|
|
$row = (object) [
|
|
'id' => '5',
|
|
'offering_id' => null,
|
|
'scope' => Question::SCOPE_ACCOUNT,
|
|
'label' => 'How did you hear about us?',
|
|
'field_type' => Question::FIELD_TEXT,
|
|
'options' => null,
|
|
'is_required' => '1',
|
|
'sort_order' => '0',
|
|
'is_active' => '1',
|
|
];
|
|
|
|
$question = Question::fromRow($row);
|
|
|
|
self::assertNull($question->offeringId);
|
|
self::assertSame(Question::SCOPE_ACCOUNT, $question->scope);
|
|
self::assertTrue($question->isRequired);
|
|
}
|
|
|
|
public function testToArrayContainsExpectedKeys(): void
|
|
{
|
|
$question = new Question(7, 'Label', Question::FIELD_TEXT, id: 9);
|
|
$arr = $question->toArray();
|
|
|
|
foreach (['id', 'offering_id', 'scope', '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);
|
|
}
|
|
|
|
public function testValidScopeConstants(): void
|
|
{
|
|
self::assertContains(Question::SCOPE_OFFERING, Question::VALID_SCOPES);
|
|
self::assertContains(Question::SCOPE_ACCOUNT, Question::VALID_SCOPES);
|
|
}
|
|
}
|