Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.0' into 3.0-i18n-next
Browse files Browse the repository at this point in the history
Conflicts:
	src/Console/Command/BakeShell.php
	src/Console/Command/Task/BakeTask.php
	src/Console/Command/Task/ProjectTask.php
  • Loading branch information
lorenzo committed Aug 4, 2014
2 parents c9b0bde + 022c847 commit 2059ac8
Show file tree
Hide file tree
Showing 35 changed files with 105 additions and 81 deletions.
2 changes: 1 addition & 1 deletion src/Console/Command/BakeShell.php
Expand Up @@ -242,7 +242,7 @@ public function getOptionParser() {
'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.'
]);
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Task/BakeTask.php
Expand Up @@ -177,10 +177,10 @@ public function getOptionParser() {
'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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Task/ProjectTask.php
Expand Up @@ -166,9 +166,9 @@ public function getOptionParser() {
])->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.'
Expand Down
76 changes: 38 additions & 38 deletions src/Console/Command/Task/TemplateTask.php
Expand Up @@ -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
*/
Expand All @@ -43,57 +43,57 @@ 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;

foreach ($paths as $i => $path) {
$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;
}

/**
Expand All @@ -111,8 +111,8 @@ public function generate($directory, $filename, $vars = null) {
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();
Expand All @@ -125,39 +125,39 @@ public function generate($directory, $filename, $vars = null) {
}

/**
* 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'
* @param string $filename lower_case_underscored filename you want.
* @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';
Expand Down
8 changes: 4 additions & 4 deletions src/Console/Command/Task/ViewTask.php
Expand Up @@ -380,19 +380,19 @@ public function getTemplate($action) {
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'])) {
Expand Down
1 change: 1 addition & 0 deletions src/Controller/Component/SessionComponent.php
Expand Up @@ -117,6 +117,7 @@ public function check($name) {
* @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') {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion src/TestSuite/ControllerTestCase.php
Expand Up @@ -254,10 +254,14 @@ protected function _testAction($url = '', $options = array()) {

$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')
Expand Down
1 change: 1 addition & 0 deletions src/View/Helper/SessionHelper.php
Expand Up @@ -111,6 +111,7 @@ public function check($name) {
* @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 = []) {
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Console/Command/CompletionShellTest.php
Expand Up @@ -151,7 +151,7 @@ public function testOptions() {
$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);
}

Expand Down
52 changes: 26 additions & 26 deletions tests/TestCase/Console/Command/Task/TemplateTaskTest.php
Expand Up @@ -49,52 +49,52 @@ public function tearDown() {
}

/**
* 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']);
}

/**
Expand All @@ -112,14 +112,14 @@ public function testGenerate() {
}

/**
* 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',
Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase/Console/Command/Task/ViewTaskTest.php
Expand Up @@ -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
*/
Expand Down Expand Up @@ -124,8 +124,8 @@ protected function _setupTask($methods) {
$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/'];
}

/**
Expand Down Expand Up @@ -707,9 +707,9 @@ public function testGetTemplatePrefixed() {
$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);
Expand Down

0 comments on commit 2059ac8

Please sign in to comment.