| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- namespace Tests\Unit;
- use Tests\TestCase;
- use App\Filament\Pages\IntelligentExamGeneration;
- use App\Services\KnowledgeGraphService;
- use App\Services\LearningAnalyticsService;
- use App\Services\QuestionBankService;
- use Illuminate\Support\Facades\Http;
- class IntelligentExamGenerationTest extends TestCase
- {
- protected function setUp(): void
- {
- parent::setUp();
- }
- /** @test */
- public function it_can_access_intelligent_exam_generation_page()
- {
- // 模拟访问智能出卷页面
- $response = $this->get('/admin/intelligent-exam-generation');
- $response->assertStatus(200);
- }
- /** @test */
- public function it_can_load_knowledge_points()
- {
- // 测试知识点获取功能
- $knowledgeGraphService = app(KnowledgeGraphService::class);
- // 模拟listKnowledgePoints方法返回
- $result = $knowledgeGraphService->listKnowledgePoints(1, 100);
- $this->assertIsArray($result);
- $this->assertArrayHasKey('data', $result);
- }
- /** @test */
- public function it_can_validate_form_before_generation()
- {
- // 创建页面实例
- $page = new IntelligentExamGeneration();
- // 设置必填字段为空,应该验证失败
- $this->assertFalse($page->paperName === 'required');
- }
- /** @test */
- public function it_can_generate_exam_with_basic_params()
- {
- // 模拟智能出卷参数
- $params = [
- 'student_id' => 'test_student_001',
- 'total_questions' => 10,
- 'kp_codes' => ['KP001', 'KP002'],
- 'skills' => [],
- 'question_type_ratio' => [
- '选择题' => 40,
- '填空题' => 30,
- '解答题' => 30,
- ],
- 'difficulty_ratio' => [
- '基础' => 50,
- '中等' => 35,
- '拔高' => 15,
- ],
- ];
- $learningAnalyticsService = app(LearningAnalyticsService::class);
- // 调用智能出卷服务
- $result = $learningAnalyticsService->generateIntelligentExam($params);
- $this->assertIsArray($result);
- $this->assertArrayHasKey('success', $result);
- }
- /** @test */
- public function it_can_save_exam_to_database()
- {
- $examData = [
- 'paper_name' => '测试试卷',
- 'paper_description' => '这是一份测试试卷',
- 'difficulty_category' => '基础',
- 'questions' => [],
- 'total_score' => 100,
- 'total_questions' => 10,
- ];
- $questionBankService = app(QuestionBankService::class);
- $paperId = $questionBankService->saveExamToDatabase($examData);
- $this->assertNotNull($paperId);
- $this->assertIsString($paperId);
- }
- /** @test */
- public function it_can_filter_by_student_weakness()
- {
- $studentId = 'test_student_001';
- $learningAnalyticsService = app(LearningAnalyticsService::class);
- // 获取学生薄弱点
- $weaknesses = $learningAnalyticsService->getStudentWeaknesses($studentId, 10);
- $this->assertIsArray($weaknesses);
- // 验证薄弱点数据结构
- if (!empty($weaknesses)) {
- $firstWeakness = $weaknesses[0];
- $this->assertArrayHasKey('kp_code', $firstWeakness);
- $this->assertArrayHasKey('mastery', $firstWeakness);
- }
- }
- /** @test */
- public function it_can_auto_generate_questions()
- {
- $filters = [
- 'kp_code' => 'KP001',
- 'count' => 5,
- 'difficulty_distribution' => [
- '基础' => 50,
- '中等' => 35,
- '拔高' => 15,
- ],
- ];
- $questionBankService = app(QuestionBankService::class);
- $result = $questionBankService->generateIntelligentQuestions($filters);
- $this->assertIsArray($result);
- $this->assertArrayHasKey('success', $result);
- }
- /** @test */
- public function it_can_export_exam_to_pdf()
- {
- $paperId = 'test_paper_001';
- $questionBankService = app(QuestionBankService::class);
- // 模拟导出PDF
- $pdfUrl = $questionBankService->exportExamToPdf($paperId);
- // 返回URL(可能是null或字符串)
- $this->assertTrue($pdfUrl === null || is_string($pdfUrl));
- }
- /** @test */
- public function it_validates_question_type_ratios_sum_to_100()
- {
- $page = new IntelligentExamGeneration();
- $ratios = $page->questionTypeRatio;
- $total = array_sum($ratios);
- $this->assertEquals(100, $total, '题型配比总和必须为100%');
- }
- /** @test */
- public function it_validates_difficulty_ratios_sum_to_100()
- {
- $page = new IntelligentExamGeneration();
- $ratios = $page->difficultyRatio;
- $total = array_sum($ratios);
- $this->assertEquals(100, $total, '难度配比总和必须为100%');
- }
- }
|