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.

97 lines
3.8 KiB

2 months ago
<?php
namespace Tests\Unit;
use App\Support\DefaultTrackScoringSheets;
use App\Support\TrackScoringSheet;
use PHPUnit\Framework\TestCase;
class TrackScoringSheetTest extends TestCase
{
1 month ago
public function test_optical_track_sheets_sum_to_100(): void
{
foreach (['guang_xinpian', 'zhizao_fengzhuang', 'guangdian_cailiao', 'guangtongxin_yingyong'] as $code) {
$sheet = DefaultTrackScoringSheets::forTrackCode($code);
$this->assertNotNull($sheet, $code);
$parsed = TrackScoringSheet::parseAndValidateConfig($sheet);
$this->assertTrue($parsed['ok'], $code.': '.($parsed['message'] ?? ''));
$this->assertSame(100.0, $parsed['sheet']['full_score']);
}
}
2 months ago
public function test_default_ai_track_sheet_sums_to_100(): void
{
$sheet = DefaultTrackScoringSheets::forTrackCode('xiaofei_ai', '消费+人工智能');
$this->assertNotNull($sheet);
$parsed = TrackScoringSheet::parseAndValidateConfig($sheet);
$this->assertTrue($parsed['ok']);
$this->assertSame(100.0, $parsed['sheet']['full_score']);
$this->assertCount(8, $parsed['sheet']['items']);
}
public function test_config_rejects_sum_not_100(): void
{
$parsed = TrackScoringSheet::parseAndValidateConfig([
'version' => 1,
'title' => 't',
'items' => [
[
'key' => 'a',
'sort' => 1,
'category' => '通用指标',
'title' => 'A',
'criteria' => '',
'max_score' => 40,
],
],
]);
$this->assertFalse($parsed['ok']);
$this->assertStringContainsString('100', $parsed['message']);
}
2 months ago
public function test_submit_accepts_total_including_zero(): void
2 months ago
{
$sheet = DefaultTrackScoringSheets::forTrackCode('xiaofei_ai', '消费+人工智能');
$this->assertNotNull($sheet);
$parsed = TrackScoringSheet::parseAndValidateConfig($sheet);
$this->assertTrue($parsed['ok']);
2 months ago
$ok = TrackScoringSheet::normalizeSubmitPayload($parsed['sheet'], ['line_total' => 0]);
2 months ago
$this->assertTrue($ok['ok']);
$this->assertSame(0.0, $ok['line_total']);
2 months ago
$ok100 = TrackScoringSheet::normalizeSubmitPayload($parsed['sheet'], ['line_total' => 100]);
$this->assertTrue($ok100['ok']);
$this->assertSame(100.0, $ok100['line_total']);
2 months ago
$ok2dp = TrackScoringSheet::normalizeSubmitPayload($parsed['sheet'], ['line_total' => '88.50']);
$this->assertTrue($ok2dp['ok']);
$this->assertSame(88.5, $ok2dp['line_total']);
2 months ago
$missing = TrackScoringSheet::normalizeSubmitPayload($parsed['sheet'], []);
2 months ago
$this->assertFalse($missing['ok']);
$this->assertStringContainsString('请填写', $missing['message']);
}
2 months ago
public function test_submit_rejects_out_of_range_total(): void
2 months ago
{
$sheet = DefaultTrackScoringSheets::forTrackCode('xiaofei_ai', '消费+人工智能');
$parsed = TrackScoringSheet::parseAndValidateConfig($sheet);
$this->assertTrue($parsed['ok']);
2 months ago
$over = TrackScoringSheet::normalizeSubmitPayload($parsed['sheet'], ['line_total' => 100.01]);
2 months ago
$this->assertFalse($over['ok']);
2 months ago
$this->assertStringContainsString('不能大于 100', $over['message']);
2 months ago
$neg = TrackScoringSheet::normalizeSubmitPayload($parsed['sheet'], ['line_total' => -1]);
$this->assertFalse($neg['ok']);
2 months ago
$this->assertStringContainsString('不能为负数', $neg['message']);
2 months ago
$tooManyDecimals = TrackScoringSheet::normalizeSubmitPayload($parsed['sheet'], ['line_total' => '88.501']);
$this->assertFalse($tooManyDecimals['ok']);
$this->assertStringContainsString('两位小数', $tooManyDecimals['message']);
2 months ago
}
}