Skip to content

Commit

Permalink
add option for callable mailTitle and mailText closes #23
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Apr 8, 2019
1 parent 73b03f3 commit 21b9bc3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file. This project make usage of the [Yii Versioning Strategy](https://github.com/yiisoft/yii2/blob/master/docs/internals/versions.md).

## 1.0.11 (in progress)
## 1.0.11 (8. April 2019)

+ [#23](https://github.com/luyadev/luya-module-contactform/issues/23) Added new modelClass propertie to define a path to a given model instead of define the model on-th-fly.

Expand Down
6 changes: 3 additions & 3 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ public function init()
parent::init();

if (!$this->modelClass && $this->attributes === null) {
throw new Exception("The attributes attributed must be defined with an array of available attributes.");
throw new Exception("The `attributes` property must be defined with an array of available attributes.");
}

if ($this->recipients === null) {
throw new Exception("The recipients attributed must be defined with an array of recipients who will recieve an email.");
throw new Exception("The `recipients` property must be defined with an array of recipients who will recieve an email.");
}
}

Expand Down Expand Up @@ -253,7 +253,7 @@ public function getMailTitle()
/**
* Setter method fro $mailTitle.
*
* @param string $title The mail title text.
* @param string|callable $title The mail title text.
*/
public function setMailTitle($title)
{
Expand Down
25 changes: 25 additions & 0 deletions tests/controllers/DefaultControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ public function getConfigArray()
'attributes' => ['firstname', 'lastname', 'email'],
'recipients' => 'test@luya.io',
],
'contactcallable' => [
'class' => 'luya\contactform\Module',
'attributes' => ['firstname', 'lastname', 'email'],
'recipients' => 'test@luya.io',
'mailText' => function() {
return 'callable text';
},
'mailTitle' => function() {
return 'callable title';
}
],
'callableform' => [
'class' => 'luya\contactform\Module',
'attributes' => ['firstname', 'lastname', 'email'],
Expand Down Expand Up @@ -54,6 +65,20 @@ public function testStringRecipient()
$this->assertSame(['test@luya.io'], $ctrl->ensureRecipients($model));
}

public function testClosureTextAndTitle()
{
$mod = new Module('contact', null, ['modelClass' => 'app/models/Stuff', 'recipients' => 'none']);
$mod->mailTitle = function() {
return 'mailtitle';
};
$mod->mailText = function() {
return 'mailtext';
};

$this->assertSame('mailtitle', $mod->mailTitle);
$this->assertSame('mailtext', $mod->mailText);
}

/**
* @runInSeparateProcess
*/
Expand Down

0 comments on commit 21b9bc3

Please sign in to comment.