From 14964d5297764d7eac40295e0e8e1fdcb0571f0b Mon Sep 17 00:00:00 2001 From: Jad Bitar Date: Mon, 20 Apr 2015 21:02:35 -0400 Subject: [PATCH 1/3] Add basic mailer task/templates --- src/Shell/Task/MailerTask.php | 86 +++++++++++ src/Template/Bake/Mailer/mailer.ctp | 33 ++++ tests/TestCase/Shell/BakeShellTest.php | 3 +- tests/TestCase/Shell/Task/MailerTaskTest.php | 151 +++++++++++++++++++ tests/comparisons/Mailer/testBakePlugin.php | 18 +++ 5 files changed, 290 insertions(+), 1 deletion(-) create mode 100644 src/Shell/Task/MailerTask.php create mode 100644 src/Template/Bake/Mailer/mailer.ctp create mode 100644 tests/TestCase/Shell/Task/MailerTaskTest.php create mode 100644 tests/comparisons/Mailer/testBakePlugin.php diff --git a/src/Shell/Task/MailerTask.php b/src/Shell/Task/MailerTask.php new file mode 100644 index 000000000..1305103a4 --- /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 c67fc6bdf..7810da06b 100644 --- a/tests/TestCase/Shell/BakeShellTest.php +++ b/tests/TestCase/Shell/BakeShellTest.php @@ -106,7 +106,7 @@ public function testMain() ->method('out') ->with($this->stringContains('The following commands')); - $this->Shell->expects($this->exactly(16)) + $this->Shell->expects($this->exactly(17)) ->method('out'); $this->Shell->loadTasks(); @@ -144,6 +144,7 @@ public function testLoadTasksCoreAndApp() 'Bake.Controller', 'Bake.Fixture', '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..83d26bf6a --- /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 @@ + Date: Sat, 27 Jun 2015 12:47:24 -0400 Subject: [PATCH 2/3] Update since tags in mailer task. --- src/Shell/Task/MailerTask.php | 2 +- tests/TestCase/Shell/Task/MailerTaskTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Shell/Task/MailerTask.php b/src/Shell/Task/MailerTask.php index 1305103a4..ab31e016e 100644 --- a/src/Shell/Task/MailerTask.php +++ b/src/Shell/Task/MailerTask.php @@ -9,7 +9,7 @@ * * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @since 0.1.0 + * @since 1.1.0 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ namespace Bake\Shell\Task; diff --git a/tests/TestCase/Shell/Task/MailerTaskTest.php b/tests/TestCase/Shell/Task/MailerTaskTest.php index 83d26bf6a..20956c148 100644 --- a/tests/TestCase/Shell/Task/MailerTaskTest.php +++ b/tests/TestCase/Shell/Task/MailerTaskTest.php @@ -9,7 +9,7 @@ * * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @since 0.1.0 + * @since 1.1.0 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ namespace Bake\Test\TestCase\Shell\Task; From a8dbc01285cf0901a6f5b72a384e5c0f3fe2dd11 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 27 Jun 2015 13:02:38 -0400 Subject: [PATCH 3/3] Update composer.json New bake, leans on new CakePHP. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2641cd665..6a21b4498 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ }, "require": { "php": ">=5.4", - "cakephp/cakephp": "dev-master" + "cakephp/cakephp": "3.1.*-dev" }, "require-dev": { "cakephp/cakephp-codesniffer": "dev-master",