2202
This commit is contained in:
parent
8c48ce115f
commit
d92bcf9e18
|
|
@ -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>$pa</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];
|
||||||
|
|
@ -288,8 +288,6 @@ function unittesting(){
|
||||||
$test = str_replace(array("\r\n","\r","\n"," "),"",$html);
|
$test = str_replace(array("\r\n","\r","\n"," "),"",$html);
|
||||||
$result_test = htmlspecialchars($test);
|
$result_test = htmlspecialchars($test);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$string = json_encode($output);
|
$string = json_encode($output);
|
||||||
|
|
||||||
$text = str_replace("\n", ' ', $output);
|
$text = str_replace("\n", ' ', $output);
|
||||||
|
|
@ -299,7 +297,7 @@ function unittesting(){
|
||||||
$pattern = '/Codeception PHP Testing Framework v([\d.]+)/';
|
$pattern = '/Codeception PHP Testing Framework v([\d.]+)/';
|
||||||
|
|
||||||
// Define patterns to extract relevant information
|
// 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_php_runtime = '/Runtime:\s+PHP\s+([\d.]+)/';
|
||||||
$pattern_configuration = '/Configuration:\s+(.+)/';
|
$pattern_configuration = '/Configuration:\s+(.+)/';
|
||||||
$pattern_failure_count = '/There was (\d+) failure/';
|
$pattern_failure_count = '/There was (\d+) failure/';
|
||||||
|
|
@ -323,7 +321,7 @@ function unittesting(){
|
||||||
preg_match($pattern_failures, $text, $matches_failures);
|
preg_match($pattern_failures, $text, $matches_failures);
|
||||||
preg_match($pattern, $cleaned, $matches);
|
preg_match($pattern, $cleaned, $matches);
|
||||||
// Extracted information
|
// 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_stat = isset($matches_ok[0]) ? $matches_ok[0] : "Not found";
|
||||||
$phpunit_time = isset($matches_time[1]) ? $matches_time[1] : "Not found";
|
$phpunit_time = isset($matches_time[1]) ? $matches_time[1] : "Not found";
|
||||||
$phpunit_memory = isset($matches_memory[0]) ? $matches_memory[0] : "Not found";
|
$phpunit_memory = isset($matches_memory[0]) ? $matches_memory[0] : "Not found";
|
||||||
|
|
|
||||||
|
|
@ -51,26 +51,71 @@ function result_test(){
|
||||||
|
|
||||||
");
|
");
|
||||||
$row = $sql[0];
|
$row = $sql[0];
|
||||||
$html2 = htmlspecialchars($row->output);
|
$html2 = htmlspecialchars($row->ket);
|
||||||
$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' => $result_content,
|
'result_up' => $html2,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// echo "$value == $sess_name";
|
// 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(){
|
function get_session(){
|
||||||
if (Auth::check()) {
|
if (Auth::check()) {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@
|
||||||
</include>
|
</include>
|
||||||
</source>
|
</source>
|
||||||
<php>
|
<php>
|
||||||
|
<ini name="error_reporting" value="-1"/>
|
||||||
|
<ini name="display_errors" value="1"/>
|
||||||
|
<ini name="output_buffering" value="Off"/>
|
||||||
<env name="APP_ENV" value="testing"/>
|
<env name="APP_ENV" value="testing"/>
|
||||||
<env name="BCRYPT_ROUNDS" value="4"/>
|
<env name="BCRYPT_ROUNDS" value="4"/>
|
||||||
<env name="CACHE_DRIVER" value="array"/>
|
<env name="CACHE_DRIVER" value="array"/>
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
Route::post('/palm-testing', [WelcomeController::class, 'palm_testing'])->name('phpunit.palm_testing');
|
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('/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', [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::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('/form-upload', [WelcomeController::class, 'form_upload'])->name('phpunit.form-upload');
|
||||||
Route::any('/proses', [WelcomeController::class, 'proses_upload'])->name('phpunit.proses');
|
Route::any('/proses', [WelcomeController::class, 'proses_upload'])->name('phpunit.proses');
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature; // Ensure the namespace is correct for feature tests
|
namespace Tests\Feature; // Ensure the namespace is correct for feature tests
|
||||||
|
ob_start();
|
||||||
use Tests\TestCase; // Use Laravel's base TestCase class
|
use Tests\TestCase; // Use Laravel's base TestCase class
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
class HomepageLayoutTest extends TestCase
|
class HomepageLayoutTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -14,60 +16,47 @@ class HomepageLayoutTest extends TestCase
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function testLatihanNumberOne():void{
|
public function testLatihanNumberOne():void{
|
||||||
|
|
||||||
$response = $this->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'");
|
$sql = DB::select("SELECT * FROM php_testing_rule WHERE testing_name = 'testing_number_one'");
|
||||||
$row = $sql[0];
|
$row = $sql[0];
|
||||||
$html = $row->testing_rule;
|
$html = $row->testing_rule;
|
||||||
|
$hasil_output = $row->output;
|
||||||
|
|
||||||
$test = str_replace(array("\r\n","\r","\n"," "),"",$html);
|
$test = str_replace(array("\r\n","\r","\n"," "),"",$html);
|
||||||
$result_test = htmlspecialchars($test);
|
$result_test = htmlspecialchars($test);
|
||||||
|
|
||||||
$result_content = str_replace(array("\r\n","\r"," "),"", $response->content());
|
$result_content = str_replace(array("\r\n","\r"," "),"", $response->content());
|
||||||
|
if($result_test == $result_content){
|
||||||
$this->assertStringContainsString($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{
|
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;
|
$hasil_output = $row->output;
|
||||||
|
|
||||||
|
$test = str_replace(array("\r\n","\r","\n"," "),"",$html);
|
||||||
|
$result_test = htmlspecialchars($test);
|
||||||
|
|
||||||
$studentFile = storage_path('app/public/uploads/Amal Dermawan Udjir/GuideA2.php');
|
$result_content = str_replace(array("\r\n","\r"," "),"", $response->content());
|
||||||
if (!file_exists($studentFile)) {
|
if($result_test == $result_content){
|
||||||
$this->fail("❌ File siswa tidak ditemukan: $studentFile");
|
$this->assertStringContainsString($result_test, $result_content);
|
||||||
return;
|
}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);
|
||||||
}
|
}
|
||||||
// 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."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user