/upload/unit_test.php
PHP | 122 lines | 81 code | 21 blank | 20 comment | 10 complexity | d551c6f29f8ef0404925deefee028f45 MD5 | raw file
Possible License(s): CC0-1.0
- <?php
- /*
- SimpleTest + CodeIgniter
-
- test.php
- the test runner - loads all needed files,
- integrates with CodeIgniter and runs the tests
-
- by Jamie Rumbelow
- http://jamierumbelow.net/
- */
- //Configure and load files
- define('ROOT', dirname(__FILE__) . '/');
- $base_dir = str_replace('upload/', 'do_not_upload/', ROOT);
- $utility_dir = "/usr/local/Zend/apache2/htdocs/utilities/";
- ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.$utility_dir); // For Utilities
- //define('APP_DIR', ROOT.'includes/application');
- define('APP_DIR', $base_dir);
- require_once 'simpletest/unit_tester.php';
- require_once 'simpletest/web_tester.php';
- require_once 'simpletest/reporter.php';
- function add_test($file, &$test) {
- $implementation = '';
-
- if (preg_match('/_controller/', $file)) {
- $controller = preg_replace('#' . APP_DIR . '/tests/controllers/([a-zA-Z0-9_\-])_controller_test.php#', '$1', $file);
- $implementation = APP_DIR . '/controllers'.$controller.'.php';
- } elseif (preg_match('/_model/', $file)) {
- $model = preg_replace('#' . APP_DIR . '/tests/models/([a-zA-Z0-9_\-])_model_test.php#', '$1', $file);
- $implementation = APP_DIR . '/models/'.$model.'_model.php';
- } elseif (preg_match('/_view/', $file)) {
- $view = preg_replace('#' . APP_DIR . '/tests/views/([a-zA-Z0-9_\-])_view_test.php#', '$1', $file);
- $view = implode('/', explode('_', $view));
- $implementation = APP_DIR . 'application/views/'.$view.'.php';
- }
-
- if (file_exists($implementation)) {
- require_once($implementation);
- }
-
- $test->addFile($file);
- }
- class CodeIgniterUnitTestCase extends UnitTestCase {
- protected $ci;
-
- public function __construct() {
- parent::UnitTestCase();
- $this->ci =& get_instance();
- }
- }
- class CodeIgniterWebTestCase extends WebTestCase {
- protected $ci;
-
- public function __construct() {
- parent::WebTestCase();
- $this->ci =& get_instance();
- }
- }
- //Capture CodeIgniter output, discard and load system into $CI variable
- ob_start();
- include(ROOT . 'index.php');
- $CI =& get_instance();
- ob_end_clean();
- //Setup the test suite
- $test =& new TestSuite();
- $test->_label = '68KB Test Suite';
- if (!isset($_GET['test'])) {
- //What are we testing?
- $files = array();
- if (isset($_GET['controllers'])) {
- $files = @scandir(APP_DIR . '/tests/controllers');
- } elseif (isset($_GET['models'])) {
- $files = @scandir(APP_DIR . '/tests/models');
- } elseif (isset($_GET['models'])) {
- $files = @scandir(APP_DIR . '/tests/views');
- } elseif (isset($_GET['all'])) {
- $files = @scandir(APP_DIR . '/tests/controllers');
- $files = array_merge($files, @scandir(APP_DIR . '/tests/models'));
- $files = array_merge($files, @scandir(APP_DIR . '/tests/views'));
- } else {
- //Use all by default
- $files = @scandir(APP_DIR . '/tests/controllers');
- $files = array_merge($files, @scandir(APP_DIR . '/tests/models'));
- $files = array_merge($files, @scandir(APP_DIR . '/tests/views'));
- }
- //Remove ., .. and any .whatever files, and add the full path
- function prepare_array($value, $key) {
- global $files;
-
- if (preg_match('/^\./', $value)) { unset($files[$key]); }
- if (preg_match('/_model/', $value)) { $files[$key] = APP_DIR . '/tests/models/' . $value; }
- if (preg_match('/_controller/', $value)) { $files[$key] = APP_DIR . '/tests/controllers/' . $value; }
- if (preg_match('/_view/', $value)) { $files[$key] = APP_DIR . '/tests/views/' . $value; }
- }
- array_walk($files, 'prepare_array');
- //Add each file to the test suite
- foreach ($files as $file) {
- add_test($file, $test);
- }
- $test->run(new HtmlReporter());
- } else {
- add_test(APP_DIR . '/tests/' . $file, $test);
- $test->run(new HtmlReporter());
- }
- //Run tests!
- include(APP_DIR . '/tests/custom_test_gui.php');
- //$test->run(new HtmlReporter());