-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from cakephp/1.1-Mailer
1.1 mailer
- Loading branch information
Showing
5 changed files
with
290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* 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 1.1.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Bake\Shell\Task; | ||
|
||
use Cake\Utility\Inflector; | ||
|
||
/** | ||
* Mailer code generator. | ||
*/ | ||
class MailerTask extends SimpleBakeTask | ||
{ | ||
/** | ||
* Task name used in path generation. | ||
* | ||
* @var string | ||
*/ | ||
public $pathFragment = 'Mailer/'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function name() | ||
{ | ||
return 'mailer'; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function fileName($name) | ||
{ | ||
return $name . 'Mailer.php'; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function template() | ||
{ | ||
return 'Mailer/mailer'; | ||
} | ||
|
||
/** | ||
* Bake the Mailer class and html/text layout files. | ||
* | ||
* @param string $name The name of the mailer to make. | ||
* @return void | ||
*/ | ||
public function bake($name) | ||
{ | ||
$this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
*/ | ||
%> | ||
<?php | ||
namespace <%= $namespace %>\Mailer; | ||
|
||
use Cake\Mailer\Mailer; | ||
|
||
/** | ||
* <%= $name %> mailer. | ||
*/ | ||
class <%= $name %>Mailer extends Mailer | ||
{ | ||
|
||
/** | ||
* Mailer's name. | ||
* | ||
* @var string | ||
*/ | ||
static public $name = '<%= $name %>'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
/** | ||
* 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 1.1.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Bake\Test\TestCase\Shell\Task; | ||
|
||
use Bake\Shell\Task\BakeTemplateTask; | ||
use Bake\Test\TestCase\TestCase; | ||
use Cake\Core\Configure; | ||
use Cake\Core\Plugin; | ||
|
||
/** | ||
* MailerTaskTest class | ||
*/ | ||
class MailerTaskTest extends TestCase | ||
{ | ||
/** | ||
* setup method | ||
* | ||
* @return void | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->_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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
namespace TestBake\Mailer; | ||
|
||
use Cake\Mailer\Mailer; | ||
|
||
/** | ||
* Example mailer. | ||
*/ | ||
class ExampleMailer extends Mailer | ||
{ | ||
|
||
/** | ||
* Mailer's name. | ||
* | ||
* @var string | ||
*/ | ||
static public $name = 'Example'; | ||
} |