get();
$topicsCount = count($topics);
return view('php.student.material.index',[
'result_up' => $actual,
'topics' => $topics,
'topicsCount' => $topicsCount,
]);
}
function php_material_detail(){
$phpid = isset($_GET['phpid']) ? $_GET['phpid'] : '';
$start = isset($_GET['start']) ? $_GET['start'] : '';
$type = isset($_GET['type']) ? $_GET['type'] : '';
$results = DB::select("select * from php_topics_detail where id_topics = $phpid and id ='$start' ");
foreach($results as $r){
if( $phpid == $r->id_topics){
if(empty($r->file_name)){
$contain = $r->description;
$pdf_reader = 0;
}else{
$contain = $r->file_name;
$pdf_reader = 1;
}
$html_start = $this->html_persyaratan($contain,$pdf_reader);
}else{
$html_start = "";
}
}
$topics = Topic::where('type', $type)->get();
$detail = Topic::findorfail($phpid);
$topicsCount = count($topics);
$detailCount = ($topicsCount/$topicsCount)*10;
return view('php.student.material.topics_detail',[
'row' => $detail,
'topics' => $topics,
'phpid' => $phpid,
'html_start' => $html_start,
'pdf_reader' => $pdf_reader ,
'topicsCount' => $topicsCount ,
'detailCount' => $detailCount ,
]);
}
function html_start(){
$html ="
Modul kelas Belajar Pengembangan Aplikasi Android Intermediate dalam bentuk cetak (buku) maupun elektronik sudah didaftarkan ke Dirjen HKI, Kemenkumham RI. Segala bentuk penggandaan dan atau komersialisasi, sebagian atau seluruh bagian, baik cetak maupun elektronik terhadap modul kelas Belajar Pengembangan Aplikasi Android Intermediate tanpa izin formal tertulis kepada pemilik hak cipta akan diproses melalui jalur hukum.
";
return $html;
}
function html_persyaratan($desc,$pdf_reader){
$html = $desc;
return $html;
}
public function upload(Request $request)
{
if ($request->hasFile('upload')) {
$originName = $request->file('upload')->getClientOriginalName();
$fileName = pathinfo($originName, PATHINFO_FILENAME);
$extension = $request->file('upload')->getClientOriginalExtension();
$fileName = $fileName . '_' . time() . '.' . $extension;
$request->file('upload')->move(public_path('media'), $fileName);
$url = asset('media/' . $fileName);
return response()->json(['fileName' => $fileName, 'uploaded' => 1, 'url' => $url]);
}
}
function send_task(){
$phpid = isset($_GET['phpid']) ? $_GET['phpid'] : '';
$task = isset($_GET['task']) ? $_GET['task'] : '';
$type = isset($_GET['type']) ? $_GET['type'] : '';
$task_db = DB::table('php_task')
->where('id_topics', $phpid)
->where('task_no', $task)
->first();
if($task_db->task_no == $task){
if($type == 1){
$html_start = $this->html_task();
}else if($type == 2){
$html_start = $this->html_task_codeception();
}
}else{
$html_start = "";
}
$pdf_reader = 0;
$topics = Topic::where('type', $type)->get();;
$detail = Topic::findorfail($phpid);
$topicsCount = count($topics);
$persen = ($topicsCount/$topicsCount)*10;
session(['params' => $persen]);
return view('php.student.material.topics_detail',[
'row' => $detail,
'topics' => $topics,
'phpid' => $phpid,
'html_start' => $html_start,
'pdf_reader' => $pdf_reader ,
'detailCount' => $persen,
]);
}
function html_task_codeception(){
return view('php.student.task.form_submission_task_codeception',[]);
}
function html_task(){
return view('php.student.task.form_submission_task',[]);
}
function php_admin(){
return view('php.admin.material.upload_materi',[]);
}
function task_submission(Request $request){
$phpid = $_POST['phpid'];
$type = $_POST['type'];
$task_id = $_POST['testing_number_one'];
$file = $request->file('file');
//$file_name = Auth::user()->name.'_'.$file->getClientOriginalName();
if($phpid == 13 and $task_id == 1){
$file_name = 'form_insert.php';
}elseif($phpid == 14 and $task_id == 1){
$file_name = 'koneksi.php';
}elseif($phpid == 14 and $task_id == 2){
$file_name = 'index.php';
}elseif($phpid == 14 and $task_id == 3){
$file_name = 'insert.php';
}elseif($phpid == 14 and $task_id == 4){
$file_name = 'update.php';
}elseif($phpid == 14 and $task_id == 5){
$file_name = 'delete.php';
}else{
$file_name = $file->getClientOriginalName();
}
Storage::disk('local')->makeDirectory('public/uploads/'.Auth::user()->name);
$file->storeAs('/uploads/'.Auth::user()->name, $file_name, 'public');
$userName = Auth::user()->name;
Session::put('user_name', $userName);
$user_name = Session::get('user_name');
$name = Session::put('ori_file_name', $file_name);
$path = storage_path("app/public/uploads/$userName/$file_name");;
Session::put('path', $path);
$val = session('key');
DB::select("TRUNCATE TABLE php_user_submits");
DB::insert("insert into php_user_submits(userid) values ('$val')");
$fileContent = file_get_contents($path);
if($_POST['testing_number_one'] == 1){
$testing_number_one = "testing_number_one";
}elseif($_POST['testing_number_one'] == 2){
$testing_number_one = "testing_number_two";
}elseif($_POST['testing_number_one'] == 3){
$testing_number_one = "testing_number_three";
}elseif($_POST['testing_number_one'] == 4){
$testing_number_one = "testing_number_four";
}elseif($_POST['testing_number_one'] == 5){
$testing_number_one = "testing_number_five";
}
$fileContent = str_replace("'", '"', $fileContent);
DB::select("insert into php_submits_submission(task_id,task_topics,task_no,testing_type,username,userfile,ket) values ('$task_id','$phpid','$type','$testing_number_one','$val','$file_name','$fileContent')");
return redirect("/php/send-task?phpid=$phpid&task=$task_id&type=$type")->with('status', 'File Successfully Uploaded!');
}
function task_submission_(Request $request){
$this->validate($request, [
'file' => 'required',
]);
// menyimpan data file yang diupload ke variabel $file
$file = $request->file('file');
$file_name = Auth::user()->name.'_'.$file->getClientOriginalName();
Storage::disk('local')->makeDirectory('private/'.Auth::user()->name);
Storage::disk('local')->put('/private/'.Auth::user()->name.'/'.$file_name,File::get($file));
$userName = Auth::user()->name;
Session::put('user_name', $userName);
$user_name = Session::get('user_name');
$name = Session::put('ori_file_name', $file_name);
$path = storage_path("app/private/{$userName}/{$file_name}");
Session::put('path', $path);
$val = session('key');
DB::select("TRUNCATE TABLE php_user_submits");
DB::insert("insert into php_user_submits(userid) values ('$val')");
$fileContent = file_get_contents($path);
$task_id = $_POST['testing_number_one'];
$phpid = $_POST['phpid'];
if($_POST['testing_number_one'] == 1){
$testing_number_one = "testing_number_one";
}elseif($_POST['testing_number_one'] == 2){
$testing_number_one = "testing_number_two";
}elseif($_POST['testing_number_one'] == 3){
$testing_number_one = "testing_number_three";
}elseif($_POST['testing_number_one'] == 4){
$testing_number_one = "testing_number_four";
}elseif($_POST['testing_number_one'] == 5){
$testing_number_one = "testing_number_five";
}elseif($_POST['testing_number_one'] == 6){
$testing_number_one = "testing_number_six";
}
DB::select("insert into php_submits_submission(task_id,testing_type,username,userfile,ket) values ('$task_id','$testing_number_one','$val','$file_name','$fileContent')");
return redirect("/php/send-task?phpid=$phpid&task=$task_id")->with('status', 'File Successfully Uploaded!');
}
function unittesting(){
$val = session('key');
DB::select("TRUNCATE TABLE php_user_submits");
DB::insert("insert into php_user_submits(userid) values ('$val')");
$kode = $_POST['kode'];
if($kode == '1'){
$unitesting_run = 'testLatihanNumberOne';
$testing_number_one = "testing_number_one";
}elseif($kode == '2'){
$unitesting_run = 'testLatihanNumberTwo';
$testing_number_one = "testing_number_two";
}elseif($kode == '3'){
$unitesting_run = 'testLatihanNumberThree';
$testing_number_one = "testing_number_three";
}elseif($kode == '4'){
$unitesting_run = 'testLatihanNumberFour';
$testing_number_one = "testing_number_four";
}elseif($kode == '5'){
$unitesting_run = 'testLatihanNumberFive';
$testing_number_one = "testing_number_five";
}elseif($kode == '6'){
$unitesting_run = 'testLatihanNumberSix';
$testing_number_one = "testing_number_six";
}
/** CODECEPTION TEST */
//$command = "cd " . base_path() . " && php codecept.phar run Functional LoginTest --filter $unitesting_run"; //(codeception)
//$command = "cd " . base_path() . " && php codecept.phar run Unit PHPBasicTest --filter testLatihanNumberOne";
// $output = shell_exec($command);
/** PHPUNIT TEST */
$path_test = base_path("phpunit.xml");
$pa = "vendor\bin\phpunit -c $path_test --filter HomepageLayoutTest::$unitesting_run";
$path = base_path($pa);
$output = shell_exec($path);
//echo "$pa
";
$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);
$string = json_encode($output);
$text = str_replace("\n", ' ', $output);
$cleaned = preg_replace('/\e\[[;?\d]*m/', '', $string);
// Pola regex untuk mengekstrak versi Codeception
$pattern = '/Codeception PHP Testing Framework v([\d.]+)/';
// Define patterns to extract relevant information
$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/';
$pattern_failure_test_case = '/Failed asserting that \'(.*?)\' contains \'(.*?)\'./';
$pattern_failure_location = '/(C:\\\\.*?\\.php):(\d+)/';
$pattern_path = 'C:\\xampp\\htdocs\\iclop\\phpunit.xml';
$pattern_time = '/Time:\s+([0-9:.]+)/';
$pattern_memory = '/Memory:\s+([\d.]+)\s+(MB|KB|GB)/';
$pattern_ok = '/OK\s+\((\d+)\s+test(?:s)?,\s+(\d+)\s+assertion(?:s)?\)/';
$pattern_failures = '/Tests:\s+(\d+),\s+Assertions:\s+(\d+),\s+Failures:\s+(\d+)/';
// Perform matching
preg_match($pattern_phpunit_version, $text, $matches_phpunit_version);
preg_match($pattern_php_runtime, $text, $matches_php_runtime);
preg_match($pattern_configuration, $text, $matches_configuration);
preg_match($pattern_failure_count, $text, $matches_failure_count);
preg_match($pattern_failure_test_case, $text, $matches_failure_test_case);
preg_match($pattern_failure_location, $text, $matches_failure_location);
preg_match($pattern_ok, $text, $matches_ok);
preg_match($pattern_time, $text, $matches_time);
preg_match($pattern_memory, $text, $matches_memory);
preg_match($pattern_failures, $text, $matches_failures);
preg_match($pattern, $cleaned, $matches);
// Extracted information
$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";
$php_runtime = isset($matches_php_runtime[1]) ? $matches_php_runtime[1] : "Not found";
$configuration_path = isset($matches_configuration[1]) ? $matches_configuration[1] : "Not found";
$num_failures = isset($matches_failure_count[1]) ? $matches_failure_count[1] : "Not found";
$failed_assertion = isset($matches_failure_test_case[1]) ? htmlspecialchars($matches_failure_test_case[1]) : "Not found";
$expected_content = isset($matches_failure_test_case[2]) ? htmlspecialchars($matches_failure_test_case[2]) : "Not found";
$failure_location = isset($matches_failure_location[1]) ? $matches_failure_location[1] : "Not found";
$failure_line = isset($matches_failure_location[2]) ? $matches_failure_location[2] : "Not found";
if (!empty($matches_failures)) {
$tests_assertions_failures = "FAILURES!
Tests: " . $matches_failures[1] . ", Assertions: " . $matches_failures[2] . ", Failures: " . $matches_failures[3];
}
if($num_failures == 1){
$username = Session::get('user_name');
$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];
$html1 = htmlspecialchars($row->testing_rule);
$html2 = htmlspecialchars($row->ket);
$diff = "";
$diff_err = "";
// Memecah string HTML menjadi array per baris
$html1_lines = explode("\n", $html1);
$html2_lines = explode("\n", $html2);
$result_content = str_replace(array("\r\n","\r"," "),"", $html1_lines);
$result_content2 = str_replace(array("\r\n","\r"," "),"", $html2_lines);
// Membandingkan setiap baris
for ($i = 0; $i < count($result_content) && $i < count($result_content2); $i++) {
if ($result_content[$i] != $result_content2[$i]) {
$diff .= $html2_lines[$i] . "\n";
$diff .= "\n
"; // Menambahkan baris kosong setelah setiap perbedaan
}
}
echo "
";
echo "
| Codeception version |
: |
$phpunit_version |
| Execution time |
: |
$phpunit_time |
| Number of failures |
: |
$num_failures |
| Failure location |
: |
".$diff." |
| Tests Status |
: |
$tests_assertions_failures |
";
}else{
echo "
| Codeception version |
: |
$phpunit_version |
| Execution time |
: |
$phpunit_time |
| Memory usage |
: |
$phpunit_memory |
| Tests Run |
: |
$phpunit_stat |
";
}
}
function codeceptiontesting(){
$val = session('key');
DB::select("TRUNCATE TABLE php_user_submits");
DB::insert("insert into php_user_submits(userid) values ('$val')");
$kode = $_POST['kode'];
if($kode == '1'){
$unitesting_run = 'testLatihanNumberOne';
$testing_number_one = "testing_number_one";
}elseif($kode == '2'){
$unitesting_run = 'testLatihanNumberTwo';
$testing_number_one = "testing_number_two";
}elseif($kode == '3'){
$unitesting_run = 'testLatihanNumberThree';
$testing_number_one = "testing_number_three";
}elseif($kode == '4'){
$unitesting_run = 'testLatihanNumberFour';
$testing_number_one = "testing_number_four";
}elseif($kode == '5'){
$unitesting_run = 'testLatihanNumberFive';
$testing_number_one = "testing_number_five";
}
/** CODECEPTION TEST */
$command = "cd " . base_path() . " && php codecept.phar run Functional LoginTest --filter $unitesting_run"; //(codeception)
//$command = "cd " . base_path() . " && php codecept.phar run Unit PHPBasicTest --filter testLatihanNumberOne";
$output = shell_exec($command);
/** PHPUNIT TEST */
/*$path_test = base_path("phpunit.xml");
$pa = "vendor\bin\phpunit -c $path_test --filter HomepageLayoutTest::$unitesting_run";
$path = base_path($pa);
$output = shell_exec($path);*/
//echo "$output
";
$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);
$string = json_encode($output);
$text = str_replace("\n", ' ', $output);
$cleaned = preg_replace('/\e\[[;?\d]*m/', '', $string);
// Pola regex untuk mengekstrak versi Codeception
$pattern = '/Codeception PHP Testing Framework v([\d.]+)/';
// Define patterns to extract relevant information
$pattern_phpunit_version = '/Codeception\s+(\d+\.\d+\.\d+)/';
$pattern_php_runtime = '/Runtime:\s+PHP\s+([\d.]+)/';
$pattern_configuration = '/Configuration:\s+(.+)/';
$pattern_failure_count = '/There was (\d+) failure/';
$pattern_failure_test_case = '/Failed asserting that \'(.*?)\' contains \'(.*?)\'./';
$pattern_failure_location = '/(C:\\\\.*?\\.php):(\d+)/';
$pattern_path = 'C:\\xampp\\htdocs\\iclop\\phpunit.xml';
$pattern_time = '/Time:\s+([0-9:.]+)/';
$pattern_memory = '/Memory:\s+([\d.]+)\s+(MB|KB|GB)/';
$pattern_ok = '/OK\s+\((\d+)\s+test(?:s)?,\s+(\d+)\s+assertion(?:s)?\)/';
$pattern_failures = '/Tests:\s+(\d+),\s+Assertions:\s+(\d+),\s+Failures:\s+(\d+)/';
// Perform matching
preg_match($pattern_phpunit_version, $text, $matches_phpunit_version);
preg_match($pattern_php_runtime, $text, $matches_php_runtime);
preg_match($pattern_configuration, $text, $matches_configuration);
preg_match($pattern_failure_count, $text, $matches_failure_count);
preg_match($pattern_failure_test_case, $text, $matches_failure_test_case);
preg_match($pattern_failure_location, $text, $matches_failure_location);
preg_match($pattern_ok, $text, $matches_ok);
preg_match($pattern_time, $text, $matches_time);
preg_match($pattern_memory, $text, $matches_memory);
preg_match($pattern_failures, $text, $matches_failures);
preg_match($pattern, $cleaned, $matches);
// Extracted information
$phpunit_version = isset($matches[1]) ? $matches[1] : "Not founds";
$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";
$php_runtime = isset($matches_php_runtime[1]) ? $matches_php_runtime[1] : "Not found";
$configuration_path = isset($matches_configuration[1]) ? $matches_configuration[1] : "Not found";
$num_failures = isset($matches_failure_count[1]) ? $matches_failure_count[1] : "Not found";
$failed_assertion = isset($matches_failure_test_case[1]) ? htmlspecialchars($matches_failure_test_case[1]) : "Not found";
$expected_content = isset($matches_failure_test_case[2]) ? htmlspecialchars($matches_failure_test_case[2]) : "Not found";
$failure_location = isset($matches_failure_location[1]) ? $matches_failure_location[1] : "Not found";
$failure_line = isset($matches_failure_location[2]) ? $matches_failure_location[2] : "Not found";
if (!empty($matches_failures)) {
$tests_assertions_failures = "FAILURES!
Tests: " . $matches_failures[1] . ", Assertions: " . $matches_failures[2] . ", Failures: " . $matches_failures[3];
}
if($num_failures == 1){
$username = Session::get('user_name');
$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];
$html1 = htmlspecialchars($row->testing_rule);
$html2 = htmlspecialchars($row->ket);
$diff = "";
$diff_err = "";
// Memecah string HTML menjadi array per baris
$html1_lines = explode("\n", $html1);
$html2_lines = explode("\n", $html2);
$result_content = str_replace(array("\r\n","\r"," "),"", $html1_lines);
$result_content2 = str_replace(array("\r\n","\r"," "),"", $html2_lines);
// Membandingkan setiap baris
for ($i = 0; $i < count($result_content) && $i < count($result_content2); $i++) {
if ($result_content[$i] != $result_content2[$i]) {
$diff .= $html2_lines[$i] . "\n";
$diff .= "\n
"; // Menambahkan baris kosong setelah setiap perbedaan
}
}
echo "
";
echo "
| Codeception version |
: |
$phpunit_version |
| Execution time |
: |
$phpunit_time |
| Number of failures |
: |
$num_failures |
| Failure location |
: |
".$diff." |
| Tests Status |
: |
$tests_assertions_failures |
";
}else{
echo "
| Codeception version |
: |
$phpunit_version |
| Execution time |
: |
$phpunit_time |
| Memory usage |
: |
$phpunit_memory |
| Tests Run |
: |
$phpunit_stat |
";
}
}
function open_terminal(){
$val = session('key');
DB::select("TRUNCATE TABLE php_user_submits");
DB::insert("insert into php_user_submits(userid) values ('$val')");
$kode = 9;
if($kode == '1'){
$unitesting_run = 'testLatihanNumberOne';
}elseif($kode == '2'){
$unitesting_run = 'testLatihanNumberTwo';
}elseif($kode == '3'){
$unitesting_run = 'testLatihanNumberThree';
}elseif($kode == '4'){
$unitesting_run = 'testLatihanNumberFour';
}elseif($kode == '5'){
$unitesting_run = 'testLatihanNumberFive';
}elseif($kode == '6'){
$unitesting_run = 'testPHPStructure';
}elseif($kode == '7'){
$unitesting_run = 'testConditions';
}elseif($kode == '8'){
$unitesting_run = 'testLoops';
}elseif($kode == '9'){
$unitesting_run = 'testArray';
}
$path_test = base_path("phpunit.xml");
$pa = "vendor\bin\phpunit -c $path_test --filter $unitesting_run";
$path = base_path($pa);
$output = shell_exec($path);
echo dd($output);
//echo json_encode($output);
}
function session_progress(){
session(['params' => $_POST['params']]);
}
function flutter(){
// Path to the Flutter testing directory
$flutterTestingDir = 'C:\\xampp\\htdocs\\iclop\\public\\flutter_testing';
// Change directory to the Flutter testing directory
chdir($flutterTestingDir);
// Command to execute Flutter test
$command = 'flutter test';
// Execute the command and capture output
$output = shell_exec($command);
// Print the output
echo "$output
";
}
function codeception_start(){
$actual = "";
$topics = Topic::where('type', '2')->get();
$topicsCount = count($topics);
return view('php.student.material.index',[
'result_up' => $actual,
'topics' => $topics,
'topicsCount' => $topicsCount,
]);
}
function unittesting_codeception(){
$val = session('key');
$kode = $_POST['kode'];
$type = $_POST['type'];
$phpid = $_POST['phpid'];
DB::select("TRUNCATE TABLE php_user_submits");
DB::insert("insert into php_user_submits(userid,phpid,task,type) values ('$val','$phpid','$kode','$type')");
$testing = DB::SELECT("SELECT material FROM php_task WHERE id_topics = '$phpid' and task_no = '$kode'");
$rt = $testing[0];
$testing_number_one = $rt->material;
$command = "cd " . base_path() . " && php codecept.phar run Functional FormMethodTest --filter $testing_number_one -v";
$output = shell_exec($command);
$string = json_encode($output);
// Hapus karakter ANSI escape
$clean_output = preg_replace('/\\x1b\[[0-9;]*m/', '', $string);
$clean_output = str_replace('\n', PHP_EOL, $clean_output);
if (preg_match('/(Pemeriksaan File pengelolaan form dengan Method POST Berhasil.*)/', $clean_output, $matches)) {
$hal = $matches[1]. PHP_EOL;
}elseif (preg_match('/(Pemeriksaan File pengelolaan form dengan Method GET terdapat kesalahan.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
} elseif (preg_match('/(Pemeriksaan File pengelolaan form dengan Method POST terdapat kesalahan.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
} elseif (preg_match('/(Pemeriksaan File pengelolaan form dengan Method GET berhasil.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
} elseif (preg_match('/(File operasi CREATE Terdapat Kesalahan*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
} elseif (preg_match('/(Pemeriksaan File Koneksi PHP berhasil.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
}elseif (preg_match('/(Pemeriksaan File Koneksi PHP Terdapat Kesalahan*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
} elseif (preg_match('/(Pemeriksaan File Koneksi Periksa variable PHP Anda, Terdapat Kesalahan*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
} elseif (preg_match('/(Pemeriksaan File Insert PHP berhasil.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
} elseif (preg_match('/(File operasi UPDATE Terdapat Kesalahan*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
}elseif (preg_match('/(File operasi DELETE Terdapat Kesalahan*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
}elseif (preg_match('/(File operasi READ Terdapat Kesalahan*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
}elseif (preg_match('/(Pemeriksaan File Select PHP berhasil.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
}elseif (preg_match('/(Pemeriksaan File Delete PHP berhasil.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
}elseif (preg_match('/(Pemeriksaan File Update PHP berhasil.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
}elseif (preg_match('/(Pemeriksaan File Session Terdapat Kesalahan*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
}elseif (preg_match('/(Pemeriksaan File Session PHP berhasil.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
}elseif (preg_match('/(Input type text untuk nama tidak ditemukan.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
}elseif (preg_match('/(Input type email tidak ditemukan.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
}elseif (preg_match('/(Select untuk prodi tidak ditemukan.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
}elseif (preg_match('/(Tombol submit tidak ditemukan.*)/', $clean_output, $matches)) {
$hal = $matches[1] . PHP_EOL;
} else {
$hal = "Testing Tidak ditemukan." . PHP_EOL;
}
$string = json_encode($output);
$text = str_replace("\n", ' ', $output);
$cleaned = preg_replace('/\\e\[[0-9;]*m/', '', $output);
$firstLine = strtok($cleaned, "\n");
$firstLine = explode(" https://", $firstLine)[0];
preg_match('/Time:\s([\d:.]+),\sMemory:\s([\d.]+ MB)/', $cleaned, $matches);
$time = $matches[1];
$memory = $matches[2];
preg_match('/Time:\s([\d:.]+),\sMemory:\s([\d.]+ MB)/', $cleaned, $matches);
$time = $matches[1] ?? 'Not Found';
$memory = $matches[2] ?? 'Not Found';
preg_match('/(Pemeriksaan File Koneksi PHP Terdapat Kesalahan)/', $cleaned, $errorMatches);
$errorMessage = $errorMatches[1] ?? 'No Error Message';
preg_match('/(FAILURES!)/', $cleaned, $failureMatches);
$failureMessage = $failureMatches[1] ?? 'No Failures';
preg_match('/Tests:\s\d+,\sAssertions:\s\d+,\sFailures:\s\d+/', $cleaned, $summaryMatches);
$testSummary = $summaryMatches[0] ?? 'No Test Summary';
preg_match('/OK\s\(\d+\stest,\s\d+\sassertions?\)/', $cleaned, $okMatches);
$okResult = $okMatches[0] ?? 'No OK Result';
if($testSummary == 'No Test Summary'){
$hasil = $okResult;
}else{
$hasil = $testSummary;
}
echo "
| Codeception version |
: |
$firstLine |
| Execution time |
: |
$time |
| Memory usage |
: |
$memory |
| Error Message |
: |
$hal |
| Failure Status |
: |
$failureMessage |
| Tests Run |
: |
$hasil |
";
}
function work_results() {
$username = session('key');
$results = DB::select("SELECT * FROM php_submits_submission WHERE username = ? AND task_topics IN (12,13,14) GROUP BY task_topics", [$username]);
if (!empty($results)) {
$output = "";
$filePath = storage_path("app/public/uploads/$username/index.php");
if (file_exists($filePath)) {
try {
ob_start();
include $filePath;
$content = ob_get_clean();
$output = "
Work Results, Generated by iCLOP
$content
";
} catch (\Throwable $e) {
$output .= "
Error: " . $e->getMessage() . "
";
}
} else {
$output .= "
File tidak ditemukan: " . $filePath . "
";
}
if (!empty(session('output'))) {
echo session('output');
}
return response($output);
}
return response("Tidak ada file untuk diproses
", 404);
}
function form_insert_by_student() {
$username = session('key');
$results = DB::select("SELECT * FROM php_submits_submission WHERE username = ? AND task_topics IN (12,13,14) GROUP BY task_topics", [$username]);
if (!empty($results)) {
$output = ""; // Simpan hasil eksekusi semua file di sini
$filePath = storage_path("app/public/uploads/$username/form_insert.php");
if (file_exists($filePath)) {
try {
ob_start();
include $filePath; // Eksekusi file
$output .= ob_get_clean(); // Simpan hasilnya
} catch (\Throwable $e) {
$output .= "Error: " . $e->getMessage();
}
} else {
$output .= "File tidak ditemukan: " . $filePath . "
";
}
return response($output);
}
return response("Tidak ada file untuk diproses", 404);
}
function save_insert() {
$username = session('key');
$results = DB::select("SELECT * FROM php_submits_submission WHERE username = ? AND task_topics IN (12,13,14) GROUP BY task_topics", [$username]);
if (!empty($results)) {
$output = ""; // Simpan hasil eksekusi semua file di sini
$filePath = storage_path("app/public/uploads/$username/insert.php");
if (file_exists($filePath)) {
try {
ob_start();
include $filePath; // Eksekusi file
$output .= ob_get_clean(); // Simpan hasilnya
} catch (\Throwable $e) {
$output .= "Error: " . $e->getMessage();
}
} else {
$output .= "File tidak ditemukan: " . $filePath . "
";
}
$result = DB::connection('mysql2')
->select("SELECT * FROM users order by id desc limit 1");
$id = $result[0]->id;
$user_name = session('key');
DB::connection('mysql2')
->select("UPDATE users SET username = '$user_name' WHERE id = $id");
return redirect('/php/work-results')->with('output', $output);
}
return response("Tidak ada file untuk diproses", 404);
}
function delete_student() {
$username = session('key');
$results = DB::select("SELECT * FROM php_submits_submission WHERE username = ? AND task_topics IN (12,13,14) GROUP BY task_topics", [$username]);
if (!empty($results)) {
$output = ""; // Simpan hasil eksekusi semua file di sini
$filePath = storage_path("app/public/uploads/$username/delete.php");
if (file_exists($filePath)) {
try {
ob_start();
include $filePath; // Eksekusi file
$output .= ob_get_clean(); // Simpan hasilnya
} catch (\Throwable $e) {
$output .= "Error: " . $e->getMessage();
}
} else {
$output .= "File tidak ditemukan: " . $filePath . "
";
}
return redirect('/php/work-results')->with('output', $output);
}
return response("Tidak ada file untuk diproses", 404);
}
function index_student(){
return redirect('/php/work-results');
}
function edit_student() {
$username = session('key');
$results = DB::select("SELECT * FROM php_submits_submission WHERE username = ? AND task_topics IN (12,13,14) GROUP BY task_topics", [$username]);
if (!empty($results)) {
$output = ""; // Simpan hasil eksekusi semua file di sini
$filePath = storage_path("app/public/uploads/$username/update.php");
if (file_exists($filePath)) {
try {
ob_start();
include $filePath; // Eksekusi file
$output .= ob_get_clean(); // Simpan hasilnya
} catch (\Throwable $e) {
$output .= "Error: " . $e->getMessage();
}
} else {
$output .= "File tidak ditemukan: " . $filePath . "
";
}
return response($output);
}
return response("Tidak ada file untuk diproses", 404);
}
}