Merge branch '2.0-phpunit' of github.com:cakephp/cakephp into 2.0-phpunit

Conflicts:
	cake/tests/cases/libs/controller/components/session.test.php
This commit is contained in:
José Lorenzo Rodríguez 2010-06-09 21:01:56 -04:30
commit bc71e14041
8 changed files with 194 additions and 155 deletions

View file

@ -88,6 +88,28 @@ class SessionComponent extends CakeSession {
$this->__active = true;
}
/**
* Check if the session is active. Returns the private __active flag.
*
* @return boolean
*/
public function active() {
return $this->__active;
}
/**
* Get / Set the userAgent
*
* @param string $userAgent Set the userAgent
* @return void
*/
public function userAgent($userAgent = null) {
if ($userAgent) {
$this->_userAgent = $userAgent;
}
return $this->_userAgent;
}
/**
* Used to write a value to a session key.
*

View file

@ -152,7 +152,7 @@ class BasicsTest extends CakeTestCase {
$_SERVER = $_ENV = array();
$this->assertFalse(env('TEST_ME'));
$this->assertNull(env('TEST_ME'));
$_ENV['TEST_ME'] = 'a';
$this->assertEqual(env('TEST_ME'), 'a');
@ -237,7 +237,7 @@ class BasicsTest extends CakeTestCase {
Configure::write('Cache.disable', false);
$result = cache('basics_test', 'simple cache write');
$this->assertTrue($result);
$this->assertTrue((boolean)$result);
$this->assertTrue(file_exists(CACHE . 'basics_test'));
$result = cache('basics_test');

View file

@ -20,6 +20,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Core', array('File'));
if (!defined('DISABLE_AUTO_DISPATCH')) {
define('DISABLE_AUTO_DISPATCH', true);
@ -35,17 +36,6 @@ if (!class_exists('ShellDispatcher')) {
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'plugin.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
Mock::generatePartial(
'ShellDispatcher', 'TestPluginTaskMockShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
);
Mock::generatePartial(
'PluginTask', 'MockPluginTask',
array('in', '_stop', 'err', 'out', 'createFile')
);
Mock::generate('ModelTask', 'PluginTestMockModelTask');
/**
* PluginTaskPlugin class
*
@ -54,16 +44,23 @@ Mock::generate('ModelTask', 'PluginTestMockModelTask');
*/
class PluginTaskTest extends CakeTestCase {
public static $_paths = array();
public static $_testPath = array();
/**
* startTest method
*
* @return void
*/
public function startTest() {
$this->Dispatcher =& new TestPluginTaskMockShellDispatcher();
$this->Dispatcher->shellPaths = App::path('shells');
$this->Task =& new MockPluginTask($this->Dispatcher);
$this->Task->Dispatch =& $this->Dispatcher;
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
));
$this->Task = $this->getMock('PluginTask',
array('in', 'err', 'createFile', '_stop'),
array(&$this->Dispatcher)
);
$this->Task->path = TMP . 'tests' . DS;
}
@ -72,9 +69,9 @@ class PluginTaskTest extends CakeTestCase {
*
* @return void
*/
public function startCase() {
$this->_paths = $paths = App::path('plugins');
$this->_testPath = array_push($paths, TMP . 'tests' . DS);
public static function setUpBeforeClass() {
self::$_paths = $paths = App::path('plugins');
self::$_testPath = array_push($paths, TMP . 'tests' . DS);
App::build(array('plugins' => $paths));
}
@ -83,8 +80,8 @@ class PluginTaskTest extends CakeTestCase {
*
* @return void
*/
public function endCase() {
App::build(array('plugins' => $this->_paths));
public static function tearDownAfterClass() {
App::build(array('plugins' => self::$_paths));
}
/**
@ -102,8 +99,19 @@ class PluginTaskTest extends CakeTestCase {
* @return void
*/
public function testBakeFoldersAndFiles() {
$this->Task->setReturnValueAt(0, 'in', $this->_testPath);
$this->Task->setReturnValueAt(1, 'in', 'y');
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue(self::$_testPath));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
$path = $this->Task->path . 'bake_test_plugin';
$file = $path . DS . 'bake_test_plugin_app_controller.php';
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$file = $path . DS . 'bake_test_plugin_app_model.php';
$this->Task->expects($this->at(4))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$this->Task->bake('BakeTestPlugin');
$path = $this->Task->path . 'bake_test_plugin';
@ -173,13 +181,7 @@ class PluginTaskTest extends CakeTestCase {
$this->assertTrue(is_dir($path . DS . 'libs'), 'No libs dir %s');
$this->assertTrue(is_dir($path . DS . 'webroot'), 'No webroot dir %s');
$file = $path . DS . 'bake_test_plugin_app_controller.php';
$this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
$file = $path . DS . 'bake_test_plugin_app_model.php';
$this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
$Folder =& new Folder($this->Task->path . 'bake_test_plugin');
$Folder = new Folder($this->Task->path . 'bake_test_plugin');
$Folder->delete();
}
@ -189,22 +191,24 @@ class PluginTaskTest extends CakeTestCase {
* @return void
*/
public function testExecuteWithNoArgs() {
$this->Task->setReturnValueAt(0, 'in', 'TestPlugin');
$this->Task->setReturnValueAt(1, 'in', '3');
$this->Task->setReturnValueAt(2, 'in', 'y');
$this->Task->setReturnValueAt(3, 'in', 'n');
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestPlugin'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('3'));
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('n'));
$path = $this->Task->path . 'test_plugin';
$file = $path . DS . 'test_plugin_app_controller.php';
$this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
$this->Task->expects($this->at(4))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$file = $path . DS . 'test_plugin_app_model.php';
$this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
$this->Task->expects($this->at(5))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$this->Task->args = array();
$this->Task->execute();
$Folder =& new Folder($path);
$Folder = new Folder($path);
$Folder->delete();
}
@ -214,21 +218,27 @@ class PluginTaskTest extends CakeTestCase {
* @return void
*/
public function testExecuteWithOneArg() {
$this->Task->setReturnValueAt(0, 'in', $this->_testPath);
$this->Task->setReturnValueAt(1, 'in', 'y');
$this->Task->Dispatch->args = array('BakeTestPlugin');
$this->Task->args =& $this->Task->Dispatch->args;
$this->Task->expects($this->at(0))->method('in')
->will($this->returnValue(self::$_testPath));
$this->Task->expects($this->at(1))->method('in')
->will($this->returnValue('y'));
$path = $this->Task->path . 'bake_test_plugin';
$file = $path . DS . 'bake_test_plugin_app_controller.php';
$this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$path = $this->Task->path . 'bake_test_plugin';
$file = $path . DS . 'bake_test_plugin_app_model.php';
$this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
$this->Task->expects($this->at(4))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$this->Task->Dispatch->args = array('BakeTestPlugin');
$this->Task->args =& $this->Task->Dispatch->args;
$this->Task->execute();
$Folder =& new Folder($this->Task->path . 'bake_test_plugin');
$Folder = new Folder($this->Task->path . 'bake_test_plugin');
$Folder->delete();
}
@ -238,17 +248,18 @@ class PluginTaskTest extends CakeTestCase {
* @return void
*/
public function testExecuteWithTwoArgs() {
$this->Task->Model =& new PluginTestMockModelTask();
$this->Task->setReturnValueAt(0, 'in', $this->_testPath);
$this->Task->setReturnValueAt(1, 'in', 'y');
$this->Task->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
$Folder =& new Folder($this->Task->path . 'bake_test_plugin', true);
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue(self::$_testPath));
$this->Task->Model->expects($this->once())->method('loadTasks');
$this->Task->Model->expects($this->once())->method('execute');
$Folder = new Folder($this->Task->path . 'bake_test_plugin', true);
$this->Task->Dispatch->args = array('BakeTestPlugin', 'model');
$this->Task->args =& $this->Task->Dispatch->args;
$this->Task->args = $this->Task->Dispatch->args;
$this->Task->Model->expectOnce('loadTasks');
$this->Task->Model->expectOnce('execute');
$this->Task->execute();
$Folder->delete();
}

View file

@ -37,16 +37,6 @@ if (!class_exists('ShellDispatcher')) {
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
Mock::generatePartial(
'ShellDispatcher', 'TestTestTaskMockShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
);
Mock::generatePartial(
'TestTask', 'MockTestTask',
array('in', '_stop', 'err', 'out', 'createFile', 'isLoadableClass')
);
/**
* Test Article model
*
@ -258,11 +248,15 @@ class TestTaskTest extends CakeTestCase {
* @return void
*/
public function startTest() {
$this->Dispatcher =& new TestTestTaskMockShellDispatcher();
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
));
$this->Task = $this->getMock('TestTask',
array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
array(&$this->Dispatcher)
);
$this->Dispatcher->shellPaths = App::path('shells');
$this->Task =& new MockTestTask($this->Dispatcher);
$this->Task->name = 'TestTask';
$this->Task->Dispatch =& $this->Dispatcher;
$this->Task->Template =& new TemplateTask($this->Dispatcher);
}
@ -280,21 +274,24 @@ class TestTaskTest extends CakeTestCase {
*
* @return void
*/
public function testFilePathGeneration() {
public function testFilePathGenerationModelRepeated() {
$this->Task->Dispatch->expects($this->never())->method('stderr');
$this->Task->Dispatch->expects($this->never())->method('_stop');
$file = TESTS . 'cases' . DS . 'models' . DS . 'my_class.test.php';
$this->Task->Dispatch->expectNever('stderr');
$this->Task->Dispatch->expectNever('_stop');
$this->Task->expects($this->at(1))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$this->Task->setReturnValue('in', 'y');
$this->Task->expectAt(0, 'createFile', array($file, '*'));
$this->Task->bake('Model', 'MyClass');
$this->Task->expectAt(1, 'createFile', array($file, '*'));
$this->Task->bake('Model', 'MyClass');
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$file = TESTS . 'cases' . DS . 'controllers' . DS . 'comments_controller.test.php';
$this->Task->expectAt(2, 'createFile', array($file, '*'));
$this->Task->expects($this->at(5))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$this->Task->bake('Model', 'MyClass');
$this->Task->bake('Model', 'MyClass');
$this->Task->bake('Controller', 'Comments');
}
@ -344,11 +341,12 @@ class TestTaskTest extends CakeTestCase {
* @return void
*/
public function testGetObjectType() {
$this->Task->expectOnce('_stop');
$this->Task->setReturnValueAt(0, 'in', 'q');
$this->Task->expects($this->once())->method('_stop');
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('q'));
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue(2));
$this->Task->getObjectType();
$this->Task->setReturnValueAt(1, 'in', 2);
$result = $this->Task->getObjectType();
$this->assertEqual($result, $this->Task->classTypes[1]);
}
@ -388,11 +386,12 @@ class TestTaskTest extends CakeTestCase {
if ($skip) {
return;
}
$this->Task->setReturnValueAt(0, 'in', 'MyCustomClass');
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('MyCustomClass'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));
$result = $this->Task->getClassName('Model');
$this->assertEqual($result, 'MyCustomClass');
$this->Task->setReturnValueAt(1, 'in', 1);
$result = $this->Task->getClassName('Model');
$options = App::objects('model');
$this->assertEqual($result, $options[0]);
@ -404,8 +403,10 @@ class TestTaskTest extends CakeTestCase {
* @return void
*/
public function testGetUserFixtures() {
$this->Task->setReturnValueAt(0, 'in', 'y');
$this->Task->setReturnValueAt(1, 'in', 'app.pizza, app.topping, app.side_dish');
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(1))->method('in')
->will($this->returnValue('app.pizza, app.topping, app.side_dish'));
$result = $this->Task->getUserFixtures();
$expected = array('app.pizza', 'app.topping', 'app.side_dish');
$this->assertEqual($result, $expected);
@ -440,8 +441,8 @@ class TestTaskTest extends CakeTestCase {
* @return void
*/
public function testBakeModelTest() {
$this->Task->setReturnValue('createFile', true);
$this->Task->setReturnValue('isLoadableClass', true);
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
$result = $this->Task->bake('Model', 'TestTaskArticle');
@ -458,9 +459,7 @@ class TestTaskTest extends CakeTestCase {
$this->assertPattern('/function testDoSomethingElse\(\)/i', $result);
$this->assertPattern("/'app\.test_task_article'/", $result);
if (PHP5) {
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
}
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
$this->assertPattern("/'app\.test_task_tag'/", $result);
$this->assertPattern("/'app\.articles_tag'/", $result);
}
@ -473,8 +472,8 @@ class TestTaskTest extends CakeTestCase {
* @return void
*/
public function testBakeControllerTest() {
$this->Task->setReturnValue('createFile', true);
$this->Task->setReturnValue('isLoadableClass', true);
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
$result = $this->Task->bake('Controller', 'TestTaskComments');
@ -493,9 +492,7 @@ class TestTaskTest extends CakeTestCase {
$this->assertPattern('/unset\(\$this->TestTaskComments\)/', $result);
$this->assertPattern("/'app\.test_task_article'/", $result);
if (PHP5) {
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
}
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
$this->assertPattern("/'app\.test_task_tag'/", $result);
$this->assertPattern("/'app\.articles_tag'/", $result);
}
@ -538,7 +535,9 @@ class TestTaskTest extends CakeTestCase {
$this->Task->plugin = 'TestTest';
$path = APP . 'plugins' . DS . 'test_test' . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'form.test.php';
$this->Task->expectAt(0, 'createFile', array($path, '*'));
$this->Task->expects($this->once())->method('createFile')
->with($path, new PHPUnit_Framework_Constraint_IsAnything());
$this->Task->bake('Helper', 'Form');
}
@ -583,9 +582,13 @@ class TestTaskTest extends CakeTestCase {
*/
public function testExecuteWithOneArg() {
$this->Task->args[0] = 'Model';
$this->Task->setReturnValueAt(0, 'in', 'TestTaskTag');
$this->Task->setReturnValue('isLoadableClass', true);
$this->Task->expectAt(0, 'createFile', array('*', new PatternExpectation('/class TestTaskTagTestCase extends CakeTestCase/')));
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
$this->Task->expects($this->once())->method('createFile')
->with(
new PHPUnit_Framework_Constraint_IsAnything(),
new PHPUnit_Framework_Constraint_PCREMatch('/class TestTaskTagTestCase extends CakeTestCase/')
);
$this->Task->execute();
}
@ -596,9 +599,13 @@ class TestTaskTest extends CakeTestCase {
*/
public function testExecuteWithTwoArgs() {
$this->Task->args = array('Model', 'TestTaskTag');
$this->Task->setReturnValueAt(0, 'in', 'TestTaskTag');
$this->Task->setReturnValue('isLoadableClass', true);
$this->Task->expectAt(0, 'createFile', array('*', new PatternExpectation('/class TestTaskTagTestCase extends CakeTestCase/')));
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
$this->Task->expects($this->once())->method('createFile')
->with(
new PHPUnit_Framework_Constraint_IsAnything(),
new PHPUnit_Framework_Constraint_PCREMatch('/class TestTaskTagTestCase extends CakeTestCase/')
);
$this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
$this->Task->execute();
}
}

View file

@ -109,13 +109,13 @@ class SessionComponentTest extends CakeTestCase {
function testSessionAutoStart() {
Configure::write('Session.start', false);
$Session = new SessionComponent();
$this->assertFalse($Session->isActive());
$this->assertFalse($Session->active());
$this->assertFalse($Session->started());
$Session->startup(new SessionTestController());
Configure::write('Session.start', true);
$Session = new SessionComponent();
$this->assertTrue($Session->isActive());
$this->assertTrue($Session->active());
$this->assertFalse($Session->started());
$Session->startup(new SessionTestController());
$this->assertTrue(isset($_SESSION));
@ -141,15 +141,15 @@ class SessionComponentTest extends CakeTestCase {
function testSessionActivate() {
$Session = new SessionComponent();
$this->assertTrue($Session->isActive());
$this->assertTrue($Session->active());
$this->assertNull($Session->activate());
$this->assertTrue($Session->isActive());
$this->assertTrue($Session->active());
Configure::write('Session.start', false);
$Session = new SessionComponent();
$this->assertFalse($Session->isActive());
$this->assertFalse($Session->active());
$this->assertNull($Session->activate());
$this->assertTrue($Session->isActive());
$this->assertTrue($Session->active());
Configure::write('Session.start', true);
$Session->destroy();
}
@ -162,11 +162,15 @@ class SessionComponentTest extends CakeTestCase {
*/
function testSessionValid() {
$Session = new SessionComponent();
$this->assertTrue($Session->valid());
$Session->userAgent('rweerw');
$this->assertFalse($Session->valid());
Configure::write('Session.start', false);
$Session = new SessionComponent();
$this->assertFalse($Session->isActive());
$this->assertFalse($Session->active());
$this->assertFalse($Session->valid());
Configure::write('Session.start', true);
@ -194,7 +198,7 @@ class SessionComponentTest extends CakeTestCase {
Configure::write('Session.start', false);
$Session = new SessionComponent();
$this->assertFalse($Session->isActive());
$this->assertFalse($Session->active());
$this->assertFalse($Session->error());
Configure::write('Session.start', true);
}

View file

@ -509,4 +509,18 @@ class CakeTestCase extends PHPUnit_Framework_TestCase {
$lower = $value - $margin;
$this->assertTrue((($expected <= $upper) && ($expected >= $lower)), $message);
}
/**
* Compatibility function for skipping.
*
* @param boolean $condition Condition to trigger skipping
* @param string $message Message for skip
* @return boolean
*/
protected function skipUnless($condition, $message = '') {
if (!$condition) {
$this->markTestSkipped($message);
}
return $condition;
}
}

View file

@ -157,7 +157,7 @@ class CakeBaseReporter implements PHPUnit_Framework_TestListener {
* @return mixed
*/
public function testCaseList() {
$testList = TestManager::getTestCaseList();
$testList = TestManager::getTestCaseList($this->params);
return $testList;
}
@ -168,7 +168,7 @@ class CakeBaseReporter implements PHPUnit_Framework_TestListener {
* @return void
*/
public function groupTestList() {
$testList = TestManager::getGroupTestList();
$testList = TestManager::getGroupTestList($this->params);
return $testList;
}

View file

@ -73,7 +73,7 @@ class TestManager {
*
* @var PHPUnit_Framework_TestSuite
*/
protected $_testSuit = null;
protected $_testSuite = null;
/**
* Object instance responsible for managing the test fixtures
@ -137,7 +137,7 @@ class TestManager {
* @return mixed Result of test case being run.
*/
public function runTestCase($testCaseFile, PHPUnit_Framework_TestListener $reporter, $codeCoverage = false) {
$testCaseFileWithPath = $this->_getTestsPath() . DS . $testCaseFile;
$testCaseFileWithPath = $this->_getTestsPath($reporter->params) . DS . $testCaseFile;
if (!file_exists($testCaseFileWithPath) || strpos($testCaseFileWithPath, '..')) {
throw new InvalidArgumentException(sprintf(__('Unable to load test file %s'), htmlentities($testCaseFile)));
@ -157,7 +157,7 @@ class TestManager {
* @return mixed Results of group test being run.
*/
public function runGroupTest($groupTestName, $reporter, $codeCoverage = false) {
$filePath = $this->_getTestsPath('groups') . DS . strtolower($groupTestName) . $this->getExtension('group');
$filePath = $this->_getTestsPath($reporter->params) . DS . strtolower($groupTestName) . $this->getExtension('group');
if (!file_exists($filePath) || strpos($filePath, '..')) {
throw new InvalidArgumentException(sprintf(
@ -238,19 +238,10 @@ class TestManager {
* @access public
* @static
*/
public static function &getTestCaseList() {
$return = self::_getTestCaseList(self::_getTestsPath());
return $return;
}
/**
* Builds the list of test cases from a given directory
*
* @param string $directory Directory to get test case list from.
* @static
*/
protected static function &_getTestCaseList($directory = '.') {
public static function getTestCaseList($params) {
$directory = self::_getTestsPath($params);
$fileList = self::_getTestFileList($directory);
$testCases = array();
foreach ($fileList as $testCaseFile) {
$testCases[$testCaseFile] = str_replace($directory . DS, '', $testCaseFile);
@ -275,9 +266,16 @@ class TestManager {
* @access public
* @static
*/
public static function &getGroupTestList() {
$return = self::_getTestGroupList(self::_getTestsPath('groups'));
return $return;
public static function getGroupTestList($params) {
$directory = self::_getTestsPath($params);
$fileList = self::_getTestGroupFileList($directory);
$groupTests = array();
foreach ($fileList as $groupTestFile) {
$groupTests[$groupTestFile] = str_replace(self::$_groupExtension, '', basename($groupTestFile));
}
sort($groupTests);
return $groupTests;
}
/**
@ -291,24 +289,6 @@ class TestManager {
return $return;
}
/**
* Returns a list of group test files from a given directory
*
* @param string $directory The directory to get group tests from.
* @static
*/
protected static function &_getTestGroupList($directory = '.') {
$fileList = self::_getTestGroupFileList($directory);
$groupTests = array();
foreach ($fileList as $groupTestFile) {
$groupTests[$groupTestFile] = str_replace(self::$_groupExtension, '', basename($groupTestFile));
}
sort($groupTests);
return $groupTests;
}
/**
* Gets a recursive list of files from a given directory and matches then against
* a given fileTestFunction, like isTestCaseFile()
@ -375,28 +355,29 @@ class TestManager {
/**
* Returns the given path to the test files depending on a given type of tests (cases, group, ..)
*
* @param string $type either 'cases' or 'groups'
* @param array $params Array of parameters for getting test paths.
* Can contain app, type, and plugin params.
* @return string The path tests are located on
* @static
*/
protected static function _getTestsPath($type = 'cases') {
if (!empty(self::$appTest)) {
if ($type == 'cases') {
protected static function _getTestsPath($params) {
if (!empty($params['app'])) {
if ($params['show'] == 'cases' || !empty($params['case'])) {
$result = APP_TEST_CASES;
} else if ($type == 'groups') {
} else if ($params['show'] == 'groups') {
$result = APP_TEST_GROUPS;
}
} else if (!empty(self::$pluginTest)) {
$_pluginBasePath = APP . 'plugins/' . self::$pluginTest . '/tests';
$pluginPath = App::pluginPath(self::$pluginTest);
} else if (!empty($params['plugin'])) {
$_pluginBasePath = APP . 'plugins/' . $params['plugin'] . '/tests';
$pluginPath = App::pluginPath($params['plugin']);
if (file_exists($pluginPath . DS . 'tests')) {
$_pluginBasePath = $pluginPath . DS . 'tests';
}
$result = $_pluginBasePath . DS . $type;
} else {
if ($type == 'cases') {
if ($params['show'] == 'cases' || !empty($params['case'])) {
$result = CORE_TEST_CASES;
} else if ($type == 'groups') {
} else if ($params['show'] == 'groups') {
$result = CORE_TEST_GROUPS;
}
}