1514
This commit is contained in:
parent
a92b90cc51
commit
8c48ce115f
|
|
@ -279,7 +279,7 @@ function unittesting(){
|
||||||
$pa = "vendor\bin\phpunit -c $path_test --filter HomepageLayoutTest::$unitesting_run";
|
$pa = "vendor\bin\phpunit -c $path_test --filter HomepageLayoutTest::$unitesting_run";
|
||||||
$path = base_path($pa);
|
$path = base_path($pa);
|
||||||
$output = shell_exec($path);
|
$output = shell_exec($path);
|
||||||
//echo "<pre>$output</pre>";
|
echo "<pre>$pa</pre>";
|
||||||
|
|
||||||
$sql = DB::select("SELECT * FROM php_testing_rule WHERE testing_name = '$testing_number_one'");
|
$sql = DB::select("SELECT * FROM php_testing_rule WHERE testing_name = '$testing_number_one'");
|
||||||
$row = $sql[0];
|
$row = $sql[0];
|
||||||
|
|
|
||||||
|
|
@ -51,17 +51,22 @@ function result_test(){
|
||||||
|
|
||||||
");
|
");
|
||||||
$row = $sql[0];
|
$row = $sql[0];
|
||||||
$html2 = htmlspecialchars($row->ket);
|
$html2 = htmlspecialchars($row->output);
|
||||||
$test = str_replace(array("\r\n","\r","\n"," "),"",$html2);
|
$test = str_replace(array("\r\n","\r","\n"," "),"",$html2);
|
||||||
|
|
||||||
$result_content2 = str_replace(array("\r\n","\r"," "),"", $test);
|
$result_content2 = str_replace(array("\r\n","\r"," "),"", $test);
|
||||||
|
|
||||||
|
$studentFile = storage_path('app/public/uploads/Amal Dermawan Udjir/GuideA2.php');
|
||||||
|
ob_start();
|
||||||
|
include $studentFile; // Jalankan file PHP siswa
|
||||||
|
$studentOutput = ob_get_clean(); // Tangkap hasil output yang dihasilkan oleh kode siswa
|
||||||
|
$result_content = str_replace(array("\r\n","\r"," "),"", $studentOutput);
|
||||||
|
|
||||||
/* $actual = storage_path("app/private/{$username}/{$userfile}");
|
/* $actual = storage_path("app/private/{$username}/{$userfile}");
|
||||||
$php_output = shell_exec("PHP $actual 2>&1");
|
$php_output = shell_exec("PHP $actual 2>&1");
|
||||||
$test = str_replace(array("\r\n","\r","\n"," "),"",highlight_string($php_output));
|
$test = str_replace(array("\r\n","\r","\n"," "),"",highlight_string($php_output));
|
||||||
*/
|
*/
|
||||||
return view('php.student.task.result_submssion_task',[
|
return view('php.student.task.result_submssion_task',[
|
||||||
'result_up' => $html2,
|
'result_up' => $result_content,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// echo "$value == $sess_name";
|
// echo "$value == $sess_name";
|
||||||
|
|
|
||||||
|
|
@ -30,19 +30,42 @@ public function testLatihanNumberOne():void{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLatihanNumberTwo():void{
|
public function testLatihanNumberTwo():void{
|
||||||
|
|
||||||
|
|
||||||
$response = $this->get("/phpunit/result-test-student/");
|
|
||||||
|
|
||||||
$sql = DB::select("SELECT * FROM php_testing_rule WHERE testing_name = 'testing_number_two'");
|
$sql = DB::select("SELECT * FROM php_testing_rule WHERE testing_name = 'testing_number_two'");
|
||||||
$row = $sql[0];
|
$row = $sql[0];
|
||||||
$html = $row->testing_rule;
|
$html = $row->testing_rule;
|
||||||
|
$output = $row->output;
|
||||||
|
|
||||||
$test = str_replace(array("\r\n","\r","\n"," "),"",$html);
|
|
||||||
$result_test = htmlspecialchars($test);
|
|
||||||
|
|
||||||
$result_content = str_replace(array("\r\n","\r"," "),"", $response->content());
|
$studentFile = storage_path('app/public/uploads/Amal Dermawan Udjir/GuideA2.php');
|
||||||
$this->assertStringContainsString($result_test, $result_content);
|
if (!file_exists($studentFile)) {
|
||||||
|
$this->fail("❌ File siswa tidak ditemukan: $studentFile");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Ambil isi file PHP siswa
|
||||||
|
$studentCode = file_get_contents($studentFile);
|
||||||
|
|
||||||
|
// Normalisasi kunci jawaban dan kode siswa untuk perbandingan
|
||||||
|
$normalizedHtml = $this->normalize($html); // Normalisasi kode kunci jawaban
|
||||||
|
$normalizedStudentCode = $this->normalize($studentCode); // Normalisasi kode siswa
|
||||||
|
if ($normalizedHtml === $normalizedStudentCode) {
|
||||||
|
// Jika kode siswa sesuai dengan kunci jawaban
|
||||||
|
$this->assertEquals(
|
||||||
|
$normalizedHtml,
|
||||||
|
$normalizedStudentCode,
|
||||||
|
"Struktur kode yang dikirim siswa tidak sesuai dengan kunci jawaban."
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Jika struktur kode tidak sesuai, periksa output dari respons HTTP
|
||||||
|
$response = $this->get("/phpunit/result-test-student/");
|
||||||
|
$actualOutput = $response->content();
|
||||||
|
|
||||||
|
// Bandingkan output yang diterima dengan output yang diharapkan
|
||||||
|
$this->assertEquals(
|
||||||
|
trim($output),
|
||||||
|
trim($actualOutput),
|
||||||
|
"Output dari respons HTTP tidak sesuai dengan output kunci jawaban."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -184,4 +207,24 @@ public function add($a, $b): int
|
||||||
{
|
{
|
||||||
return $a + $b;
|
return $a + $b;
|
||||||
}
|
}
|
||||||
|
private function normalize($string): string
|
||||||
|
{
|
||||||
|
return preg_replace('/\s+/', '', $string); // hilangkan semua spasi, tab, newline
|
||||||
|
}
|
||||||
|
// Fungsi untuk mengganti nama variabel dengan placeholder
|
||||||
|
private function normalizeVariables(string $code): string
|
||||||
|
{
|
||||||
|
// Menangkap nama variabel menggunakan ekspresi regular
|
||||||
|
preg_match_all('/\$(\w+)/', $code, $matches);
|
||||||
|
|
||||||
|
// Membuat daftar variabel unik
|
||||||
|
$uniqueVariables = array_unique($matches[1]);
|
||||||
|
|
||||||
|
// Gantikan nama variabel dengan placeholder dinamis
|
||||||
|
foreach ($uniqueVariables as $index => $variable) {
|
||||||
|
$code = str_replace('$' . $variable, '$var' . $index, $code); // Ganti variabel dengan placeholder
|
||||||
|
}
|
||||||
|
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user