diff --git a/CHANGELOG.md b/CHANGELOG.md index d0c282e..1047baa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/Module.php b/src/Module.php index a8cbfe6..f08f8c1 100644 --- a/src/Module.php +++ b/src/Module.php @@ -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."); } } @@ -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) { diff --git a/tests/controllers/DefaultControllerTest.php b/tests/controllers/DefaultControllerTest.php index fd3f373..c4e224f 100644 --- a/tests/controllers/DefaultControllerTest.php +++ b/tests/controllers/DefaultControllerTest.php @@ -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'], @@ -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 */