[TYPO3-dev] init FE environment manually
Elmar HInz
elmar.hinz at team.MINUS.red.DOT.net
Wed Feb 21 08:28:49 CET 2007
This is a skeleton for testcases:
Features:
* runs within T3Unit
* runs from commonadline, called from different directories
* minimal editing to startup: 6 places marked with xxx
* XCLASSED: no errors in extManager
* copyright notice
<?php
/***************************************************************
* Copyright notice
*
* (c) 2006 xxx
* Contact: xxx
* All rights reserved
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
***************************************************************/
// Set configuration first
$key = 'xxx'; // extension key
$class = 'tx_xxx_testcase'; // class name
// Fix part to set before class definition
error_reporting (E_ALL ^ E_NOTICE);
if(!defined('PATH_site')) { // If running from command line
define('T3UNIT_commandline', TRUE); // Remember it
// Setup environment
$path = realpath($_SERVER['PWD'] .'/'. $_SERVER['SCRIPT_NAME']);
if(!preg_match('|(.*)(typo3conf.*)(' . $key . '/test)|', $path, $matches))
if(! preg_match('|(.*)(typo3/ext.*)(' . $key . '/test)|', $path, $matches))
if(! preg_match('|(.*)(typo3/sysext.*)(' . $key . '/test)|', $path, $matches))
exit(chr(10) . 'Unknown installation path' . chr(10). $path . chr(10));
define('PATH_site', $matches[1]);
define('PATH_t3lib', PATH_site . 't3lib/');
require_once(PATH_t3lib . 'class.t3lib_div.php');
require_once(PATH_t3lib . 'class.t3lib_extmgm.php');
// "Load" t3unit
$GLOBALS['TYPO3_LOADED_EXT'][$key]['siteRelPath']= $matches[2] . $key . '/';
if(is_file(PATH_site . 'typo3conf/ext/t3unit/class.tx_t3unit_testcase.php')) {
$GLOBALS['TYPO3_LOADED_EXT']['t3unit']['siteRelPath']= 'typo3conf/ext/t3unit/';
}elseif(is_file(PATH_site . 'typo3/ext/t3unit/class.tx_t3unit_testcase.php')) {
$GLOBALS['TYPO3_LOADED_EXT']['t3unit']['siteRelPath']= 'typo3/ext/t3unit/';
}elseif(is_file(PATH_site . 'typo3/sysext/t3unit/class.tx_t3unit_testcase.php')) {
$GLOBALS['TYPO3_LOADED_EXT']['t3unit']['siteRelPath']= 'typo3/sysext/t3unit/';
}else{
exit(chr(10) . 'Unknown installation path of t3unit');
}
}
require_once(t3lib_extMgm::extPath('t3unit') . 'class.tx_t3unit_testcase.php');
/**
* Test class for tx_xxx
*/
class tx_xxx_testcase extends tx_t3unit_testcase {
/****************************************************************
* main, setUP, tearDown
****************************************************************/
public function __construct ($name) {
parent::__construct ($name);
}
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function setUp() {
}
/**
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
*
* @access protected
*/
protected function tearDown() {
}
/**
* Runs the test methods of this class.
*
* @access public
* @static
*/
public static function main() {
global $class;
require_once "PHPUnit2/TextUI/TestRunner.php";
$suite = new PHPUnit2_Framework_TestSuite($class);
$result = PHPUnit2_TextUI_TestRunner::run($suite);
}
}
if(T3UNIT_commandline === TRUE){
// Fix part to set after class definition
if (!defined('PHPUnit2_MAIN_METHOD')) {
define('PHPUnit2_MAIN_METHOD', $class . '::main');
}
if (PHPUnit2_MAIN_METHOD == $class . '::main') {
eval($class . '::main();');
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/' . $key . '/tests/class.' . $class . '.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/' . $key . '/tests/class.' . $class . '.php']);
}
?>
More information about the TYPO3-dev
mailing list