ソースを参照

cleanup and minor fixes

euromark 12 年 前
コミット
ebf25c80d2

+ 1 - 1
Console/Command/CopyShell.php

@@ -478,7 +478,7 @@ class CopyShell extends AppShell {
 			$this->out('');
 			$this->_exec(false, array('--version'));
 		}
-		$this->_stop();
+		return $this->_stop();
 	}
 
 	/**

+ 1 - 1
Console/Command/IndexShell.php

@@ -231,7 +231,7 @@ class IndexShell extends AppShell {
 			$continue = strtoupper($this->in(__('Run this statement?'), array('Y', 'N', 'A', 'Q')));
 			switch ($continue) {
 				case 'Q':
-					$this->_stop();
+					return $this->_stop();
 					return;
 				case 'N':
 					return;

+ 2 - 0
Lib/EmailLib.php

@@ -16,6 +16,7 @@ if (!defined('BR')) {
  * - create mails with blob attachments (embedded or attached)
  * - allow wrapLength to be adjusted
  * - Configure::read('Config.x-mailer') can modify the x-mailer
+ * - basic validation supported
  *
  * @author Mark Scherer
  * @license MIT
@@ -238,6 +239,7 @@ class EmailLib extends CakeEmail {
 
 	/**
 	 * Validate if the email has the required fields necessary to make send() work.
+	 * Assumes layouting (does not check on content to be present or if view/layout files are missing).
 	 *
 	 * @return boolean Success
 	 */

+ 21 - 0
Lib/Utility/TextLib.php

@@ -17,6 +17,27 @@ class TextLib extends String {
 	}
 
 	/**
+	 * Count words in a text.
+	 *
+	 * //TODO use str_word_count() instead!!!
+	 *
+	 * @param string $text
+	 * @return int
+	 * 2009-11-11 ms
+	 */
+	public static function numberOfWords($text) {
+		$count = 0;
+		$words = explode(' ', $text);
+		foreach ($words as $word) {
+			$word = trim($word);
+			if (!empty($word)) {
+				$count++;
+			}
+		}
+		return $count;
+	}
+
+	/**
 	 * Return an abbreviated string, with characters in the middle of the
 	 * excessively long string replaced by $ending.
 	 *

+ 36 - 0
Test/Case/Lib/EmailLibTest.php

@@ -18,11 +18,21 @@ class EmailLibTest extends MyCakeTestCase {
 		$this->Email = new TestEmailLib();
 	}
 
+	/**
+	 * EmailLibTest::testObject()
+	 *
+	 * @return void
+	 */
 	public function testObject() {
 		$this->assertTrue(is_object($this->Email));
 		$this->assertInstanceOf('EmailLib', $this->Email);
 	}
 
+	/**
+	 * EmailLibTest::testSendDefault()
+	 *
+	 * @return void
+	 */
 	public function testSendDefault() {
 		# start
 		$this->Email->to(Configure::read('Config.admin_email'), Configure::read('Config.admin_emailname'));
@@ -54,6 +64,11 @@ class EmailLibTest extends MyCakeTestCase {
 		$this->assertTrue($res);
 	}
 
+	/**
+	 * EmailLibTest::testSendFast()
+	 *
+	 * @return void
+	 */
 	public function testSendFast() {
 		//$this->Email->resetAndSet();
 		//$this->Email->from(Configure::read('Config.admin_email'), Configure::read('Config.admin_emailname'));
@@ -62,6 +77,11 @@ class EmailLibTest extends MyCakeTestCase {
 		$this->assertTrue($res);
 	}
 
+	/**
+	 * EmailLibTest::testXMailer()
+	 *
+	 * @return void
+	 */
 	public function testXMailer() {
 		$this->Email = new TestEmailLib();
 		$this->Email->from('cake@cakephp.org');
@@ -260,6 +280,8 @@ class EmailLibTest extends MyCakeTestCase {
 
 	/**
 	 * html email
+	 *
+	 * @return void
 	 */
 	public function testAddEmbeddedAttachmentSend() {
 		$file = CakePlugin::path('Tools').'Test'.DS.'test_files'.DS.'img'.DS.'hotel.png';
@@ -344,21 +366,35 @@ html-part
 		$this->assertEquals($expected, $res['my_other_hotel.png']);
 	}
 
+	/**
+	 * EmailLibTest::testValidates()
+	 *
+	 * @return void
+	 */
 	public function testValidates() {
+		$this->Email = new TestEmailLib();
 		$res = $this->Email->validates();
 		$this->assertFalse($res);
+		$res = $this->Email->send();
+		$this->assertFalse($res);
 
 		$this->Email->subject('foo');
 		$res = $this->Email->validates();
 		$this->assertFalse($res);
+		$res = $this->Email->send();
+		$this->assertFalse($res);
 
 		$this->Email->to('some@web.de');
 		$res = $this->Email->validates();
 		$this->assertTrue($res);
+		$res = $this->Email->send();
+		$this->assertTrue($res);
 	}
 
 	/**
 	 * html email
+	 *
+	 * @return void
 	 */
 	public function testAddEmbeddedBlobAttachmentSend() {
 		$file = CakePlugin::path('Tools').'Test'.DS.'test_files'.DS.'img'.DS.'hotel.png';