From a091c630d703a8ca9a04f0922e4825b50fa8ab49 Mon Sep 17 00:00:00 2001 From: Rick Guyer Date: Wed, 9 Oct 2013 23:18:27 -0500 Subject: [PATCH] Prevent name param from overwriting file if both are passed --- lib/Cake/Console/Command/SchemaShell.php | 2 +- .../Case/Console/Command/SchemaShellTest.php | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Console/Command/SchemaShell.php b/lib/Cake/Console/Command/SchemaShell.php index 223b1179b..f7adcd5e9 100644 --- a/lib/Cake/Console/Command/SchemaShell.php +++ b/lib/Cake/Console/Command/SchemaShell.php @@ -67,7 +67,7 @@ class SchemaShell extends AppShell { $name = $this->params['name'] = $splitName; } - if ($name) { + if ($name && empty($this->params['file'])) { $this->params['file'] = Inflector::underscore($name); } diff --git a/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php b/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php index 512d9b1bf..9568b1381 100644 --- a/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php @@ -585,6 +585,42 @@ class SchemaShellTest extends CakeTestCase { CakePlugin::unload(); } +/** + * test that passing name and file creates the passed filename with the + * passed classname + * + * @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. *