Skip to content

Commit

Permalink
Allow setting only default layout without specifying template in emai…
Browse files Browse the repository at this point in the history
…l config.

Closes #3336
  • Loading branch information
ADmad committed Apr 22, 2014
1 parent bd5ce96 commit ead494e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/Cake/Network/Email/CakeEmail.php
Expand Up @@ -1224,15 +1224,14 @@ protected function _applyConfig($config) {
$this->setHeaders($config['headers']);
unset($config['headers']);
}

if (array_key_exists('template', $config)) {
$layout = false;
if (array_key_exists('layout', $config)) {
$layout = $config['layout'];
unset($config['layout']);
}
$this->template($config['template'], $layout);
unset($config['template']);
$this->_template = $config['template'];
}
if (array_key_exists('layout', $config)) {
$this->_layout = $config['layout'];
}

$this->transportClass()->config($config);
}

Expand Down
20 changes: 20 additions & 0 deletions lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
Expand Up @@ -1807,6 +1807,26 @@ public function testConstructWithConfigArray() {
$this->assertTrue((bool)strpos($result['headers'], 'To: '));
}

/**
* testConfigArrayWithLayoutWithoutTemplate method
*
* @return void
*/
public function testConfigArrayWithLayoutWithoutTemplate() {
$configs = array(
'from' => array('some@example.com' => 'My website'),
'to' => 'test@example.com',
'subject' => 'Test mail subject',
'transport' => 'Debug',
'layout' => 'custom'
);
$this->CakeEmail = new CakeEmail($configs);

$result = $this->CakeEmail->template();
$this->assertEquals('', $result['template']);
$this->assertEquals($configs['layout'], $result['layout']);
}

/**
* testConstructWithConfigString method
*
Expand Down

0 comments on commit ead494e

Please sign in to comment.