Browse Source

Merge remote-tracking branch 'origin/3.0' into 3.0-i18n-next

Conflicts:
	src/Console/Command/BakeShell.php
	src/Console/Command/Task/BakeTask.php
	src/Console/Command/Task/ProjectTask.php
Jose Lorenzo Rodriguez 11 years ago
parent
commit
2059ac8f52
35 changed files with 105 additions and 81 deletions
  1. 1 1
      src/Console/Command/BakeShell.php
  2. 2 2
      src/Console/Command/Task/BakeTask.php
  3. 2 2
      src/Console/Command/Task/ProjectTask.php
  4. 38 38
      src/Console/Command/Task/TemplateTask.php
  5. 4 4
      src/Console/Command/Task/ViewTask.php
  6. 1 0
      src/Controller/Component/SessionComponent.php
  7. 0 0
      src/Template/Bake/default/actions/controller_actions.ctp
  8. 0 0
      src/Template/Bake/default/classes/behavior.ctp
  9. 0 0
      src/Template/Bake/default/classes/cell.ctp
  10. 0 0
      src/Template/Bake/default/classes/component.ctp
  11. 0 0
      src/Template/Bake/default/classes/controller.ctp
  12. 0 0
      src/Template/Bake/default/classes/entity.ctp
  13. 0 0
      src/Template/Bake/default/classes/fixture.ctp
  14. 0 0
      src/Template/Bake/default/classes/helper.ctp
  15. 0 0
      src/Template/Bake/default/classes/shell.ctp
  16. 0 0
      src/Template/Bake/default/classes/table.ctp
  17. 0 0
      src/Template/Bake/default/classes/test.ctp
  18. 0 0
      src/Template/Bake/default/config/routes.ctp
  19. 0 0
      src/Template/Bake/default/test/bootstrap.ctp
  20. 0 0
      src/Template/Bake/default/test/phpunit.xml.ctp
  21. 0 0
      src/Template/Bake/default/views/form.ctp
  22. 0 0
      src/Template/Bake/default/views/index.ctp
  23. 0 0
      src/Template/Bake/default/views/view.ctp
  24. 5 1
      src/TestSuite/ControllerTestCase.php
  25. 1 0
      src/View/Helper/SessionHelper.php
  26. 1 1
      tests/TestCase/Console/Command/CompletionShellTest.php
  27. 26 26
      tests/TestCase/Console/Command/Task/TemplateTaskTest.php
  28. 5 5
      tests/TestCase/Console/Command/Task/ViewTaskTest.php
  29. 18 0
      tests/TestCase/TestSuite/ControllerTestCaseTest.php
  30. 1 1
      tests/TestCase/Utility/FolderTest.php
  31. 0 0
      tests/test_app/Plugin/TestPlugin/src/Template/Bake/empty
  32. 0 0
      tests/test_app/Plugin/TestPluginTwo/src/Template/Bake/empty
  33. 0 0
      tests/test_app/TestApp/Template/Bake/test/classes/test_object.ctp
  34. 0 0
      tests/test_app/TestApp/Template/Bake/test/views/admin_edit.ctp
  35. 0 0
      tests/test_app/TestApp/Template/Bake/test/views/admin_form.ctp

+ 1 - 1
src/Console/Command/BakeShell.php

@@ -242,7 +242,7 @@ class BakeShell extends Shell {
 			'help' => 'Database connection to use in conjunction with `bake all`.',
 			'short' => 'c',
 			'default' => 'default'
-		])->addOption('theme', [
+		])->addOption('template', [
 			'short' => 't',
 			'help' => 'Theme to use when baking code.'
 		]);

+ 2 - 2
src/Console/Command/Task/BakeTask.php

@@ -177,10 +177,10 @@ class BakeTask extends Shell {
 			'short' => 'c',
 			'default' => 'default',
 			'help' => 'The datasource connection to get data from.'
-		])->addOption('theme', [
+		])->addOption('template', [
 			'short' => 't',
 			'default' => 'default',
-			'help' => 'Theme to use when baking code.'
+			'help' => 'Template to use when baking code.'
 		]);
 		return $parser;
 	}

+ 2 - 2
src/Console/Command/Task/ProjectTask.php

@@ -166,9 +166,9 @@ class ProjectTask extends BakeTask {
 			])->addOption('empty', [
 				'boolean' => true,
 				'help' => 'Create empty files in each of the directories. Good if you are using git'
-			])->addOption('theme', [
+			])->addOption('template', [
 				'short' => 't',
-				'help' => 'Theme to use when baking code.'
+				'help' => 'Template to use when baking code.'
 			])->addOption('composer', [
 				'default' => ROOT . '/composer.phar',
 				'help' => 'The path to the composer executable.'

+ 38 - 38
src/Console/Command/Task/TemplateTask.php

@@ -31,7 +31,7 @@ class TemplateTask extends Shell {
 
 /**
  * Paths to look for templates on.
- * Contains a list of $theme => $path
+ * Contains a list of $template => $path
  *
  * @var array
  */
@@ -43,30 +43,30 @@ class TemplateTask extends Shell {
  * @return void
  */
 	public function initialize() {
-		$this->templatePaths = $this->_findThemes();
+		$this->templatePaths = $this->_findTemplates();
 	}
 
 /**
- * Find the paths to all the installed shell themes in the app.
+ * Find the paths to all the installed shell templates in the app.
  *
- * Bake themes are directories not named `skel` inside a `Console/Templates` path.
+ * Bake templates are directories under `Template/Bake` path.
  * They are listed in this order: app -> plugin -> default
  *
- * @return array Array of bake themes that are installed.
+ * @return array Array of bake templates that are installed.
  */
-	protected function _findThemes() {
-		$paths = App::path('Console');
+	protected function _findTemplates() {
+		$paths = App::path('Template');
 
 		$plugins = App::objects('Plugin');
 		foreach ($plugins as $plugin) {
-			$paths[] = $this->_pluginPath($plugin) . 'src/Console/';
+			$paths[] = $this->_pluginPath($plugin) . 'src' . DS . 'Template' . DS;
 		}
 
-		$core = current(App::core('Console'));
-		$Folder = new Folder($core . 'Templates/default');
+		$core = current(App::core('Template'));
+		$Folder = new Folder($core . 'Bake' . DS . 'default');
 
 		$contents = $Folder->read();
-		$themeFolders = $contents[0];
+		$templateFolders = $contents[0];
 
 		$paths[] = $core;
 
@@ -74,26 +74,26 @@ class TemplateTask extends Shell {
 			$paths[$i] = rtrim($path, DS) . DS;
 		}
 
-		$this->_io->verbose('Found the following bake themes:');
+		$this->_io->verbose('Found the following bake templates:');
 
-		$themes = [];
+		$templates = [];
 		foreach ($paths as $path) {
-			$Folder = new Folder($path . 'Templates', false);
+			$Folder = new Folder($path . 'Bake', false);
 			$contents = $Folder->read();
 			$subDirs = $contents[0];
 			foreach ($subDirs as $dir) {
-				$Folder = new Folder($path . 'Templates/' . $dir);
+				$Folder = new Folder($path . 'Bake' . DS . $dir);
 				$contents = $Folder->read();
 				$subDirs = $contents[0];
-				if (array_intersect($contents[0], $themeFolders)) {
-					$templateDir = $path . 'Templates/' . $dir . DS;
-					$themes[$dir] = $templateDir;
+				if (array_intersect($contents[0], $templateFolders)) {
+					$templateDir = $path . 'Bake' . DS . $dir . DS;
+					$templates[$dir] = $templateDir;
 
 					$this->_io->verbose(sprintf("- %s -> %s", $dir, $templateDir));
 				}
 			}
 		}
-		return $themes;
+		return $templates;
 	}
 
 /**
@@ -111,8 +111,8 @@ class TemplateTask extends Shell {
 		if (empty($this->templatePaths)) {
 			$this->initialize();
 		}
-		$themePath = $this->getThemePath();
-		$templateFile = $this->_findTemplate($themePath, $directory, $filename);
+		$templatePath = $this->getTemplatePath();
+		$templateFile = $this->_findTemplate($templatePath, $directory, $filename);
 		if ($templateFile) {
 			extract($this->viewVars);
 			ob_start();
@@ -125,29 +125,29 @@ class TemplateTask extends Shell {
 	}
 
 /**
- * Find the theme name for the current operation.
- * If there is only one theme in $templatePaths it will be used.
- * If there is a -theme param in the cli args, it will be used.
- * If there is more than one installed theme user interaction will happen
+ * Find the template name for the current operation.
+ * If there is only one template in $templatePaths it will be used.
+ * If there is a -template param in the cli args, it will be used.
+ * If there is more than one installed template user interaction will happen
  *
- * @return string returns the path to the selected theme.
- * @throws \RuntimeException When the chosen theme cannot be found.
+ * @return string returns the path to the selected template.
+ * @throws \RuntimeException When the chosen template cannot be found.
  */
-	public function getThemePath() {
-		if (empty($this->params['theme'])) {
-			$this->params['theme'] = 'default';
+	public function getTemplatePath() {
+		if (empty($this->params['template'])) {
+			$this->params['template'] = 'default';
 		}
-		if (!isset($this->templatePaths[$this->params['theme']])) {
-			$msg = sprintf('Unable to locate "%s" bake theme templates.', $this->params['theme']);
+		if (!isset($this->templatePaths[$this->params['template']])) {
+			$msg = sprintf('Unable to locate "%s" bake template', $this->params['template']);
 			throw new \RuntimeException($msg);
 		}
-		$this->_io->verbose(sprintf('Using "%s" bake theme', $this->params['theme']));
-		return $this->templatePaths[$this->params['theme']];
+		$this->_io->verbose(sprintf('Using "%s" bake template', $this->params['template']));
+		return $this->templatePaths[$this->params['template']];
 	}
 
 /**
  * Find a template inside a directory inside a path.
- * Will scan all other theme dirs if the template is not found in the first directory.
+ * Will scan all other template dirs if the template is not found in the first directory.
  *
  * @param string $path The initial path to look for the file on. If it is not found fallbacks will be used.
  * @param string $directory Subdirectory to look for ie. 'views', 'objects'
@@ -155,9 +155,9 @@ class TemplateTask extends Shell {
  * @return string filename will exit program if template is not found.
  */
 	protected function _findTemplate($path, $directory, $filename) {
-		$themeFile = $path . $directory . DS . $filename . '.ctp';
-		if (file_exists($themeFile)) {
-			return $themeFile;
+		$templateFile = $path . $directory . DS . $filename . '.ctp';
+		if (file_exists($templateFile)) {
+			return $templateFile;
 		}
 		foreach ($this->templatePaths as $path) {
 			$templatePath = $path . $directory . DS . $filename . '.ctp';

+ 4 - 4
src/Console/Command/Task/ViewTask.php

@@ -380,19 +380,19 @@ class ViewTask extends BakeTask {
 		if (!empty($this->template) && $action != $this->template) {
 			return $this->template;
 		}
-		$themePath = $this->Template->getThemePath();
+		$templatePath = $this->Template->getTemplatePath();
 
 		if (!empty($this->params['prefix'])) {
 			$prefixed = Inflector::underscore($this->params['prefix']) . '_' . $action;
-			if (file_exists($themePath . 'views/' . $prefixed . '.ctp')) {
+			if (file_exists($templatePath . 'views/' . $prefixed . '.ctp')) {
 				return $prefixed;
 			}
 			$generic = preg_replace('/(.*)(_add|_edit)$/', '\1_form', $prefixed);
-			if (file_exists($themePath . 'views/' . $generic . '.ctp')) {
+			if (file_exists($templatePath . 'views/' . $generic . '.ctp')) {
 				return $generic;
 			}
 		}
-		if (file_exists($themePath . 'views/' . $action . '.ctp')) {
+		if (file_exists($templatePath . 'views/' . $action . '.ctp')) {
 			return $action;
 		}
 		if (in_array($action, ['add', 'edit'])) {

+ 1 - 0
src/Controller/Component/SessionComponent.php

@@ -117,6 +117,7 @@ class SessionComponent extends Component {
  * @param array $params Parameters to be sent to layout as view variables
  * @param string $key Message key, default is 'flash'
  * @return void
+ * @deprecated 3.0 Use FlashComponent::set() instead.
  * @link http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#creating-notification-messages
  */
 	public function setFlash($message, $element = null, array $params = array(), $key = 'flash') {

src/Console/Templates/default/actions/controller_actions.ctp → src/Template/Bake/default/actions/controller_actions.ctp


src/Console/Templates/default/classes/behavior.ctp → src/Template/Bake/default/classes/behavior.ctp


src/Console/Templates/default/classes/cell.ctp → src/Template/Bake/default/classes/cell.ctp


src/Console/Templates/default/classes/component.ctp → src/Template/Bake/default/classes/component.ctp


src/Console/Templates/default/classes/controller.ctp → src/Template/Bake/default/classes/controller.ctp


src/Console/Templates/default/classes/entity.ctp → src/Template/Bake/default/classes/entity.ctp


src/Console/Templates/default/classes/fixture.ctp → src/Template/Bake/default/classes/fixture.ctp


src/Console/Templates/default/classes/helper.ctp → src/Template/Bake/default/classes/helper.ctp


src/Console/Templates/default/classes/shell.ctp → src/Template/Bake/default/classes/shell.ctp


src/Console/Templates/default/classes/table.ctp → src/Template/Bake/default/classes/table.ctp


src/Console/Templates/default/classes/test.ctp → src/Template/Bake/default/classes/test.ctp


src/Console/Templates/default/config/routes.ctp → src/Template/Bake/default/config/routes.ctp


src/Console/Templates/default/test/bootstrap.ctp → src/Template/Bake/default/test/bootstrap.ctp


src/Console/Templates/default/test/phpunit.xml.ctp → src/Template/Bake/default/test/phpunit.xml.ctp


src/Console/Templates/default/views/form.ctp → src/Template/Bake/default/views/form.ctp


src/Console/Templates/default/views/index.ctp → src/Template/Bake/default/views/index.ctp


src/Console/Templates/default/views/view.ctp → src/Template/Bake/default/views/view.ctp


+ 5 - 1
src/TestSuite/ControllerTestCase.php

@@ -254,10 +254,14 @@ abstract class ControllerTestCase extends TestCase {
 
 		$request = $this->getMock(
 			'Cake\Network\Request',
-			array('_readInput'),
+			array('_readInput', 'method'),
 			array($requestData)
 		);
 
+		$request->expects($this->any())
+			->method('method')
+			->will($this->returnValue($method));
+
 		if (is_string($options['data'])) {
 			$request->expects($this->any())
 				->method('_readInput')

+ 1 - 0
src/View/Helper/SessionHelper.php

@@ -111,6 +111,7 @@ class SessionHelper extends Helper {
  * @param array $attrs Additional attributes to use for the creation of this flash message.
  *    Supports the 'params', and 'element' keys that are used in the helper.
  * @return string
+ * @deprecated 3.0 Use FlashHelper::render() instead.
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#SessionHelper::flash
  */
 	public function flash($key = 'flash', $attrs = []) {

+ 1 - 1
tests/TestCase/Console/Command/CompletionShellTest.php

@@ -151,7 +151,7 @@ class CompletionShellTest extends TestCase {
 		$this->Shell->runCommand(['options', 'bake']);
 		$output = $this->out->output;
 
-		$expected = "--help -h --verbose -v --quiet -q --connection -c --theme -t\n";
+		$expected = "--help -h --verbose -v --quiet -q --connection -c --template -t\n";
 		$this->assertTextEquals($expected, $output);
 	}
 

+ 26 - 26
tests/TestCase/Console/Command/Task/TemplateTaskTest.php

@@ -49,52 +49,52 @@ class TemplateTaskTest extends TestCase {
 	}
 
 /**
- * test finding themes installed in
+ * test finding templates installed in
  *
  * @return void
  */
-	public function testFindingInstalledThemesForBake() {
-		$consoleLibs = CAKE . 'Console' . DS;
+	public function testFindingInstalledTemplatesForBake() {
+		$consoleLibs = CAKE . 'Template' . DS;
 		$this->Task->initialize();
-		$this->assertPathEquals($this->Task->templatePaths['default'], $consoleLibs . 'Templates/default/');
+		$this->assertPathEquals($this->Task->templatePaths['default'], $consoleLibs . 'Bake/default/');
 	}
 
 /**
- * test using an invalid theme name.
+ * test using an invalid template name.
  *
  * @expectedException \RuntimeException
- * @expectedExceptionMessage Unable to locate "nope" bake theme
+ * @expectedExceptionMessage Unable to locate "nope" bake template
  * @return void
  */
-	public function testGetThemePathInvalid() {
-		$defaultTheme = CAKE . 'Console/Templates/default/';
-		$this->Task->templatePaths = ['default' => $defaultTheme];
-		$this->Task->params['theme'] = 'nope';
-		$this->Task->getThemePath();
+	public function testGetTemplatePathInvalid() {
+		$defaultTemplate = CAKE . 'Template/Bake/default/';
+		$this->Task->templatePaths = ['default' => $defaultTemplate];
+		$this->Task->params['template'] = 'nope';
+		$this->Task->getTemplatePath();
 	}
 
 /**
- * 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 template name. Ensure that with only one template, or a template param
+ * that the user is not bugged. If there are more, find and return the correct template name
  *
  * @return void
  */
-	public function testGetThemePath() {
-		$defaultTheme = CAKE . 'Console/Templates/default/';
-		$this->Task->templatePaths = ['default' => $defaultTheme];
+	public function testGetTemplatePath() {
+		$defaultTemplate = CAKE . 'Template/Bake/default/';
+		$this->Task->templatePaths = ['default' => $defaultTemplate];
 
-		$result = $this->Task->getThemePath();
-		$this->assertEquals($defaultTheme, $result);
+		$result = $this->Task->getTemplatePath();
+		$this->assertEquals($defaultTemplate, $result);
 
-		$this->Task->templatePaths = ['other' => '/some/path', 'default' => $defaultTheme];
-		$this->Task->params['theme'] = 'other';
-		$result = $this->Task->getThemePath();
+		$this->Task->templatePaths = ['other' => '/some/path', 'default' => $defaultTemplate];
+		$this->Task->params['template'] = 'other';
+		$result = $this->Task->getTemplatePath();
 		$this->assertEquals('/some/path', $result);
 
 		$this->Task->params = array();
-		$result = $this->Task->getThemePath();
-		$this->assertEquals($defaultTheme, $result);
-		$this->assertEquals('default', $this->Task->params['theme']);
+		$result = $this->Task->getTemplatePath();
+		$this->assertEquals($defaultTemplate, $result);
+		$this->assertEquals('default', $this->Task->params['template']);
 	}
 
 /**
@@ -112,14 +112,14 @@ class TemplateTaskTest extends TestCase {
 	}
 
 /**
- * test generate with a missing template in the chosen theme.
+ * test generate with a missing template in the chosen template.
  * ensure fallback to default works.
  *
  * @return void
  */
 	public function testGenerateWithTemplateFallbacks() {
 		$this->Task->initialize();
-		$this->Task->params['theme'] = 'test';
+		$this->Task->params['template'] = 'test';
 		$this->Task->set(array(
 			'name' => 'Article',
 			'model' => 'Article',

+ 5 - 5
tests/TestCase/Console/Command/Task/ViewTaskTest.php

@@ -94,7 +94,7 @@ class ViewTaskTest extends TestCase {
 /**
  * setUp method
  *
- * Ensure that the default theme is used
+ * Ensure that the default template is used
  *
  * @return void
  */
@@ -124,8 +124,8 @@ class ViewTaskTest extends TestCase {
 		$this->Task->Template = new TemplateTask($io);
 		$this->Task->Model = $this->getMock('Cake\Console\Command\Task\ModelTask', [], [$io]);
 
-		$this->Task->Template->params['theme'] = 'default';
-		$this->Task->Template->templatePaths = ['default' => CAKE . 'Console/Templates/default/'];
+		$this->Task->Template->params['template'] = 'default';
+		$this->Task->Template->templatePaths = ['default' => CAKE . 'Template/Bake/default/'];
 	}
 
 /**
@@ -707,9 +707,9 @@ class ViewTaskTest extends TestCase {
 		$this->assertEquals('form', $result);
 
 		$this->Task->Template->templatePaths = array(
-			'test' => CORE_TESTS . '/test_app/TestApp/Console/Templates/test/'
+			'test' => CORE_TESTS . '/test_app/TestApp/Template/Bake/test/'
 		);
-		$this->Task->Template->params['theme'] = 'test';
+		$this->Task->Template->params['template'] = 'test';
 
 		$result = $this->Task->getTemplate('edit');
 		$this->assertEquals('admin_edit', $result);

+ 18 - 0
tests/TestCase/TestSuite/ControllerTestCaseTest.php

@@ -215,6 +215,24 @@ class ControllerTestCaseTest extends TestCase {
 	}
 
 /**
+ * Tests testAction with call to request::method()
+ *
+ * @return void
+ */
+	public function testTestActionWithRequestMethod() {
+		$Controller = $this->Case->generate('TestsApps');
+		$this->Case->testAction('/tests_apps/index', [
+			'method' => 'get'
+		]);
+		$this->assertSame('GET', $this->Case->controller->request->method());
+
+		$this->Case->testAction('/tests_apps/set_action', [
+			'method' => 'post'
+		]);
+		$this->assertSame('POST', $this->Case->controller->request->method());
+	}
+
+/**
  * Test testAction() with prefix routes.
  *
  * @return void

+ 1 - 1
tests/TestCase/Utility/FolderTest.php

@@ -180,7 +180,7 @@ class FolderTest extends TestCase {
  * @return void
  */
 	public function testOperations() {
-		$path = CAKE . 'Console/Templates';
+		$path = CAKE . 'Template/Bake';
 		$Folder = new Folder($path);
 
 		$result = is_dir($Folder->pwd());

tests/test_app/Plugin/TestPlugin/src/Console/Templates/empty → tests/test_app/Plugin/TestPlugin/src/Template/Bake/empty


tests/test_app/Plugin/TestPluginTwo/src/Console/Templates/empty → tests/test_app/Plugin/TestPluginTwo/src/Template/Bake/empty


tests/test_app/TestApp/Console/Templates/test/classes/test_object.ctp → tests/test_app/TestApp/Template/Bake/test/classes/test_object.ctp


tests/test_app/TestApp/Console/Templates/test/views/admin_edit.ctp → tests/test_app/TestApp/Template/Bake/test/views/admin_edit.ctp


tests/test_app/TestApp/Console/Templates/test/views/admin_form.ctp → tests/test_app/TestApp/Template/Bake/test/views/admin_form.ctp