-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_answer.php
More file actions
30 lines (24 loc) · 967 Bytes
/
test_answer.php
File metadata and controls
30 lines (24 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
require 'vendor/autoload.php';
$app = require_once 'bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
try {
$user = App\Models\User::has('examSession')->first();
if (!$user) {
echo "No user with exam session found\n";
exit;
}
$session = $user->examSession;
Auth::login($user);
$req = Illuminate\Http\Request::create('/student/exam/save', 'POST', ['question_id' => 11, 'answer' => 'C']);
$req->headers->set('X-Exam-Token', $session->exam_token);
$controller = new App\Http\Controllers\ExamController();
$res = $controller->saveAnswer($req);
echo "Response: " . $res->getContent() . "\n";
$answer = App\Models\TestAnswer::where('user_id', $user->id)->first();
echo "is_correct: " . ($answer->is_correct ? 'TRUE' : 'FALSE') . "\n";
}
catch (\Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}