|
|
|
|
@ -279,6 +279,40 @@ class SurveyWorkflowTest extends TestCase
|
|
|
|
|
$this->assertSame(1, DB::table('course_content_evaluation_forms')->count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testUnavailableSurveysHideContentAndBlockSubmissionIncludingExistingReplies(): void
|
|
|
|
|
{
|
|
|
|
|
\Illuminate\Support\Carbon::setTestNow(\Illuminate\Support\Carbon::parse('2026-10-22 12:00:00'));
|
|
|
|
|
try {
|
|
|
|
|
$id = $this->createQuestion();
|
|
|
|
|
$detail = '/api/mobile/course/evaluation-detail?course_content_evaluation_id=10';
|
|
|
|
|
$submit = '/api/mobile/course/course-content-form';
|
|
|
|
|
$payload = ['course_content_evaluation_id' => 10, 'answer_version' => 2, 'data' => [['id' => $id, 'value' => ['count' => 0, 'follow' => 'no']]]];
|
|
|
|
|
$replyId = $this->postJson($submit, $payload)->assertOk()->json('id');
|
|
|
|
|
$original = DB::table('course_content_evaluation_forms')->where('id', $replyId)->value('data');
|
|
|
|
|
foreach ([
|
|
|
|
|
[1, '2026-10-23 00:00:00', null, 'not_started', '该问卷尚未开始,请于2026年10月23日后扫码打开该问卷。'],
|
|
|
|
|
[1, '2026-10-23 09:30:15', null, 'not_started', '该问卷尚未开始,请于2026年10月23日 09:30:15后扫码打开该问卷。'],
|
|
|
|
|
[1, null, '2026-10-22 12:00:00', 'ended', '该问卷已结束。'],
|
|
|
|
|
[0, null, null, 'draft', '该问卷还未开始。'],
|
|
|
|
|
[0, '2026-10-26 00:00:00', null, 'not_started', '该问卷尚未开始,请于2026年10月26日后扫码打开该问卷。'],
|
|
|
|
|
[0, '2026-10-26 09:30:15', null, 'not_started', '该问卷尚未开始,请于2026年10月26日 09:30:15后扫码打开该问卷。'],
|
|
|
|
|
[0, '2026-10-21 00:00:00', null, 'draft', '该问卷还未开始。'],
|
|
|
|
|
[0, null, '2020-01-01 00:00:00', 'draft', '该问卷还未开始。'],
|
|
|
|
|
] as [$status, $start, $end, $state, $message]) {
|
|
|
|
|
DB::table('course_content_evaluations')->where('id', 10)->update(['status' => $status, 'start_time' => $start, 'end_time' => $end]);
|
|
|
|
|
$this->getJson($detail)->assertExactJson(['id' => 10, 'access_state' => $state, 'access_error' => $message]);
|
|
|
|
|
$this->postJson($submit, $payload)->assertJsonPath('access_state', $state)->assertJsonPath('access_error', $message);
|
|
|
|
|
$this->assertSame($original, DB::table('course_content_evaluation_forms')->where('id', $replyId)->value('data'));
|
|
|
|
|
$this->assertSame(1, DB::table('course_content_evaluation_forms')->count());
|
|
|
|
|
}
|
|
|
|
|
DB::table('course_content_evaluations')->where('id', 10)->update(['status' => 1, 'start_time' => '2026-10-22 12:00:00', 'end_time' => null]);
|
|
|
|
|
$this->getJson($detail)->assertJsonPath('my_response.questions.0.id', $id);
|
|
|
|
|
$this->postJson($submit, $payload)->assertJsonPath('id', $replyId);
|
|
|
|
|
} finally {
|
|
|
|
|
\Illuminate\Support\Carbon::setTestNow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAudienceAndDeadlineProtectEntryAndSubmission(): void
|
|
|
|
|
{
|
|
|
|
|
Schema::create('courses', function (Blueprint $table) { $table->id(); $table->softDeletes(); });
|
|
|
|
|
@ -302,8 +336,8 @@ class SurveyWorkflowTest extends TestCase
|
|
|
|
|
$replyId = $this->postJson($submit, $payload)->assertOk()->json('id');
|
|
|
|
|
$this->assertNotNull($replyId);
|
|
|
|
|
DB::table('course_content_evaluations')->where('id', 10)->update(['end_time' => '2000-01-01 00:00:00']);
|
|
|
|
|
$this->getJson($detail)->assertJsonPath('access_error', '当前问卷已截止');
|
|
|
|
|
$this->postJson($submit, $payload)->assertJsonPath('access_error', '当前问卷已截止');
|
|
|
|
|
$this->getJson($detail)->assertJsonPath('access_state', 'ended')->assertJsonPath('access_error', '该问卷已结束。');
|
|
|
|
|
$this->postJson($submit, $payload)->assertJsonPath('access_state', 'ended')->assertJsonPath('access_error', '该问卷已结束。');
|
|
|
|
|
$this->assertSame(1, DB::table('course_content_evaluation_forms')->count());
|
|
|
|
|
DB::table('course_content_evaluations')->where('id', 10)->update(['end_time' => null]);
|
|
|
|
|
$this->postJson('/api/admin/course-content-evaluations/save', ['id' => 10, 'audience_course_ids' => []])->assertJsonPath('audience_course_ids', []);
|
|
|
|
|
@ -392,6 +426,8 @@ class SurveyWorkflowTest extends TestCase
|
|
|
|
|
])->assertOk();
|
|
|
|
|
DB::table('course_content_evaluations')->where('id', 10)->update(['title' => '新标题', 'status' => 0]);
|
|
|
|
|
DB::table('course_content_evaluation_asks')->where('id', $id)->update(['name' => '新题目']);
|
|
|
|
|
$this->getJson($url)->assertExactJson(['id' => 10, 'access_state' => 'draft', 'access_error' => '该问卷还未开始。']);
|
|
|
|
|
DB::table('course_content_evaluations')->where('id', 10)->update(['status' => 1]);
|
|
|
|
|
$this->getJson($url)->assertJsonPath('my_response.title', '培训问卷')
|
|
|
|
|
->assertJsonPath('my_response.questions.0.name', '融资对接')
|
|
|
|
|
->assertJsonPath('my_response.questions.0.value.count', 0)
|
|
|
|
|
@ -415,7 +451,7 @@ class SurveyWorkflowTest extends TestCase
|
|
|
|
|
$this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('errcode', 10001);
|
|
|
|
|
$this->getJson('/api/mobile/course/evaluation-detail?course_content_evaluation_id=10')->assertJsonPath('my_response.questions.0.value.count', 8);
|
|
|
|
|
DB::table('course_content_evaluations')->where('id', 10)->update(['end_time' => '2020-01-01 00:00:00']);
|
|
|
|
|
$this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('access_error', '当前问卷已截止');
|
|
|
|
|
$this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('access_error', '该问卷已结束。');
|
|
|
|
|
DB::table('course_content_evaluations')->where('id', 10)->update(['end_time' => null]);
|
|
|
|
|
$guest = new User();
|
|
|
|
|
$guest->forceFill(['id' => 201]);
|
|
|
|
|
|