Allow setting only default layout without specifying template in email config.

Closes #3336
This commit is contained in:
ADmad 2014-04-22 19:50:18 +05:30
parent bd5ce96388
commit ead494eec1
2 changed files with 26 additions and 7 deletions

View file

@ -1224,15 +1224,14 @@ class CakeEmail {
$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);
}

View file

@ -1807,6 +1807,26 @@ class CakeEmailTest extends CakeTestCase {
$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
*