From 42f710546bfa5a5d193a0a66f3d2ff84aa9da969 Mon Sep 17 00:00:00 2001 From: Basil Suter Date: Mon, 4 Jun 2018 10:59:13 +0200 Subject: [PATCH] Fixed bug with wrong declared new line chars. closes #17 --- CHANGELOG.md | 4 +++ composer.lock | 37 +++++++++++--------- src/Module.php | 38 ++++++++++++++++++--- src/controllers/DefaultController.php | 2 +- tests/controllers/DefaultControllerTest.php | 14 ++++++++ 5 files changed, 73 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 090a62b..82895d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ 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.8.1 (4. June 2018) + ++ [#17](https://github.com/luyadev/luya-module-contactform/issues/17) Fixed bug with wrong declared new line chars. + ## 1.0.8 (22. May 2018) + [#16](https://github.com/luyadev/luya-module-contactform/issues/16) Added option to configure footer message and mail template. diff --git a/composer.lock b/composer.lock index 72789e2..c6bea2b 100644 --- a/composer.lock +++ b/composer.lock @@ -225,16 +225,16 @@ }, { "name": "curl/curl", - "version": "1.9.0", + "version": "1.9.1", "source": { "type": "git", "url": "https://github.com/php-mod/curl.git", - "reference": "d4970cf3451de7688b90af77299548ada72b53dd" + "reference": "958363d1fed599aa24efb2221e2c1e6c61711464" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-mod/curl/zipball/d4970cf3451de7688b90af77299548ada72b53dd", - "reference": "d4970cf3451de7688b90af77299548ada72b53dd", + "url": "https://api.github.com/repos/php-mod/curl/zipball/958363d1fed599aa24efb2221e2c1e6c61711464", + "reference": "958363d1fed599aa24efb2221e2c1e6c61711464", "shasum": "" }, "require": { @@ -276,7 +276,7 @@ "curl", "dot" ], - "time": "2018-05-02T16:32:35+00:00" + "time": "2018-05-23T20:32:06+00:00" }, { "name": "doctrine/instantiator", @@ -541,16 +541,16 @@ }, { "name": "luyadev/luya-core", - "version": "1.0.8", + "version": "1.0.9", "source": { "type": "git", "url": "https://github.com/luyadev/luya-core.git", - "reference": "393af7540a371dba40929545bc3b82acc9dddd17" + "reference": "449fd840937e88a0f7a013770c544c61a959df41" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/luyadev/luya-core/zipball/393af7540a371dba40929545bc3b82acc9dddd17", - "reference": "393af7540a371dba40929545bc3b82acc9dddd17", + "url": "https://api.github.com/repos/luyadev/luya-core/zipball/449fd840937e88a0f7a013770c544c61a959df41", + "reference": "449fd840937e88a0f7a013770c544c61a959df41", "shasum": "" }, "require": { @@ -594,7 +594,7 @@ "yii", "yii2" ], - "time": "2018-05-14T11:08:07+00:00" + "time": "2018-06-01T10:03:31+00:00" }, { "name": "luyadev/luya-module-admin", @@ -788,25 +788,28 @@ }, { "name": "myclabs/deep-copy", - "version": "1.7.0", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e" + "reference": "478465659fd987669df0bd8a9bf22a8710e5f1b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/478465659fd987669df0bd8a9bf22a8710e5f1b6", + "reference": "478465659fd987669df0bd8a9bf22a8710e5f1b6", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" }, "require-dev": { "doctrine/collections": "^1.0", "doctrine/common": "^2.6", - "phpunit/phpunit": "^4.1" + "phpunit/phpunit": "^7.1" }, "type": "library", "autoload": { @@ -829,7 +832,7 @@ "object", "object graph" ], - "time": "2017-10-19T19:58:43+00:00" + "time": "2018-05-29T17:25:09+00:00" }, { "name": "phpdocumentor/reflection-common", diff --git a/src/Module.php b/src/Module.php index 5475ea2..2cc3ae8 100644 --- a/src/Module.php +++ b/src/Module.php @@ -115,26 +115,56 @@ class Module extends \luya\base\Module public $sendToUserEmail = false; /** - * @var string Markdown enabled text which can be prepand to the e-mail sent body. + * @var string An optional mail text which is displayed above the table with the form values. The text will be parsed with markdown and is therfore enclosed with a

tag. + * + * An example of how to use markdown and newlines in a string: + * + * ```php + * 'mailText' => "## Hello\nParagraph\n+ foo\n+ bar", + * ``` + * + * Which would be equals to: + * + * ```php + * 'mailText' => ' + * ## Hello + * Paragraph + * + foo + * + bar + * ``` + * + * And would renderd in the email as followed: + * + * ```php + *

Hello

+ *

Paragraph

+ * + * ``` */ public $mailText; /** - * @var string An optional text which is displayed as footer in the email message. + * @var string An optional text which is displayed as footer in the email message. The text will be parsed with markdown and is therfore enclosed with a

tag. + * @see {{luya\contactform\Module::$mailText}} * @since 1.0.8 */ public $mailFooterText; /** - * @var string The template which is used to render the email. Default template is `

{title}

{time}

{text}\n{table}\n{footer}` with variables: + * @var string The template which is used to render the email. Default template is `

{title}

{time}

{text}{table}{footer}` with variables: * + title: Value from $mailTitle * + time: Contains the timestamp of when the email is sent. * + text: Value from $mailText * + table: The attributes with the values from the user input. * + footer: Value from $mailFooterText + * + * Keep in mind the {text} and {footer} variables will be parsed with {{luya\TagParsers::convertWithMarkdown()}} and is therefore enclosed with a

tag. * @since 1.0.8 */ - public $mailTemplate = '

{title}

{time}

{text}\n{table}\n{footer}'; + public $mailTemplate = "

{title}

{time}

{text}{table}{footer}"; /** * @inheritdoc diff --git a/src/controllers/DefaultController.php b/src/controllers/DefaultController.php index fdbee21..ed9ac8d 100644 --- a/src/controllers/DefaultController.php +++ b/src/controllers/DefaultController.php @@ -108,7 +108,7 @@ public function generateMailMessage(Model $model) 'title' => $this->module->mailTitle, 'text' => TagParser::convertWithMarkdown($this->module->mailText), 'template' => $this->module->mailTemplate, - 'footerText' => $this->module->mailFooterText, + 'footerText' => TagParser::convertWithMarkdown($this->module->mailFooterText), ]); } diff --git a/tests/controllers/DefaultControllerTest.php b/tests/controllers/DefaultControllerTest.php index 0e68437..cd50f84 100644 --- a/tests/controllers/DefaultControllerTest.php +++ b/tests/controllers/DefaultControllerTest.php @@ -136,4 +136,18 @@ public function testModuleMailTemplateProperty() $ctrl = new DefaultController('default', $module); $this->assertSame('

foo-bar

', $ctrl->generateMailMessage($model)); } + + /** + * @see https://github.com/luyadev/luya-module-contactform/issues/17 + */ + public function testGenericEmailTemplateOutput() + { + $model = new DynamicModel(['foo']); + $model->foo = 'bar'; + + $module = Yii::$app->getModule('contactform'); + $module->mailText = "## Hello\nParagraph\n+ foo\n+ bar"; + $ctrl = new DefaultController('default', $module); + $this->assertContainsTrimmed('

Hello

Paragraph

Foobar
', $ctrl->generateMailMessage($model)); + } }