mirror of
				https://github.com/brmlab/brmsklad.git
				synced 2025-10-31 00:03:58 +01:00 
			
		
		
		
	Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
		
							parent
							
								
									5a580df460
								
							
						
					
					
						commit
						235a541597
					
				
					 793 changed files with 60746 additions and 23753 deletions
				
			
		|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * AllConsoleLibsTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  * @since         CakePHP(tm) v 2.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| /** | ||||
|  | @ -45,4 +44,4 @@ class AllConsoleLibsTest extends PHPUnit_Framework_TestSuite { | |||
| 		} | ||||
| 		return $suite; | ||||
| 	} | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * AllConsoleTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  * @since         CakePHP(tm) v 2.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| /** | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * AllShellsTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  * @since         CakePHP(tm) v 2.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| /** | ||||
|  | @ -39,4 +38,4 @@ class AllShellsTest extends PHPUnit_Framework_TestSuite { | |||
| 		$suite->addTestDirectory($path); | ||||
| 		return $suite; | ||||
| 	} | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * AllTasksTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  * @since         CakePHP(tm) v 2.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| /** | ||||
|  | @ -39,4 +38,3 @@ class AllTasksTest extends PHPUnit_Framework_TestSuite { | |||
| 		return $suite; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * AclShell Test file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP :  Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  * @since         CakePHP v 1.2.0.7726 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ConsoleOutput', 'Console'); | ||||
|  | @ -115,6 +114,7 @@ class AclShellTest extends CakeTestCase { | |||
| 	public function testParsingModelAndForeignKey() { | ||||
| 		$result = $this->Task->parseIdentifier('Model.foreignKey'); | ||||
| 		$expected = array('model' => 'Model', 'foreign_key' => 'foreignKey'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = $this->Task->parseIdentifier('mySuperUser'); | ||||
| 		$this->assertEquals('mySuperUser', $result); | ||||
|  | @ -253,7 +253,7 @@ class AclShellTest extends CakeTestCase { | |||
| 		$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create'); | ||||
| 		$this->Task->check(); | ||||
| 
 | ||||
| 		$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', '*'); | ||||
| 		$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'delete'); | ||||
| 		$this->Task->check(); | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * ApiShellTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP :  Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  * @since         CakePHP v 1.2.0.7726 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ConsoleOutput', 'Console'); | ||||
|  | @ -43,7 +42,7 @@ class ApiShellTest extends CakeTestCase { | |||
| 		$this->Shell = $this->getMock( | ||||
| 			'ApiShell', | ||||
| 			array('in', 'out', 'createFile', 'hr', '_stop'), | ||||
| 			array(	$out, $out, $in) | ||||
| 			array($out, $out, $in) | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,20 +2,18 @@ | |||
| /** | ||||
|  * BakeShell Test Case | ||||
|  * | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  * @since         CakePHP(tm) v 1.3 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ConsoleOutput', 'Console'); | ||||
|  | @ -30,9 +28,6 @@ App::uses('Controller', 'Controller'); | |||
| 
 | ||||
| if (!class_exists('UsersController')) { | ||||
| 	class UsersController extends Controller { | ||||
| 
 | ||||
| 		public $name = 'Users'; | ||||
| 
 | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,27 +2,31 @@ | |||
| /** | ||||
|  * CommandListShellTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP :  Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  * @since         CakePHP v 2.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('CommandListShell', 'Console/Command'); | ||||
| App::uses('ConsoleOutput', 'Console'); | ||||
| App::uses('ConsoleInput', 'Console'); | ||||
| App::uses('Shell', 'Console'); | ||||
| App::uses('CommandTask', 'Console/Command/Task'); | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * TestStringOutput | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  */ | ||||
| class TestStringOutput extends ConsoleOutput { | ||||
| 
 | ||||
| 	public $output = ''; | ||||
|  | @ -33,6 +37,11 @@ class TestStringOutput extends ConsoleOutput { | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * CommandListShellTest | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  */ | ||||
| class CommandListShellTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  | @ -60,6 +69,12 @@ class CommandListShellTest extends CakeTestCase { | |||
| 			array('in', '_stop', 'clear'), | ||||
| 			array($out, $out, $in) | ||||
| 		); | ||||
| 
 | ||||
| 		$this->Shell->Command = $this->getMock( | ||||
| 			'CommandTask', | ||||
| 			array('in', '_stop', 'clear'), | ||||
| 			array($out, $out, $in) | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -88,7 +103,7 @@ class CommandListShellTest extends CakeTestCase { | |||
| 		$expected = "/\[.*TestPluginTwo.*\] example, welcome/"; | ||||
| 		$this->assertRegExp($expected, $output); | ||||
| 
 | ||||
| 		$expected = "/\[.*CORE.*\] acl, api, bake, command_list, console, i18n, schema, test, testsuite, upgrade/"; | ||||
| 		$expected = "/\[.*CORE.*\] acl, api, bake, command_list, completion, console, i18n, schema, server, test, testsuite, upgrade/"; | ||||
| 		$this->assertRegExp($expected, $output); | ||||
| 
 | ||||
| 		$expected = "/\[.*app.*\] sample/"; | ||||
|  |  | |||
							
								
								
									
										261
									
								
								lib/Cake/Test/Case/Console/Command/CompletionShellTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										261
									
								
								lib/Cake/Test/Case/Console/Command/CompletionShellTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,261 @@ | |||
| <?php | ||||
| /** | ||||
|  * CompletionShellTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP :  Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  * @since         CakePHP v 2.5 | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('CompletionShell', 'Console/Command'); | ||||
| App::uses('ConsoleOutput', 'Console'); | ||||
| App::uses('ConsoleInput', 'Console'); | ||||
| App::uses('Shell', 'Console'); | ||||
| App::uses('CommandTask', 'Console/Command/Task'); | ||||
| 
 | ||||
| /** | ||||
|  * TestCompletionStringOutput | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  */ | ||||
| class TestCompletionStringOutput extends ConsoleOutput { | ||||
| 
 | ||||
| 	public $output = ''; | ||||
| 
 | ||||
| 	protected function _write($message) { | ||||
| 		$this->output .= $message; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * CompletionShellTest | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  */ | ||||
| class CompletionShellTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		App::build(array( | ||||
| 			'Plugin' => array( | ||||
| 				CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS | ||||
| 			), | ||||
| 			'Console/Command' => array( | ||||
| 				CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS | ||||
| 			) | ||||
| 		), App::RESET); | ||||
| 		CakePlugin::load(array('TestPlugin', 'TestPluginTwo')); | ||||
| 
 | ||||
| 		$out = new TestCompletionStringOutput(); | ||||
| 		$in = $this->getMock('ConsoleInput', array(), array(), '', false); | ||||
| 
 | ||||
| 		$this->Shell = $this->getMock( | ||||
| 			'CompletionShell', | ||||
| 			array('in', '_stop', 'clear'), | ||||
| 			array($out, $out, $in) | ||||
| 		); | ||||
| 
 | ||||
| 		$this->Shell->Command = $this->getMock( | ||||
| 			'CommandTask', | ||||
| 			array('in', '_stop', 'clear'), | ||||
| 			array($out, $out, $in) | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * tearDown | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		unset($this->Shell); | ||||
| 		CakePlugin::unload(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that the startup method supresses the shell header | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testStartup() { | ||||
| 		$this->Shell->runCommand('main', array()); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$needle = 'Welcome to CakePHP'; | ||||
| 		$this->assertTextNotContains($needle, $output); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that main displays a warning | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testMain() { | ||||
| 		$this->Shell->runCommand('main', array()); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$expected = "/This command is not intended to be called manually/"; | ||||
| 		$this->assertRegExp($expected, $output); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test commands method that list all available commands | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testCommands() { | ||||
| 		$this->Shell->runCommand('commands', array()); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$expected = "TestPlugin.example TestPlugin.test_plugin TestPluginTwo.example TestPluginTwo.welcome acl api bake command_list completion console i18n schema server test testsuite upgrade sample\n"; | ||||
| 		$this->assertEquals($expected, $output); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that options without argument returns the default options | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOptionsNoArguments() { | ||||
| 		$this->Shell->runCommand('options', array()); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$expected = "--help -h --verbose -v --quiet -q\n"; | ||||
| 		$this->assertEquals($expected, $output); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that options with a nonexisting command returns the default options | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOptionsNonExistingCommand() { | ||||
| 		$this->Shell->runCommand('options', array('options', 'foo')); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$expected = "--help -h --verbose -v --quiet -q\n"; | ||||
| 		$this->assertEquals($expected, $output); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that options with a existing command returns the proper options | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOptions() { | ||||
| 		$this->Shell->runCommand('options', array('options', 'bake')); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$expected = "--help -h --verbose -v --quiet -q --connection -c --theme -t\n"; | ||||
| 		$this->assertEquals($expected, $output); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that subCommands with a existing CORE command returns the proper sub commands | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSubCommandsCorePlugin() { | ||||
| 		$this->Shell->runCommand('subCommands', array('subCommands', 'CORE.bake')); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$expected = "controller db_config fixture model plugin project test view\n"; | ||||
| 		$this->assertEquals($expected, $output); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that subCommands with a existing APP command returns the proper sub commands (in this case none) | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSubCommandsAppPlugin() { | ||||
| 		$this->Shell->runCommand('subCommands', array('subCommands', 'app.sample')); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$expected = ''; | ||||
| 		$this->assertEquals($expected, $output); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that subCommands with a existing plugin command returns the proper sub commands | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSubCommandsPlugin() { | ||||
| 		$this->Shell->runCommand('subCommands', array('subCommands', 'TestPluginTwo.welcome')); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$expected = "say_hello\n"; | ||||
| 		$this->assertEquals($expected, $output); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that subcommands without arguments returns nothing | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSubCommandsNoArguments() { | ||||
| 		$this->Shell->runCommand('subCommands', array()); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$expected = ''; | ||||
| 		$this->assertEquals($expected, $output); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that subcommands with a nonexisting command returns nothing | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSubCommandsNonExistingCommand() { | ||||
| 		$this->Shell->runCommand('subCommands', array('subCommands', 'foo')); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$expected = ''; | ||||
| 		$this->assertEquals($expected, $output); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that subcommands returns the available subcommands for the given command | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSubCommands() { | ||||
| 		$this->Shell->runCommand('subCommands', array('subCommands', 'bake')); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$expected = "controller db_config fixture model plugin project test view\n"; | ||||
| 		$this->assertEquals($expected, $output); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that fuzzy returns nothing | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testFuzzy() { | ||||
| 		$this->Shell->runCommand('fuzzy', array()); | ||||
| 		$output = $this->Shell->stdout->output; | ||||
| 
 | ||||
| 		$expected = ''; | ||||
| 		$this->assertEquals($expected, $output); | ||||
| 	} | ||||
| } | ||||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * SchemaShellTest Test file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  * @since         CakePHP v 1.3 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ShellDispatcher', 'Console'); | ||||
|  | @ -31,17 +30,10 @@ App::uses('SchemaShell', 'Console/Command'); | |||
|  */ | ||||
| class SchemaShellTestSchema extends CakeSchema { | ||||
| 
 | ||||
| /** | ||||
|  * name property | ||||
|  * | ||||
|  * @var string 'MyApp' | ||||
|  */ | ||||
| 	public $name = 'SchemaShellTest'; | ||||
| 
 | ||||
| /** | ||||
|  * connection property | ||||
|  * | ||||
|  * @var string 'test' | ||||
|  * @var string | ||||
|  */ | ||||
| 	public $connection = 'test'; | ||||
| 
 | ||||
|  | @ -78,6 +70,14 @@ class SchemaShellTestSchema extends CakeSchema { | |||
| 		'updated' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||||
| 		'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)), | ||||
| 	); | ||||
| 
 | ||||
| 	public $newone = array( | ||||
| 		'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'), | ||||
| 		'testit' => array('type' => 'string', 'null' => false, 'default' => 'Title'), | ||||
| 		'created' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||||
| 		'updated' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||||
| 		'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)), | ||||
| 	); | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  | @ -92,8 +92,9 @@ class SchemaShellTest extends CakeTestCase { | |||
|  * | ||||
|  * @var array | ||||
|  */ | ||||
| 	public $fixtures = array('core.article', 'core.user', 'core.post', 'core.auth_user', 'core.author', | ||||
| 		'core.comment', 'core.test_plugin_comment' | ||||
| 	public $fixtures = array( | ||||
| 		'core.article', 'core.user', 'core.post', 'core.auth_user', 'core.author', | ||||
| 		'core.comment', 'core.test_plugin_comment', 'core.aco', 'core.aro', 'core.aros_aco', | ||||
| 	); | ||||
| 
 | ||||
| /** | ||||
|  | @ -134,7 +135,7 @@ class SchemaShellTest extends CakeTestCase { | |||
| 	public function testStartup() { | ||||
| 		$this->Shell->startup(); | ||||
| 		$this->assertTrue(isset($this->Shell->Schema)); | ||||
| 		$this->assertTrue(is_a($this->Shell->Schema, 'CakeSchema')); | ||||
| 		$this->assertInstanceOf('CakeSchema', $this->Shell->Schema); | ||||
| 		$this->assertEquals(Inflector::camelize(Inflector::slug(APP_DIR)), $this->Shell->Schema->name); | ||||
| 		$this->assertEquals('schema.php', $this->Shell->Schema->file); | ||||
| 
 | ||||
|  | @ -294,7 +295,7 @@ class SchemaShellTest extends CakeTestCase { | |||
| 		$this->Shell->Schema->path = TMP; | ||||
| 		$this->Shell->Schema->expects($this->never())->method('read'); | ||||
| 
 | ||||
| 		$result = $this->Shell->generate(); | ||||
| 		$this->Shell->generate(); | ||||
| 		unlink(TMP . 'schema.php'); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -362,6 +363,90 @@ class SchemaShellTest extends CakeTestCase { | |||
| 		CakePlugin::unload(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test generate with specific models | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGenerateModels() { | ||||
| 		App::build(array( | ||||
| 			'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS) | ||||
| 		), App::RESET); | ||||
| 		CakePlugin::load('TestPlugin'); | ||||
| 
 | ||||
| 		$this->db->cacheSources = false; | ||||
| 		$this->Shell->params = array( | ||||
| 			'plugin' => 'TestPlugin', | ||||
| 			'connection' => 'test', | ||||
| 			'models' => 'TestPluginComment', | ||||
| 			'force' => false, | ||||
| 			'overwrite' => true | ||||
| 		); | ||||
| 		$this->Shell->startup(); | ||||
| 		$this->Shell->Schema->path = TMP . 'tests' . DS; | ||||
| 
 | ||||
| 		$this->Shell->generate(); | ||||
| 		$this->file = new File(TMP . 'tests' . DS . 'schema.php'); | ||||
| 		$contents = $this->file->read(); | ||||
| 
 | ||||
| 		$this->assertRegExp('/class TestPluginSchema/', $contents); | ||||
| 		$this->assertRegExp('/public \$test_plugin_comments/', $contents); | ||||
| 		$this->assertNotRegExp('/public \$authors/', $contents); | ||||
| 		$this->assertNotRegExp('/public \$auth_users/', $contents); | ||||
| 		$this->assertNotRegExp('/public \$posts/', $contents); | ||||
| 		CakePlugin::unload(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test generate with excluded tables | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGenerateExclude() { | ||||
| 		Configure::write('Acl.database', 'test'); | ||||
| 		$this->db->cacheSources = false; | ||||
| 		$this->Shell->params = array( | ||||
| 			'connection' => 'test', | ||||
| 			'force' => false, | ||||
| 			'models' => 'Aro, Aco, Permission', | ||||
| 			'overwrite' => true, | ||||
| 			'exclude' => 'acos, aros', | ||||
| 		); | ||||
| 		$this->Shell->startup(); | ||||
| 		$this->Shell->Schema->path = TMP . 'tests' . DS; | ||||
| 
 | ||||
| 		$this->Shell->generate(); | ||||
| 		$this->file = new File(TMP . 'tests' . DS . 'schema.php'); | ||||
| 		$contents = $this->file->read(); | ||||
| 
 | ||||
| 		$this->assertNotContains('public $acos = array(', $contents); | ||||
| 		$this->assertNotContains('public $aros = array(', $contents); | ||||
| 		$this->assertContains('public $aros_acos = array(', $contents); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test schema run create with --yes option | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testCreateOptionYes() { | ||||
| 		$this->Shell = $this->getMock( | ||||
| 			'SchemaShell', | ||||
| 			array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'), | ||||
| 			array(&$this->Dispatcher) | ||||
| 		); | ||||
| 
 | ||||
| 		$this->Shell->params = array( | ||||
| 			'connection' => 'test', | ||||
| 			'yes' => true, | ||||
| 		); | ||||
| 		$this->Shell->args = array('i18n'); | ||||
| 		$this->Shell->expects($this->never())->method('in'); | ||||
| 		$this->Shell->expects($this->exactly(2))->method('_run'); | ||||
| 		$this->Shell->startup(); | ||||
| 		$this->Shell->create(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test schema run create with no table args. | ||||
|  * | ||||
|  | @ -394,15 +479,15 @@ class SchemaShellTest extends CakeTestCase { | |||
| 	public function testCreateWithTableArgs() { | ||||
| 		$db = ConnectionManager::getDataSource('test'); | ||||
| 		$sources = $db->listSources(); | ||||
| 		if (in_array('acos', $sources)) { | ||||
| 			$this->markTestSkipped('acos table already exists, cannot try to create it again.'); | ||||
| 		if (in_array('i18n', $sources)) { | ||||
| 			$this->markTestSkipped('i18n table already exists, cannot try to create it again.'); | ||||
| 		} | ||||
| 		$this->Shell->params = array( | ||||
| 			'connection' => 'test', | ||||
| 			'name' => 'DbAcl', | ||||
| 			'name' => 'I18n', | ||||
| 			'path' => APP . 'Config' . DS . 'Schema' | ||||
| 		); | ||||
| 		$this->Shell->args = array('DbAcl', 'acos'); | ||||
| 		$this->Shell->args = array('I18n', 'i18n'); | ||||
| 		$this->Shell->startup(); | ||||
| 		$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y')); | ||||
| 		$this->Shell->create(); | ||||
|  | @ -410,12 +495,10 @@ class SchemaShellTest extends CakeTestCase { | |||
| 		$db = ConnectionManager::getDataSource('test'); | ||||
| 		$db->cacheSources = false; | ||||
| 		$sources = $db->listSources(); | ||||
| 		$this->assertTrue(in_array($db->config['prefix'] . 'acos', $sources), 'acos should be present.'); | ||||
| 		$this->assertFalse(in_array($db->config['prefix'] . 'aros', $sources), 'aros should not be found.'); | ||||
| 		$this->assertFalse(in_array('aros_acos', $sources), 'aros_acos should not be found.'); | ||||
| 		$this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources), 'i18n should be present.'); | ||||
| 
 | ||||
| 		$schema = new DbAclSchema(); | ||||
| 		$db->execute($db->dropSchema($schema, 'acos')); | ||||
| 		$schema = new I18nSchema(); | ||||
| 		$db->execute($db->dropSchema($schema, 'i18n')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -436,8 +519,66 @@ class SchemaShellTest extends CakeTestCase { | |||
| 		); | ||||
| 		$this->Shell->args = array('SchemaShellTest', 'articles'); | ||||
| 		$this->Shell->startup(); | ||||
| 		$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y')); | ||||
| 		$this->Shell->expects($this->once())->method('_run') | ||||
| 		$this->Shell->expects($this->any()) | ||||
| 			->method('in') | ||||
| 			->will($this->returnValue('y')); | ||||
| 		$this->Shell->expects($this->once()) | ||||
| 			->method('_run') | ||||
| 			->with($this->arrayHasKey('articles'), 'update', $this->isInstanceOf('CakeSchema')); | ||||
| 
 | ||||
| 		$this->Shell->update(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test run update with a table arg. and checks that a CREATE statement is issued | ||||
|  * table creation | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testUpdateWithTableCreate() { | ||||
| 		$this->Shell = $this->getMock( | ||||
| 			'SchemaShell', | ||||
| 			array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'), | ||||
| 			array(&$this->Dispatcher) | ||||
| 		); | ||||
| 
 | ||||
| 		$this->Shell->params = array( | ||||
| 			'connection' => 'test', | ||||
| 			'force' => true | ||||
| 		); | ||||
| 		$this->Shell->args = array('SchemaShellTest', 'newone'); | ||||
| 		$this->Shell->startup(); | ||||
| 		$this->Shell->expects($this->any()) | ||||
| 			->method('in') | ||||
| 			->will($this->returnValue('y')); | ||||
| 		$this->Shell->expects($this->once()) | ||||
| 			->method('_run') | ||||
| 			->with($this->arrayHasKey('newone'), 'update', $this->isInstanceOf('CakeSchema')); | ||||
| 
 | ||||
| 		$this->Shell->update(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test run update with --yes option | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testUpdateWithOptionYes() { | ||||
| 		$this->Shell = $this->getMock( | ||||
| 			'SchemaShell', | ||||
| 			array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_run'), | ||||
| 			array(&$this->Dispatcher) | ||||
| 		); | ||||
| 
 | ||||
| 		$this->Shell->params = array( | ||||
| 			'connection' => 'test', | ||||
| 			'force' => true, | ||||
| 			'yes' => true, | ||||
| 		); | ||||
| 		$this->Shell->args = array('SchemaShellTest', 'articles'); | ||||
| 		$this->Shell->startup(); | ||||
| 		$this->Shell->expects($this->never())->method('in'); | ||||
| 		$this->Shell->expects($this->once()) | ||||
| 			->method('_run') | ||||
| 			->with($this->arrayHasKey('articles'), 'update', $this->isInstanceOf('CakeSchema')); | ||||
| 
 | ||||
| 		$this->Shell->update(); | ||||
|  | @ -463,6 +604,71 @@ class SchemaShellTest extends CakeTestCase { | |||
| 		CakePlugin::unload(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that underscored names also result in CamelCased class names | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testName() { | ||||
| 		App::build(array( | ||||
| 			'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS) | ||||
| 		)); | ||||
| 		CakePlugin::load('TestPlugin'); | ||||
| 		$this->Shell->params = array( | ||||
| 			'plugin' => 'TestPlugin', | ||||
| 			'connection' => 'test', | ||||
| 			'name' => 'custom_names', | ||||
| 			'force' => false, | ||||
| 			'overwrite' => true, | ||||
| 		); | ||||
| 		$this->Shell->startup(); | ||||
| 		if (file_exists($this->Shell->Schema->path . DS . 'custom_names.php')) { | ||||
| 			unlink($this->Shell->Schema->path . DS . 'custom_names.php'); | ||||
| 		} | ||||
| 		$this->Shell->generate(); | ||||
| 
 | ||||
| 		$contents = file_get_contents($this->Shell->Schema->path . DS . 'custom_names.php'); | ||||
| 		$this->assertRegExp('/class CustomNamesSchema/', $contents); | ||||
| 		unlink($this->Shell->Schema->path . DS . 'custom_names.php'); | ||||
| 		CakePlugin::unload(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that passing name and file creates the passed filename with the | ||||
|  * passed class name | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testNameAndFile() { | ||||
| 		App::build(array( | ||||
| 			'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS) | ||||
| 		)); | ||||
| 		CakePlugin::load('TestPlugin'); | ||||
| 		$this->Shell->params = array( | ||||
| 			'plugin' => 'TestPlugin', | ||||
| 			'connection' => 'test', | ||||
| 			'name' => 'custom_name', | ||||
| 			'file' => 'other_name', | ||||
| 			'force' => false, | ||||
| 			'overwrite' => true, | ||||
| 		); | ||||
| 		$this->Shell->startup(); | ||||
| 		$file = $this->Shell->Schema->path . DS . 'other_name.php'; | ||||
| 		if (file_exists($file)) { | ||||
| 			unlink($file); | ||||
| 		} | ||||
| 		$this->Shell->generate(); | ||||
| 
 | ||||
| 		$this->assertFileExists($file); | ||||
| 		$contents = file_get_contents($file); | ||||
| 		$this->assertRegExp('/class CustomNameSchema/', $contents); | ||||
| 
 | ||||
| 		if (file_exists($file)) { | ||||
| 			unlink($file); | ||||
| 		} | ||||
| 		CakePlugin::unload(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that using Plugin.name with write. | ||||
|  * | ||||
|  |  | |||
							
								
								
									
										242
									
								
								lib/Cake/Test/Case/Console/Command/Task/CommandTaskTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										242
									
								
								lib/Cake/Test/Case/Console/Command/Task/CommandTaskTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,242 @@ | |||
| <?php | ||||
| /** | ||||
|  * CakePHP : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  * @since         CakePHP v 2.5 | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('CommandTask', 'Console/Command/Task'); | ||||
| 
 | ||||
| /** | ||||
|  * CommandTaskTest class | ||||
|  * | ||||
|  * @package   Cake.Test.Case.Console.Command.Task | ||||
|  */ | ||||
| class CommandTaskTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		App::build(array( | ||||
| 			'Plugin' => array( | ||||
| 				CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS | ||||
| 			), | ||||
| 			'Console/Command' => array( | ||||
| 				CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS | ||||
| 			) | ||||
| 		), App::RESET); | ||||
| 		CakePlugin::load(array('TestPlugin', 'TestPluginTwo')); | ||||
| 
 | ||||
| 		$out = $this->getMock('ConsoleOutput', array(), array(), '', false); | ||||
| 		$in = $this->getMock('ConsoleInput', array(), array(), '', false); | ||||
| 
 | ||||
| 		$this->CommandTask = $this->getMock( | ||||
| 			'CommandTask', | ||||
| 			array('in', '_stop', 'clear'), | ||||
| 			array($out, $out, $in) | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * tearDown | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		unset($this->CommandTask); | ||||
| 		CakePlugin::unload(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test the resulting list of shells | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGetShellList() { | ||||
| 		$result = $this->CommandTask->getShellList(); | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			'CORE' => array( | ||||
| 				'acl', | ||||
| 				'api', | ||||
| 				'bake', | ||||
| 				'command_list', | ||||
| 				'completion', | ||||
| 				'console', | ||||
| 				'i18n', | ||||
| 				'schema', | ||||
| 				'server', | ||||
| 				'test', | ||||
| 				'testsuite', | ||||
| 				'upgrade' | ||||
| 			), | ||||
| 			'TestPlugin' => array( | ||||
| 				'example', | ||||
| 				'test_plugin' | ||||
| 			), | ||||
| 			'TestPluginTwo' => array( | ||||
| 				'example', | ||||
| 				'welcome' | ||||
| 			), | ||||
| 			'app' => array( | ||||
| 				'sample' | ||||
| 			), | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test the resulting list of commands | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testCommands() { | ||||
| 		$result = $this->CommandTask->commands(); | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			'TestPlugin.example', | ||||
| 			'TestPlugin.test_plugin', | ||||
| 			'TestPluginTwo.example', | ||||
| 			'TestPluginTwo.welcome', | ||||
| 			'acl', | ||||
| 			'api', | ||||
| 			'bake', | ||||
| 			'command_list', | ||||
| 			'completion', | ||||
| 			'console', | ||||
| 			'i18n', | ||||
| 			'schema', | ||||
| 			'server', | ||||
| 			'test', | ||||
| 			'testsuite', | ||||
| 			'upgrade', | ||||
| 			'sample' | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test the resulting list of subcommands for the given command | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSubCommands() { | ||||
| 		$result = $this->CommandTask->subCommands('acl'); | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			'check', | ||||
| 			'create', | ||||
| 			'db_config', | ||||
| 			'delete', | ||||
| 			'deny', | ||||
| 			'getPath', | ||||
| 			'grant', | ||||
| 			'inherit', | ||||
| 			'initdb', | ||||
| 			'nodeExists', | ||||
| 			'parseIdentifier', | ||||
| 			'setParent', | ||||
| 			'view' | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that unknown commands return an empty array | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSubCommandsUnknownCommand() { | ||||
| 		$result = $this->CommandTask->subCommands('yoghurt'); | ||||
| 
 | ||||
| 		$expected = array(); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that getting a existing shell returns the shell instance | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGetShell() { | ||||
| 		$result = $this->CommandTask->getShell('acl'); | ||||
| 		$this->assertInstanceOf('AclShell', $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that getting a non-existing shell returns false | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGetShellNonExisting() { | ||||
| 		$result = $this->CommandTask->getShell('strawberry'); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that getting a existing core shell with 'core.' prefix returns the correct shell instance | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGetShellCore() { | ||||
| 		$result = $this->CommandTask->getShell('core.bake'); | ||||
| 		$this->assertInstanceOf('BakeShell', $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test the options array for a known command | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOptions() { | ||||
| 		$result = $this->CommandTask->options('bake'); | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			'--help', | ||||
| 			'-h', | ||||
| 			'--verbose', | ||||
| 			'-v', | ||||
| 			'--quiet', | ||||
| 			'-q', | ||||
| 			'--connection', | ||||
| 			'-c', | ||||
| 			'--theme', | ||||
| 			'-t' | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test the options array for an unknown command | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOptionsUnknownCommand() { | ||||
| 		$result = $this->CommandTask->options('pie'); | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			'--help', | ||||
| 			'-h', | ||||
| 			'--verbose', | ||||
| 			'-v', | ||||
| 			'--quiet', | ||||
| 			'-q' | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * ControllerTask Test Case | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @since         CakePHP(tm) v 1.3 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ConsoleOutput', 'Console'); | ||||
|  | @ -39,10 +38,11 @@ $imported = class_exists('BakeArticle') || class_exists('BakeComment') || class_ | |||
| if (!$imported) { | ||||
| 	define('ARTICLE_MODEL_CREATED', true); | ||||
| 
 | ||||
| /** | ||||
|  * BakeArticle | ||||
|  */ | ||||
| 	class BakeArticle extends Model { | ||||
| 
 | ||||
| 		public $name = 'BakeArticle'; | ||||
| 
 | ||||
| 		public $hasMany = array('BakeComment'); | ||||
| 
 | ||||
| 		public $hasAndBelongsToMany = array('BakeTag'); | ||||
|  | @ -90,6 +90,10 @@ class ControllerTaskTest extends CakeTestCase { | |||
| 			array($out, $out, $in) | ||||
| 		); | ||||
| 		$this->Task->Test = $this->getMock('TestTask', array(), array($out, $out, $in)); | ||||
| 
 | ||||
| 		if (!defined('ARTICLE_MODEL_CREATED')) { | ||||
| 			$this->markTestSkipped('Could not run as an Article, Tag or Comment model was already loaded.'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -191,9 +195,9 @@ class ControllerTaskTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testDoHelpersTrailingSpace() { | ||||
| 		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y')); | ||||
| 		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne  ')); | ||||
| 		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne  ')); | ||||
| 		$result = $this->Task->doHelpers(); | ||||
| 		$expected = array('Javascript', 'Ajax', 'CustomOne'); | ||||
| 		$expected = array('Text', 'Number', 'CustomOne'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -204,9 +208,9 @@ class ControllerTaskTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testDoHelpersTrailingCommas() { | ||||
| 		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y')); | ||||
| 		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne, , ')); | ||||
| 		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne, , ')); | ||||
| 		$result = $this->Task->doHelpers(); | ||||
| 		$expected = array('Javascript', 'Ajax', 'CustomOne'); | ||||
| 		$expected = array('Text', 'Number', 'CustomOne'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -218,7 +222,7 @@ class ControllerTaskTest extends CakeTestCase { | |||
| 	public function testDoComponentsNo() { | ||||
| 		$this->Task->expects($this->any())->method('in')->will($this->returnValue('n')); | ||||
| 		$result = $this->Task->doComponents(); | ||||
| 		$this->assertSame(array(), $result); | ||||
| 		$this->assertSame(array('Paginator'), $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -231,7 +235,7 @@ class ControllerTaskTest extends CakeTestCase { | |||
| 		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security  ')); | ||||
| 
 | ||||
| 		$result = $this->Task->doComponents(); | ||||
| 		$expected = array('RequestHandler', 'Security'); | ||||
| 		$expected = array('Paginator', 'RequestHandler', 'Security'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -245,7 +249,7 @@ class ControllerTaskTest extends CakeTestCase { | |||
| 		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security, , ')); | ||||
| 
 | ||||
| 		$result = $this->Task->doComponents(); | ||||
| 		$expected = array('RequestHandler', 'Security'); | ||||
| 		$expected = array('Paginator', 'RequestHandler', 'Security'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -257,11 +261,11 @@ class ControllerTaskTest extends CakeTestCase { | |||
| 	public function testConfirmController() { | ||||
| 		$controller = 'Posts'; | ||||
| 		$scaffold = false; | ||||
| 		$helpers = array('Ajax', 'Time'); | ||||
| 		$helpers = array('Js', 'Time'); | ||||
| 		$components = array('Acl', 'Auth'); | ||||
| 
 | ||||
| 		$this->Task->expects($this->at(4))->method('out')->with("Controller Name:\n\t$controller"); | ||||
| 		$this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tAjax, Time"); | ||||
| 		$this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tJs, Time"); | ||||
| 		$this->Task->expects($this->at(6))->method('out')->with("Components:\n\tAcl, Auth"); | ||||
| 		$this->Task->confirmController($controller, $scaffold, $helpers, $components); | ||||
| 	} | ||||
|  | @ -272,32 +276,21 @@ class ControllerTaskTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testBake() { | ||||
| 		$helpers = array('Ajax', 'Time'); | ||||
| 		$helpers = array('Js', 'Time'); | ||||
| 		$components = array('Acl', 'Auth'); | ||||
| 		$this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true)); | ||||
| 
 | ||||
| 		$result = $this->Task->bake('Articles', '--actions--', $helpers, $components); | ||||
| 		$this->assertContains(' * @property Article $Article', $result); | ||||
| 		$this->assertContains(' * @property AclComponent $Acl', $result); | ||||
| 		$this->assertContains(' * @property AuthComponent $Auth', $result); | ||||
| 		$this->assertContains('class ArticlesController extends AppController', $result); | ||||
| 		$this->assertContains("public \$components = array('Acl', 'Auth')", $result); | ||||
| 		$this->assertContains("public \$helpers = array('Ajax', 'Time')", $result); | ||||
| 		$this->assertContains("--actions--", $result); | ||||
| 		$result = $this->Task->bake('Articles', null, $helpers, $components); | ||||
| 		$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'NoActions.ctp'); | ||||
| 		$this->assertTextEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = $this->Task->bake('Articles', null, array(), array()); | ||||
| 		$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'NoHelpersOrComponents.ctp'); | ||||
| 		$this->assertTextEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = $this->Task->bake('Articles', 'scaffold', $helpers, $components); | ||||
| 		$this->assertContains("class ArticlesController extends AppController", $result); | ||||
| 		$this->assertContains("public \$scaffold", $result); | ||||
| 		$this->assertNotContains('@property', $result); | ||||
| 		$this->assertNotContains('helpers', $result); | ||||
| 		$this->assertNotContains('components', $result); | ||||
| 
 | ||||
| 		$result = $this->Task->bake('Articles', '--actions--', array(), array()); | ||||
| 		$this->assertContains('class ArticlesController extends AppController', $result); | ||||
| 		$this->assertSame(substr_count($result, '@property'), 1); | ||||
| 		$this->assertNotContains('components', $result); | ||||
| 		$this->assertNotContains('helpers', $result); | ||||
| 		$this->assertContains('--actions--', $result); | ||||
| 		$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'Scaffold.ctp'); | ||||
| 		$this->assertTextEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -340,32 +333,11 @@ class ControllerTaskTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testBakeActionsUsingSessions() { | ||||
| 		$this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Testing bakeActions requires Article, Comment & Tag Model to be undefined.'); | ||||
| 
 | ||||
| 		$result = $this->Task->bakeActions('BakeArticles', null, true); | ||||
| 
 | ||||
| 		$this->assertContains('function index() {', $result); | ||||
| 		$this->assertContains('$this->BakeArticle->recursive = 0;', $result); | ||||
| 		$this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result); | ||||
| 
 | ||||
| 		$this->assertContains('function view($id = null)', $result); | ||||
| 		$this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result); | ||||
| 		$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result); | ||||
| 
 | ||||
| 		$this->assertContains('function add()', $result); | ||||
| 		$this->assertContains("if (\$this->request->is('post'))", $result); | ||||
| 		$this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result); | ||||
| 		$this->assertContains("\$this->Session->setFlash(__('The bake article has been saved'));", $result); | ||||
| 
 | ||||
| 		$this->assertContains('function edit($id = null)', $result); | ||||
| 		$this->assertContains("\$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));", $result); | ||||
| 
 | ||||
| 		$this->assertContains('function delete($id = null)', $result); | ||||
| 		$this->assertContains('if ($this->BakeArticle->delete())', $result); | ||||
| 		$this->assertContains("\$this->Session->setFlash(__('Bake article deleted'));", $result); | ||||
| 		$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'ActionsUsingSessions.ctp'); | ||||
| 		$this->assertTextEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = $this->Task->bakeActions('BakeArticles', 'admin_', true); | ||||
| 
 | ||||
| 		$this->assertContains('function admin_index() {', $result); | ||||
| 		$this->assertContains('function admin_add()', $result); | ||||
| 		$this->assertContains('function admin_view($id = null)', $result); | ||||
|  | @ -379,31 +351,9 @@ class ControllerTaskTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testBakeActionsWithNoSessions() { | ||||
| 		$this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Testing bakeActions requires Article, Tag, Comment Models to be undefined.'); | ||||
| 
 | ||||
| 		$result = $this->Task->bakeActions('BakeArticles', null, false); | ||||
| 
 | ||||
| 		$this->assertContains('function index() {', $result); | ||||
| 		$this->assertContains('$this->BakeArticle->recursive = 0;', $result); | ||||
| 		$this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result); | ||||
| 
 | ||||
| 		$this->assertContains('function view($id = null)', $result); | ||||
| 		$this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result); | ||||
| 		$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result); | ||||
| 
 | ||||
| 		$this->assertContains('function add()', $result); | ||||
| 		$this->assertContains("if (\$this->request->is('post'))", $result); | ||||
| 		$this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result); | ||||
| 
 | ||||
| 		$this->assertContains("\$this->flash(__('The bake article has been saved.'), array('action' => 'index'))", $result); | ||||
| 
 | ||||
| 		$this->assertContains('function edit($id = null)', $result); | ||||
| 		$this->assertContains("\$this->BakeArticle->BakeTag->find('list')", $result); | ||||
| 		$this->assertContains("\$this->set(compact('bakeTags'))", $result); | ||||
| 
 | ||||
| 		$this->assertContains('function delete($id = null)', $result); | ||||
| 		$this->assertContains('if ($this->BakeArticle->delete())', $result); | ||||
| 		$this->assertContains("\$this->flash(__('Bake article deleted'), array('action' => 'index'))", $result); | ||||
| 		$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'ActionsWithNoSessions.ctp'); | ||||
| 		$this->assertTextEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -511,9 +461,7 @@ class ControllerTaskTest extends CakeTestCase { | |||
| 		if ($count != count($this->fixtures)) { | ||||
| 			$this->markTestSkipped('Additional tables detected.'); | ||||
| 		} | ||||
| 		if (!defined('ARTICLE_MODEL_CREATED')) { | ||||
| 			$this->markTestSkipped('Execute into all could not be run as an Article, Tag or Comment model was already loaded.'); | ||||
| 		} | ||||
| 
 | ||||
| 		$this->Task->connection = 'test'; | ||||
| 		$this->Task->path = '/my/path/'; | ||||
| 		$this->Task->args = array('all'); | ||||
|  | @ -530,15 +478,45 @@ class ControllerTaskTest extends CakeTestCase { | |||
| 		$this->Task->execute(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test execute() with all and --admin | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExecuteIntoAllAdmin() { | ||||
| 		$count = count($this->Task->listAll('test')); | ||||
| 		if ($count != count($this->fixtures)) { | ||||
| 			$this->markTestSkipped('Additional tables detected.'); | ||||
| 		} | ||||
| 
 | ||||
| 		$this->Task->connection = 'test'; | ||||
| 		$this->Task->path = '/my/path/'; | ||||
| 		$this->Task->args = array('all'); | ||||
| 		$this->Task->params['admin'] = true; | ||||
| 
 | ||||
| 		$this->Task->Project->expects($this->any()) | ||||
| 			->method('getPrefix') | ||||
| 			->will($this->returnValue('admin_')); | ||||
| 		$this->Task->expects($this->any()) | ||||
| 			->method('_checkUnitTest') | ||||
| 			->will($this->returnValue(true)); | ||||
| 		$this->Task->Test->expects($this->once())->method('bake'); | ||||
| 
 | ||||
| 		$filename = '/my/path/BakeArticlesController.php'; | ||||
| 		$this->Task->expects($this->once())->method('createFile')->with( | ||||
| 			$filename, | ||||
| 			$this->stringContains('function admin_index') | ||||
| 		)->will($this->returnValue(true)); | ||||
| 
 | ||||
| 		$this->Task->execute(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that `cake bake controller foos` works. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExecuteWithController() { | ||||
| 		if (!defined('ARTICLE_MODEL_CREATED')) { | ||||
| 			$this->markTestSkipped('Execute with scaffold param requires no Article, Tag or Comment model to be defined'); | ||||
| 		} | ||||
| 		$this->Task->connection = 'test'; | ||||
| 		$this->Task->path = '/my/path/'; | ||||
| 		$this->Task->args = array('BakeArticles'); | ||||
|  | @ -570,9 +548,6 @@ class ControllerTaskTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testExecuteWithControllerNameVariations($name) { | ||||
| 		if (!defined('ARTICLE_MODEL_CREATED')) { | ||||
| 			$this->markTestSkipped('Execute with scaffold param requires no Article, Tag or Comment model to be defined.'); | ||||
| 		} | ||||
| 		$this->Task->connection = 'test'; | ||||
| 		$this->Task->path = '/my/path/'; | ||||
| 		$this->Task->args = array($name); | ||||
|  | @ -590,9 +565,6 @@ class ControllerTaskTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testExecuteWithPublicParam() { | ||||
| 		if (!defined('ARTICLE_MODEL_CREATED')) { | ||||
| 			$this->markTestSkipped('Execute with public param requires no Article, Tag or Comment model to be defined.'); | ||||
| 		} | ||||
| 		$this->Task->connection = 'test'; | ||||
| 		$this->Task->path = '/my/path/'; | ||||
| 		$this->Task->args = array('BakeArticles'); | ||||
|  | @ -612,9 +584,6 @@ class ControllerTaskTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testExecuteWithControllerAndBoth() { | ||||
| 		if (!defined('ARTICLE_MODEL_CREATED')) { | ||||
| 			$this->markTestSkipped('Execute with controller and both requires no Article, Tag or Comment model to be defined.'); | ||||
| 		} | ||||
| 		$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_')); | ||||
| 		$this->Task->connection = 'test'; | ||||
| 		$this->Task->path = '/my/path/'; | ||||
|  | @ -634,9 +603,6 @@ class ControllerTaskTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testExecuteWithControllerAndAdmin() { | ||||
| 		if (!defined('ARTICLE_MODEL_CREATED')) { | ||||
| 			$this->markTestSkipped('Execute with controller and admin requires no Article, Tag or Comment model to be defined.'); | ||||
| 		} | ||||
| 		$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_')); | ||||
| 		$this->Task->connection = 'test'; | ||||
| 		$this->Task->path = '/my/path/'; | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * DBConfigTask Test Case | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @since         CakePHP(tm) v 1.3 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ShellDispatcher', 'Console'); | ||||
|  | @ -101,7 +100,7 @@ class DbConfigTaskTest extends CakeTestCase { | |||
| 		$this->Task->expects($this->once())->method('_stop'); | ||||
| 		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('default')); //name
 | ||||
| 		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('mysql')); //db type
 | ||||
| 		$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); //persistant
 | ||||
| 		$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); //persistent
 | ||||
| 		$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('localhost')); //server
 | ||||
| 		$this->Task->expects($this->at(4))->method('in')->will($this->returnValue('n')); //port
 | ||||
| 		$this->Task->expects($this->at(5))->method('in')->will($this->returnValue('root')); //user
 | ||||
|  | @ -128,6 +127,6 @@ class DbConfigTaskTest extends CakeTestCase { | |||
| 				) | ||||
| 			)); | ||||
| 
 | ||||
| 		$result = $this->Task->execute(); | ||||
| 		$this->Task->execute(); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -4,19 +4,18 @@ | |||
|  * | ||||
|  * Test Case for i18n extraction shell task | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP :  Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @since         CakePHP v 1.2.0.7726 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Folder', 'Utility'); | ||||
|  | @ -49,7 +48,7 @@ class ExtractTaskTest extends CakeTestCase { | |||
| 			array($out, $out, $in) | ||||
| 		); | ||||
| 		$this->path = TMP . 'tests' . DS . 'extract_task_test'; | ||||
| 		$Folder = new Folder($this->path . DS . 'locale', true); | ||||
| 		new Folder($this->path . DS . 'locale', true); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -136,23 +135,23 @@ class ExtractTaskTest extends CakeTestCase { | |||
| 		$this->assertRegExp($pattern, $result); | ||||
| 
 | ||||
| 		// extract.ctp
 | ||||
| 		$pattern = '/\#: (\\\\|\/)extract\.ctp:15;6\n'; | ||||
| 		$pattern = '/\#: extract\.ctp:15;6\n'; | ||||
| 		$pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/'; | ||||
| 		$this->assertRegExp($pattern, $result); | ||||
| 
 | ||||
| 		$pattern = '/msgid "You have %d new message."\nmsgstr ""/'; | ||||
| 		$this->assertNotRegExp($pattern, $result, 'No duplicate msgid'); | ||||
| 
 | ||||
| 		$pattern = '/\#: (\\\\|\/)extract\.ctp:7\n'; | ||||
| 		$pattern = '/\#: extract\.ctp:7\n'; | ||||
| 		$pattern .= 'msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/'; | ||||
| 		$this->assertRegExp($pattern, $result); | ||||
| 
 | ||||
| 		$pattern = '/\#: (\\\\|\/)extract\.ctp:14\n'; | ||||
| 		$pattern .= '\#: (\\\\|\/)home\.ctp:99\n'; | ||||
| 		$pattern = '/\#: extract\.ctp:14\n'; | ||||
| 		$pattern .= '\#: home\.ctp:68\n'; | ||||
| 		$pattern .= 'msgid "Editing this Page"\nmsgstr ""/'; | ||||
| 		$this->assertRegExp($pattern, $result); | ||||
| 
 | ||||
| 		$pattern = '/\#: (\\\\|\/)extract\.ctp:22\nmsgid "'; | ||||
| 		$pattern = '/\#: extract\.ctp:22\nmsgid "'; | ||||
| 		$pattern .= 'Hot features!'; | ||||
| 		$pattern .= '\\\n - No Configuration: Set-up the database and let the magic begin'; | ||||
| 		$pattern .= '\\\n - Extremely Simple: Just look at the name...It\'s Cake'; | ||||
|  | @ -163,6 +162,21 @@ class ExtractTaskTest extends CakeTestCase { | |||
| 		$this->assertContains('msgid "double \\"quoted\\""', $result, 'Strings with quotes not handled correctly'); | ||||
| 		$this->assertContains("msgid \"single 'quoted'\"", $result, 'Strings with quotes not handled correctly'); | ||||
| 
 | ||||
| 		$pattern = '/\#: extract\.ctp:36\nmsgid "letter"/'; | ||||
| 		$this->assertRegExp($pattern, $result, 'Strings with context should not overwrite strings without context'); | ||||
| 
 | ||||
| 		$pattern = '/\#: extract\.ctp:37;39\nmsgctxt "A"\nmsgid "letter"/'; | ||||
| 		$this->assertRegExp($pattern, $result, 'Should contain string with context "A"'); | ||||
| 
 | ||||
| 		$pattern = '/\#: extract\.ctp:38\nmsgctxt "B"\nmsgid "letter"/'; | ||||
| 		$this->assertRegExp($pattern, $result, 'Should contain string with context "B"'); | ||||
| 
 | ||||
| 		$pattern = '/\#: extract\.ctp:40\nmsgid "%d letter"\nmsgid_plural "%d letters"/'; | ||||
| 		$this->assertRegExp($pattern, $result, 'Plural strings with context should not overwrite strings without context'); | ||||
| 
 | ||||
| 		$pattern = '/\#: extract\.ctp:41\nmsgctxt "A"\nmsgid "%d letter"\nmsgid_plural "%d letters"/'; | ||||
| 		$this->assertRegExp($pattern, $result, 'Should contain plural string with context "A"'); | ||||
| 
 | ||||
| 		// extract.ctp - reading the domain.pot
 | ||||
| 		$result = file_get_contents($this->path . DS . 'domain.pot'); | ||||
| 
 | ||||
|  | @ -177,6 +191,64 @@ class ExtractTaskTest extends CakeTestCase { | |||
| 		$this->assertRegExp($pattern, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testExtractCategory method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExtractCategory() { | ||||
| 		$this->Task->interactive = false; | ||||
| 
 | ||||
| 		$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages'; | ||||
| 		$this->Task->params['output'] = $this->path . DS; | ||||
| 		$this->Task->params['extract-core'] = 'no'; | ||||
| 		$this->Task->params['merge'] = 'no'; | ||||
| 		$this->Task->expects($this->never())->method('err'); | ||||
| 		$this->Task->expects($this->any())->method('in') | ||||
| 			->will($this->returnValue('y')); | ||||
| 		$this->Task->expects($this->never())->method('_stop'); | ||||
| 
 | ||||
| 		$this->Task->execute(); | ||||
| 		$this->assertTrue(file_exists($this->path . DS . 'LC_NUMERIC' . DS . 'default.pot')); | ||||
| 		$this->assertFalse(file_exists($this->path . DS . 'LC_TIME' . DS . 'default.pot')); | ||||
| 
 | ||||
| 		$result = file_get_contents($this->path . DS . 'default.pot'); | ||||
| 
 | ||||
| 		$pattern = '/\#: .*extract\.ctp:31\n/'; | ||||
| 		$this->assertNotRegExp($pattern, $result); | ||||
| 
 | ||||
| 		$pattern = '/\#: .*extract\.ctp:33\n/'; | ||||
| 		$this->assertNotRegExp($pattern, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testExtractWithoutLocations method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExtractWithoutLocations() { | ||||
| 		$this->Task->interactive = false; | ||||
| 
 | ||||
| 		$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages'; | ||||
| 		$this->Task->params['output'] = $this->path . DS; | ||||
| 		$this->Task->params['extract-core'] = 'no'; | ||||
| 		$this->Task->params['merge'] = 'no'; | ||||
| 		$this->Task->params['no-location'] = true; | ||||
| 
 | ||||
| 		$this->Task->expects($this->never())->method('err'); | ||||
| 		$this->Task->expects($this->any())->method('in') | ||||
| 			->will($this->returnValue('y')); | ||||
| 		$this->Task->expects($this->never())->method('_stop'); | ||||
| 
 | ||||
| 		$this->Task->execute(); | ||||
| 		$this->assertTrue(file_exists($this->path . DS . 'default.pot')); | ||||
| 
 | ||||
| 		$result = file_get_contents($this->path . DS . 'default.pot'); | ||||
| 
 | ||||
| 		$pattern = '/\n\#: .*\n/'; | ||||
| 		$this->assertNotRegExp($pattern, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test exclusions | ||||
|  * | ||||
|  | @ -267,7 +339,7 @@ class ExtractTaskTest extends CakeTestCase { | |||
| 		$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false); | ||||
| 		$this->in = $this->getMock('ConsoleInput', array(), array(), '', false); | ||||
| 		$this->Task = $this->getMock('ExtractTask', | ||||
| 			array('_isExtractingApp', '_extractValidationMessages', 'in', 'out', 'err', 'clear', '_stop'), | ||||
| 			array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'), | ||||
| 			array($this->out, $this->out, $this->in) | ||||
| 		); | ||||
| 
 | ||||
|  | @ -279,6 +351,7 @@ class ExtractTaskTest extends CakeTestCase { | |||
| 		$this->assertNotRegExp('#Pages#', $result); | ||||
| 		$this->assertContains('translate.ctp:1', $result); | ||||
| 		$this->assertContains('This is a translatable string', $result); | ||||
| 		$this->assertContains('I can haz plugin model validation message', $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -308,10 +381,10 @@ class ExtractTaskTest extends CakeTestCase { | |||
| 		$this->Task->execute(); | ||||
| 		$result = file_get_contents($this->path . DS . 'default.pot'); | ||||
| 
 | ||||
| 		$pattern = preg_quote('#Model' . DS . 'PersisterOne.php:validation for field title#', '\\'); | ||||
| 		$pattern = preg_quote('#Model/PersisterOne.php:validation for field title#', '\\'); | ||||
| 		$this->assertRegExp($pattern, $result); | ||||
| 
 | ||||
| 		$pattern = preg_quote('#Model' . DS . 'PersisterOne.php:validation for field body#', '\\'); | ||||
| 		$pattern = preg_quote('#Model/PersisterOne.php:validation for field body#', '\\'); | ||||
| 		$this->assertRegExp($pattern, $result); | ||||
| 
 | ||||
| 		$pattern = '#msgid "Post title is required"#'; | ||||
|  | @ -325,6 +398,9 @@ class ExtractTaskTest extends CakeTestCase { | |||
| 
 | ||||
| 		$pattern = '#msgid "Post body is super required"#'; | ||||
| 		$this->assertRegExp($pattern, $result); | ||||
| 
 | ||||
| 		$this->assertContains('msgid "double \\"quoted\\" validation"', $result, 'Strings with quotes not handled correctly'); | ||||
| 		$this->assertContains("msgid \"single 'quoted' validation\"", $result, 'Strings with quotes not handled correctly'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -354,10 +430,10 @@ class ExtractTaskTest extends CakeTestCase { | |||
| 		$this->Task->execute(); | ||||
| 		$result = file_get_contents($this->path . DS . 'test_plugin.pot'); | ||||
| 
 | ||||
| 		$pattern = preg_quote('#Plugin' . DS . 'TestPlugin' . DS . 'Model' . DS . 'TestPluginPost.php:validation for field title#', '\\'); | ||||
| 		$pattern = preg_quote('#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title#', '\\'); | ||||
| 		$this->assertRegExp($pattern, $result); | ||||
| 
 | ||||
| 		$pattern = preg_quote('#Plugin' . DS . 'TestPlugin' . DS . 'Model' . DS . 'TestPluginPost.php:validation for field body#', '\\'); | ||||
| 		$pattern = preg_quote('#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field body#', '\\'); | ||||
| 		$this->assertRegExp($pattern, $result); | ||||
| 
 | ||||
| 		$pattern = '#msgid "Post title is required"#'; | ||||
|  | @ -393,10 +469,10 @@ class ExtractTaskTest extends CakeTestCase { | |||
| 		$this->Task->execute(); | ||||
| 		$result = file_get_contents($this->path . DS . 'test_plugin.pot'); | ||||
| 
 | ||||
| 		$pattern = preg_quote('#Model' . DS . 'TestPluginPost.php:validation for field title#', '\\'); | ||||
| 		$pattern = preg_quote('#Model/TestPluginPost.php:validation for field title#', '\\'); | ||||
| 		$this->assertRegExp($pattern, $result); | ||||
| 
 | ||||
| 		$pattern = preg_quote('#Model' . DS . 'TestPluginPost.php:validation for field body#', '\\'); | ||||
| 		$pattern = preg_quote('#Model/TestPluginPost.php:validation for field body#', '\\'); | ||||
| 		$this->assertRegExp($pattern, $result); | ||||
| 
 | ||||
| 		$pattern = '#msgid "Post title is required"#'; | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * FixtureTask Test case | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @since         CakePHP(tm) v 1.3 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ShellDispatcher', 'Console'); | ||||
|  | @ -43,7 +42,7 @@ class FixtureTaskTest extends CakeTestCase { | |||
| /** | ||||
|  * Whether backup global state for each test method or not | ||||
|  * | ||||
|  * @var bool false | ||||
|  * @var bool | ||||
|  */ | ||||
| 	public $backupGlobals = false; | ||||
| 
 | ||||
|  | @ -99,6 +98,7 @@ class FixtureTaskTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testImportOptionsSchemaRecords() { | ||||
| 		$this->Task->interactive = true; | ||||
| 		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y')); | ||||
| 		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y')); | ||||
| 
 | ||||
|  | @ -113,6 +113,7 @@ class FixtureTaskTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testImportOptionsNothing() { | ||||
| 		$this->Task->interactive = true; | ||||
| 		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n')); | ||||
| 		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n')); | ||||
| 		$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); | ||||
|  | @ -122,12 +123,70 @@ class FixtureTaskTest extends CakeTestCase { | |||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test importOptions with overwriting command line options. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testImportOptionsWithCommandLineOptions() { | ||||
| 		$this->Task->params = array('schema' => true, 'records' => true); | ||||
| 
 | ||||
| 		$result = $this->Task->importOptions('Article'); | ||||
| 		$expected = array('schema' => 'Article', 'fromTable' => true); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test importOptions with overwriting CLI options | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testImportOptionsWithCommandLineOptionsPlugin() { | ||||
| 		$this->Task->params = array('schema' => true, 'records' => true, 'plugin' => 'TestPlugin'); | ||||
| 
 | ||||
| 		$result = $this->Task->importOptions('Article'); | ||||
| 		$expected = array('schema' => 'TestPlugin.Article', 'fromTable' => true); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test importOptions with schema. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testImportOptionsWithSchema() { | ||||
| 		$this->Task->interactive = true; | ||||
| 		$this->Task->params = array('schema' => true); | ||||
| 		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n')); | ||||
| 		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n')); | ||||
| 
 | ||||
| 		$result = $this->Task->importOptions('Article'); | ||||
| 		$expected = array('schema' => 'Article'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test importOptions with records. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testImportOptionsWithRecords() { | ||||
| 		$this->Task->interactive = true; | ||||
| 		$this->Task->params = array('records' => true); | ||||
| 		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n')); | ||||
| 
 | ||||
| 		$result = $this->Task->importOptions('Article'); | ||||
| 		$expected = array('fromTable' => true); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test importOptions choosing from Table. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testImportOptionsTable() { | ||||
| 		$this->Task->interactive = true; | ||||
| 		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n')); | ||||
| 		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n')); | ||||
| 		$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y')); | ||||
|  | @ -145,6 +204,9 @@ class FixtureTaskTest extends CakeTestCase { | |||
| 		$this->Task->interactive = true; | ||||
| 		$this->Task->expects($this->at(0))->method('in') | ||||
| 			->will($this->returnValue('WHERE 1=1')); | ||||
| 		$this->Task->expects($this->at(1))->method('in') | ||||
| 			->with($this->anything(), $this->anything(), '3') | ||||
| 			->will($this->returnValue('2')); | ||||
| 
 | ||||
| 		$this->Task->connection = 'test'; | ||||
| 		$this->Task->path = '/my/path/'; | ||||
|  | @ -156,9 +218,8 @@ class FixtureTaskTest extends CakeTestCase { | |||
| 		$this->assertContains('class ArticleFixture extends CakeTestFixture', $result); | ||||
| 		$this->assertContains('public $records', $result); | ||||
| 		$this->assertContains('public $import', $result); | ||||
| 		$this->assertContains("'title' => 'First Article'", $result, 'Missing import data %s'); | ||||
| 		$this->assertContains('Second Article', $result, 'Missing import data %s'); | ||||
| 		$this->assertContains('Third Article', $result, 'Missing import data %s'); | ||||
| 		$this->assertContains("'title' => 'First Article'", $result, 'Missing import data'); | ||||
| 		$this->assertContains('Second Article', $result, 'Missing import data'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -202,8 +263,63 @@ class FixtureTaskTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that execute passes runs bake depending with named model. | ||||
|  * test that execute includes import options | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExecuteWithImportSchema() { | ||||
| 		$this->Task->connection = 'test'; | ||||
| 		$this->Task->path = '/my/path/'; | ||||
| 		$this->Task->args = array('article'); | ||||
| 		$this->Task->params = array( | ||||
| 			'schema' => true, | ||||
| 			'records' => false, | ||||
| 		); | ||||
| 		$filename = '/my/path/ArticleFixture.php'; | ||||
| 
 | ||||
| 		$this->Task->expects($this->never()) | ||||
| 			->method('in'); | ||||
| 
 | ||||
| 		$this->Task->expects($this->at(0)) | ||||
| 			->method('createFile') | ||||
| 			->with($filename, $this->logicalAnd( | ||||
| 				$this->stringContains('class ArticleFixture'), | ||||
| 				$this->stringContains("\$import = array('model' => 'Article'") | ||||
| 			)); | ||||
| 
 | ||||
| 		$this->Task->execute(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that execute includes import options | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExecuteWithImportRecords() { | ||||
| 		$this->Task->connection = 'test'; | ||||
| 		$this->Task->path = '/my/path/'; | ||||
| 		$this->Task->args = array('article'); | ||||
| 		$this->Task->params = array( | ||||
| 			'schema' => true, | ||||
| 			'records' => true, | ||||
| 		); | ||||
| 		$filename = '/my/path/ArticleFixture.php'; | ||||
| 
 | ||||
| 		$this->Task->expects($this->never()) | ||||
| 			->method('in'); | ||||
| 
 | ||||
| 		$this->Task->expects($this->at(0)) | ||||
| 			->method('createFile') | ||||
| 			->with($filename, $this->logicalAnd( | ||||
| 				$this->stringContains('class ArticleFixture'), | ||||
| 				$this->stringContains("\$import = array('model' => 'Article', 'connection' => 'test')") | ||||
| 			)); | ||||
| 
 | ||||
| 		$this->Task->execute(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that execute passes runs bake depending with named model. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  | @ -271,6 +387,32 @@ class FixtureTaskTest extends CakeTestCase { | |||
| 		$this->Task->all(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test using all() with -schema | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAllWithSchemaImport() { | ||||
| 		$this->Task->connection = 'test'; | ||||
| 		$this->Task->path = '/my/path/'; | ||||
| 		$this->Task->args = array('all'); | ||||
| 		$this->Task->params = array('schema' => true); | ||||
| 
 | ||||
| 		$this->Task->Model->expects($this->any())->method('listAll') | ||||
| 			->will($this->returnValue(array('Articles', 'comments'))); | ||||
| 
 | ||||
| 		$filename = '/my/path/ArticleFixture.php'; | ||||
| 		$this->Task->expects($this->at(0))->method('createFile') | ||||
| 			->with($filename, $this->stringContains('public $import = array(\'model\' => \'Article\'')); | ||||
| 
 | ||||
| 		$filename = '/my/path/CommentFixture.php'; | ||||
| 		$this->Task->expects($this->at(1))->method('createFile') | ||||
| 			->with($filename, $this->stringContains('public $import = array(\'model\' => \'Comment\'')); | ||||
| 		$this->Task->expects($this->exactly(2))->method('createFile'); | ||||
| 
 | ||||
| 		$this->Task->all(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test interactive mode of execute | ||||
|  * | ||||
|  | @ -360,9 +502,8 @@ class FixtureTaskTest extends CakeTestCase { | |||
| 		$this->Task->expects($this->at(1))->method('createFile') | ||||
| 			->with($filename, $this->stringContains('<?php')); | ||||
| 
 | ||||
| 		$result = $this->Task->generateFixtureFile('Article', array()); | ||||
| 
 | ||||
| 		$result = $this->Task->generateFixtureFile('Article', array()); | ||||
| 		$this->Task->generateFixtureFile('Article', array()); | ||||
| 		$this->Task->generateFixtureFile('Article', array()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -381,7 +522,7 @@ class FixtureTaskTest extends CakeTestCase { | |||
| 		$this->Task->expects($this->at(0))->method('createFile') | ||||
| 			->with($filename, $this->stringContains('class Article')); | ||||
| 
 | ||||
| 		$result = $this->Task->generateFixtureFile('Article', array()); | ||||
| 		$this->Task->generateFixtureFile('Article', array()); | ||||
| 		CakePlugin::unload(); | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,19 +4,18 @@ | |||
|  * | ||||
|  * Test Case for test generation shell task | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @since         CakePHP v 1.2.6 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ShellDispatcher', 'Console'); | ||||
|  | @ -31,6 +30,7 @@ App::uses('ModelTask', 'Console/Command/Task'); | |||
|  * ModelTaskTest class | ||||
|  * | ||||
|  * @package	   Cake.Test.Case.Console.Command.Task | ||||
|  * @property   ModelTask $Task | ||||
|  */ | ||||
| class ModelTaskTest extends CakeTestCase { | ||||
| 
 | ||||
|  | @ -41,7 +41,7 @@ class ModelTaskTest extends CakeTestCase { | |||
|  */ | ||||
| 	public $fixtures = array( | ||||
| 		'core.bake_article', 'core.bake_comment', 'core.bake_articles_bake_tag', | ||||
| 		'core.bake_tag', 'core.category_thread' | ||||
| 		'core.bake_tag', 'core.category_thread', 'core.number_tree' | ||||
| 	); | ||||
| 
 | ||||
| /** | ||||
|  | @ -62,7 +62,7 @@ class ModelTaskTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Setup a mock that has out mocked.  Normally this is not used as it makes $this->at() really tricky. | ||||
|  * Setup a mock that has out mocked. Normally this is not used as it makes $this->at() really tricky. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  | @ -173,7 +173,7 @@ class ModelTaskTest extends CakeTestCase { | |||
| 		$this->Task->expects($this->any())->method('in')->will($this->onConsecutiveCalls(99, 1)); | ||||
| 		$this->Task->expects($this->once())->method('err'); | ||||
| 
 | ||||
| 		$result = $this->Task->getName('test'); | ||||
| 		$this->Task->getName('test'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -189,7 +189,7 @@ class ModelTaskTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test gettting a custom table name. | ||||
|  * test getting a custom table name. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  | @ -268,7 +268,7 @@ class ModelTaskTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testInitValidations() { | ||||
| 		$result = $this->Task->initValidations(); | ||||
| 		$this->assertTrue(in_array('notempty', $result)); | ||||
| 		$this->assertTrue(in_array('notBlank', $result)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -282,7 +282,7 @@ class ModelTaskTest extends CakeTestCase { | |||
| 		$this->Task->initValidations(); | ||||
| 
 | ||||
| 		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); | ||||
| 		$expected = array('notempty' => 'notempty'); | ||||
| 		$expected = array('notBlank' => 'notBlank'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = $this->Task->fieldValidation('text', array('type' => 'date', 'length' => 10, 'null' => false)); | ||||
|  | @ -315,10 +315,10 @@ class ModelTaskTest extends CakeTestCase { | |||
| 		$this->Task->initValidations(); | ||||
| 		$this->Task->interactive = true; | ||||
| 		$this->Task->expects($this->any())->method('in') | ||||
| 			->will($this->onConsecutiveCalls('23', 'y', '17', 'n')); | ||||
| 			->will($this->onConsecutiveCalls('24', 'y', '18', 'n')); | ||||
| 
 | ||||
| 		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); | ||||
| 		$expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength'); | ||||
| 		$expected = array('notBlank' => 'notBlank', 'maxLength' => 'maxLength'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -333,13 +333,13 @@ class ModelTaskTest extends CakeTestCase { | |||
| 		$this->Task->interactive = true; | ||||
| 
 | ||||
| 		$this->Task->expects($this->any())->method('in') | ||||
| 			->will($this->onConsecutiveCalls('999999', '23', 'n')); | ||||
| 			->will($this->onConsecutiveCalls('999999', '24', 'n')); | ||||
| 
 | ||||
| 		$this->Task->expects($this->at(10))->method('out') | ||||
| 			->with($this->stringContains('make a valid')); | ||||
| 
 | ||||
| 		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); | ||||
| 		$expected = array('notempty' => 'notempty'); | ||||
| 		$expected = array('notBlank' => 'notBlank'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -359,6 +359,100 @@ class ModelTaskTest extends CakeTestCase { | |||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that skipping fields during rule choice works when doing interactive field validation. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSkippingChoiceInteractiveFieldValidation() { | ||||
| 		$this->Task->initValidations(); | ||||
| 		$this->Task->interactive = true; | ||||
| 		$this->Task->expects($this->any())->method('in') | ||||
| 			->will($this->onConsecutiveCalls('24', 'y', 's')); | ||||
| 
 | ||||
| 		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); | ||||
| 		$expected = array('notBlank' => 'notBlank', '_skipFields' => true); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that skipping fields after rule choice works when doing interactive field validation. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSkippingAnotherInteractiveFieldValidation() { | ||||
| 		$this->Task->initValidations(); | ||||
| 		$this->Task->interactive = true; | ||||
| 		$this->Task->expects($this->any())->method('in') | ||||
| 			->will($this->onConsecutiveCalls('24', 's')); | ||||
| 
 | ||||
| 		$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); | ||||
| 		$expected = array('notBlank' => 'notBlank', '_skipFields' => true); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test the validation generation routine with skipping the rest of the fields | ||||
|  * when doing interactive field validation. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testInteractiveDoValidationWithSkipping() { | ||||
| 		$this->Task->expects($this->any()) | ||||
| 			->method('in') | ||||
| 			->will($this->onConsecutiveCalls('35', '24', 'n', '10', 's')); | ||||
| 		$this->Task->interactive = true; | ||||
| 		$Model = $this->getMock('Model'); | ||||
| 		$Model->primaryKey = 'id'; | ||||
| 		$Model->expects($this->any()) | ||||
| 			->method('schema') | ||||
| 			->will($this->returnValue(array( | ||||
| 					'id' => array( | ||||
| 						'type' => 'integer', | ||||
| 						'length' => 11, | ||||
| 						'null' => false, | ||||
| 						'key' => 'primary', | ||||
| 					), | ||||
| 					'name' => array( | ||||
| 						'type' => 'string', | ||||
| 						'length' => 20, | ||||
| 						'null' => false, | ||||
| 					), | ||||
| 					'email' => array( | ||||
| 						'type' => 'string', | ||||
| 						'length' => 255, | ||||
| 						'null' => false, | ||||
| 					), | ||||
| 					'some_date' => array( | ||||
| 						'type' => 'date', | ||||
| 						'length' => '', | ||||
| 						'null' => false, | ||||
| 					), | ||||
| 					'some_time' => array( | ||||
| 						'type' => 'time', | ||||
| 						'length' => '', | ||||
| 						'null' => false, | ||||
| 					), | ||||
| 					'created' => array( | ||||
| 						'type' => 'datetime', | ||||
| 						'length' => '', | ||||
| 						'null' => false, | ||||
| 					) | ||||
| 				) | ||||
| 			)); | ||||
| 
 | ||||
| 		$result = $this->Task->doValidation($Model); | ||||
| 		$expected = array( | ||||
| 			'name' => array( | ||||
| 				'notBlank' => 'notBlank' | ||||
| 			), | ||||
| 			'email' => array( | ||||
| 				'email' => 'email', | ||||
| 			), | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test the validation Generation routine | ||||
|  * | ||||
|  | @ -367,45 +461,48 @@ class ModelTaskTest extends CakeTestCase { | |||
| 	public function testNonInteractiveDoValidation() { | ||||
| 		$Model = $this->getMock('Model'); | ||||
| 		$Model->primaryKey = 'id'; | ||||
| 		$Model->expects($this->any())->method('schema')->will($this->returnValue(array( | ||||
| 			'id' => array( | ||||
| 				'type' => 'integer', | ||||
| 				'length' => 11, | ||||
| 				'null' => false, | ||||
| 				'key' => 'primary', | ||||
| 			), | ||||
| 			'name' => array( | ||||
| 				'type' => 'string', | ||||
| 				'length' => 20, | ||||
| 				'null' => false, | ||||
| 			), | ||||
| 			'email' => array( | ||||
| 				'type' => 'string', | ||||
| 				'length' => 255, | ||||
| 				'null' => false, | ||||
| 			), | ||||
| 			'some_date' => array( | ||||
| 				'type' => 'date', | ||||
| 				'length' => '', | ||||
| 				'null' => false, | ||||
| 			), | ||||
| 			'some_time' => array( | ||||
| 				'type' => 'time', | ||||
| 				'length' => '', | ||||
| 				'null' => false, | ||||
| 			), | ||||
| 			'created' => array( | ||||
| 				'type' => 'datetime', | ||||
| 				'length' => '', | ||||
| 				'null' => false, | ||||
| 		$Model->expects($this->any()) | ||||
| 			->method('schema') | ||||
| 			->will($this->returnValue(array( | ||||
| 				'id' => array( | ||||
| 					'type' => 'integer', | ||||
| 					'length' => 11, | ||||
| 					'null' => false, | ||||
| 					'key' => 'primary', | ||||
| 				), | ||||
| 				'name' => array( | ||||
| 					'type' => 'string', | ||||
| 					'length' => 20, | ||||
| 					'null' => false, | ||||
| 				), | ||||
| 				'email' => array( | ||||
| 					'type' => 'string', | ||||
| 					'length' => 255, | ||||
| 					'null' => false, | ||||
| 				), | ||||
| 				'some_date' => array( | ||||
| 					'type' => 'date', | ||||
| 					'length' => '', | ||||
| 					'null' => false, | ||||
| 				), | ||||
| 				'some_time' => array( | ||||
| 					'type' => 'time', | ||||
| 					'length' => '', | ||||
| 					'null' => false, | ||||
| 				), | ||||
| 				'created' => array( | ||||
| 					'type' => 'datetime', | ||||
| 					'length' => '', | ||||
| 					'null' => false, | ||||
| 				) | ||||
| 			) | ||||
| 		))); | ||||
| 		)); | ||||
| 		$this->Task->interactive = false; | ||||
| 
 | ||||
| 		$result = $this->Task->doValidation($Model); | ||||
| 		$expected = array( | ||||
| 			'name' => array( | ||||
| 				'notempty' => 'notempty' | ||||
| 				'notBlank' => 'notBlank' | ||||
| 			), | ||||
| 			'email' => array( | ||||
| 				'email' => 'email', | ||||
|  | @ -622,6 +719,20 @@ class ModelTaskTest extends CakeTestCase { | |||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test non interactive doActsAs | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDoActsAs() { | ||||
| 		$this->Task->connection = 'test'; | ||||
| 		$this->Task->interactive = false; | ||||
| 		$model = new Model(array('ds' => 'test', 'name' => 'NumberTree')); | ||||
| 		$result = $this->Task->doActsAs($model); | ||||
| 
 | ||||
| 		$this->assertEquals(array('Tree'), $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Ensure that the fixture object is correctly called. | ||||
|  * | ||||
|  | @ -727,7 +838,7 @@ class ModelTaskTest extends CakeTestCase { | |||
| 	public function testBakeValidation() { | ||||
| 		$validate = array( | ||||
| 			'name' => array( | ||||
| 				'notempty' => 'notempty' | ||||
| 				'notBlank' => 'notBlank' | ||||
| 			), | ||||
| 			'email' => array( | ||||
| 				'email' => 'email', | ||||
|  | @ -744,8 +855,8 @@ class ModelTaskTest extends CakeTestCase { | |||
| 		$this->assertRegExp('/\$validate \= array\(/', $result); | ||||
| 		$expected = <<< STRINGEND | ||||
| array( | ||||
| 			'notempty' => array( | ||||
| 				'rule' => array('notempty'), | ||||
| 			'notBlank' => array( | ||||
| 				'rule' => array('notBlank'), | ||||
| 				//'message' => 'Your custom message here',
 | ||||
| 				//'allowEmpty' => false,
 | ||||
| 				//'required' => false,
 | ||||
|  | @ -835,6 +946,27 @@ STRINGEND; | |||
| 		$this->assertEquals(count(ClassRegistry::mapKeys()), 0); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test bake() for models with behaviors | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testBakeWithBehaviors() { | ||||
| 		$result = $this->Task->bake('NumberTree', array('actsAs' => array('Tree', 'PluginName.Sluggable'))); | ||||
| 		$expected = <<<TEXT | ||||
| /** | ||||
|  * Behaviors | ||||
|  * | ||||
|  * @var array | ||||
|  */ | ||||
| 	public \$actsAs = array( | ||||
| 		'Tree', | ||||
| 		'PluginName.Sluggable', | ||||
| 	); | ||||
| TEXT; | ||||
| 		$this->assertTextContains($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that execute passes runs bake depending with named model. | ||||
|  * | ||||
|  | @ -920,8 +1052,8 @@ STRINGEND; | |||
| 		$this->Task->args = array('all'); | ||||
| 		$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true)); | ||||
| 
 | ||||
| 		$this->Task->Fixture->expects($this->exactly(5))->method('bake'); | ||||
| 		$this->Task->Test->expects($this->exactly(5))->method('bake'); | ||||
| 		$this->Task->Fixture->expects($this->exactly(6))->method('bake'); | ||||
| 		$this->Task->Test->expects($this->exactly(6))->method('bake'); | ||||
| 
 | ||||
| 		$filename = '/my/path/BakeArticle.php'; | ||||
| 		$this->Task->expects($this->at(1))->method('createFile') | ||||
|  | @ -951,6 +1083,10 @@ STRINGEND; | |||
| 		$this->Task->expects($this->at(5))->method('createFile') | ||||
| 			->with($filename, $this->stringContains('class CategoryThread')); | ||||
| 
 | ||||
| 		$filename = '/my/path/NumberTree.php'; | ||||
| 		$this->Task->expects($this->at(6))->method('createFile') | ||||
| 			->with($filename, $this->stringContains('class NumberTree')); | ||||
| 
 | ||||
| 		$this->Task->execute(); | ||||
| 
 | ||||
| 		$this->assertEquals(count(ClassRegistry::keys()), 0); | ||||
|  | @ -958,7 +1094,7 @@ STRINGEND; | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that odd tablenames arent inflected back from modelname | ||||
|  * test that odd tablenames aren't inflected back from modelname | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  | @ -986,7 +1122,7 @@ STRINGEND; | |||
| 		$out = $this->getMock('ConsoleOutput', array(), array(), '', false); | ||||
| 		$in = $this->getMock('ConsoleInput', array(), array(), '', false); | ||||
| 		$this->Task = $this->getMock('ModelTask', | ||||
| 			array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'createFile'), | ||||
| 			array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'doActsAs', 'createFile'), | ||||
| 			array($out, $out, $in) | ||||
| 		); | ||||
| 		$this->_setupOtherMocks(); | ||||
|  | @ -1000,6 +1136,7 @@ STRINGEND; | |||
| 		$this->Task->expects($this->once())->method('_getModelObject')->will($this->returnValue($object)); | ||||
| 		$this->Task->expects($this->once())->method('doAssociations')->will($this->returnValue(array())); | ||||
| 		$this->Task->expects($this->once())->method('doValidation')->will($this->returnValue(array())); | ||||
| 		$this->Task->expects($this->once())->method('doActsAs')->will($this->returnValue(array())); | ||||
| 
 | ||||
| 		$filename = '/my/path/BakeOdd.php'; | ||||
| 		$this->Task->expects($this->once())->method('createFile') | ||||
|  | @ -1013,7 +1150,7 @@ STRINGEND; | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that odd tablenames arent inflected back from modelname | ||||
|  * test that odd tablenames aren't inflected back from modelname | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  | @ -1041,7 +1178,7 @@ STRINGEND; | |||
| 		$out = $this->getMock('ConsoleOutput', array(), array(), '', false); | ||||
| 		$in = $this->getMock('ConsoleInput', array(), array(), '', false); | ||||
| 		$this->Task = $this->getMock('ModelTask', | ||||
| 			array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'createFile'), | ||||
| 			array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'doActsAs', 'createFile'), | ||||
| 			array($out, $out, $in) | ||||
| 		); | ||||
| 		$this->_setupOtherMocks(); | ||||
|  | @ -1055,6 +1192,7 @@ STRINGEND; | |||
| 		$this->Task->expects($this->once())->method('_getModelObject')->will($this->returnValue($object)); | ||||
| 		$this->Task->expects($this->once())->method('doAssociations')->will($this->returnValue(array())); | ||||
| 		$this->Task->expects($this->once())->method('doValidation')->will($this->returnValue(array())); | ||||
| 		$this->Task->expects($this->once())->method('doActsAs')->will($this->returnValue(array())); | ||||
| 
 | ||||
| 		$filename = '/my/path/BakeOdd.php'; | ||||
| 		$this->Task->expects($this->once())->method('createFile') | ||||
|  | @ -1082,7 +1220,7 @@ STRINGEND; | |||
| 		$this->Task->path = '/my/path/'; | ||||
| 		$this->Task->args = array('all'); | ||||
| 		$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true)); | ||||
| 		$this->Task->skipTables = array('bake_tags'); | ||||
| 		$this->Task->skipTables = array('bake_tags', 'number_trees'); | ||||
| 
 | ||||
| 		$this->Task->Fixture->expects($this->exactly(4))->method('bake'); | ||||
| 		$this->Task->Test->expects($this->exactly(4))->method('bake'); | ||||
|  |  | |||
|  | @ -4,19 +4,18 @@ | |||
|  * | ||||
|  * Test Case for plugin generation shell task | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @since         CakePHP v 1.3.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ShellDispatcher', 'Console'); | ||||
|  | @ -59,7 +58,7 @@ class PluginTaskTest extends CakeTestCase { | |||
| 				array_splice($paths, $i, 1); | ||||
| 			} | ||||
| 		} | ||||
| 		$this->_testPath = array_push($paths, TMP . 'tests' . DS); | ||||
| 		$this->_testPath = array_push($paths, TMP . 'tests' . DS) - 1; | ||||
| 		App::build(array('plugins' => $paths)); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -81,17 +80,23 @@ class PluginTaskTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testBakeFoldersAndFiles() { | ||||
| 		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue($this->_testPath)); | ||||
| 		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y')); | ||||
| 		$this->Task->expects($this->at(0)) | ||||
| 			->method('in') | ||||
| 			->will($this->returnValue($this->_testPath)); | ||||
| 		$this->Task->expects($this->at(1)) | ||||
| 			->method('in') | ||||
| 			->will($this->returnValue('y')); | ||||
| 
 | ||||
| 		$path = $this->Task->path . 'BakeTestPlugin'; | ||||
| 
 | ||||
| 		$file = $path . DS . 'Controller' . DS . 'BakeTestPluginAppController.php'; | ||||
| 		$this->Task->expects($this->at(2))->method('createFile') | ||||
| 		$this->Task->expects($this->at(2)) | ||||
| 			->method('createFile') | ||||
| 			->with($file, new PHPUnit_Framework_Constraint_IsAnything()); | ||||
| 
 | ||||
| 		$file = $path . DS . 'Model' . DS . 'BakeTestPluginAppModel.php'; | ||||
| 		$this->Task->expects($this->at(3))->method('createFile') | ||||
| 		$this->Task->expects($this->at(3)) | ||||
| 			->method('createFile') | ||||
| 			->with($file, new PHPUnit_Framework_Constraint_IsAnything()); | ||||
| 
 | ||||
| 		$this->Task->bake('BakeTestPlugin'); | ||||
|  | @ -101,18 +106,25 @@ class PluginTaskTest extends CakeTestCase { | |||
| 
 | ||||
| 		$directories = array( | ||||
| 			'Config' . DS . 'Schema', | ||||
| 			'Model' . DS . 'Behavior', | ||||
| 			'Model' . DS . 'Datasource', | ||||
| 			'Console' . DS . 'Command' . DS . 'Task', | ||||
| 			'Console' . DS . 'Templates', | ||||
| 			'Controller' . DS . 'Component', | ||||
| 			'Lib', | ||||
| 			'View' . DS . 'Helper', | ||||
| 			'Locale' . DS . 'eng' . DS . 'LC_MESSAGES', | ||||
| 			'Model' . DS . 'Behavior', | ||||
| 			'Model' . DS . 'Datasource', | ||||
| 			'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component', | ||||
| 			'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper', | ||||
| 			'Test' . DS . 'Case' . DS . 'Lib', | ||||
| 			'Test' . DS . 'Case' . DS . 'Model' . DS . 'Behavior', | ||||
| 			'Test' . DS . 'Case' . DS . 'Model' . DS . 'Datasource', | ||||
| 			'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper', | ||||
| 			'Test' . DS . 'Fixture', | ||||
| 			'Vendor', | ||||
| 			'webroot' | ||||
| 			'View' . DS . 'Elements', | ||||
| 			'View' . DS . 'Helper', | ||||
| 			'View' . DS . 'Layouts', | ||||
| 			'webroot' . DS . 'css', | ||||
| 			'webroot' . DS . 'js', | ||||
| 			'webroot' . DS . 'img', | ||||
| 		); | ||||
| 		foreach ($directories as $dir) { | ||||
| 			$this->assertTrue(is_dir($path . DS . $dir), 'Missing directory for ' . $dir); | ||||
|  | @ -186,7 +198,9 @@ class PluginTaskTest extends CakeTestCase { | |||
| 	public function testFindPathNonExistant() { | ||||
| 		$paths = App::path('plugins'); | ||||
| 		$last = count($paths); | ||||
| 		$paths[] = '/fake/path'; | ||||
| 
 | ||||
| 		array_unshift($paths, '/fake/path'); | ||||
| 		$paths[] = '/fake/path2'; | ||||
| 
 | ||||
| 		$this->Task = $this->getMock('PluginTask', | ||||
| 			array('in', 'out', 'err', 'createFile', '_stop'), | ||||
|  |  | |||
|  | @ -4,19 +4,18 @@ | |||
|  * | ||||
|  * Test Case for project generation shell task | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @since         CakePHP v 1.3.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ShellDispatcher', 'Console'); | ||||
|  | @ -150,7 +149,7 @@ class ProjectTaskTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test bake with CakePHP on the include path.  The constants should remain commented out. | ||||
|  * test bake with CakePHP on the include path. The constants should remain commented out. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  | @ -198,7 +197,6 @@ class ProjectTaskTest extends CakeTestCase { | |||
| 			'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' => 'empty', | ||||
| 			'Test' . DS . 'Fixture' => 'empty', | ||||
| 			'Vendor' => 'empty', | ||||
| 			'View' . DS . 'Elements' => 'empty', | ||||
| 			'View' . DS . 'Scaffolds' => 'empty', | ||||
| 			'tmp' . DS . 'cache' . DS . 'models' => 'empty', | ||||
| 			'tmp' . DS . 'cache' . DS . 'persistent' => 'empty', | ||||
|  | @ -249,6 +247,24 @@ class ProjectTaskTest extends CakeTestCase { | |||
| 		$this->assertNotRegExp('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test generation of cache prefix | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testCachePrefixGeneration() { | ||||
| 		$this->_setupTestProject(); | ||||
| 
 | ||||
| 		$path = $this->Task->path . 'bake_test_app' . DS; | ||||
| 		$result = $this->Task->cachePrefix($path); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$File = new File($path . 'Config' . DS . 'core.php'); | ||||
| 		$contents = $File->read(); | ||||
| 		$this->assertRegExp('/\$prefix = \'.+\';/', $contents, '$prefix is not defined'); | ||||
| 		$this->assertNotRegExp('/\$prefix = \'myapp_\';/', $contents, 'Default cache prefix left behind. %s'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that index.php is generated correctly. | ||||
|  * | ||||
|  |  | |||
|  | @ -4,21 +4,20 @@ | |||
|  * | ||||
|  * Test Case for TemplateTask generation shell task | ||||
|  * | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @since         CakePHP(tm) v 1.3 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ShellDispatcher', 'Console'); | ||||
| App::uses('ConsoleOutput', 'Console'); | ||||
| App::uses('ConsoleInput', 'Console'); | ||||
|  | @ -93,8 +92,8 @@ class TemplateTaskTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test getting the correct theme name.  Ensure that with only one theme, or a theme param | ||||
|  * that the user is not bugged.  If there are more, find and return the correct theme name | ||||
|  * test getting the correct theme name. Ensure that with only one theme, or a theme param | ||||
|  * that the user is not bugged. If there are more, find and return the correct theme name | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  |  | |||
|  | @ -4,19 +4,18 @@ | |||
|  * | ||||
|  * Test Case for test generation shell task | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP :  Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @since         CakePHP v 1.2.0.7726 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ShellDispatcher', 'Console'); | ||||
|  | @ -32,17 +31,9 @@ App::uses('Model', 'Model'); | |||
|  * Test Article model | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  */ | ||||
| class TestTaskArticle extends Model { | ||||
| 
 | ||||
| /** | ||||
|  * Model name | ||||
|  * | ||||
|  * @var string | ||||
|  */ | ||||
| 	public $name = 'TestTaskArticle'; | ||||
| 
 | ||||
| /** | ||||
|  * Table name to use | ||||
|  * | ||||
|  | @ -106,17 +97,9 @@ class TestTaskArticle extends Model { | |||
|  * Tag Testing Model | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  */ | ||||
| class TestTaskTag extends Model { | ||||
| 
 | ||||
| /** | ||||
|  * Model name | ||||
|  * | ||||
|  * @var string | ||||
|  */ | ||||
| 	public $name = 'TestTaskTag'; | ||||
| 
 | ||||
| /** | ||||
|  * Table name | ||||
|  * | ||||
|  | @ -143,7 +126,6 @@ class TestTaskTag extends Model { | |||
|  * Simulated plugin | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  */ | ||||
| class TestTaskAppModel extends Model { | ||||
| } | ||||
|  | @ -152,17 +134,9 @@ class TestTaskAppModel extends Model { | |||
|  * Testing AppMode (TaskComment) | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  */ | ||||
| class TestTaskComment extends TestTaskAppModel { | ||||
| 
 | ||||
| /** | ||||
|  * Model name | ||||
|  * | ||||
|  * @var string | ||||
|  */ | ||||
| 	public $name = 'TestTaskComment'; | ||||
| 
 | ||||
| /** | ||||
|  * Table name | ||||
|  * | ||||
|  | @ -187,17 +161,9 @@ class TestTaskComment extends TestTaskAppModel { | |||
|  * Test Task Comments Controller | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  */ | ||||
| class TestTaskCommentsController extends Controller { | ||||
| 
 | ||||
| /** | ||||
|  * Controller Name | ||||
|  * | ||||
|  * @var string | ||||
|  */ | ||||
| 	public $name = 'TestTaskComments'; | ||||
| 
 | ||||
| /** | ||||
|  * Models to use | ||||
|  * | ||||
|  | @ -349,14 +315,14 @@ class TestTaskTest extends CakeTestCase { | |||
| 		)); | ||||
| 		$keys = ClassRegistry::keys(); | ||||
| 		$this->assertTrue(in_array('test_task_comment', $keys)); | ||||
| 		$object = $this->Task->buildTestSubject('Model', 'TestTaskComment'); | ||||
| 		$this->Task->buildTestSubject('Model', 'TestTaskComment'); | ||||
| 
 | ||||
| 		$keys = ClassRegistry::keys(); | ||||
| 		$this->assertFalse(in_array('random', $keys)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that getClassName returns the user choice as a classname. | ||||
|  * test that getClassName returns the user choice as a class name. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  | @ -391,7 +357,7 @@ class TestTaskTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that resolving classnames works | ||||
|  * test that resolving class names works | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  | @ -425,8 +391,8 @@ class TestTaskTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test baking files.  The conditionally run tests are known to fail in PHP4 | ||||
|  * as PHP4 classnames are all lower case, breaking the plugin path inflection. | ||||
|  * test baking files. The conditionally run tests are known to fail in PHP4 | ||||
|  * as PHP4 class names are all lower case, breaking the plugin path inflection. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  | @ -447,6 +413,8 @@ class TestTaskTest extends CakeTestCase { | |||
| 
 | ||||
| 		$this->assertContains('function testDoSomething()', $result); | ||||
| 		$this->assertContains('function testDoSomethingElse()', $result); | ||||
| 		$this->assertContains('$this->markTestIncomplete(\'testDoSomething not implemented.\')', $result); | ||||
| 		$this->assertContains('$this->markTestIncomplete(\'testDoSomethingElse not implemented.\')', $result); | ||||
| 
 | ||||
| 		$this->assertContains("'app.test_task_article'", $result); | ||||
| 		$this->assertContains("'app.test_task_comment'", $result); | ||||
|  | @ -566,6 +534,8 @@ class TestTaskTest extends CakeTestCase { | |||
| 
 | ||||
| /** | ||||
|  * Test generateUses() | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGenerateUses() { | ||||
| 		$result = $this->Task->generateUses('model', 'Model', 'Post'); | ||||
|  | @ -694,7 +664,7 @@ class TestTaskTest extends CakeTestCase { | |||
| 	public function testTestCaseFileNamePlugin() { | ||||
| 		$this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS; | ||||
| 
 | ||||
| 		CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS )); | ||||
| 		CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS)); | ||||
| 		$this->Task->plugin = 'TestTest'; | ||||
| 		$result = $this->Task->testCaseFileName('Model', 'Post'); | ||||
| 		$expected = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'PostTest.php'; | ||||
|  |  | |||
|  | @ -4,19 +4,18 @@ | |||
|  * | ||||
|  * Test Case for view generation shell task | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @since         CakePHP v 1.2.0.7726 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ShellDispatcher', 'Console'); | ||||
|  | @ -30,22 +29,15 @@ App::uses('ProjectTask', 'Console/Command/Task'); | |||
| App::uses('DbConfigTask', 'Console/Command/Task'); | ||||
| App::uses('Model', 'Model'); | ||||
| App::uses('Controller', 'Controller'); | ||||
| App::uses('AppController', 'Controller'); | ||||
| 
 | ||||
| /** | ||||
|  * Test View Task Comment Model | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  */ | ||||
| class ViewTaskComment extends Model { | ||||
| 
 | ||||
| /** | ||||
|  * Model name | ||||
|  * | ||||
|  * @var string | ||||
|  */ | ||||
| 	public $name = 'ViewTaskComment'; | ||||
| 
 | ||||
| /** | ||||
|  * Table name | ||||
|  * | ||||
|  | @ -70,17 +62,9 @@ class ViewTaskComment extends Model { | |||
|  * Test View Task Article Model | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  */ | ||||
| class ViewTaskArticle extends Model { | ||||
| 
 | ||||
| /** | ||||
|  * Model name | ||||
|  * | ||||
|  * @var string | ||||
|  */ | ||||
| 	public $name = 'ViewTaskArticle'; | ||||
| 
 | ||||
| /** | ||||
|  * Table name | ||||
|  * | ||||
|  | @ -93,17 +77,9 @@ class ViewTaskArticle extends Model { | |||
|  * Test View Task Comments Controller | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  */ | ||||
| class ViewTaskCommentsController extends Controller { | ||||
| 
 | ||||
| /** | ||||
|  * Controller name | ||||
|  * | ||||
|  * @var string | ||||
|  */ | ||||
| 	public $name = 'ViewTaskComments'; | ||||
| 
 | ||||
| /** | ||||
|  * Testing public controller action | ||||
|  * | ||||
|  | @ -126,17 +102,9 @@ class ViewTaskCommentsController extends Controller { | |||
|  * Test View Task Articles Controller | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  * @package       Cake.Test.Case.Console.Command.Task | ||||
|  */ | ||||
| class ViewTaskArticlesController extends Controller { | ||||
| 
 | ||||
| /** | ||||
|  * Controller name | ||||
|  * | ||||
|  * @var string | ||||
|  */ | ||||
| 	public $name = 'ViewTaskArticles'; | ||||
| 
 | ||||
| /** | ||||
|  * Test public controller action | ||||
|  * | ||||
|  | @ -355,10 +323,11 @@ class ViewTaskTest extends CakeTestCase { | |||
| 	public function testBakeIndex() { | ||||
| 		$this->Task->controllerName = 'ViewTaskComments'; | ||||
| 
 | ||||
| 		$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'View' . DS . 'index.ctp'); | ||||
| 		$this->Task->expects($this->at(0))->method('createFile') | ||||
| 			->with( | ||||
| 				TMP . 'ViewTaskComments' . DS . 'index.ctp', | ||||
| 				$this->stringContains("\$viewTaskComment['Article']['title']") | ||||
| 				$expected | ||||
| 			); | ||||
| 		$this->Task->bake('index', true); | ||||
| 	} | ||||
|  |  | |||
|  | @ -2,24 +2,28 @@ | |||
| /** | ||||
|  * TestSuiteShell test case | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  * @since         CakePHP(tm) v 2.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ShellDispatcher', 'Console'); | ||||
| App::uses('TestShell', 'Console/Command'); | ||||
| 
 | ||||
| /** | ||||
|  * TestTestShell | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  */ | ||||
| class TestTestShell extends TestShell { | ||||
| 
 | ||||
| 	public function mapFileToCase($file, $category, $throwOnMissingFile = true) { | ||||
|  | @ -32,6 +36,11 @@ class TestTestShell extends TestShell { | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * TestShellTest | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  */ | ||||
| class TestShellTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  | @ -332,4 +341,40 @@ class TestShellTest extends CakeTestCase { | |||
| 			); | ||||
| 		$this->Shell->main(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests that the 'quiet' parameter gets swallowed before calling PHPUnit | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testRunnerOptionsQuiet() { | ||||
| 		$this->Shell->startup(); | ||||
| 		$this->Shell->args = array('core', 'Basics'); | ||||
| 		$this->Shell->params = array('quiet' => true); | ||||
| 
 | ||||
| 		$this->Shell->expects($this->once())->method('_run') | ||||
| 			->with( | ||||
| 				array('app' => false, 'plugin' => null, 'core' => true, 'output' => 'text', 'case' => 'Basics'), | ||||
| 				array('--colors') | ||||
| 			); | ||||
| 		$this->Shell->main(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests that the '--directive' parameter change to '-d' before calling PHPUnit | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testRunnerOptionsDirective() { | ||||
| 		$this->Shell->startup(); | ||||
| 		$this->Shell->args = array('core', 'Basics'); | ||||
| 		$this->Shell->params = array('directive' => 'memory_limit=128M'); | ||||
| 
 | ||||
| 		$this->Shell->expects($this->once())->method('_run') | ||||
| 			->with( | ||||
| 				array('app' => false, 'plugin' => null, 'core' => true, 'output' => 'text', 'case' => 'Basics'), | ||||
| 				array('-d', 'memory_limit=128M', '--colors') | ||||
| 			); | ||||
| 		$this->Shell->main(); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * ConsoleErrorHandler Test case | ||||
|  * | ||||
|  * PHP versions 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  * @since         CakePHP(tm) v 2.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ConsoleErrorHandler', 'Console'); | ||||
|  | @ -148,4 +147,31 @@ class ConsoleErrorHandlerTest extends CakeTestCase { | |||
| 		$this->Error->handleException($exception); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test a exception with non-integer code | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testNonIntegerExceptionCode() { | ||||
| 		if (PHP_VERSION_ID < 50300) { | ||||
| 			$this->markTestSkipped('ReflectionProperty::setAccessible() is available since 5.3'); | ||||
| 		} | ||||
| 
 | ||||
| 		$exception = new Exception('Non-integer exception code'); | ||||
| 
 | ||||
| 		$class = new ReflectionClass('Exception'); | ||||
| 		$property = $class->getProperty('code'); | ||||
| 		$property->setAccessible(true); | ||||
| 		$property->setValue($exception, '42S22'); | ||||
| 
 | ||||
| 		ConsoleErrorHandler::$stderr->expects($this->once())->method('write') | ||||
| 			->with($this->stringContains('Non-integer exception code')); | ||||
| 
 | ||||
| 		$this->Error->expects($this->once()) | ||||
| 			->method('_stop') | ||||
| 			->with(1); | ||||
| 
 | ||||
| 		$this->Error->handleException($exception); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -2,23 +2,27 @@ | |||
| /** | ||||
|  * ConsoleOptionParserTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  * @since         CakePHP(tm) v 2.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ConsoleOptionParser', 'Console'); | ||||
| 
 | ||||
| /** | ||||
|  * ConsoleOptionParserTest | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  */ | ||||
| class ConsoleOptionParserTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  | @ -33,7 +37,7 @@ class ConsoleOptionParserTest extends CakeTestCase { | |||
| 		$this->assertEquals($parser, $result, 'Setting description is not chainable'); | ||||
| 		$this->assertEquals('A test', $parser->description(), 'getting value is wrong.'); | ||||
| 
 | ||||
| 		$result = $parser->description(array('A test', 'something')); | ||||
| 		$parser->description(array('A test', 'something')); | ||||
| 		$this->assertEquals("A test\nsomething", $parser->description(), 'getting value is wrong.'); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -49,7 +53,7 @@ class ConsoleOptionParserTest extends CakeTestCase { | |||
| 		$this->assertEquals($parser, $result, 'Setting epilog is not chainable'); | ||||
| 		$this->assertEquals('A test', $parser->epilog(), 'getting value is wrong.'); | ||||
| 
 | ||||
| 		$result = $parser->epilog(array('A test', 'something')); | ||||
| 		$parser->epilog(array('A test', 'something')); | ||||
| 		$this->assertEquals("A test\nsomething", $parser->epilog(), 'getting value is wrong.'); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -254,24 +258,26 @@ class ConsoleOptionParserTest extends CakeTestCase { | |||
|  * test parsing options that do not exist. | ||||
|  * | ||||
|  * @expectedException ConsoleException | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOptionThatDoesNotExist() { | ||||
| 		$parser = new ConsoleOptionParser('test', false); | ||||
| 		$parser->addOption('no-commit', array('boolean' => true)); | ||||
| 
 | ||||
| 		$result = $parser->parse(array('--fail', 'other')); | ||||
| 		$parser->parse(array('--fail', 'other')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test parsing short options that do not exist. | ||||
|  * | ||||
|  * @expectedException ConsoleException | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testShortOptionThatDoesNotExist() { | ||||
| 		$parser = new ConsoleOptionParser('test', false); | ||||
| 		$parser->addOption('no-commit', array('boolean' => true)); | ||||
| 
 | ||||
| 		$result = $parser->parse(array('-f')); | ||||
| 		$parser->parse(array('-f')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -288,7 +294,7 @@ class ConsoleOptionParserTest extends CakeTestCase { | |||
| 		$expected = array('name' => 'mark', 'help' => false); | ||||
| 		$this->assertEquals($expected, $result[0], 'Got the correct value.'); | ||||
| 
 | ||||
| 		$result = $parser->parse(array('--name', 'jimmy')); | ||||
| 		$parser->parse(array('--name', 'jimmy')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -378,7 +384,7 @@ class ConsoleOptionParserTest extends CakeTestCase { | |||
| 		$result = $parser->parse($expected); | ||||
| 		$this->assertEquals($expected, $result[1], 'Arguments are not as expected'); | ||||
| 
 | ||||
| 		$result = $parser->parse(array('one', 'two', 'three')); | ||||
| 		$parser->parse(array('one', 'two', 'three')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -424,7 +430,7 @@ class ConsoleOptionParserTest extends CakeTestCase { | |||
| 		$expected = array('mark', 'samurai', 'sword'); | ||||
| 		$this->assertEquals($expected, $result[1], 'Got the correct value.'); | ||||
| 
 | ||||
| 		$result = $parser->parse(array('jose', 'coder')); | ||||
| 		$parser->parse(array('jose', 'coder')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -470,6 +476,21 @@ class ConsoleOptionParserTest extends CakeTestCase { | |||
| 		$this->assertEquals('test', $result['test']->name()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test removeSubcommand with an object. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testRemoveSubcommand() { | ||||
| 		$parser = new ConsoleOptionParser('test', false); | ||||
| 		$parser->addSubcommand(new ConsoleInputSubcommand('test')); | ||||
| 		$result = $parser->subcommands(); | ||||
| 		$this->assertEquals(1, count($result)); | ||||
| 		$parser->removeSubcommand('test'); | ||||
| 		$result = $parser->subcommands(); | ||||
| 		$this->assertEquals(0, count($result), 'Remove a subcommand does not work'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test adding multiple subcommands | ||||
|  * | ||||
|  |  | |||
|  | @ -2,23 +2,27 @@ | |||
| /** | ||||
|  * ConsoleOutputTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  * @since         CakePHP(tm) v 1.2.0.5432 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ConsoleOutput', 'Console'); | ||||
| 
 | ||||
| /** | ||||
|  * ConsoleOutputTest | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  */ | ||||
| class ConsoleOutputTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  | @ -90,6 +94,27 @@ class ConsoleOutputTest extends CakeTestCase { | |||
| 		$this->output->write(array('Line', 'Line', 'Line')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test writing an array of messages. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOverwrite() { | ||||
| 		$testString = "Text"; | ||||
| 
 | ||||
| 		$this->output->expects($this->at(0))->method('_write') | ||||
| 			->with($testString); | ||||
| 
 | ||||
| 		$this->output->expects($this->at(1))->method('_write') | ||||
| 			->with(""); | ||||
| 
 | ||||
| 		$this->output->expects($this->at(2))->method('_write') | ||||
| 			->with("Overwriting text"); | ||||
| 
 | ||||
| 		$this->output->write($testString, 0); | ||||
| 		$this->output->overwrite("Overwriting text"); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test getting a style. | ||||
|  * | ||||
|  | @ -227,6 +252,17 @@ class ConsoleOutputTest extends CakeTestCase { | |||
| 		$this->output->write('<error>Bad</error> Regular', false); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test plain output when php://output, as php://output is | ||||
|  * not compatible with posix_ functions. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOutputAsPlainWhenOutputStream() { | ||||
| 		$output = $this->getMock('ConsoleOutput', array('_write'), array('php://output')); | ||||
| 		$this->assertEquals(ConsoleOutput::PLAIN, $output->outputAs()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test plain output only strips tags used for formatting. | ||||
|  * | ||||
|  |  | |||
|  | @ -2,24 +2,28 @@ | |||
| /** | ||||
|  * HelpFormatterTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  * @since         CakePHP(tm) v 2.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ConsoleOptionParser', 'Console'); | ||||
| App::uses('HelpFormatter', 'Console'); | ||||
| 
 | ||||
| /** | ||||
|  * HelpFormatterTest | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  */ | ||||
| class HelpFormatterTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  |  | |||
							
								
								
									
										223
									
								
								lib/Cake/Test/Case/Console/Helper/ProgressShellHelperTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										223
									
								
								lib/Cake/Test/Case/Console/Helper/ProgressShellHelperTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,223 @@ | |||
| <?php | ||||
| /** | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @since         2.8 | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| App::uses("ProgressShellHelper", "Console/Helper"); | ||||
| App::uses("ConsoleOutputStub", "TestSuite/Stub"); | ||||
| 
 | ||||
| /** | ||||
|  * ProgressHelper test. | ||||
|  * @property ConsoleOutputStub $consoleOutput | ||||
|  * @property ProgressShellHelper $helper | ||||
|  */ | ||||
| class ProgressShellHelperTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 
 | ||||
| 		$this->consoleOutput = new ConsoleOutputStub(); | ||||
| 		$this->helper = new ProgressShellHelper($this->consoleOutput); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that a callback is required.* | ||||
|  * | ||||
|  * @expectedException \RuntimeException | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOutputFailure() { | ||||
| 		$this->helper->output(array('not a callback')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that the callback is invoked until 100 is reached. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOutputSuccess() { | ||||
| 		$this->helper->output(array(function ($progress) { | ||||
| 			$progress->increment(20); | ||||
| 		})); | ||||
| 		$expected = array( | ||||
| 			'', | ||||
| 			'==============>                                                              20%', | ||||
| 			'', | ||||
| 			'=============================>                                               40%', | ||||
| 			'', | ||||
| 			'============================================>                                60%', | ||||
| 			'', | ||||
| 			'===========================================================>                 80%', | ||||
| 			'', | ||||
| 			'==========================================================================> 100%', | ||||
| 			'', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test output with options | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOutputSuccessOptions() { | ||||
| 		$this->helper->output(array( | ||||
| 			'total' => 10, | ||||
| 			'width' => 20, | ||||
| 			'callback' => function ($progress) { | ||||
| 				$progress->increment(2); | ||||
| 			} | ||||
| 		)); | ||||
| 		$expected = array( | ||||
| 			'', | ||||
| 			'==>              20%', | ||||
| 			'', | ||||
| 			'=====>           40%', | ||||
| 			'', | ||||
| 			'========>        60%', | ||||
| 			'', | ||||
| 			'===========>     80%', | ||||
| 			'', | ||||
| 			'==============> 100%', | ||||
| 			'', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test using the helper manually. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIncrementAndRender() { | ||||
| 		$this->helper->init(); | ||||
| 		$this->helper->increment(20); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(40); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(40); | ||||
| 		$this->helper->draw(); | ||||
| 		$expected = array( | ||||
| 			'', | ||||
| 			'==============>                                                              20%', | ||||
| 			'', | ||||
| 			'============================================>                                60%', | ||||
| 			'', | ||||
| 			'==========================================================================> 100%', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test negative numbers | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIncrementWithNegatives() { | ||||
| 		$this->helper->init(); | ||||
| 		$this->helper->increment(40); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(-60); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(80); | ||||
| 		$this->helper->draw(); | ||||
| 		$expected = array( | ||||
| 			'', | ||||
| 			'=============================>                                               40%', | ||||
| 			'', | ||||
| 			'                                                                              0%', | ||||
| 			'', | ||||
| 			'===========================================================>                 80%', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test increment and draw with options | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIncrementWithOptions() { | ||||
| 		$this->helper->init(array( | ||||
| 			'total' => 10, | ||||
| 			'width' => 20, | ||||
| 		)); | ||||
| 		$this->helper->increment(4); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(4); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(4); | ||||
| 		$this->helper->draw(); | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			'', | ||||
| 			'=====>           40%', | ||||
| 			'', | ||||
| 			'===========>     80%', | ||||
| 			'', | ||||
| 			'==============> 100%', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test increment and draw with value that makes the pad | ||||
|  * be a float | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIncrementFloatPad() { | ||||
| 		$this->helper->init(array( | ||||
| 			'total' => 50 | ||||
| 		)); | ||||
| 		$this->helper->increment(7); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(7); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(7); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(7); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(7); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(3); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(4); | ||||
| 		$this->helper->draw(); | ||||
| 		$this->helper->increment(8); | ||||
| 		$this->helper->draw(); | ||||
| 		$expected = array( | ||||
| 			'', | ||||
| 			'=========>                                                                   14%', | ||||
| 			'', | ||||
| 			'====================>                                                        28%', | ||||
| 			'', | ||||
| 			'==============================>                                              42%', | ||||
| 			'', | ||||
| 			'=========================================>                                   56%', | ||||
| 			'', | ||||
| 			'===================================================>                         70%', | ||||
| 			'', | ||||
| 			'========================================================>                    76%', | ||||
| 			'', | ||||
| 			'==============================================================>              84%', | ||||
| 			'', | ||||
| 			'==========================================================================> 100%', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										201
									
								
								lib/Cake/Test/Case/Console/Helper/TableShellHelperTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										201
									
								
								lib/Cake/Test/Case/Console/Helper/TableShellHelperTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,201 @@ | |||
| <?php | ||||
| /** | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @since         2.8 | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| App::uses("TableShellHelper", "Console/Helper"); | ||||
| App::uses("ConsoleOutputStub", "TestSuite/Stub"); | ||||
| 
 | ||||
| /** | ||||
|  * ProgressHelper test. | ||||
|  * @property ConsoleOutputStub $consoleOutput | ||||
|  * @property TableShellHelper $helper | ||||
|  */ | ||||
| class TableShellHelperTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 
 | ||||
| 		$this->consoleOutput = new ConsoleOutputStub(); | ||||
| 		$this->helper = new TableShellHelper($this->consoleOutput); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test output | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDefaultOutput() { | ||||
| 		$data = array( | ||||
| 			array('Header 1', 'Header', 'Long Header'), | ||||
| 			array('short', 'Longish thing', 'short'), | ||||
| 			array('Longer thing', 'short', 'Longest Value'), | ||||
| 		); | ||||
| 		$this->helper->output($data); | ||||
| 		$expected = array( | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| <info>Header 1</info>     | <info>Header</info>        | <info>Long Header</info>   |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| short        | Longish thing | short         |', | ||||
| 			'| Longer thing | short         | Longest Value |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test output with multibyte characters | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOutputUtf8() { | ||||
| 		$data = array( | ||||
| 			array('Header 1', 'Head', 'Long Header'), | ||||
| 			array('short', 'ÄÄÄÜÜÜ', 'short'), | ||||
| 			array('Longer thing', 'longerish', 'Longest Value'), | ||||
| 		); | ||||
| 		$this->helper->output($data); | ||||
| 		$expected = array( | ||||
| 			'+--------------+-----------+---------------+', | ||||
| 			'| <info>Header 1</info>     | <info>Head</info>      | <info>Long Header</info>   |', | ||||
| 			'+--------------+-----------+---------------+', | ||||
| 			'| short        | ÄÄÄÜÜÜ    | short         |', | ||||
| 			'| Longer thing | longerish | Longest Value |', | ||||
| 			'+--------------+-----------+---------------+', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test output without headers | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOutputWithoutHeaderStyle() { | ||||
| 		$data = array( | ||||
| 			array('Header 1', 'Header', 'Long Header'), | ||||
| 			array('short', 'Longish thing', 'short'), | ||||
| 			array('Longer thing', 'short', 'Longest Value'), | ||||
| 		); | ||||
| 		$this->helper->config(array('headerStyle' => false)); | ||||
| 		$this->helper->output($data); | ||||
| 		$expected = array( | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| Header 1     | Header        | Long Header   |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| short        | Longish thing | short         |', | ||||
| 			'| Longer thing | short         | Longest Value |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test output with different header style | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOutputWithDifferentHeaderStyle() { | ||||
| 		$data = array( | ||||
| 			array('Header 1', 'Header', 'Long Header'), | ||||
| 			array('short', 'Longish thing', 'short'), | ||||
| 			array('Longer thing', 'short', 'Longest Value'), | ||||
| 		); | ||||
| 		$this->helper->config(array('headerStyle' => 'error')); | ||||
| 		$this->helper->output($data); | ||||
| 		$expected = array( | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| <error>Header 1</error>     | <error>Header</error>        | <error>Long Header</error>   |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| short        | Longish thing | short         |', | ||||
| 			'| Longer thing | short         | Longest Value |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test output without table headers | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOutputWithoutHeaders() { | ||||
| 		$data = array( | ||||
| 			array('short', 'Longish thing', 'short'), | ||||
| 			array('Longer thing', 'short', 'Longest Value'), | ||||
| 		); | ||||
| 		$this->helper->config(array('headers' => false)); | ||||
| 		$this->helper->output($data); | ||||
| 		$expected = array( | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| short        | Longish thing | short         |', | ||||
| 			'| Longer thing | short         | Longest Value |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test output with row separator | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOutputWithRowSeparator() { | ||||
| 		$data = array( | ||||
| 			array('Header 1', 'Header', 'Long Header'), | ||||
| 			array('short', 'Longish thing', 'short'), | ||||
| 			array('Longer thing', 'short', 'Longest Value') | ||||
| 		); | ||||
| 		$this->helper->config(array('rowSeparator' => true)); | ||||
| 		$this->helper->output($data); | ||||
| 		$expected = array( | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| <info>Header 1</info>     | <info>Header</info>        | <info>Long Header</info>   |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| short        | Longish thing | short         |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| Longer thing | short         | Longest Value |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test output with row separator and no headers | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOutputWithRowSeparatorAndHeaders() { | ||||
| 		$data = array( | ||||
| 			array('Header 1', 'Header', 'Long Header'), | ||||
| 			array('short', 'Longish thing', 'short'), | ||||
| 			array('Longer thing', 'short', 'Longest Value'), | ||||
| 		); | ||||
| 		$this->helper->config(array('rowSeparator' => true)); | ||||
| 		$this->helper->output($data); | ||||
| 		$expected = array( | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| <info>Header 1</info>     | <info>Header</info>        | <info>Long Header</info>   |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| short        | Longish thing | short         |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 			'| Longer thing | short         | Longest Value |', | ||||
| 			'+--------------+---------------+---------------+', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->consoleOutput->messages()); | ||||
| 	} | ||||
| } | ||||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * ShellDispatcherTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  * @since         CakePHP(tm) v 1.2.0.5432 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ShellDispatcher', 'Console'); | ||||
|  | @ -138,9 +137,8 @@ class ShellDispatcherTest extends CakeTestCase { | |||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testParseParams() { | ||||
| 	public function testParseParamsAppWorkingAbsolute() { | ||||
| 		$Dispatcher = new TestShellDispatcher(); | ||||
| 
 | ||||
| 		$params = array( | ||||
| 			'/cake/1.2.x.x/cake/console/cake.php', | ||||
| 			'bake', | ||||
|  | @ -153,11 +151,19 @@ class ShellDispatcherTest extends CakeTestCase { | |||
| 			'app' => 'new', | ||||
| 			'webroot' => 'webroot', | ||||
| 			'working' => str_replace('/', DS, '/var/www/htdocs/new'), | ||||
| 			'root' => str_replace('/', DS,'/var/www/htdocs') | ||||
| 			'root' => str_replace('/', DS, '/var/www/htdocs') | ||||
| 		); | ||||
| 		$Dispatcher->parseParams($params); | ||||
| 		$this->assertEquals($expected, $Dispatcher->params); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testParseParams method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testParseParamsNone() { | ||||
| 		$Dispatcher = new TestShellDispatcher(); | ||||
| 		$params = array('cake.php'); | ||||
| 		$expected = array( | ||||
| 			'app' => 'app', | ||||
|  | @ -168,7 +174,15 @@ class ShellDispatcherTest extends CakeTestCase { | |||
| 		$Dispatcher->params = $Dispatcher->args = array(); | ||||
| 		$Dispatcher->parseParams($params); | ||||
| 		$this->assertEquals($expected, $Dispatcher->params); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testParseParams method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testParseParamsApp() { | ||||
| 		$Dispatcher = new TestShellDispatcher(); | ||||
| 		$params = array( | ||||
| 			'cake.php', | ||||
| 			'-app', | ||||
|  | @ -183,7 +197,15 @@ class ShellDispatcherTest extends CakeTestCase { | |||
| 		$Dispatcher->params = $Dispatcher->args = array(); | ||||
| 		$Dispatcher->parseParams($params); | ||||
| 		$this->assertEquals($expected, $Dispatcher->params); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testParseParams method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testParseParamsAppWorkingRelative() { | ||||
| 		$Dispatcher = new TestShellDispatcher(); | ||||
| 		$params = array( | ||||
| 			'./cake.php', | ||||
| 			'bake', | ||||
|  | @ -192,17 +214,24 @@ class ShellDispatcherTest extends CakeTestCase { | |||
| 			'-working', | ||||
| 			'/cake/1.2.x.x/cake/console' | ||||
| 		); | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			'app' => 'new', | ||||
| 			'webroot' => 'webroot', | ||||
| 			'working' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'new'), | ||||
| 			'root' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH)) | ||||
| 		); | ||||
| 
 | ||||
| 		$Dispatcher->params = $Dispatcher->args = array(); | ||||
| 		$Dispatcher->parseParams($params); | ||||
| 		$this->assertEquals($expected, $Dispatcher->params); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testParseParams method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testParseParams() { | ||||
| 		$Dispatcher = new TestShellDispatcher(); | ||||
| 
 | ||||
| 		$params = array( | ||||
| 			'./console/cake.php', | ||||
|  | @ -379,7 +408,7 @@ class ShellDispatcherTest extends CakeTestCase { | |||
| 			'app' => 'old', | ||||
| 			'webroot' => 'webroot', | ||||
| 			'working' => str_replace('/', DS, '/var/www/htdocs/old'), | ||||
| 			'root' => str_replace('/', DS,'/var/www/htdocs') | ||||
| 			'root' => str_replace('/', DS, '/var/www/htdocs') | ||||
| 		); | ||||
| 		$Dispatcher->parseParams($params); | ||||
| 		$this->assertEquals($expected, $Dispatcher->params); | ||||
|  | @ -428,6 +457,14 @@ class ShellDispatcherTest extends CakeTestCase { | |||
| 		$Dispatcher = new TestShellDispatcher(); | ||||
| 		$result = $Dispatcher->getShell('TestPlugin.example'); | ||||
| 		$this->assertInstanceOf('ExampleShell', $result); | ||||
| 
 | ||||
| 		$Dispatcher = new TestShellDispatcher(); | ||||
| 		$result = $Dispatcher->getShell('test_plugin'); | ||||
| 		$this->assertInstanceOf('TestPluginShell', $result); | ||||
| 
 | ||||
| 		$Dispatcher = new TestShellDispatcher(); | ||||
| 		$result = $Dispatcher->getShell('TestPlugin'); | ||||
| 		$this->assertInstanceOf('TestPluginShell', $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -437,15 +474,14 @@ class ShellDispatcherTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testDispatchShellWithMain() { | ||||
| 		$Dispatcher = new TestShellDispatcher(); | ||||
| 		$Mock = $this->getMock('Shell', array(), array(), 'MockWithMainShell'); | ||||
| 		$Shell = $this->getMock('Shell'); | ||||
| 
 | ||||
| 		$Mock->expects($this->once())->method('initialize'); | ||||
| 		$Mock->expects($this->once())->method('loadTasks'); | ||||
| 		$Mock->expects($this->once())->method('runCommand') | ||||
| 		$Shell->expects($this->once())->method('initialize'); | ||||
| 		$Shell->expects($this->once())->method('runCommand') | ||||
| 			->with(null, array()) | ||||
| 			->will($this->returnValue(true)); | ||||
| 
 | ||||
| 		$Dispatcher->TestShell = $Mock; | ||||
| 		$Dispatcher->TestShell = $Shell; | ||||
| 
 | ||||
| 		$Dispatcher->args = array('mock_with_main'); | ||||
| 		$result = $Dispatcher->dispatch(); | ||||
|  | @ -460,13 +496,9 @@ class ShellDispatcherTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testDispatchShellWithoutMain() { | ||||
| 		$Dispatcher = new TestShellDispatcher(); | ||||
| 		$Shell = $this->getMock('Shell', array(), array(), 'MockWithoutMainShell'); | ||||
| 
 | ||||
| 		$Shell = new MockWithoutMainShell(); | ||||
| 		$this->mockObjects[] = $Shell; | ||||
| 		$Shell = $this->getMock('Shell'); | ||||
| 
 | ||||
| 		$Shell->expects($this->once())->method('initialize'); | ||||
| 		$Shell->expects($this->once())->method('loadTasks'); | ||||
| 		$Shell->expects($this->once())->method('runCommand') | ||||
| 			->with('initdb', array('initdb')) | ||||
| 			->will($this->returnValue(true)); | ||||
|  | @ -485,12 +517,11 @@ class ShellDispatcherTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testDispatchNotAShellWithMain() { | ||||
| 		$Dispatcher = new TestShellDispatcher(); | ||||
| 		$methods = get_class_methods('Object'); | ||||
| 		$methods = get_class_methods('CakeObject'); | ||||
| 		array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret'); | ||||
| 		$Shell = $this->getMock('Object', $methods, array(), 'MockWithMainNotAShell'); | ||||
| 		$Shell = $this->getMock('CakeObject', $methods); | ||||
| 
 | ||||
| 		$Shell->expects($this->never())->method('initialize'); | ||||
| 		$Shell->expects($this->never())->method('loadTasks'); | ||||
| 		$Shell->expects($this->once())->method('startup'); | ||||
| 		$Shell->expects($this->once())->method('main')->will($this->returnValue(true)); | ||||
| 		$Dispatcher->TestShell = $Shell; | ||||
|  | @ -500,8 +531,7 @@ class ShellDispatcherTest extends CakeTestCase { | |||
| 		$this->assertTrue($result); | ||||
| 		$this->assertEquals(array(), $Dispatcher->args); | ||||
| 
 | ||||
| 		$Shell = new MockWithMainNotAShell($Dispatcher); | ||||
| 		$this->mockObjects[] = $Shell; | ||||
| 		$Shell = $this->getMock('CakeObject', $methods); | ||||
| 		$Shell->expects($this->once())->method('initdb')->will($this->returnValue(true)); | ||||
| 		$Shell->expects($this->once())->method('startup'); | ||||
| 		$Dispatcher->TestShell = $Shell; | ||||
|  | @ -518,12 +548,11 @@ class ShellDispatcherTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testDispatchNotAShellWithoutMain() { | ||||
| 		$Dispatcher = new TestShellDispatcher(); | ||||
| 		$methods = get_class_methods('Object'); | ||||
| 		$methods = get_class_methods('CakeObject'); | ||||
| 		array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret'); | ||||
| 		$Shell = $this->getMock('Object', $methods, array(&$Dispatcher), 'MockWithoutMainNotAShell'); | ||||
| 		$Shell = $this->getMock('CakeObject', $methods); | ||||
| 
 | ||||
| 		$Shell->expects($this->never())->method('initialize'); | ||||
| 		$Shell->expects($this->never())->method('loadTasks'); | ||||
| 		$Shell->expects($this->once())->method('startup'); | ||||
| 		$Shell->expects($this->once())->method('main')->will($this->returnValue(true)); | ||||
| 		$Dispatcher->TestShell = $Shell; | ||||
|  | @ -533,8 +562,7 @@ class ShellDispatcherTest extends CakeTestCase { | |||
| 		$this->assertTrue($result); | ||||
| 		$this->assertEquals(array(), $Dispatcher->args); | ||||
| 
 | ||||
| 		$Shell = new MockWithoutMainNotAShell($Dispatcher); | ||||
| 		$this->mockObjects[] = $Shell; | ||||
| 		$Shell = $this->getMock('CakeObject', $methods); | ||||
| 		$Shell->expects($this->once())->method('initdb')->will($this->returnValue(true)); | ||||
| 		$Shell->expects($this->once())->method('startup'); | ||||
| 		$Dispatcher->TestShell = $Shell; | ||||
|  | @ -564,7 +592,7 @@ class ShellDispatcherTest extends CakeTestCase { | |||
| 		$this->assertEquals('a', $Dispatcher->shiftArgs()); | ||||
| 		$this->assertSame($Dispatcher->args, array('b' => 'c', 'd')); | ||||
| 
 | ||||
| 		$Dispatcher->args = array(0 => 'a',  2 => 'b', 30 => 'c'); | ||||
| 		$Dispatcher->args = array(0 => 'a', 2 => 'b', 30 => 'c'); | ||||
| 		$this->assertEquals('a', $Dispatcher->shiftArgs()); | ||||
| 		$this->assertSame($Dispatcher->args, array(0 => 'b', 1 => 'c')); | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,24 +4,24 @@ | |||
|  * | ||||
|  * Test Case for Shell | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP :  Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Console.Command | ||||
|  * @since         CakePHP v 1.2.0.7726 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('ShellDispatcher', 'Console'); | ||||
| App::uses('Shell', 'Console'); | ||||
| App::uses('Folder', 'Utility'); | ||||
| App::uses("ProgressHelper", "Console/Helper"); | ||||
| 
 | ||||
| /** | ||||
|  * ShellTestShell class | ||||
|  | @ -40,7 +40,7 @@ class ShellTestShell extends Shell { | |||
| /** | ||||
|  * stopped property | ||||
|  * | ||||
|  * @var integer | ||||
|  * @var int | ||||
|  */ | ||||
| 	public $stopped; | ||||
| 
 | ||||
|  | @ -54,7 +54,7 @@ class ShellTestShell extends Shell { | |||
| /** | ||||
|  * stop method | ||||
|  * | ||||
|  * @param integer $status | ||||
|  * @param int $status | ||||
|  * @return void | ||||
|  */ | ||||
| 	protected function _stop($status = 0) { | ||||
|  | @ -194,6 +194,7 @@ class ShellTest extends CakeTestCase { | |||
| 		), App::RESET); | ||||
| 
 | ||||
| 		CakePlugin::load('TestPlugin'); | ||||
| 		$this->Shell->tasks = array('DbConfig' => array('one', 'two')); | ||||
| 		$this->Shell->uses = array('TestPlugin.TestPluginPost'); | ||||
| 		$this->Shell->initialize(); | ||||
| 
 | ||||
|  | @ -207,6 +208,33 @@ class ShellTest extends CakeTestCase { | |||
| 		$this->assertTrue(isset($this->Shell->Comment)); | ||||
| 		$this->assertInstanceOf('Comment', $this->Shell->Comment); | ||||
| 		$this->assertEquals('Comment', $this->Shell->modelClass); | ||||
| 		$this->assertInstanceOf('DbConfigTask', $this->Shell->DbConfig); | ||||
| 
 | ||||
| 		App::build(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testLoadModel method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testLoadModel() { | ||||
| 		App::build(array( | ||||
| 			'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS), | ||||
| 			'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS) | ||||
| 		), App::RESET); | ||||
| 
 | ||||
| 		$Shell = new TestMergeShell(); | ||||
| 		$this->assertEquals('Comment', $Shell->Comment->alias); | ||||
| 		$this->assertInstanceOf('Comment', $Shell->Comment); | ||||
| 		$this->assertEquals('Comment', $Shell->modelClass); | ||||
| 
 | ||||
| 		CakePlugin::load('TestPlugin'); | ||||
| 		$this->Shell->loadModel('TestPlugin.TestPluginPost'); | ||||
| 		$this->assertTrue(isset($this->Shell->TestPluginPost)); | ||||
| 		$this->assertInstanceOf('TestPluginPost', $this->Shell->TestPluginPost); | ||||
| 		$this->assertEquals('TestPluginPost', $this->Shell->modelClass); | ||||
| 		CakePlugin::unload('TestPlugin'); | ||||
| 
 | ||||
| 		App::build(); | ||||
| 	} | ||||
|  | @ -341,6 +369,36 @@ class ShellTest extends CakeTestCase { | |||
| 		$this->Shell->out('Quiet', 1, Shell::QUIET); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test overwriting. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOverwrite() { | ||||
| 		$number = strlen('Some text I want to overwrite'); | ||||
| 
 | ||||
| 		$this->Shell->stdout->expects($this->at(0)) | ||||
| 			->method('write') | ||||
| 			->with('Some <info>text</info> I want to overwrite', 0) | ||||
| 			->will($this->returnValue($number)); | ||||
| 
 | ||||
| 		$this->Shell->stdout->expects($this->at(1)) | ||||
| 			->method('write') | ||||
| 			->with(str_repeat("\x08", $number), 0); | ||||
| 
 | ||||
| 		$this->Shell->stdout->expects($this->at(2)) | ||||
| 			->method('write') | ||||
| 			->with('Less text', 0) | ||||
| 			->will($this->returnValue(9)); | ||||
| 
 | ||||
| 		$this->Shell->stdout->expects($this->at(3)) | ||||
| 			->method('write') | ||||
| 			->with(str_repeat(' ', $number - 9), 0); | ||||
| 
 | ||||
| 		$this->Shell->out('Some <info>text</info> I want to overwrite', 0); | ||||
| 		$this->Shell->overwrite('Less text'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testErr method | ||||
|  * | ||||
|  | @ -545,7 +603,7 @@ class ShellTest extends CakeTestCase { | |||
| 		$path = TMP . 'shell_test'; | ||||
| 		$file = $path . DS . 'file1.php'; | ||||
| 
 | ||||
| 		$Folder = new Folder($path, true); | ||||
| 		new Folder($path, true); | ||||
| 
 | ||||
| 		$this->Shell->interactive = false; | ||||
| 
 | ||||
|  | @ -572,7 +630,7 @@ class ShellTest extends CakeTestCase { | |||
| 
 | ||||
| 		$path = TMP . 'shell_test'; | ||||
| 		$file = $path . DS . 'file1.php'; | ||||
| 		$Folder = new Folder($path, true); | ||||
| 		new Folder($path, true); | ||||
| 
 | ||||
| 		$this->Shell->interactive = true; | ||||
| 
 | ||||
|  | @ -611,7 +669,7 @@ class ShellTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testCreateFileNoPermissions() { | ||||
| 		$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Cant perform operations using permissions on windows.'); | ||||
| 		$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Cant perform operations using permissions on Windows.'); | ||||
| 
 | ||||
| 		$path = TMP . 'shell_test'; | ||||
| 		$file = $path . DS . 'no_perms'; | ||||
|  | @ -663,7 +721,6 @@ class ShellTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testRunCommandMain() { | ||||
| 		$methods = get_class_methods('Shell'); | ||||
| 		$Mock = $this->getMock('Shell', array('main', 'startup'), array(), '', false); | ||||
| 
 | ||||
| 		$Mock->expects($this->once())->method('main')->will($this->returnValue(true)); | ||||
|  | @ -677,7 +734,6 @@ class ShellTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testRunCommandWithMethod() { | ||||
| 		$methods = get_class_methods('Shell'); | ||||
| 		$Mock = $this->getMock('Shell', array('hit_me', 'startup'), array(), '', false); | ||||
| 
 | ||||
| 		$Mock->expects($this->once())->method('hit_me')->will($this->returnValue(true)); | ||||
|  | @ -700,7 +756,7 @@ class ShellTest extends CakeTestCase { | |||
| 		$Mock->expects($this->never())->method('hr'); | ||||
| 		$Mock->expects($this->once())->method('out'); | ||||
| 
 | ||||
| 		$result = $Mock->runCommand('hr', array()); | ||||
| 		$Mock->runCommand('hr', array()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -709,7 +765,6 @@ class ShellTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testRunCommandMissingMethod() { | ||||
| 		$methods = get_class_methods('Shell'); | ||||
| 		$Mock = $this->getMock('Shell', array('startup', 'getOptionParser', 'out'), array(), '', false); | ||||
| 		$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false); | ||||
| 
 | ||||
|  | @ -762,7 +817,7 @@ class ShellTest extends CakeTestCase { | |||
| 
 | ||||
| 		$Shell->RunCommand = $task; | ||||
| 
 | ||||
| 		$result = $Shell->runCommand('run_command', array('run_command', 'one', 'value')); | ||||
| 		$Shell->runCommand('run_command', array('run_command', 'one', 'value')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -801,6 +856,51 @@ TEXT; | |||
| 		$this->assertEquals($expected, $this->Shell->TestApple->name); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test reading params | ||||
|  * | ||||
|  * @dataProvider paramReadingDataProvider | ||||
|  */ | ||||
| 	public function testParamReading($toRead, $expected) { | ||||
| 		$this->Shell->params = array( | ||||
| 			'key' => 'value', | ||||
| 			'help' => false, | ||||
| 			'emptykey' => '', | ||||
| 			'truthy' => true | ||||
| 		); | ||||
| 		$this->assertSame($expected, $this->Shell->param($toRead)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Data provider for testing reading values with Shell::param() | ||||
|  * | ||||
|  * @return array | ||||
|  */ | ||||
| 	public function paramReadingDataProvider() { | ||||
| 		return array( | ||||
| 			array( | ||||
| 				'key', | ||||
| 				'value', | ||||
| 			), | ||||
| 			array( | ||||
| 				'help', | ||||
| 				false, | ||||
| 			), | ||||
| 			array( | ||||
| 				'emptykey', | ||||
| 				'', | ||||
| 			), | ||||
| 			array( | ||||
| 				'truthy', | ||||
| 				true, | ||||
| 			), | ||||
| 			array( | ||||
| 				'does_not_exist', | ||||
| 				null, | ||||
| 			) | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that option parsers are created with the correct name/command. | ||||
|  * | ||||
|  | @ -816,8 +916,12 @@ TEXT; | |||
| 
 | ||||
| /** | ||||
|  * Test file and console and logging | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testFileAndConsoleLogging() { | ||||
| 		CakeLog::disable('stdout'); | ||||
| 		CakeLog::disable('stderr'); | ||||
| 		// file logging
 | ||||
| 		$this->Shell->log_something(); | ||||
| 		$this->assertTrue(file_exists(LOGS . 'error.log')); | ||||
|  | @ -831,7 +935,7 @@ TEXT; | |||
| 			array('types' => 'error'), | ||||
| 		)); | ||||
| 		TestCakeLog::config('console', array( | ||||
| 			'engine' => 'ConsoleLog', | ||||
| 			'engine' => 'Console', | ||||
| 			'stream' => 'php://stderr', | ||||
| 			)); | ||||
| 		TestCakeLog::replace('console', $mock); | ||||
|  | @ -842,13 +946,16 @@ TEXT; | |||
| 		$this->assertTrue(file_exists(LOGS . 'error.log')); | ||||
| 		$contents = file_get_contents(LOGS . 'error.log'); | ||||
| 		$this->assertContains($this->Shell->testMessage, $contents); | ||||
| 
 | ||||
| 		CakeLog::enable('stdout'); | ||||
| 		CakeLog::enable('stderr'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests that _useLogger works properly | ||||
|  * | ||||
|  * @return void | ||||
|  **/ | ||||
|  */ | ||||
| 	public function testProtectedUseLogger() { | ||||
| 		CakeLog::drop('stdout'); | ||||
| 		CakeLog::drop('stderr'); | ||||
|  | @ -862,6 +969,8 @@ TEXT; | |||
| 
 | ||||
| /** | ||||
|  * Test file and console and logging quiet output | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testQuietLog() { | ||||
| 		$output = $this->getMock('ConsoleOutput', array(), array(), '', false); | ||||
|  | @ -872,4 +981,53 @@ TEXT; | |||
| 		$this->Shell->runCommand('foo', array('--quiet')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test getting an instance of a helper | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGetInstanceOfHelper() { | ||||
| 		$actual = $this->Shell->helper("progress"); | ||||
| 		$this->assertInstanceOf("ProgressShellHelper", $actual); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test getting an invalid helper | ||||
|  * | ||||
|  * @expectedException RunTimeException | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGetInvalidHelper() { | ||||
| 		$this->Shell->helper("tomato"); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that shell loggers do not get overridden in constructor if already configured | ||||
|  *  | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testShellLoggersDoNotGetOverridden() { | ||||
| 		$shell = $this->getMock( | ||||
| 			"Shell", array( | ||||
| 				"_loggerIsConfigured", | ||||
| 				"configureStdOutLogger", | ||||
| 				"configureStdErrLogger", | ||||
| 			), | ||||
| 			array(), | ||||
| 			"", | ||||
| 			false | ||||
| 		); | ||||
| 
 | ||||
| 		$shell->expects($this->exactly(2)) | ||||
| 			->method("_loggerIsConfigured") | ||||
| 			->will($this->returnValue(true)); | ||||
| 
 | ||||
| 		$shell->expects($this->never()) | ||||
| 			->method("_configureStdOutLogger"); | ||||
| 
 | ||||
| 		$shell->expects($this->never()) | ||||
| 			->method("_configureStdErrLogger"); | ||||
| 
 | ||||
| 		$shell->__construct(); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -2,24 +2,34 @@ | |||
| /** | ||||
|  * TaskCollectionTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  * @since         CakePHP(tm) v 2.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('TaskCollection', 'Console'); | ||||
| App::uses('Shell', 'Console'); | ||||
| 
 | ||||
| /** | ||||
|  * Extended Task | ||||
|  */ | ||||
| class DbConfigAliasedTask extends Shell { | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * TaskCollectionTest | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Console | ||||
|  */ | ||||
| class TaskCollectionTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  | @ -54,8 +64,8 @@ class TaskCollectionTest extends CakeTestCase { | |||
| 		$this->assertInstanceOf('DbConfigTask', $result); | ||||
| 		$this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig); | ||||
| 
 | ||||
| 		$result = $this->Tasks->attached(); | ||||
| 		$this->assertEquals(array('DbConfig'), $result, 'attached() results are wrong.'); | ||||
| 		$result = $this->Tasks->loaded(); | ||||
| 		$this->assertEquals(array('DbConfig'), $result, 'loaded() results are wrong.'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -78,7 +88,7 @@ class TaskCollectionTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testLoadMissingTask() { | ||||
| 		$result = $this->Tasks->load('ThisTaskShouldAlwaysBeMissing'); | ||||
| 		$this->Tasks->load('ThisTaskShouldAlwaysBeMissing'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -110,15 +120,36 @@ class TaskCollectionTest extends CakeTestCase { | |||
| 		$this->Tasks->load('Extract'); | ||||
| 		$this->Tasks->load('DbConfig'); | ||||
| 
 | ||||
| 		$result = $this->Tasks->attached(); | ||||
| 		$result = $this->Tasks->loaded(); | ||||
| 		$this->assertEquals(array('Extract', 'DbConfig'), $result, 'loaded tasks is wrong'); | ||||
| 
 | ||||
| 		$this->Tasks->unload('DbConfig'); | ||||
| 		$this->assertFalse(isset($this->Tasks->DbConfig)); | ||||
| 		$this->assertTrue(isset($this->Tasks->Extract)); | ||||
| 
 | ||||
| 		$result = $this->Tasks->attached(); | ||||
| 		$result = $this->Tasks->loaded(); | ||||
| 		$this->assertEquals(array('Extract'), $result, 'loaded tasks is wrong'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests loading as an alias | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testLoadWithAlias() { | ||||
| 		$result = $this->Tasks->load('DbConfig', array('className' => 'DbConfigAliased')); | ||||
| 		$this->assertInstanceOf('DbConfigAliasedTask', $result); | ||||
| 		$this->assertInstanceOf('DbConfigAliasedTask', $this->Tasks->DbConfig); | ||||
| 
 | ||||
| 		$result = $this->Tasks->loaded(); | ||||
| 		$this->assertEquals(array('DbConfig'), $result, 'loaded() results are wrong.'); | ||||
| 
 | ||||
| 		$result = $this->Tasks->load('SomeTask', array('className' => 'TestPlugin.OtherTask')); | ||||
| 		$this->assertInstanceOf('OtherTaskTask', $result); | ||||
| 		$this->assertInstanceOf('OtherTaskTask', $this->Tasks->SomeTask); | ||||
| 
 | ||||
| 		$result = $this->Tasks->loaded(); | ||||
| 		$this->assertEquals(array('DbConfig', 'SomeTask'), $result, 'loaded() results are wrong.'); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brm Ko
						Brm Ko