From c48c0d62950d28e0c0cb01cfb25bef3b21cc0529 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 23 Aug 2010 21:49:30 -0400 Subject: [PATCH] Fixing issue where ViewTask would make empty view files for actions that did not have templates. Test case added. Fixes #1040 --- cake/console/libs/tasks/view.php | 3 +++ cake/tests/cases/console/libs/tasks/view.test.php | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/cake/console/libs/tasks/view.php b/cake/console/libs/tasks/view.php index 2ebffc733..7ccc74072 100644 --- a/cake/console/libs/tasks/view.php +++ b/cake/console/libs/tasks/view.php @@ -366,6 +366,9 @@ class ViewTask extends BakeTask { if ($content === true) { $content = $this->getContent($action); } + if (empty($content)) { + return false; + } $path = $this->getPath(); $filename = $path . $this->controllerPath . DS . Inflector::underscore($action) . '.ctp'; return $this->createFile($filename, $content); diff --git a/cake/tests/cases/console/libs/tasks/view.test.php b/cake/tests/cases/console/libs/tasks/view.test.php index 12f9d79d7..405b00a9a 100644 --- a/cake/tests/cases/console/libs/tasks/view.test.php +++ b/cake/tests/cases/console/libs/tasks/view.test.php @@ -374,6 +374,19 @@ class ViewTaskTest extends CakeTestCase { $this->Task->bake('index', true); } +/** + * test that baking a view with no template doesn't make a file. + * + * @return void + */ + function testBakeWithNoTemplate() { + $this->Task->controllerName = 'ViewTaskComments'; + $this->Task->controllerPath = 'view_task_comments'; + + $this->Task->expectNever('createFile'); + $this->Task->bake('delete', true); + } + /** * test bake() with a -plugin param *