public function upgrade_java_tests() { $this->load->database(); $tests = new Test(); $tests->include_related('task'); $tests->where('type', 'java'); $tests->where('subtype', 'unit_test'); $tests->order_by_related('task', 'name', 'asc'); $tests->order_by('name', 'asc'); $tests->get_iterated(); $unsuccessful_files = array(); if ($tests->exists()) { echo 'Found ' . $tests->result_count() . ' java unit tests to check, starting process now.' . PHP_EOL; $this->load->library('cli_progress_bar'); $this->cli_progress_bar->init($tests->result_count()); $this->cli_progress_bar->increment(0); $this->load->helper('application'); foreach ($tests as $test) { $this->cli_progress_bar->print_text('Task "' . $test->task_name . '" test "' . $test->name . '" ...', true); $path_to_dir = APPPATH . '../private/uploads/unit_tests/test_' . $test->id; $path_to_file = $path_to_dir . '/unit_test/unit_test.zip'; $backup_file = $path_to_dir . '/unit_test/unit_test.backup-' . date('U') . '-' . date('Y-m-d-H-i-s') . '.zip'; if (file_exists($path_to_file)) { copy($path_to_file, $backup_file); if (file_exists($backup_file)) { $this->cli_progress_bar->tick(); do { $temp_directory = $path_to_dir . '/temp_' . date('U') . '-' . rand(1000, 9999); } while (file_exists($temp_directory) && is_dir($temp_directory)); mkdir($temp_directory); if (file_exists($temp_directory) && is_dir($temp_directory)) { $this->cli_progress_bar->tick(); $zip = new ZipArchive(); if ($zip->open($path_to_file)) { $zip->extractTo($temp_directory); $zip->close(); $configuration = @unserialize($test->configuration); if (is_array($configuration) && array_key_exists('class_to_run', $configuration)) { $this->cli_progress_bar->tick(); if ($this->upgrade_single_java_unit_test($temp_directory, 'Test' . $configuration['class_to_run'] . '.java')) { $this->cli_progress_bar->tick(); $zip = new ZipArchive(); if ($zip->open($path_to_file)) { if ($zip->addFile($temp_directory . '/' . 'Test' . $configuration['class_to_run'] . '.java', 'Test' . $configuration['class_to_run'] . '.java')) { $this->cli_progress_bar->print_text(' ... Done'); } else { $this->cli_progress_bar->print_text(' Can\'t update zip archive.'); $unsuccessful_files[] = $path_to_file; } $zip->close(); } else { $this->cli_progress_bar->print_text(' Can\'t open zip archive.'); $unsuccessful_files[] = $path_to_file; } } else { $unsuccessful_files[] = $path_to_file; } } else { $this->cli_progress_bar->print_text(' Can\'t read test configuration.'); $unsuccessful_files[] = $path_to_file; } } else { $this->cli_progress_bar->print_text(' Can\'t open zip archive.'); $unsuccessful_files[] = $path_to_file; } unlink_recursive($temp_directory, true); } else { $this->cli_progress_bar->print_text(' Can\'t create temporary directory.'); $unsuccessful_files[] = $path_to_file; } } else { $this->cli_progress_bar->print_text(' Can\'t back up zip file.'); $unsuccessful_files[] = $path_to_file; } } else { $this->cli_progress_bar->print_text(' Can\'t find zip file.'); } $this->cli_progress_bar->increment(); } } else { echo 'No java unit tests found.'; } if (count($unsuccessful_files)) { echo PHP_EOL . 'Some files can\'t be processed:' . PHP_EOL; foreach ($unsuccessful_files as $file) { echo ' ' . $file . PHP_EOL; } } }
public function run_testing_execution($test_id) { $test = new Test(); $test->include_related('task'); $test->get_by_id(intval($test_id)); $file_name = ''; if ($test->exists()) { $path = 'private/test_to_execute/testing_execution/'; if (!file_exists($path)) { @mkdir($path, DIR_READ_MODE); } $config['upload_path'] = $path; $config['allowed_types'] = 'zip'; $config['overwrite'] = FALSE; $config['encrypt_name'] = TRUE; $this->load->library('upload'); $this->upload->initialize($config); if ($this->upload->do_upload('source_codes')) { $data = $this->upload->data(); $file_name = $data['file_name']; } else { $this->parser->assign('source_codes_error', $this->upload->display_errors()); $this->prepare_execution($test_id); return; } } $this->parser->add_js_file('admin_tests/run_testing_execution.js'); $this->parser->parse('backend/tests/run_testing_execution.tpl', array('test' => $test, 'file_name' => $file_name)); }