2010-07-14 01:58:21 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* TestSuiteShell test case
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-07-14 01:58:21 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-07-14 01:58:21 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command
|
2010-07-14 01:58:21 +00:00
|
|
|
* @since CakePHP(tm) v 2.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
|
2010-12-09 05:13:11 +00:00
|
|
|
App::uses('ShellDispatcher', 'Console');
|
2011-10-18 08:21:53 +00:00
|
|
|
App::uses('TestShell', 'Console/Command');
|
2010-07-14 01:58:21 +00:00
|
|
|
|
2011-10-18 09:02:08 +00:00
|
|
|
class TestTestShell extends TestShell {
|
|
|
|
|
|
|
|
public function mapFileToCase($file, $category, $throwOnMissingFile = true) {
|
|
|
|
return $this->_mapFileToCase($file, $category, $throwOnMissingFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function mapFileToCategory($file) {
|
|
|
|
return $this->_mapFileToCategory($file);
|
|
|
|
}
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2011-10-18 09:02:08 +00:00
|
|
|
}
|
|
|
|
|
2011-10-18 08:21:53 +00:00
|
|
|
class TestShellTest extends CakeTestCase {
|
2010-07-14 01:58:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setUp test case
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUp() {
|
2010-10-24 19:11:30 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
|
2010-07-14 01:58:21 +00:00
|
|
|
$this->Shell = $this->getMock(
|
2011-10-18 09:02:08 +00:00
|
|
|
'TestTestShell',
|
2011-08-21 05:04:55 +00:00
|
|
|
array('in', 'out', 'hr', 'help', 'error', 'err', '_stop', 'initialize', '_run', 'clear'),
|
2010-10-24 19:11:30 +00:00
|
|
|
array($out, $out, $in)
|
2010-07-14 01:58:21 +00:00
|
|
|
);
|
2010-11-21 19:39:07 +00:00
|
|
|
$this->Shell->OptionParser = $this->getMock('ConsoleOptionParser', array(), array(null, false));
|
2010-07-14 01:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function tearDown() {
|
|
|
|
unset($this->Dispatch, $this->Shell);
|
|
|
|
}
|
|
|
|
|
2011-10-18 09:02:08 +00:00
|
|
|
/**
|
|
|
|
* testMapCoreFileToCategory
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapCoreFileToCategory() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCategory('lib/Cake/basics.php');
|
|
|
|
$this->assertSame('core', $return);
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCategory('lib/Cake/Core/App.php');
|
|
|
|
$this->assertSame('core', $return);
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCategory('lib/Cake/Some/Deeply/Nested/Structure.php');
|
|
|
|
$this->assertSame('core', $return);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMapCoreFileToCase
|
|
|
|
*
|
|
|
|
* basics.php is a slightly special case - it's the only file in the core with a test that isn't Capitalized
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapCoreFileToCase() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCase('lib/Cake/basics.php', 'core');
|
|
|
|
$this->assertSame('Basics', $return);
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCase('lib/Cake/Core/App.php', 'core');
|
|
|
|
$this->assertSame('Core/App', $return);
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCase('lib/Cake/Some/Deeply/Nested/Structure.php', 'core', false);
|
|
|
|
$this->assertSame('Some/Deeply/Nested/Structure', $return);
|
|
|
|
}
|
|
|
|
|
2011-10-18 09:36:30 +00:00
|
|
|
/**
|
|
|
|
* testMapAppFileToCategory
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapAppFileToCategory() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
2011-10-18 09:48:12 +00:00
|
|
|
$return = $this->Shell->mapFileToCategory(APP . 'Controller/ExampleController.php');
|
2011-10-18 09:36:30 +00:00
|
|
|
$this->assertSame('app', $return);
|
2011-10-18 09:37:47 +00:00
|
|
|
|
2011-10-18 09:48:12 +00:00
|
|
|
$return = $this->Shell->mapFileToCategory(APP . 'My/File/Is/Here.php');
|
2011-10-18 09:37:47 +00:00
|
|
|
$this->assertSame('app', $return);
|
2011-10-18 09:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMapAppFileToCase
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapAppFileToCase() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
2011-10-18 09:48:12 +00:00
|
|
|
$return = $this->Shell->mapFileToCase(APP . 'Controller/ExampleController.php', 'app', false);
|
2011-10-18 09:36:30 +00:00
|
|
|
$this->assertSame('Controller/ExampleController', $return);
|
2011-10-18 09:37:47 +00:00
|
|
|
|
2011-10-18 09:48:12 +00:00
|
|
|
$return = $this->Shell->mapFileToCase(APP . 'My/File/Is/Here.php', 'app', false);
|
2011-10-18 09:37:47 +00:00
|
|
|
$this->assertSame('My/File/Is/Here', $return);
|
2011-10-18 09:36:30 +00:00
|
|
|
}
|
|
|
|
|
2011-10-18 09:40:53 +00:00
|
|
|
/**
|
|
|
|
* testMapPluginFileToCategory
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapPluginFileToCategory() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
2011-10-18 09:48:12 +00:00
|
|
|
$return = $this->Shell->mapFileToCategory(APP . 'Plugin/awesome/Controller/ExampleController.php');
|
2011-10-18 09:40:53 +00:00
|
|
|
$this->assertSame('awesome', $return);
|
|
|
|
|
2011-10-18 09:48:12 +00:00
|
|
|
$return = $this->Shell->mapFileToCategory(dirname(CAKE) . 'plugins/awesome/Controller/ExampleController.php');
|
2011-10-18 09:40:53 +00:00
|
|
|
$this->assertSame('awesome', $return);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMapPluginFileToCase
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapPluginFileToCase() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
2011-10-18 09:48:12 +00:00
|
|
|
$return = $this->Shell->mapFileToCase(APP . 'Plugin/awesome/Controller/ExampleController.php', 'awesome', false);
|
2011-10-18 09:40:53 +00:00
|
|
|
$this->assertSame('Controller/ExampleController', $return);
|
|
|
|
|
2011-10-18 09:48:12 +00:00
|
|
|
$return = $this->Shell->mapFileToCase(dirname(CAKE) . 'plugins/awesome/Controller/ExampleController.php', 'awesome', false);
|
2011-10-18 09:40:53 +00:00
|
|
|
$this->assertSame('Controller/ExampleController', $return);
|
|
|
|
}
|
|
|
|
|
2011-10-18 09:54:58 +00:00
|
|
|
/**
|
|
|
|
* testMapCoreTestToCategory
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapCoreTestToCategory() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCategory('lib/Cake/Test/Case/BasicsTest.php');
|
|
|
|
$this->assertSame('core', $return);
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCategory('lib/Cake/Test/Case/BasicsTest.php');
|
|
|
|
$this->assertSame('core', $return);
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCategory('lib/Cake/Test/Case/Some/Deeply/Nested/StructureTest.php');
|
|
|
|
$this->assertSame('core', $return);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMapCoreTestToCase
|
|
|
|
*
|
|
|
|
* basics.php is a slightly special case - it's the only file in the core with a test that isn't Capitalized
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapCoreTestToCase() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCase('lib/Cake/Test/Case/BasicsTest.php', 'core');
|
|
|
|
$this->assertSame('Basics', $return);
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCase('lib/Cake/Test/Case/Core/AppTest.php', 'core');
|
|
|
|
$this->assertSame('Core/App', $return);
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCase('lib/Cake/Test/Case/Some/Deeply/Nested/StructureTest.php', 'core', false);
|
|
|
|
$this->assertSame('Some/Deeply/Nested/Structure', $return);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMapAppTestToCategory
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapAppTestToCategory() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCategory(APP . 'Test/Case/Controller/ExampleControllerTest.php');
|
|
|
|
$this->assertSame('app', $return);
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCategory(APP . 'Test/Case/My/File/Is/HereTest.php');
|
|
|
|
$this->assertSame('app', $return);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMapAppTestToCase
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapAppTestToCase() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCase(APP . 'Test/Case/Controller/ExampleControllerTest.php', 'app', false);
|
|
|
|
$this->assertSame('Controller/ExampleController', $return);
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCase(APP . 'Test/Case/My/File/Is/HereTest.php', 'app', false);
|
|
|
|
$this->assertSame('My/File/Is/Here', $return);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMapPluginTestToCategory
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapPluginTestToCategory() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCategory(APP . 'Plugin/awesome/Test/Case/Controller/ExampleControllerTest.php');
|
|
|
|
$this->assertSame('awesome', $return);
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCategory(dirname(CAKE) . 'plugins/awesome/Test/Case/Controller/ExampleControllerTest.php');
|
|
|
|
$this->assertSame('awesome', $return);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMapPluginTestToCase
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapPluginTestToCase() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCase(APP . 'Plugin/awesome/Test/Case/Controller/ExampleControllerTest.php', 'awesome', false);
|
|
|
|
$this->assertSame('Controller/ExampleController', $return);
|
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCase(dirname(CAKE) . 'plugins/awesome/Test/Case/Controller/ExampleControllerTest.php', 'awesome', false);
|
|
|
|
$this->assertSame('Controller/ExampleController', $return);
|
|
|
|
}
|
|
|
|
|
2011-10-18 09:57:14 +00:00
|
|
|
/**
|
|
|
|
* testMapNotTestToNothing
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapNotTestToNothing() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
|
2011-10-18 09:58:34 +00:00
|
|
|
$return = $this->Shell->mapFileToCategory(APP . 'Test/Case/NotATestFile.php');
|
2011-10-18 10:00:46 +00:00
|
|
|
$this->assertSame('app', $return);
|
2011-10-18 09:57:14 +00:00
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCase(APP . 'Test/Case/NotATestFile.php', false, false);
|
|
|
|
$this->assertFalse($return);
|
2011-10-18 09:58:34 +00:00
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCategory(APP . 'Test/Fixture/SomeTest.php');
|
2011-10-18 10:00:46 +00:00
|
|
|
$this->assertSame('app', $return);
|
2011-10-18 09:58:34 +00:00
|
|
|
|
|
|
|
$return = $this->Shell->mapFileToCase(APP . 'Test/Fixture/SomeTest.php', false, false);
|
|
|
|
$this->assertFalse($return);
|
2011-10-18 09:57:14 +00:00
|
|
|
}
|
|
|
|
|
2010-07-14 01:58:21 +00:00
|
|
|
/**
|
|
|
|
* test available list of test cases for an empty category
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAvailableWithEmptyList() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
$this->Shell->args = array('unexistant-category');
|
2011-03-19 17:48:00 +00:00
|
|
|
$this->Shell->expects($this->at(0))->method('out')->with(__d('cake_console', "No test cases available \n\n"));
|
2010-11-21 19:39:07 +00:00
|
|
|
$this->Shell->OptionParser->expects($this->once())->method('help');
|
2010-07-14 01:58:21 +00:00
|
|
|
$this->Shell->available();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test available list of test cases for core category
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAvailableCoreCategory() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
$this->Shell->args = array('core');
|
|
|
|
$this->Shell->expects($this->at(0))->method('out')->with('Core Test Cases:');
|
|
|
|
$this->Shell->expects($this->at(1))->method('out')
|
2011-10-18 15:49:52 +00:00
|
|
|
->with($this->stringContains('[1]'));
|
2010-07-14 01:58:21 +00:00
|
|
|
$this->Shell->expects($this->at(2))->method('out')
|
2011-10-18 15:49:52 +00:00
|
|
|
->with($this->stringContains('[2]'));
|
2011-03-19 17:48:00 +00:00
|
|
|
|
2010-07-14 01:58:21 +00:00
|
|
|
$this->Shell->expects($this->once())->method('in')
|
2011-03-19 17:48:00 +00:00
|
|
|
->with(__d('cake_console', 'What test case would you like to run?'), null, 'q')
|
2010-07-14 01:58:21 +00:00
|
|
|
->will($this->returnValue('1'));
|
|
|
|
|
2011-08-21 05:04:55 +00:00
|
|
|
$this->Shell->expects($this->once())->method('_run');
|
2010-07-14 01:58:21 +00:00
|
|
|
$this->Shell->available();
|
2011-04-12 02:46:19 +00:00
|
|
|
$this->assertEquals($this->Shell->args, array('core', 'AllBehaviors'));
|
2010-07-14 01:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that correct option for test runner are passed
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRunnerOptions() {
|
|
|
|
$this->Shell->startup();
|
|
|
|
$this->Shell->args = array('core', 'Basics');
|
2010-10-16 04:42:37 +00:00
|
|
|
$this->Shell->params = array('filter' => 'myFilter', 'colors' => true, 'verbose' => true);
|
2010-07-14 01:58:21 +00:00
|
|
|
|
2011-08-21 05:04:55 +00:00
|
|
|
$this->Shell->expects($this->once())->method('_run')
|
2010-07-14 01:58:21 +00:00
|
|
|
->with(
|
2011-04-12 02:46:19 +00:00
|
|
|
array('app' => false, 'plugin' => null, 'core' => true, 'output' => 'text', 'case' => 'Basics'),
|
2010-10-11 05:33:24 +00:00
|
|
|
array('--filter', 'myFilter', '--colors', '--verbose')
|
2010-07-14 01:58:21 +00:00
|
|
|
);
|
|
|
|
$this->Shell->main();
|
|
|
|
}
|
2011-10-18 08:21:53 +00:00
|
|
|
}
|