test.php

Go to the documentation of this file.
00001 <?php
00002 /* SVN FILE: $Id: app_2webroot_2test_8php-source.html 580 2008-07-01 14:45:49Z gwoo $ */
00003 /**
00004  * Short description for file.
00005  *
00006  * Long description for file
00007  *
00008  * PHP versions 4 and 5
00009  *
00010  * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
00011  * Copyright 2005-2008, Cake Software Foundation, Inc.
00012  *                              1785 E. Sahara Avenue, Suite 490-204
00013  *                              Las Vegas, Nevada 89104
00014  *
00015  *  Licensed under The Open Group Test Suite License
00016  *  Redistributions of files must retain the above copyright notice.
00017  *
00018  * @filesource
00019  * @copyright       Copyright 2005-2008, Cake Software Foundation, Inc.
00020  * @link                https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
00021  * @package         cake
00022  * @subpackage      cake.cake.tests.libs
00023  * @since           CakePHP(tm) v 1.2.0.4433
00024  * @version         $Revision: 580 $
00025  * @modifiedby      $LastChangedBy: gwoo $
00026  * @lastmodified    $Date: 2008-07-01 09:45:49 -0500 (Tue, 01 Jul 2008) $
00027  * @license         http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
00028  */
00029 error_reporting(E_ALL);
00030 set_time_limit(0);
00031 ini_set('memory_limit','128M');
00032 ini_set('display_errors', 1);
00033 /**
00034  * Use the DS to separate the directories in other defines
00035  */
00036     if (!defined('DS')) {
00037         define('DS', DIRECTORY_SEPARATOR);
00038     }
00039 /**
00040  * These defines should only be edited if you have cake installed in
00041  * a directory layout other than the way it is distributed.
00042  * When using custom settings be sure to use the DS and do not add a trailing DS.
00043  */
00044 
00045 /**
00046  * The full path to the directory which holds "app", WITHOUT a trailing DS.
00047  *
00048  */
00049     if (!defined('ROOT')) {
00050         define('ROOT', dirname(dirname(dirname(__FILE__))));
00051     }
00052 /**
00053  * The actual directory name for the "app".
00054  *
00055  */
00056     if (!defined('APP_DIR')) {
00057         define('APP_DIR', basename(dirname(dirname(__FILE__))));
00058     }
00059 /**
00060  * The absolute path to the "cake" directory, WITHOUT a trailing DS.
00061  *
00062  */
00063     if (!defined('CAKE_CORE_INCLUDE_PATH')) {
00064         define('CAKE_CORE_INCLUDE_PATH', ROOT);
00065     }
00066 
00067 /**
00068  * Editing below this line should not be necessary.
00069  * Change at your own risk.
00070  *
00071  */
00072 if (!defined('WEBROOT_DIR')) {
00073     define('WEBROOT_DIR', basename(dirname(__FILE__)));
00074 }
00075 if (!defined('WWW_ROOT')) {
00076     define('WWW_ROOT', dirname(__FILE__) . DS);
00077 }
00078 if (!defined('CORE_PATH')) {
00079     if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) {
00080         define('APP_PATH', null);
00081         define('CORE_PATH', null);
00082     } else {
00083         define('APP_PATH', ROOT . DS . APP_DIR . DS);
00084         define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
00085     }
00086 }
00087 if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
00088     trigger_error("CakePHP core could not be found.  Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php.  It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
00089 }
00090 
00091 $corePath = Configure::corePaths('cake');
00092 if (isset($corePath[0])) {
00093     define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
00094 } else {
00095     define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
00096 }
00097 
00098 require_once CAKE_TESTS_LIB . 'test_manager.php';
00099 
00100 if (Configure::read('debug') < 1) {
00101     die(__('Debug setting does not allow access to this url.', true));
00102 }
00103 
00104 if (!isset($_SERVER['SERVER_NAME'])) {
00105     $_SERVER['SERVER_NAME'] = '';
00106 }
00107 if (empty( $_GET['output'])) {
00108     $_GET['output'] = 'html';
00109 }
00110 /**
00111  *
00112  * Used to determine output to display
00113  */
00114 define('CAKE_TEST_OUTPUT_HTML', 1);
00115 define('CAKE_TEST_OUTPUT_TEXT', 2);
00116 
00117 if (isset($_GET['output']) && $_GET['output'] == 'html') {
00118     define('CAKE_TEST_OUTPUT', CAKE_TEST_OUTPUT_HTML);
00119 } else {
00120     Debugger::output('txt');
00121     define('CAKE_TEST_OUTPUT', CAKE_TEST_OUTPUT_TEXT);
00122 }
00123 
00124 if (!App::import('Vendor', 'simpletest' . DS . 'reporter')) {
00125     CakePHPTestHeader();
00126     include CAKE_TESTS_LIB . 'simpletest.php';
00127     CakePHPTestSuiteFooter();
00128     exit();
00129 }
00130 
00131 $analyzeCodeCoverage = false;
00132 if (isset($_GET['code_coverage'])) {
00133     $analyzeCodeCoverage = true;
00134     require_once CAKE_TESTS_LIB . 'code_coverage_manager.php';
00135     if (!extension_loaded('xdebug')) {
00136         CakePHPTestHeader();
00137         include CAKE_TESTS_LIB . 'xdebug.php';
00138         CakePHPTestSuiteFooter();
00139         exit();
00140     }
00141 }
00142 
00143 CakePHPTestHeader();
00144 CakePHPTestSuiteHeader();
00145 define('RUN_TEST_LINK', $_SERVER['PHP_SELF']);
00146 
00147 if (isset($_GET['group'])) {
00148     if ('all' == $_GET['group']) {
00149         TestManager::runAllTests(CakeTestsGetReporter());
00150     } else {
00151         if ($analyzeCodeCoverage) {
00152             CodeCoverageManager::start($_GET['group'], CakeTestsGetReporter());
00153         }
00154         TestManager::runGroupTest(ucfirst($_GET['group']), CakeTestsGetReporter());
00155         if ($analyzeCodeCoverage) {
00156             CodeCoverageManager::report();
00157         }
00158     }
00159 
00160     CakePHPTestRunMore();
00161     CakePHPTestAnalyzeCodeCoverage();
00162 } elseif (isset($_GET['case'])) {
00163     if ($analyzeCodeCoverage) {
00164         CodeCoverageManager::start($_GET['case'], CakeTestsGetReporter());
00165     }
00166 
00167     TestManager::runTestCase($_GET['case'], CakeTestsGetReporter());
00168 
00169     if ($analyzeCodeCoverage) {
00170         CodeCoverageManager::report();
00171     }
00172 
00173     CakePHPTestRunMore();
00174     CakePHPTestAnalyzeCodeCoverage();
00175 } elseif (isset($_GET['show']) && $_GET['show'] == 'cases') {
00176     CakePHPTestCaseList();
00177 } else {
00178     CakePHPTestGroupTestList();
00179 }
00180 CakePHPTestSuiteFooter();
00181 $output = ob_get_clean();
00182 echo $output;
00183 ?>