You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.4 KiB
76 lines
2.4 KiB
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Support\SignupApplicationFieldRegistry;
|
|
use Tests\TestCase;
|
|
|
|
class SignupApplicationFieldRegistryTest extends TestCase
|
|
{
|
|
public function test_validate_signup_schema_accepts_unknown_generic_scalar_field_key(): void
|
|
{
|
|
$error = SignupApplicationFieldRegistry::validateSignupSchemaJson([
|
|
[
|
|
'key' => 'custom_field',
|
|
'type' => 'text',
|
|
'label' => '自定义',
|
|
],
|
|
]);
|
|
|
|
$this->assertNull($error);
|
|
}
|
|
|
|
public function test_validate_signup_schema_accepts_recommend(): void
|
|
{
|
|
$error = SignupApplicationFieldRegistry::validateSignupSchemaJson([
|
|
[
|
|
'key' => 'recommend',
|
|
'type' => 'text',
|
|
'label' => '推荐方',
|
|
],
|
|
]);
|
|
|
|
$this->assertNull($error);
|
|
}
|
|
|
|
public function test_scalar_keys_derive_from_application_fillable(): void
|
|
{
|
|
$keys = SignupApplicationFieldRegistry::scalarColumnKeys();
|
|
|
|
$this->assertContains('recommend', $keys);
|
|
$this->assertContains('event_location', $keys);
|
|
$this->assertContains('team_members', $keys);
|
|
$this->assertContains('player_name', $keys);
|
|
$this->assertNotContains('entry_group', $keys);
|
|
$this->assertNotContains('status', $keys);
|
|
$this->assertNotContains('user_id', $keys);
|
|
}
|
|
|
|
public function test_manifest_lists_fillable_scalar_keys(): void
|
|
{
|
|
$manifest = SignupApplicationFieldRegistry::manifest();
|
|
|
|
$this->assertSame(SignupApplicationFieldRegistry::scalarColumnKeys(), $manifest['scalar_field_keys']);
|
|
$this->assertContains('recommend', $manifest['all_supported_form_keys']);
|
|
}
|
|
|
|
public function test_scalar_attributes_include_all_registry_columns(): void
|
|
{
|
|
$keys = array_keys(SignupApplicationFieldRegistry::scalarAttributesFromApplication(
|
|
new \App\Models\Application,
|
|
));
|
|
|
|
$this->assertSame(SignupApplicationFieldRegistry::scalarColumnKeys(), $keys);
|
|
}
|
|
|
|
public function test_filter_fillable_scalar_data_strips_unknown_keys(): void
|
|
{
|
|
$filtered = SignupApplicationFieldRegistry::filterFillableScalarData([
|
|
'recommend' => '某单位',
|
|
'unknown' => 'x',
|
|
]);
|
|
|
|
$this->assertSame(['recommend' => '某单位'], $filtered);
|
|
}
|
|
}
|