Browse Source

'yii\mail\MessageInterface' methods renamed: 'text' to 'textBody', 'html' to 'htmlBody'

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
104cfd7cb2
  1. 4
      extensions/swiftmailer/yii/swiftmailer/Message.php
  2. 16
      framework/yii/mail/BaseMailer.php
  3. 4
      framework/yii/mail/MessageInterface.php
  4. 16
      tests/unit/extensions/swiftmailer/MessageTest.php
  5. 24
      tests/unit/framework/mail/BaseMailerTest.php
  6. 4
      tests/unit/framework/mail/BaseMessageTest.php

4
extensions/swiftmailer/yii/swiftmailer/Message.php

@ -97,7 +97,7 @@ class Message extends BaseMessage
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function text($text) public function textBody($text)
{ {
$this->setBody($text, 'text/plain'); $this->setBody($text, 'text/plain');
return $this; return $this;
@ -106,7 +106,7 @@ class Message extends BaseMessage
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function html($html) public function htmlBody($html)
{ {
$this->setBody($html, 'text/html'); $this->setBody($html, 'text/html');
return $this; return $this;

16
framework/yii/mail/BaseMailer.php

@ -52,8 +52,8 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
* - 'cc' argument for [[MessageInterface::cc()]] * - 'cc' argument for [[MessageInterface::cc()]]
* - 'bcc' argument for [[MessageInterface::bcc()]] * - 'bcc' argument for [[MessageInterface::bcc()]]
* - 'subject' argument for [[MessageInterface::subject()]] * - 'subject' argument for [[MessageInterface::subject()]]
* - 'text' argument for [[MessageInterface::text()]] * - 'textBody' argument for [[MessageInterface::textBody()]]
* - 'html' argument for [[MessageInterface::html()]] * - 'htmlBody' argument for [[MessageInterface::htmlBody()]]
* For example: * For example:
* ~~~ * ~~~
* array( * array(
@ -115,15 +115,15 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
$params['message'] = $message; $params['message'] = $message;
if (is_array($view)) { if (is_array($view)) {
if (array_key_exists('html', $view)) { if (array_key_exists('html', $view)) {
$message->html($this->render($view['html'], $params, $this->htmlLayout)); $message->htmlBody($this->render($view['html'], $params, $this->htmlLayout));
} }
if (array_key_exists('text', $view)) { if (array_key_exists('text', $view)) {
$message->text($this->render($view['text'], $params, $this->textLayout)); $message->textBody($this->render($view['text'], $params, $this->textLayout));
} }
} else { } else {
$html = $this->render($view, $params, $this->htmlLayout); $html = $this->render($view, $params, $this->htmlLayout);
$message->html($html); $message->htmlBody($html);
$message->text(strip_tags($html)); $message->textBody(strip_tags($html));
} }
} }
return $message; return $message;
@ -147,8 +147,8 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
'cc', 'cc',
'bcc', 'bcc',
'subject', 'subject',
'text', 'textBody',
'html', 'htmlBody',
]; ];
$directSetterConfig = []; $directSetterConfig = [];
foreach ($config as $name => $value) { foreach ($config as $name => $value) {

4
framework/yii/mail/MessageInterface.php

@ -87,14 +87,14 @@ interface MessageInterface
* @param string $text message plain text content. * @param string $text message plain text content.
* @return static self reference. * @return static self reference.
*/ */
public function text($text); public function textBody($text);
/** /**
* Sets message HTML content. * Sets message HTML content.
* @param string $html message HTML content. * @param string $html message HTML content.
* @return static self reference. * @return static self reference.
*/ */
public function html($html); public function htmlBody($html);
/** /**
* Attaches existing file to the email message. * Attaches existing file to the email message.

16
tests/unit/extensions/swiftmailer/MessageTest.php

@ -160,7 +160,7 @@ class MessageTest extends VendorTestCase
$message->to($this->testEmailReceiver); $message->to($this->testEmailReceiver);
$message->from('someuser@somedomain.com'); $message->from('someuser@somedomain.com');
$message->subject('Yii Swift Test'); $message->subject('Yii Swift Test');
$message->text('Yii Swift Test body'); $message->textBody('Yii Swift Test body');
$this->assertTrue($message->send()); $this->assertTrue($message->send());
} }
@ -174,7 +174,7 @@ class MessageTest extends VendorTestCase
$message->to($this->testEmailReceiver); $message->to($this->testEmailReceiver);
$message->from('someuser@somedomain.com'); $message->from('someuser@somedomain.com');
$message->subject('Yii Swift Attach File Test'); $message->subject('Yii Swift Attach File Test');
$message->text('Yii Swift Attach File Test body'); $message->textBody('Yii Swift Attach File Test body');
$fileName = __FILE__; $fileName = __FILE__;
$message->attach($fileName); $message->attach($fileName);
@ -195,7 +195,7 @@ class MessageTest extends VendorTestCase
$message->to($this->testEmailReceiver); $message->to($this->testEmailReceiver);
$message->from('someuser@somedomain.com'); $message->from('someuser@somedomain.com');
$message->subject('Yii Swift Create Attachment Test'); $message->subject('Yii Swift Create Attachment Test');
$message->text('Yii Swift Create Attachment Test body'); $message->textBody('Yii Swift Create Attachment Test body');
$fileName = 'test.txt'; $fileName = 'test.txt';
$fileContent = 'Test attachment content'; $fileContent = 'Test attachment content';
$message->attachContent($fileContent, ['fileName' => $fileName]); $message->attachContent($fileContent, ['fileName' => $fileName]);
@ -221,7 +221,7 @@ class MessageTest extends VendorTestCase
$message->to($this->testEmailReceiver); $message->to($this->testEmailReceiver);
$message->from('someuser@somedomain.com'); $message->from('someuser@somedomain.com');
$message->subject('Yii Swift Embed File Test'); $message->subject('Yii Swift Embed File Test');
$message->html('Embed image: <img src="' . $cid. '" alt="pic">'); $message->htmlBody('Embed image: <img src="' . $cid. '" alt="pic">');
$this->assertTrue($message->send()); $this->assertTrue($message->send());
@ -247,7 +247,7 @@ class MessageTest extends VendorTestCase
$message->to($this->testEmailReceiver); $message->to($this->testEmailReceiver);
$message->from('someuser@somedomain.com'); $message->from('someuser@somedomain.com');
$message->subject('Yii Swift Embed File Test'); $message->subject('Yii Swift Embed File Test');
$message->html('Embed image: <img src="' . $cid. '" alt="pic">'); $message->htmlBody('Embed image: <img src="' . $cid. '" alt="pic">');
$this->assertTrue($message->send()); $this->assertTrue($message->send());
@ -267,8 +267,8 @@ class MessageTest extends VendorTestCase
$message->to($this->testEmailReceiver); $message->to($this->testEmailReceiver);
$message->from('someuser@somedomain.com'); $message->from('someuser@somedomain.com');
$message->subject('Yii Swift Alternative Body Test'); $message->subject('Yii Swift Alternative Body Test');
$message->html('<b>Yii Swift</b> test HTML body'); $message->htmlBody('<b>Yii Swift</b> test HTML body');
$message->text('Yii Swift test plain text body'); $message->textBody('Yii Swift test plain text body');
$this->assertTrue($message->send()); $this->assertTrue($message->send());
@ -300,7 +300,7 @@ class MessageTest extends VendorTestCase
$message->to($this->testEmailReceiver); $message->to($this->testEmailReceiver);
$message->from('someuser@somedomain.com'); $message->from('someuser@somedomain.com');
$message->subject('Yii Swift Alternative Body Test'); $message->subject('Yii Swift Alternative Body Test');
$message->text('Yii Swift test plain text body'); $message->textBody('Yii Swift test plain text body');
$serializedMessage = serialize($message); $serializedMessage = serialize($message);
$this->assertNotEmpty($serializedMessage, 'Unable to serialize message!'); $this->assertNotEmpty($serializedMessage, 'Unable to serialize message!');

24
tests/unit/framework/mail/BaseMailerTest.php

@ -115,8 +115,8 @@ class BaseMailerTest extends TestCase
'cc' => 'cc@domain.com', 'cc' => 'cc@domain.com',
'bcc' => 'bcc@domain.com', 'bcc' => 'bcc@domain.com',
'subject' => 'Test subject', 'subject' => 'Test subject',
'text' => 'Test text body', 'textBody' => 'Test text body',
'html' => 'Test HTML body', 'htmlBody' => 'Test HTML body',
]; ];
$propertyConfig = [ $propertyConfig = [
'id' => 'test-id', 'id' => 'test-id',
@ -201,12 +201,12 @@ class BaseMailerTest extends TestCase
'html' => $htmlViewName, 'html' => $htmlViewName,
'text' => $textViewName, 'text' => $textViewName,
]); ]);
$this->assertEquals($htmlViewFileContent, $message->_html, 'Unable to render html!'); $this->assertEquals($htmlViewFileContent, $message->_htmlBody, 'Unable to render html!');
$this->assertEquals($textViewFileContent, $message->_text, 'Unable to render text!'); $this->assertEquals($textViewFileContent, $message->_textBody, 'Unable to render text!');
$message = $mailer->compose($htmlViewName); $message = $mailer->compose($htmlViewName);
$this->assertEquals($htmlViewFileContent, $message->_html, 'Unable to render html by direct view!'); $this->assertEquals($htmlViewFileContent, $message->_htmlBody, 'Unable to render html by direct view!');
$this->assertEquals(strip_tags($htmlViewFileContent), $message->_text, 'Unable to render text by direct view!'); $this->assertEquals(strip_tags($htmlViewFileContent), $message->_textBody, 'Unable to render text by direct view!');
} }
} }
@ -237,8 +237,8 @@ class Message extends BaseMessage
public $_cc; public $_cc;
public $_bcc; public $_bcc;
public $_subject; public $_subject;
public $_text; public $_textBody;
public $_html; public $_htmlBody;
public function charset($charset) public function charset($charset)
{ {
@ -276,15 +276,15 @@ class Message extends BaseMessage
return $this; return $this;
} }
public function text($text) public function textBody($text)
{ {
$this->_text = $text; $this->_textBody = $text;
return $this; return $this;
} }
public function html($html) public function htmlBody($html)
{ {
$this->_html = $html; $this->_htmlBody = $html;
return $this; return $this;
} }

4
tests/unit/framework/mail/BaseMessageTest.php

@ -97,11 +97,11 @@ class TestMessage extends BaseMessage
public function subject($subject) {} public function subject($subject) {}
public function text($text) { public function textBody($text) {
$this->text = $text; $this->text = $text;
} }
public function html($html) { public function htmlBody($html) {
$this->html = $html; $this->html = $html;
} }

Loading…
Cancel
Save