Skip to content

Commit

Permalink
Fixed bug with wrong declared new line chars. closes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Jun 4, 2018
1 parent ed83b12 commit 42f7105
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 20 additions & 17 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 34 additions & 4 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <p> 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
* <h2>Hello</h2>
* <p>Paragraph</p>
* <ul>
* <li>foo</li>
* <li>bar</li>
* </ul>
* ```
*/
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 <p> 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 `<h2>{title}</h2><p><i>{time}</i></p>{text}\n{table}\n{footer}` with variables:
* @var string The template which is used to render the email. Default template is `<h2>{title}</h2><p><i>{time}</i></p>{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 <p> tag.
* @since 1.0.8
*/
public $mailTemplate = '<h2>{title}</h2><p><i>{time}</i></p>{text}\n{table}\n{footer}';
public $mailTemplate = "<h2>{title}</h2><p><i>{time}</i></p>{text}{table}{footer}";

/**
* @inheritdoc
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
}

Expand Down
14 changes: 14 additions & 0 deletions tests/controllers/DefaultControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,18 @@ public function testModuleMailTemplateProperty()
$ctrl = new DefaultController('default', $module);
$this->assertSame('<p>foo-bar</p>', $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('<h2>Hello</h2><p>Paragraph</p><ul><li>foo</li><li>bar</li></ul><table id="w5" style="width:100%" cellpadding="5" cellpsacing="2" border="0"><tr><th width="150" style="border-bottom:1px solid #F0F0F0">Foo</th><td style="border-bottom:1px solid #F0F0F0">bar</td></tr></table>', $ctrl->generateMailMessage($model));
}
}

0 comments on commit 42f7105

Please sign in to comment.