ソースを参照

documentation improvement and test case

euromark 12 年 前
コミット
dc994073b9
2 ファイル変更41 行追加7 行削除
  1. 14 6
      Lib/EmailLib.php
  2. 27 1
      Test/Case/Lib/EmailLibTest.php

+ 14 - 6
Lib/EmailLib.php

@@ -9,10 +9,9 @@ if (!defined('BR')) {
 
 /**
  * Convenience class for internal mailer.
- * Adds some nice features and fixes some bugs:
+ * Adds some useful features and fixes some bugs:
+ * - enable easier attachment adding (and also from blob)
  * - enable embedded images in html mails
- * - allow setting domain for CLI environment (now in core)
- * - enable easier attachment adding
  * - extensive logging and error tracing
  * - create mails with blob attachments (embedded or attached)
  * - allow wrapLength to be adjusted
@@ -43,10 +42,14 @@ class EmailLib extends CakeEmail {
 	}
 
 	/**
-	 * quick way to send emails to admin
+	 * Quick way to send emails to admin.
 	 * App::uses() + EmailLib::systemEmail()
 	 *
 	 * Note: always go out with default settings (e.g.: SMTP even if debug > 0)
+	 *
+	 * @param string $subject
+	 * @param string $message
+	 * @param string $transportConfig
 	 * @return bool $success
 	 * 2011-10-31 ms
 	 */
@@ -463,7 +466,7 @@ class EmailLib extends CakeEmail {
 	 * Set the body of the mail as we send it.
 	 * Note: the text can be an array, each element will appear as a seperate line in the message body.
 	 *
-	 * LEAVE empty if you use $this->set() in combination with templates
+	 * Do NOT pass a message if you use $this->set() in combination with templates
 	 *
 	 * @overwrite
 	 * @param string/array: message
@@ -531,18 +534,22 @@ class EmailLib extends CakeEmail {
 	 * Set/Get wrapLength
 	 *
 	 * @param int $length Must not be more than CakeEmail::LINE_LENGTH_MUST
-	 * @return void|int
+	 * @return int|CakeEmail
 	 */
 	public function wrapLength($length = null) {
 		if ($length === null) {
 			return $this->_wrapLength;
 		}
 		$this->_wrapLength = $length;
+		return $this;
 	}
 
 	/**
 	 * Fix line length
+	 *
 	 * @overwrite
+	 * @param string $message Message to wrap
+	 * @return array Wrapped message
 	 */
 	protected function _wrap($message, $wrapLength = CakeEmail::LINE_LENGTH_MUST) {
 		if ($this->_wrapLength !== null) {
@@ -553,6 +560,7 @@ class EmailLib extends CakeEmail {
 
 	/**
 	 * Logs Email to type email
+	 *
 	 * @return void
 	 */
 	protected function _logEmail($append = null) {

+ 27 - 1
Test/Case/Lib/EmailLibTest.php

@@ -13,7 +13,6 @@ class EmailLibTest extends MyCakeTestCase {
 
 	public function setUp() {
 		parent::setUp();
-
 		$this->skipIf(!file_exists(APP . 'Config' . DS . 'email.php'), 'no email.php');
 
 		$this->Email = new TestEmailLib();
@@ -63,6 +62,33 @@ class EmailLibTest extends MyCakeTestCase {
 		$this->assertTrue($res);
 	}
 
+	public function testXMailer() {
+		$this->Email = new TestEmailLib();
+		$this->Email->from('cake@cakephp.org');
+		$this->Email->to('cake@cakephp.org');
+		$this->Email->subject('My title');
+		$this->Email->emailFormat('both');
+
+		$result = $this->Email->send();
+		$this->assertTrue($result);
+		$result = $this->Email->getDebug();
+		$this->assertTextContains('X-Mailer: CakePHP Email', $result['headers']);
+
+		Configure::write('Config.x-mailer', 'Tools Plugin');
+
+		$this->Email = new TestEmailLib();
+		$this->Email->from('cake@cakephp.org');
+		$this->Email->to('cake@cakephp.org');
+		$this->Email->subject('My title');
+		$this->Email->emailFormat('both');
+
+		$result = $this->Email->send();
+		$this->assertTrue($result);
+		$result = $this->Email->getDebug();
+		$this->assertTextNotContains('X-Mailer: CakePHP Email', $result['headers']);
+		$this->assertTextContains('X-Mailer: Tools Plugin', $result['headers']);
+	}
+
 	public function _testSendWithInlineAttachments() {
 		$this->Email = new TestEmailLib();
 		$this->Email->transport('debug');