diff --git a/app/Http/Controllers/PHP/PHPController.php b/app/Http/Controllers/PHP/PHPController.php index 68b8dc1..c53a004 100644 --- a/app/Http/Controllers/PHP/PHPController.php +++ b/app/Http/Controllers/PHP/PHPController.php @@ -279,7 +279,7 @@ function unittesting(){ $pa = "vendor\bin\phpunit -c $path_test --filter HomepageLayoutTest::$unitesting_run"; $path = base_path($pa); $output = shell_exec($path); - echo "
$pa
"; + //echo "
$pa
"; $sql = DB::select("SELECT * FROM php_testing_rule WHERE testing_name = '$testing_number_one'"); $row = $sql[0]; @@ -288,8 +288,6 @@ function unittesting(){ $test = str_replace(array("\r\n","\r","\n"," "),"",$html); $result_test = htmlspecialchars($test); - - $string = json_encode($output); $text = str_replace("\n", ' ', $output); @@ -299,7 +297,7 @@ function unittesting(){ $pattern = '/Codeception PHP Testing Framework v([\d.]+)/'; // Define patterns to extract relevant information - $pattern_phpunit_version = '/Codeception\s+(\d+\.\d+\.\d+)/'; + $pattern_phpunit_version = '/PHPUnit\s+([\d.]+)\s+by/'; $pattern_php_runtime = '/Runtime:\s+PHP\s+([\d.]+)/'; $pattern_configuration = '/Configuration:\s+(.+)/'; $pattern_failure_count = '/There was (\d+) failure/'; @@ -323,7 +321,7 @@ function unittesting(){ preg_match($pattern_failures, $text, $matches_failures); preg_match($pattern, $cleaned, $matches); // Extracted information - $phpunit_version = isset($matches[1]) ? $matches[1] : "Not founds"; + $phpunit_version = $matches_phpunit_version[1] ?? 'Not found'; $phpunit_stat = isset($matches_ok[0]) ? $matches_ok[0] : "Not found"; $phpunit_time = isset($matches_time[1]) ? $matches_time[1] : "Not found"; $phpunit_memory = isset($matches_memory[0]) ? $matches_memory[0] : "Not found"; diff --git a/app/Http/Controllers/PHP/Student/WelcomeController.php b/app/Http/Controllers/PHP/Student/WelcomeController.php index dc0bdbb..0cfe00f 100644 --- a/app/Http/Controllers/PHP/Student/WelcomeController.php +++ b/app/Http/Controllers/PHP/Student/WelcomeController.php @@ -51,26 +51,71 @@ function result_test(){ "); $row = $sql[0]; - $html2 = htmlspecialchars($row->output); + $html2 = htmlspecialchars($row->ket); $test = str_replace(array("\r\n","\r","\n"," "),"",$html2); $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}"); $php_output = shell_exec("PHP $actual 2>&1"); $test = str_replace(array("\r\n","\r","\n"," "),"",highlight_string($php_output)); */ return view('php.student.task.result_submssion_task',[ - 'result_up' => $result_content, + 'result_up' => $html2, ]); // echo "$value == $sess_name"; + } + function result_test_output(){ + $uname = DB::select("SELECT * FROM users + WHERE name COLLATE utf8mb4_general_ci IN (SELECT userid FROM php_user_submits) "); + + if (!empty($uname)) { + $firstUser = reset($uname); // Get the first element of the array + $sess_name = isset($firstUser->name) ? $firstUser->name : ''; // Access the 'name' property of the first user + } + + + $task = DB::table('php_submits_submission')->where('username', "$sess_name")->first(); + $username = $task->username; + + $sql = DB::select("SELECT + * + FROM + php_submits_submission a + LEFT JOIN php_testing_rule b ON a.testing_type = b.testing_name + WHERE + a.username COLLATE utf8mb4_general_ci = '$username' + ORDER BY + a.id DESC + LIMIT 1; + + "); + $row = $sql[0]; + $userfile = $row->userfile; + $ket = htmlspecialchars($row->ket); + $html2 = htmlspecialchars($row->output); + $test = str_replace(array("\r\n","\r","\n"," "),"",$html2); + $result_content2 = str_replace(array("\r\n","\r"," "),"", $test); + + $studentFile = storage_path("app/public/uploads/$username/$userfile"); + //$studentFile = storage_path("app/public/uploads/$val/GuideA1.php"); + + ob_start(); + include ($studentFile); + $studentOutput = ob_get_clean(); + + + $result_content = str_replace(array("\r\n", "\r", "\n", " "), "", $studentOutput); + + return view('php.student.task.result_submssion_task', [ + 'result_up' => $result_content, + ]); + ob_end_clean(); + // echo "$value == $sess_name"; + } function get_session(){ if (Auth::check()) { diff --git a/phpunit.xml b/phpunit.xml index f112c0c..5c8fbca 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,6 +18,9 @@ + + + diff --git a/routes/phpunit_routes.php b/routes/phpunit_routes.php index af93f72..c7da6bd 100644 --- a/routes/phpunit_routes.php +++ b/routes/phpunit_routes.php @@ -12,6 +12,7 @@ Route::post('/palm-testing', [WelcomeController::class, 'palm_testing'])->name('phpunit.palm_testing'); Route::get('/unit-testing', [WelcomeController::class, 'unittesting'])->name('phpunit.unit-testing'); Route::get('/result-test-student', [WelcomeController::class, 'result_test'])->name('phpunit.result-test-student'); + Route::get('/result-test-student-output', [WelcomeController::class, 'result_test_output'])->name('phpunit.result-test-student-output'); Route::get('/result-test-student-add', [WelcomeController::class, 'result_add'])->name('phpunit.result-test-student-add'); Route::any('/form-upload', [WelcomeController::class, 'form_upload'])->name('phpunit.form-upload'); Route::any('/proses', [WelcomeController::class, 'proses_upload'])->name('phpunit.proses'); diff --git a/tests/Unit/HomepageLayoutTest.php b/tests/Unit/HomepageLayoutTest.php index e50496c..63d63e8 100644 --- a/tests/Unit/HomepageLayoutTest.php +++ b/tests/Unit/HomepageLayoutTest.php @@ -1,11 +1,13 @@ get("/phpunit/result-test-student/"); + $response = $this->get("/phpunit/result-test-student/"); - $sql = DB::select("SELECT * FROM php_testing_rule WHERE testing_name = 'testing_number_one'"); - $row = $sql[0]; - $html = $row->testing_rule; - - $test = str_replace(array("\r\n","\r","\n"," "),"",$html); - $result_test = htmlspecialchars($test); - - $result_content = str_replace(array("\r\n","\r"," "),"", $response->content()); - $this->assertStringContainsString($result_test, $result_content); + $sql = DB::select("SELECT * FROM php_testing_rule WHERE testing_name = 'testing_number_one'"); + $row = $sql[0]; + $html = $row->testing_rule; + $hasil_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()); + if($result_test == $result_content){ + $this->assertStringContainsString($result_test, $result_content); + }else{ + $response = $this->get("/phpunit/result-test-student-output/"); + $response->assertSeeText('BelajarMembuatHeadingdanParagraphHeadingke-1Headingke-2Headingke-3Headingke-4Headingke-5Headingke-6inicontohparagraph'); + } } public function testLatihanNumberTwo():void{ - $sql = DB::select("SELECT * FROM php_testing_rule WHERE testing_name = 'testing_number_two'"); - $row = $sql[0]; - $html = $row->testing_rule; - $output = $row->output; - - - $studentFile = storage_path('app/public/uploads/Amal Dermawan Udjir/GuideA2.php'); - 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." - ); - } - - + $sql = DB::select("SELECT * FROM php_testing_rule WHERE testing_name = 'testing_number_two'"); + $row = $sql[0]; + $html = $row->testing_rule; + $hasil_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()); + if($result_test == $result_content){ + $this->assertStringContainsString($result_test, $result_content); + }else{ + $response = $this->get("/phpunit/result-test-student-output/"); + $test = str_replace(array("\r\n","\r","\n"," "),"",$hasil_output); + $result_test = htmlspecialchars($test); + $result_content = str_replace(array("\r\n","\r"," "),"", $response->content()); + $this->assertEquals($result_test, $result_content); + } }