diff --git a/src/Shell/Task/MailerTask.php b/src/Shell/Task/MailerTask.php new file mode 100644 index 000000000..ab31e016e --- /dev/null +++ b/src/Shell/Task/MailerTask.php @@ -0,0 +1,86 @@ +bakeLayouts($name); + return parent::bake($name); + } + + /** + * Bake empty layout files for html/text emails. + * + * @param string $name The name of the mailer layouts are needed for. + * @return void + */ + public function bakeLayouts($name) + { + $restore = $this->pathFragment; + $layoutsPath = implode(DS, ['Template', 'Layout', 'Email']); + + foreach (['html', 'text'] as $type) { + $this->pathFragment = implode(DS, [$layoutsPath, $type, Inflector::underscore($name) . '.ctp']); + $path = $this->getPath(); + $this->createFile($path, ''); + } + + $this->pathFragment = $restore; + } +} diff --git a/src/Template/Bake/Mailer/mailer.ctp b/src/Template/Bake/Mailer/mailer.ctp new file mode 100644 index 000000000..822d38945 --- /dev/null +++ b/src/Template/Bake/Mailer/mailer.ctp @@ -0,0 +1,33 @@ +<% +/** + * 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 0.1.0 + * @license http://www.opensource.org/licenses/mit-license.php MIT License + */ +%> +\Mailer; + +use Cake\Mailer\Mailer; + +/** + * <%= $name %> mailer. + */ +class <%= $name %>Mailer extends Mailer +{ + + /** + * Mailer's name. + * + * @var string + */ + static public $name = '<%= $name %>'; +} diff --git a/tests/TestCase/Shell/BakeShellTest.php b/tests/TestCase/Shell/BakeShellTest.php index c093f58b3..d85638082 100644 --- a/tests/TestCase/Shell/BakeShellTest.php +++ b/tests/TestCase/Shell/BakeShellTest.php @@ -125,6 +125,7 @@ public function testMain() '- fixture', '- form', '- helper', + '- mailer', '- model', '- plugin', '- shell', @@ -169,6 +170,7 @@ public function testLoadTasksCoreAndApp() 'Bake.Fixture', 'Bake.Form', 'Bake.Helper', + 'Bake.Mailer', 'Bake.Model', 'Bake.Plugin', 'Bake.Shell', diff --git a/tests/TestCase/Shell/Task/MailerTaskTest.php b/tests/TestCase/Shell/Task/MailerTaskTest.php new file mode 100644 index 000000000..20956c148 --- /dev/null +++ b/tests/TestCase/Shell/Task/MailerTaskTest.php @@ -0,0 +1,151 @@ +_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Mailer' . DS; + $io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false); + + $this->Task = $this->getMock( + 'Bake\Shell\Task\MailerTask', + ['in', 'err', 'createFile', '_stop'], + [$io] + ); + $this->Task->Test = $this->getMock( + 'Bake\Shell\Task\TestTask', + [], + [$io] + ); + $this->Task->BakeTemplate = new BakeTemplateTask($io); + $this->Task->BakeTemplate->initialize(); + $this->Task->BakeTemplate->interactive = false; + } + + /** + * Test the excute method. + * + * @return void + */ + public function testMain() + { + $this->Task->Test->expects($this->once()) + ->method('bake') + ->with('mailer', 'Example'); + + $this->Task->expects($this->at(0)) + ->method('createFile') + ->with( + $this->_normalizePath(APP . 'Template/Layout/Email/html/example.ctp'), + '' + ); + $this->Task->expects($this->at(1)) + ->method('createFile') + ->with( + $this->_normalizePath(APP . 'Template/Layout/Email/text/example.ctp'), + '' + ); + $this->Task->expects($this->at(2)) + ->method('createFile') + ->with( + $this->_normalizePath(APP . 'Mailer/ExampleMailer.php'), + $this->stringContains('class ExampleMailer extends Mailer') + ); + + $this->Task->main('Example'); + } + + /** + * Test main within a plugin. + * + * @return void + */ + public function testMainPlugin() + { + $this->_loadTestPlugin('TestBake'); + $path = Plugin::path('TestBake'); + + $this->Task->expects($this->at(0)) + ->method('createFile') + ->with( + $this->_normalizePath($path . 'src/Template/Layout/Email/html/example.ctp'), + '' + ); + $this->Task->expects($this->at(1)) + ->method('createFile') + ->with( + $this->_normalizePath($path . 'src/Template/Layout/Email/text/example.ctp'), + '' + ); + $this->Task->expects($this->at(2)) + ->method('createFile') + ->with( + $this->_normalizePath($path . 'src/Mailer/ExampleMailer.php'), + $this->stringContains('class ExampleMailer extends Mailer') + ); + + $this->Task->main('TestBake.Example'); + } + + /** + * Test baking within a plugin. + * + * @return void + */ + public function testBakePlugin() + { + $this->_loadTestPlugin('TestBake'); + $path = Plugin::path('TestBake'); + + $this->Task->plugin = 'TestBake'; + $this->Task->expects($this->at(0)) + ->method('createFile') + ->with( + $this->_normalizePath($path . 'src/Template/Layout/Email/html/example.ctp'), + '' + ); + $this->Task->expects($this->at(1)) + ->method('createFile') + ->with( + $this->_normalizePath($path . 'src/Template/Layout/Email/text/example.ctp'), + '' + ); + $this->Task->expects($this->at(2)) + ->method('createFile') + ->with( + $this->_normalizePath($path . 'src/Mailer/ExampleMailer.php'), + $this->stringContains('class ExampleMailer extends Mailer') + ); + + $result = $this->Task->bake('Example'); + $this->assertSameAsFile(__FUNCTION__ . '.php', $result); + } +} diff --git a/tests/comparisons/Mailer/testBakePlugin.php b/tests/comparisons/Mailer/testBakePlugin.php new file mode 100644 index 000000000..d5ad913ee --- /dev/null +++ b/tests/comparisons/Mailer/testBakePlugin.php @@ -0,0 +1,18 @@ +