ソースを参照

added missing test cases

euromark 14 年 前
コミット
ab9af245e9

+ 21 - 0
Test/Case/Behavior/ConfirmableBehaviorTest.php

@@ -0,0 +1,21 @@
+<?php
+
+App::uses('ConfirmableBehavior', 'Tools.Model/Behavior');
+App::uses('ModelBehavior', 'Model');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+
+class ConfirmableBehaviorTest extends MyCakeTestCase {
+
+	public $ConfirmableBehavior;
+
+	public function startTest() {
+		$this->ConfirmableBehavior = new ConfirmableBehavior();
+	}
+
+	public function testObject() {
+		$this->assertTrue(is_object($this->ConfirmableBehavior));
+		$this->assertIsA($this->ConfirmableBehavior, 'ConfirmableBehavior');
+	}
+
+	//TODO
+}

+ 119 - 0
Test/Case/Behavior/DecimalInputBehaviorTest.php

@@ -0,0 +1,119 @@
+<?php
+
+App::import('Behavior', 'Tools.DecimalInput');
+App::import('Model', 'App');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+
+
+class DecimalInputBehaviorTest extends MyCakeTestCase {
+
+	public function startTest() {
+		//$this->Comment = ClassRegistry::init('Comment');
+		$this->Comment = new TestModel();
+		$this->Comment->Behaviors->attach('Tools.DecimalInput', array('fields'=>array('rel_rate', 'set_rate'), 'output'=>true));
+	}
+
+	public function setUp() {
+
+	}
+
+	public function tearDown() {
+
+	}
+
+	public function testObject() {
+		$this->assertTrue(is_a($this->Comment->Behaviors->DecimalInput, 'DecimalInputBehavior'));
+	}
+
+
+	public function testBasic() {
+		echo $this->_header(__FUNCTION__);
+		// accuracy >= 5
+		$data = array(
+			'name' => 'some Name',
+			'set_rate' => '0,1',
+			'rel_rate' => '-0,02',
+		);
+		$this->Comment->set($data);
+		$res = $this->Comment->validates();
+		$this->assertTrue($res);
+
+		$res = $this->Comment->data;
+		echo returns($res);
+		$this->assertSame($res['TestModel']['set_rate'], 0.1);
+		$this->assertSame($res['TestModel']['rel_rate'], -0.02);
+	}
+
+	public function testValidates() {
+		echo $this->_header(__FUNCTION__);
+		// accuracy >= 5
+		$data = array(
+			'name' => 'some Name',
+			'set_rate' => '0,1',
+			'rel_rate' => '-0,02',
+		);
+		$this->Comment->set($data);
+		$res = $this->Comment->validates();
+		$this->assertTrue($res);
+
+		$res = $this->Comment->data;
+		echo returns($res);
+		$this->assertSame($res['TestModel']['set_rate'], 0.1);
+		$this->assertSame($res['TestModel']['rel_rate'], -0.02);
+	}
+
+	public function testFind() {
+		echo $this->_header(__FUNCTION__);
+		$res = $this->Comment->find('all', array());
+		$this->assertTrue(!empty($res));
+		echo returns($res);
+		$this->assertSame($res[0]['TestModel']['set_rate'], '0,1');
+		$this->assertSame($res[0]['TestModel']['rel_rate'], '-0,02');
+
+		echo BR.BR;
+
+		$res = $this->Comment->find('first', array());
+		$this->assertTrue(!empty($res));
+		echo returns($res);
+		$this->assertSame($res['TestModel']['set_rate'], '0,1');
+		$this->assertSame($res['TestModel']['rel_rate'], '-0,02');
+
+		$res = $this->Comment->find('count', array());
+		echo returns($res);
+		$this->assertSame($res[0][0]['count'], 2);
+
+	}
+
+}
+
+/** other files **/
+
+class TestModel extends AppModel {
+
+
+	public $alias = 'TestModel';
+	public $useTable = false;
+	public $displayField = 'title';
+
+	public function find($type = null, $options = array(), $customData = null) {
+		$data = array(
+			'name' => 'some Name',
+			'set_rate' => 0.1,
+			'rel_rate' => -0.02,
+		);
+		if ($customData !== null) {
+			$data = $customData;
+		}
+		if ($type == 'count') {
+			$results = array(0=>array(0=>array('count'=>2)));
+		} else {
+			$results = array(0=>array($this->alias=>$data));
+		}
+
+		$results = $this->_filterResults($results);
+		if ($type == 'first') {
+			$results = $this->_findFirst('after', null, $results);
+		}
+		return $results;
+	}
+}

+ 169 - 0
Test/Case/Behavior/MasterPasswordBehaviorTest.php

@@ -0,0 +1,169 @@
+<?php
+
+App::uses('MasterPasswordBehavior', 'Tools.Model/Behavior');
+App::uses('ModelBehavior', 'Model');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+
+Configure::write('MasterPassword.password', '7c4a8d09ca3762af61e59520943dc26494f8941b');
+
+class MasterPasswordBehaviorTest extends MyCakeTestCase {
+
+	public $MasterPasswordBehavior;
+
+	public function setUp() {
+		$this->MasterPasswordBehavior = new MasterPasswordBehavior();
+		$this->Model = ClassRegistry::init('InputTestModel');
+	}
+
+	public function testObject() {
+		$this->assertTrue(is_object($this->MasterPasswordBehavior));
+		$this->assertIsA($this->MasterPasswordBehavior, 'MasterPasswordBehavior');
+	}
+
+	/**
+	 * test 123456
+	 */
+	public function testSinglePwd() {
+		$this->Model->Behaviors->attach('Tools.MasterPassword');
+
+		$data = array(
+			'some_comment' => 'xyz',
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertFalse($res);
+
+		$data = array(
+			'some_comment' => 'xyz',
+			'master_pwd' => ''
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertFalse($res);
+
+		$data = array(
+			'some_comment' => 'xyz',
+			'master_pwd' => '123'
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertFalse($res);
+
+		$data = array(
+			'some_comment' => 'xyz',
+			'master_pwd' => '123456'
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertTrue($res);
+	}
+
+	/**
+	 * test xxzzyy
+	 * with specific settings
+	 */
+	public function testComplex() {
+		Configure::write('MasterPassword.password', '373e28e7cdb42d7aefc49c5f34fa589a7ff1eefd0ac01f573d90299f79a01a05');
+		$this->Model->Behaviors->attach('Tools.MasterPassword', array('field'=>'master_password', 'hash'=>'sha256', 'message'=>'No way'));
+
+		$data = array(
+			'some_comment' => 'xyz',
+			'master_password' => '123'
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertFalse($res);
+		$this->assertEquals(__('No way'), $this->Model->validationErrors['master_password'][0]);
+
+		$data = array(
+			'some_comment' => 'xyz',
+			'master_password' => 'xxyyzz'
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertTrue($res);
+		$this->assertEmpty($this->Model->invalidFields());
+	}
+
+	/**
+	 * test xxzzyy with salt
+	 * with specific settings
+	 */
+	public function testWithSalt() {
+		$hash = hash('sha256', Configure::read('Security.salt').'xxyyzz');
+		Configure::write('MasterPassword.password', $hash);
+		$this->Model->Behaviors->attach('Tools.MasterPassword', array('hash'=>'sha256', 'salt'=>true));
+		$data = array(
+			'some_comment' => 'xyz',
+			'master_pwd' => 'xxyyzz'
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertTrue($res);
+
+		$hash = hash('sha256', '123'.'xxyyzz');
+		Configure::write('MasterPassword.password', $hash);
+		$this->Model->Behaviors->attach('Tools.MasterPassword', array('hash'=>'sha256', 'salt'=>'123'));
+		$data = array(
+			'some_comment' => 'xyz',
+			'master_pwd' => 'xxyyzz'
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertTrue($res);
+	}
+
+	/**
+	 * test 123456 and 654321
+	 */
+	public function testMultiplePwd() {
+		Configure::write('MasterPassword.password', array('dd5fef9c1c1da1394d6d34b248c51be2ad740840', '7c4a8d09ca3762af61e59520943dc26494f8941b'));
+		$this->Model->Behaviors->attach('Tools.MasterPassword');
+
+		$data = array(
+			'some_comment' => 'xyz',
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertFalse($res);
+
+		$data = array(
+			'some_comment' => 'xyz',
+			'master_pwd' => ''
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertFalse($res);
+
+		$data = array(
+			'some_comment' => 'xyz',
+			'master_pwd' => '123'
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertFalse($res);
+
+		$data = array(
+			'some_comment' => 'xyz',
+			'master_pwd' => '123456'
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertTrue($res);
+
+		$data = array(
+			'some_comment' => 'xyz',
+			'master_pwd' => '654321'
+		);
+		$this->Model->set($data);
+		$res = $this->Model->validates();
+		$this->assertTrue($res);
+	}
+
+}
+
+
+class InputTestModel extends CakeTestModel {
+	public $useTable = false;
+
+}

+ 20 - 0
Test/Case/Behavior/SluggedBehaviorTest.php

@@ -0,0 +1,20 @@
+<?php
+
+App::uses('SluggedBehavior', 'Tools.Model/Behavior');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+
+class SluggedBehaviorTest extends MyCakeTestCase {
+
+	public $SluggedBehavior;
+
+	public function startTest() {
+		$this->SluggedBehavior = new SluggedBehavior();
+	}
+
+	public function testObject() {
+		$this->assertTrue(is_object($this->SluggedBehavior));
+		$this->assertIsA($this->SluggedBehavior, 'SluggedBehavior');
+	}
+
+	//TODO
+}

ファイルの差分が大きいため隠しています
+ 1 - 0
Test/Case/Behavior/TypographicBehaviorTest.php


+ 29 - 15
Test/Case/Helper/CaptchaHelperTest.php

@@ -3,32 +3,46 @@
 App::import('Helper', 'Tools.Captcha');
 App::import('Helper', 'Html');
 App::uses('View', 'View');
+App::uses('Controller', 'Controller');
 
 /**
  * 2010-06-24 ms
  */
 class CaptchaHelperTest extends CakeTestCase {
 
-/**
- * setUp method
- */
 	public function setUp() {
-		$this->Captcha = new CaptchaHelper(new View(null));
+		$this->Captcha = new CaptchaHelper(new View(new Controller(new CakeRequest, new CakeResponse)));
 		$this->Captcha->Html = new HtmlHelper(new View(null));
 	}
 
-	/** TODO **/
-
-	public function testXXX() {
-		//TODO
-	}
-
-
-/**
- * tearDown method
- */
 	public function tearDown() {
 		unset($this->Captcha);
 	}
-}
+	
+	
+	/**
+	 * 2011-11-15 ms
+	 */
+	public function testFields() {
+		$is = $this->Captcha->active();
+		pr(h($is));
+		
+		$is = $this->Captcha->passive();
+		pr(h($is));
+		
+		
+		
+		$is = $this->Captcha->captcha('SomeModelName');
+		pr(h($is));
+	}
+	
+	public function testDataInsideHelper() {
+		echo returns($this->Captcha->webroot);
+		echo returns($this->Captcha->request->webroot);
+		
+		echo returns($this->Captcha->data);
+		echo returns($this->Captcha->request->data);
+	}
+
 
+}

+ 126 - 0
Test/Case/Helper/CommonHelperTest.php

@@ -0,0 +1,126 @@
+<?php
+
+App::import('Helper', 'Tools.Common');
+App::uses('View', 'View');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+
+/**
+ * Datetime Test Case
+ *
+ * @package       cake.tests
+ * @subpackage    cake.tests.cases.libs.view.helpers
+ */
+class CommonHelperTest extends MyCakeTestCase {
+/**
+ * setUp method
+ *
+ * @access public
+ * @return void
+ */
+	public function setUp() {
+		$this->Common = new CommonHelper(new View(null));
+	}
+	
+
+	public function testMetaCanonical() {
+		$is = $this->Common->metaCanonical('/some/url/param1');
+		$this->out(h($is));
+		$this->assertEquals('<link rel="canonical" href="/some/url/param1" />', trim($is));
+	}
+	
+	public function testMetaAlternate() {
+		$is = $this->Common->metaAlternate('/some/url/param1', 'de-de');
+		$this->out(h($is));
+		$this->assertEquals('<link href="http://'.HTTP_HOST.'/some/url/param1" rel="alternate" hreflang="de-de" />', trim($is));
+		
+		$is = $this->Common->metaAlternate(array('controller'=>'some', 'action'=>'url'), 'de', true);
+		$this->out(h($is));
+		$this->assertEquals('<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="de" />', trim($is));
+		
+		$is = $this->Common->metaAlternate(array('controller'=>'some', 'action'=>'url'), array('de', 'de-ch'), true);
+		$this->out(h($is));
+		$this->assertEquals('<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="de" />'.PHP_EOL.'<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="de-ch" />', trim($is));
+		
+		$is = $this->Common->metaAlternate(array('controller'=>'some', 'action'=>'url'), array('de' => array('ch', 'at'), 'en'=>array('gb', 'us')), true);
+		$this->out(h($is));
+		$this->assertEquals('<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="de-ch" />'.PHP_EOL.
+			'<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="de-at" />'.PHP_EOL.
+			'<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="en-gb" />'.PHP_EOL.
+			'<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="en-us" />', trim($is));
+	}
+	
+	
+
+	public function testEsc() {
+		$is = $this->Common->esc('Some Cool Text with <b>Html</b>');
+		$this->assertEquals($is, 'Some Cool Text with &lt;b&gt;Html&lt;/b&gt;');
+		
+		$is = $this->Common->esc('Some Cool Text'.PHP_EOL.'with <b>Html</b>');
+		$this->assertEquals($is, 'Some Cool Text<br />'.PHP_EOL.'with &lt;b&gt;Html&lt;/b&gt;');
+		
+		$is = $this->Common->esc('Some Cool'.PHP_EOL.'  2 indends and'.PHP_EOL.'     5 indends'.PHP_EOL.'YEAH');
+		$this->assertEquals($is, 'Some Cool<br />'.PHP_EOL.'&nbsp;&nbsp;2 indends and<br />'.PHP_EOL.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5 indends<br />'.PHP_EOL.'YEAH');
+		
+		$options = array('tabsToSpaces'=>2);
+		$is = $this->Common->esc('Some Cool'.PHP_EOL.TB.'1 tab and'.PHP_EOL.TB.TB.'2 tabs'.PHP_EOL.'YEAH', $options);
+		$this->assertEquals($is, 'Some Cool<br />'.PHP_EOL.'&nbsp;&nbsp;1 tab and<br />'.PHP_EOL.'&nbsp;&nbsp;&nbsp;&nbsp;2 tabs<br />'.PHP_EOL.'YEAH');
+		
+	}
+
+	/**
+	 * test minimizeUrl
+	 *
+	 * @access public
+	 * @return void
+	 * 2009-03-11 ms
+	 */
+	public function testMinimizeUrl() {
+
+		$url = 'http://www.test.de';
+		$this->assertEquals($url, $this->Common->minimizeUrl($url,20));
+
+		$url = 'http://www.test.de';
+		$this->assertEquals($url, $this->Common->minimizeUrl($url,18));
+
+		$url = 'http://www.test.de';
+		$this->assertEquals('www.test.de', $this->Common->minimizeUrl($url,17));
+
+		$url = 'http://www.testpage.de';
+		$this->assertEquals('ww&#8230;ge.de', $this->Common->minimizeUrl($url,10));
+
+		$url = 'http://www.testpage.de';
+		$this->assertEquals('ww...ge.de', $this->Common->minimizeUrl($url,10, array('placeholder'=>'...')));
+
+		# without full http://
+		$url = 'www.testpage.de';
+		$this->assertEquals($url, $this->Common->minimizeUrl($url,15));
+
+		$url = 'www.testpage.de';
+		$this->assertEquals('www.te&#8230;ge.de', $this->Common->minimizeUrl($url,14));
+
+	}
+
+
+	/**
+	 * test shortenText
+	 *
+	 * @access public
+	 * @return void
+	 * 2009-03-11 ms
+	 */
+	public function testShortenText() {
+
+	}
+
+
+/**
+ * tearDown method
+ *
+ * @access public
+ * @return void
+ */
+	public function tearDown() {
+		unset($this->Common);
+	}
+}
+

+ 40 - 0
Test/Case/Helper/FlattrHelperTest.php

@@ -0,0 +1,40 @@
+<?php
+
+App::import('Helper', 'Tools.Flattr');
+App::import('Helper', 'Html');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+App::uses('View', 'View');
+
+class FlattrHelperTest extends MyCakeTestCase {
+	
+	public $uid;
+	
+	public function startTest() {
+		$this->Flattr = new FlattrHelper(new View(null));
+		$this->Flattr->Html = new HtmlHelper(new View(null));
+		
+		$this->uid = '1234';
+	}
+	
+	public function tearDown() {
+		
+	}
+	
+	public function testObject() {
+		$this->assertTrue(is_a($this->Flattr, 'FlattrHelper'));
+	}
+		
+	public function testBadge() {
+		$res = $this->Flattr->badge($this->uid, array());
+		echo $res;
+		$this->assertTrue(!empty($res));
+	}
+	
+	public function testBadgeWithOptions() {
+		$options = array('dsc'=>'Eine Beschreibung', 'lng'=>'de_DE', 'tags'=>array('Spende', 'Geld', 'Hilfe'));
+		
+		$res = $this->Flattr->badge($this->uid, $options);
+		echo $res;
+		$this->assertTrue(!empty($res));
+	}
+}

+ 25 - 0
Test/Case/Helper/FormExtHelperTest.php

@@ -0,0 +1,25 @@
+<?php
+
+App::import('Helper', 'Tools.FormExt');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+App::uses('View', 'View');
+
+class FormExtHelperTest extends MyCakeTestCase {
+	
+	public function setUp() {
+		$this->FormExt = new FormExtHelper(new View(null));
+	}
+	
+	public function tearDown() {
+		
+	}
+	
+	public function testObject() {
+		$this->assertTrue(is_a($this->FormExt, 'FormExtHelper'));
+	}
+		
+	public function testX() {
+		//TODO
+	}
+	
+}

+ 239 - 0
Test/Case/Helper/FormatHelperTest.php

@@ -0,0 +1,239 @@
+<?php
+
+App::import('Helper', 'Tools.Format');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+App::import('Helper', 'Html');
+App::uses('View', 'View');
+
+/**
+ * Datetime Test Case
+ *
+ * @package       cake.tests
+ * @subpackage    cake.tests.cases.libs.view.helpers
+ */
+class FormatHelperTest extends MyCakeTestCase {
+	/**
+	* setUp method
+
+	* @access public
+	* @return void
+	*/
+	public function setUp() {
+		$this->Format = new FormatHelper(new View(null));
+		$this->Format->Html = new HtmlHelper(new View(null));
+	}
+
+
+	/**
+	 * 2009-08-30 ms
+	 */
+	public function testDisabledLink() {
+		$content = 'xyz';
+		$data = array(
+			array(),
+			array('class'=>'disabledLink', 'title'=>false),
+			array('class'=>'helloClass', 'title'=>'helloTitle')
+		);
+		foreach ($data as $key => $value) {
+			$res = $this->Format->disabledLink($content, $value);
+			echo ''.$res.' (\''.h($res).'\')';
+			$this->assertTrue(!empty($res));
+		}
+	}
+
+
+	/**
+	 * 2009-08-30 ms
+	 */
+	public function testWarning() {
+		$content = 'xyz';
+		$data = array(
+			true,
+			false
+		);
+		foreach ($data as $key => $value) {
+			$res = $this->Format->warning($content.' '.(int)$value, $value);
+			echo ''.$res.'';
+			$this->assertTrue(!empty($res));
+		}
+	}
+
+
+	/**
+	 * 2009-08-30 ms
+	 */
+	public function testOk() {
+		$content = 'xyz';
+		$data = array(
+			true,
+			false
+		);
+		foreach ($data as $key => $value) {
+			$res = $this->Format->ok($content.' '.(int)$value, $value);
+			echo ''.$res.'';
+			$this->assertTrue(!empty($res));
+		}
+	}
+
+
+
+	/**
+	 * 2009-08-30 ms
+	 */
+	public function testShortenText() {
+		$data = array(
+			'dfssdfsdj sdkfj sdkfj ksdfj sdkf ksdfj ksdfjsd kfjsdk fjsdkfj ksdjf ksdf jsdsdf',
+			'122 jsdf sjdkf sdfj sdf',
+			'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd',
+			'\';alert(String.fromCharCode(88,83,83))//\';alert(String.fromCharCode(88,83,83))//";alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//--></SCRIPT>">\'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>'
+		);
+		foreach ($data as $key => $value) {
+			$res = $this->Format->shortenText($value, 30);
+
+			echo '\''.h($value).'\' becomes \''.$res.'\'';
+			$this->assertTrue(!empty($res));
+		}
+
+	}
+
+	/**
+	 * 2009-08-30 ms
+	 */
+	public function testTruncate() {
+		$data = array(
+			'dfssdfsdj sdkfj sdkfj ksdfj sdkf ksdfj ksdfjsd kfjsdk fjsdkfj ksdjf ksdf jsdsdf',
+			'122 jsdf sjdkf sdfj sdf',
+			'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd',
+			'\';alert(String.fromCharCode(88,83,83))//\';alert(String.fromCharCode(88,83,83))//";alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//--></SCRIPT>">\'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>'
+		);
+		foreach ($data as $key => $value) {
+			$res = $this->Format->truncate($value, 30);
+
+			echo '\''.h($value).'\' becomes \''.$res.'\'';
+			$this->assertTrue(!empty($res));
+		}
+
+	}
+
+	/**
+	 * 2009-08-30 ms
+	 */
+	public function testHideEmail() {
+		$mails = array(
+			'test@test.de' => 't..t@t..t.de',
+			'xx@yy.de' => 'x..x@y..y.de',
+			'erk-wf@ve-eeervdg.com' => 'e..f@v..g.com',
+		);
+		foreach ($mails as $mail => $expected) {
+			$res = $this->Format->hideEmail($mail);
+
+			echo '\''.$mail.'\' becomes \''.$res.'\' - expected \''.$expected.'\'';
+			$this->assertEquals($res, $expected);
+		}
+
+	}
+
+
+
+	/**
+	 * 2009-08-30 ms
+	 */
+	public function testWordCensor() {
+		$data = array(
+			'dfssdfsdj sdkfj sdkfj ksdfj arsch ksdfj ksdfjsd kfjsdk fjsdkfj ksdjf ksdf jsdsdf',
+			'122 jsdf ficken Sjdkf sdfj sdf',
+			'122 jsdf FICKEN sjdkf sdfj sdf',
+			'ddddddddddddddddddddddddd ARSCH dddddddddddddddddddddddddddddddddddddddddddddddddd',
+			'\';alert(String.fromCharCode(88,83,83))//\';alert(String.fromCharCode(88,83,83))//";alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//--></SCRIPT>">\'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>'
+		);
+		foreach ($data as $key => $value) {
+			$res = $this->Format->wordCensor($value, array('Arsch', 'Ficken'));
+
+			echo '\''.h($value).'\' becomes \''.h($res).'\'';
+			$this->assertTrue(!empty($res));
+		}
+
+	}
+
+
+/**
+ * 2009-03-11 ms
+ */
+/*
+	public function testReverseAscii() {
+		$is = $this->Format->reverseAscii('f&eacute;s');
+		$expected = 'fés';
+		$this->assertEquals($expected, $is);
+
+
+		$is = entDec('f&eacute;s');
+		$expected = 'fés';
+		$this->assertEquals($expected, $is);
+
+		$is = html_entity_decode('f&eacute;s');
+		$expected = 'fés';
+		$this->assertEquals($expected, $is);
+
+		#TODO: correct it + more
+
+	}
+*/
+
+	/**
+	 * 2009-03-11 ms
+	 */
+/*
+	public function testDecodeEntities() {
+		$is = $this->Format->decodeEntities('f&eacute;s');
+		$expected = 'fés';
+		$this->assertEquals($expected, $is);
+
+	}
+*/
+
+	public function testTab2space() {
+		echo '<h2>'.__FUNCTION__.'</h2>';
+		
+		$text  = "foo\t\tfoobar\tbla\n";
+		$text .= "fooo\t\tbar\t\tbla\n";
+		$text .= "foooo\t\tbar\t\tbla\n";
+		echo "<pre>" . $text . "</pre>";
+		echo'becomes';
+		echo "<pre>" . $this->Format->tab2space($text) . "</pre>";
+		
+	}
+	
+
+	public function testArray2table() {
+		echo '<h2>'.__FUNCTION__.'</h2>';
+		$array = array(
+			array('x'=>'0', 'y'=>'0.5', 'z'=>'0.9'),
+			array('1', '2', '3'),
+			array('4', '5', '6'),
+		);
+
+		$is = $this->Format->array2table($array);
+		echo $is;
+		//$this->assertEquals($expected, $is);
+
+		# recursive?
+		$array = array(
+			array('a'=>array('2'), 'b'=>array('2'), 'c'=>array('2')),
+			array(array('2'), array('2'), array('2')),
+			array(array('2'), array('2'), array(array('s'=>'3', 't'=>'4'))),
+		);
+
+		$is = $this->Format->array2table($array, array('recursive'=>true));
+		echo $is;
+	}
+
+/**
+ * tearDown method
+ *
+ * @access public
+ * @return void
+ */
+	public function tearDown() {
+		unset($this->Format);
+	}
+}

+ 91 - 0
Test/Case/Helper/NumericHelperTest.php

@@ -0,0 +1,91 @@
+<?php
+
+App::import('Helper', 'Tools.Numeric');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+App::uses('View', 'View');
+/**
+ * Numeric Test Case
+ *
+ * @package       cake.tests
+ * @subpackage    cake.tests.cases.libs.view.helpers
+ */
+class NumericHelperTest extends MyCakeTestCase {
+/**
+ * setUp method
+ *
+ * @access public
+ * @return void
+ */
+	public function setUp() {
+		$this->Numeric = new NumericHelper(new View(null));
+	}
+
+
+/**
+ * test cweek
+ *
+ * @access public
+ * @return void
+ * 2009-03-11 ms
+ */
+	public function testFormat() {
+		$is = $this->Numeric->format('22');
+		$expected = '22,00';
+		$this->assertEquals($expected, $is);
+		
+		$is = $this->Numeric->format('22.30', 1);
+		$expected = '22,3';
+		$this->assertEquals($expected, $is);
+		
+		$is = $this->Numeric->format('22.30', -1);
+		$expected = '20';
+		$this->assertEquals($expected, $is);
+		
+		$is = $this->Numeric->format('22.30', -2);
+		$expected = '0';
+		$this->assertEquals($expected, $is);
+		
+		$is = $this->Numeric->format('22.30', 3);
+		$expected = '22,300';
+		$this->assertEquals($expected, $is);
+
+		$is = $this->Numeric->format('abc', 2);
+		$expected = '---';
+		$this->assertEquals($expected, $is);
+		
+		$is = $this->Numeric->format('12.2', 'a');
+		$expected = '12,20';
+		$this->assertEquals($expected, $is);
+		
+		$is = $this->Numeric->format('22.3', 2, array('before'=>'EUR '));
+		$expected = 'EUR 22,30';
+		$this->assertEquals($expected, $is);
+
+		$is = $this->Numeric->format('22.3', 2, array('after'=>' EUR'));
+		$expected = '22,30 EUR';
+		$this->assertEquals($expected, $is);
+		
+		$is = $this->Numeric->format('22.3', 2, array('after'=>'x','before'=>'v'));
+		$expected = 'v22,30x';
+		$this->assertEquals($expected, $is);
+		
+		#TODO: more		
+		
+		
+		
+	}
+
+
+
+
+/**
+ * tearDown method
+ *
+ * @access public
+ * @return void
+ */
+	public function tearDown() {
+		unset($this->Numeric);
+	}
+}
+

+ 158 - 0
Test/Case/Helper/QrCodeHelperTest.php

@@ -0,0 +1,158 @@
+<?php
+
+if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
+	define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
+
+}
+
+define('QR_TEST_STRING', 'Some Text to Translate');
+define('QR_TEST_STRING_UTF', 'Some äöü Test String with $ and @ etc');
+
+App::import('Helper', 'Html');
+App::import('Helper', 'Tools.QrCode');
+App::uses('View', 'View');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+
+/**
+ * QrCode Test Case
+ *
+ * @package       cake.tests
+ * @subpackage    cake.tests.cases.libs.view.helpers
+ */
+class QrCodeHelperTest extends MyCakeTestCase {
+/**
+ * setUp method
+ *
+ * @access public
+ * @return void
+ */
+	public function setUp() {
+		$this->QrCode = new QrCodeHelper(new View(null));
+		$this->QrCode->Html = new HtmlHelper(new View(null));
+	}
+
+
+	/**
+	 * @access public
+	 * @return void
+	 * 2009-07-30 ms
+	 */
+	public function testSetSize() {
+		$is = $this->QrCode->setSize(1000);
+		pr($this->QrCode->debug());
+		$this->assertFalse($is);
+
+		$is = $this->QrCode->setSize(300);
+		pr($this->QrCode->debug());
+		$this->assertTrue($is);
+
+
+
+	}
+
+
+	/**
+	 * @access public
+	 * @return void
+	 * 2009-07-30 ms
+	 */
+	public function testImages() {
+		$this->QrCode->reset();
+
+		$is = $this->QrCode->image(QR_TEST_STRING);
+		echo $is;
+		$this->assertTrue(!empty($is));
+
+		$is = $this->QrCode->image(QR_TEST_STRING_UTF);
+		echo $is;
+		$this->assertTrue(!empty($is));
+
+		$is = $this->QrCode->image('');
+		echo $is;
+		$this->assertTrue(!empty($is));
+
+	}
+
+
+	/**
+	 * @access public
+	 * @return void
+	 * 2009-07-30 ms
+	 */
+	public function testImagesModified() {
+		$this->QrCode->reset();
+		$this->QrCode->setLevel('H');
+		$is = $this->QrCode->image(QR_TEST_STRING);
+		echo $is;
+		$this->assertTrue(!empty($is));
+
+		$this->QrCode->reset();
+		$this->QrCode->setLevel('H', 20);
+		$is = $this->QrCode->image(QR_TEST_STRING_UTF);
+		echo $is;
+		$this->assertTrue(!empty($is));
+
+
+		$this->QrCode->reset();
+		$this->QrCode->setSize(300);
+		$this->QrCode->setLevel('L', 1);
+		$is = $this->QrCode->image(QR_TEST_STRING);
+		echo $is;
+		pr($this->QrCode->debug());
+		$this->assertTrue(!empty($is));
+
+		$this->QrCode->reset();
+		$this->QrCode->setSize(300);
+		$this->QrCode->setLevel('H', 1);
+		$is = $this->QrCode->image(QR_TEST_STRING);
+		echo $is;
+		pr($this->QrCode->debug());
+		$this->assertTrue(!empty($is));
+	}
+
+	public function testSpecialImages() {
+		$this->QrCode->reset();
+		$this->QrCode->setSize(300);
+		$this->QrCode->setLevel('H');
+		echo 'CARD'.BR;
+		$string = $this->QrCode->formatCard(array(
+			'name' => 'Maier,Susanne',
+			'tel' => array('0111222123', '012224344'),
+			'nickname' => 'sssnick',
+			'birthday' => '1999-01-03',
+			'address' => 'Bluetenweg 11, 85375, Neufahrn, Deutschland',
+			'email' => 'test@test.de',
+			'note' => 'someNote;someOtherNote :)',
+			'url' => 'http://www.some_url.de'
+		));
+		$is = $this->QrCode->image($string);
+		echo $is;
+		$this->assertTrue(!empty($is));
+	}
+
+ 	/**
+ 	 * 2011-07-19 ms
+ 	 */
+	public function testBitcoin() {
+		$this->QrCode->reset();
+		$this->QrCode->setSize(100);
+		$this->QrCode->setLevel('H');
+		echo 'CARD'.BR;
+		$string = $this->QrCode->format('bitcoin', '18pnDgDYFMAKsHTA3ZqyAi6t8q9ztaWWXt');
+		$is = $this->QrCode->image($string);
+		echo $is;
+		$this->assertTrue(!empty($is));
+
+	}
+
+/**
+ * tearDown method
+ *
+ * @access public
+ * @return void
+ */
+	public function tearDown() {
+		unset($this->QrCode);
+	}
+}
+

+ 70 - 0
Test/Case/Helper/TypographyHelperTest.php

@@ -0,0 +1,70 @@
+<?php
+App::uses('TypographyHelper', 'Tools.View/Helper');
+App::uses('View', 'View');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+
+/**
+ * TypographyHelper Test Case
+ *
+ */
+class TypographyHelperTest extends MyCakeTestCase {
+	
+	public $Typography;
+	
+/**
+ * setUp method
+ *
+ * @return void
+ */
+	public function setUp() {
+		parent::setUp();
+
+		$this->Typography = new TypographyHelper(new View(null));
+	}
+
+/**
+ * tearDown method
+ *
+ * @return void
+ */
+	public function tearDown() {
+		unset($this->Typography);
+
+		parent::tearDown();
+	}
+
+/**
+ * testAutoTypography method
+ *
+ * @return void
+ */
+	public function testAutoTypography() {
+		$str = 'Some \'funny\' and "funky" test with a new
+		
+paragraph and a
+	new line tabbed in.';
+		
+		$res = $this->Typography->autoTypography($str);
+		$this->out($res);
+		$this->out(h($res));
+	}
+
+/**
+ * testFormatCharacter method
+ *
+ * @return void
+ */
+	public function testFormatCharacter() {
+
+	}
+
+/**
+ * testNl2brExceptPre method
+ *
+ * @return void
+ */
+	public function testNl2brExceptPre() {
+
+	}
+
+}

ファイルの差分が大きいため隠しています
+ 1 - 0
Test/Case/Lib/ChmodLibTest.php


+ 404 - 0
Test/Case/Lib/DatetimeLibTest.php

@@ -0,0 +1,404 @@
+<?php
+
+App::uses('DatetimeLib', 'Tools.Lib');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+
+class DatetimeLibTest extends MyCakeTestCase {
+
+	public $Datetime;
+
+	public function setUp() {
+		$this->Datetime = new DatetimeLib();
+		$this->assertTrue(is_object($this->Datetime));
+	}
+
+
+	public function tearDown() {
+		unset($this->Datetime);
+	}
+
+	public function testParse() {
+		$this->out($this->_header(__FUNCTION__));
+		
+		$ret = $this->Datetime->parseDate('15-Feb-2009', 'j-M-Y', 'start');
+		pr($ret);
+		$this->assertEquals($ret, '2009-02-15 00:00:00');
+		
+		# problem when not passing months or days as well - no way of knowing how exact the date was
+		$ret = $this->Datetime->parseDate('2009', 'Y', 'start');
+		pr($ret);
+		//$this->assertEquals($ret, '2009-01-01 00:00:00');
+		$ret = $this->Datetime->parseDate('Feb 2009', 'M Y', 'start');
+		pr($ret);
+		//$this->assertEquals($ret, '2009-02-01 00:00:00');
+		
+		
+		$values = array(
+			array(__('Today'), array(date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y'))), date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y'))))),
+			array('2010', array('2010-01-01 00:00:00', '2010-12-31 23:59:59')),
+			array('23.02.2011', array('2011-02-23 00:00:00', '2011-02-23 23:59:59')),
+			array('22/02/2011', array('2011-02-22 00:00:00', '2011-02-22 23:59:59')),
+			array('3/2/11', array('2011-02-03 00:00:00', '2011-02-03 23:59:59')),
+			array('2/12/9', array('2009-12-02 00:00:00', '2009-12-02 23:59:59')),
+			array('12/2009', array('2009-12-01 00:00:00', '2009-12-31 23:59:59')),
+		);
+		foreach ($values as $v) {
+			$ret = $this->Datetime->parseDate($v[0], null, 'start');
+			pr($ret);
+			$this->assertEquals($ret, $v[1][0]);
+			
+			$ret = $this->Datetime->parseDate($v[0], null, 'end');
+			pr($ret);
+			$this->assertEquals($ret, $v[1][1]);
+		}
+	}
+
+
+	public function testPeriod() {
+		$this->out($this->_header(__FUNCTION__));
+		$values = array(
+			array(__('Today'), array(date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y'))), date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y'))))),
+			
+			array('2010', array('2010-01-01 00:00:00', '2010-12-31 23:59:59')),
+			array('2011-02', array('2011-02-01 00:00:00', '2011-02-28 23:59:59')),
+			array('2012-02', array('2012-02-01 00:00:00', '2012-02-29 23:59:59')),
+			array('2010-02-23', array('2010-02-23 00:00:00', '2010-02-23 23:59:59')),
+			array('2010-02-23 bis 2010-02-26', array('2010-02-23 00:00:00', '2010-02-26 23:59:59')),
+			//array('2010-02-23 11:11:11 bis 2010-02-23 11:12:01', array('2010-02-23 11:11:11', '2010-02-23 11:12:01')),
+			# localized
+			array('23.02.2011', array('2011-02-23 00:00:00', '2011-02-23 23:59:59')),
+			array('23.2.2010 bis 26.2.2011', array('2010-02-23 00:00:00', '2011-02-26 23:59:59')),
+		);
+		
+		foreach ($values as $v) {
+			$ret = $this->Datetime->period($v[0]);
+			pr($ret);
+			$this->assertEquals($ret, $v[1]);
+			
+		}
+	}
+	
+	public function testPeriodAsSql() {
+		$this->out($this->_header(__FUNCTION__));
+		$values = array(
+			array(__('Today'), "(Model.field >= '".date(FORMAT_DB_DATE)." 00:00:00') AND (Model.field <= '".date(FORMAT_DB_DATE)." 23:59:59')"),
+			array(__('Yesterday').' '.__('until').' '.__('Today'), "(Model.field >= '".date(FORMAT_DB_DATE, time()-DAY)." 00:00:00') AND (Model.field <= '".date(FORMAT_DB_DATE)." 23:59:59')"),
+			array(__('Tomorrow').' '.__('until').' '.__('The day after tomorrow'), "(Model.field >= '".date(FORMAT_DB_DATE, time()+DAY)." 00:00:00') AND (Model.field <= '".date(FORMAT_DB_DATE, time()+2*DAY)." 23:59:59')"),
+		);
+		
+		foreach ($values as $v) {
+			$ret = $this->Datetime->periodAsSql($v[0], 'Model.field');
+			pr($ret);
+			$this->assertEquals($ret, $v[1]);
+			
+		}
+	}
+
+
+	public function testDifference() {
+		$this->out($this->_header(__FUNCTION__));
+		$values = array(
+			array('2010-02-23 11:11:11', '2010-02-23 11:12:01', 50),
+			array('2010-02-23 11:11:11', '2010-02-24 11:12:01', DAY+50)
+		);
+		
+		foreach ($values as $v) {
+			$ret = $this->Datetime->difference($v[0], $v[1]);
+			$this->assertEquals($ret, $v[2]);
+		}
+	}
+	
+	public function testAgeBounds() {
+		$this->out($this->_header(__FUNCTION__));
+		$values = array(
+			array(20, 20, array('min'=>'1990-07-07', 'max'=>'1991-07-06')),
+			array(10, 30, array('min'=>'1980-07-07', 'max'=>'2001-07-06')),
+			array(11, 12, array('min'=>'1998-07-07', 'max'=>'2000-07-06'))
+		);
+		
+		foreach ($values as $v) {
+			echo $v[0].'/'.$v[1];
+			$ret = $this->Datetime->ageBounds($v[0], $v[1], true, '2011-07-06'); //TODO: relative time
+			pr($ret);
+			if (isset($v[2])) {
+				$this->assertSame($ret, $v[2]);
+				pr($this->Datetime->age($v[2]['min']));
+				pr($this->Datetime->age($v[2]['max']));
+				$this->assertEquals($v[0], $this->Datetime->age($v[2]['max']));
+				$this->assertEquals($v[1], $this->Datetime->age($v[2]['min']));
+			}
+		}
+	}
+		
+	public function testAgeByYear() {
+		$this->out($this->_header(__FUNCTION__));
+		
+		# year only
+		$is = $this->Datetime->ageByYear(2000);
+		$this->out($is);
+		$this->assertEquals($is, (date('Y')-2001).'/'.(date('Y')-2000));
+		
+		$is = $this->Datetime->ageByYear(1985);
+		$this->assertEquals($is, (date('Y')-1986).'/'.(date('Y')-1985));
+		
+		# with month
+		if (($month = date('n')+1) <= 12) {
+			$is = $this->Datetime->ageByYear(2000, $month);
+			$this->out($is);
+			//$this->assertEquals($is, (date('Y')-2001).'/'.(date('Y')-2000), null, '2000/'.$month);
+			$this->assertEquals($is, (date('Y')-2001), null, '2000/'.$month);
+		}
+		
+		if (($month = date('n')-1) >= 1) {
+			$is = $this->Datetime->ageByYear(2000, $month);
+			$this->out($is);
+			//$this->assertEquals($is, (date('Y')-2001).'/'.(date('Y')-2000), null, '2000/'.$month);
+			$this->assertEquals($is, (date('Y')-2000), null, '2000/'.$month);
+		}
+	}
+	
+	
+	public function testDaysInMonth() {
+		$this->out($this->_header(__FUNCTION__));
+		
+		$ret = $this->Datetime->daysInMonth('2004', '3');
+		$this->assertEquals($ret, 31);
+		
+		$ret = $this->Datetime->daysInMonth('2006', '4');
+		$this->assertEquals($ret, 30);
+		
+		$ret = $this->Datetime->daysInMonth('2007', '2');
+		$this->assertEquals($ret, 28);
+		
+		$ret = $this->Datetime->daysInMonth('2008', '2');
+		$this->assertEquals($ret, 29);	
+	}	
+	
+	public function testDay() {
+		$this->out($this->_header(__FUNCTION__));
+		$ret = $this->Datetime->day('0');
+		$this->assertEquals(__('Sunday'), $ret);
+		
+		$ret = $this->Datetime->day(2, true);
+		$this->assertEquals(__('Tue'), $ret);
+		
+		$ret = $this->Datetime->day(6);
+		$this->assertEquals(__('Saturday'), $ret);
+		
+		$ret = $this->Datetime->day(6, false, 1);
+		$this->assertEquals(__('Sunday'), $ret);
+		
+		$ret = $this->Datetime->day(0, false, 2);
+		$this->assertEquals(__('Tuesday'), $ret);
+		
+		$ret = $this->Datetime->day(1, false, 6);
+		$this->assertEquals(__('Sunday'), $ret);
+	}
+	
+	public function testMonth() {
+		$this->out($this->_header(__FUNCTION__));
+		$ret = $this->Datetime->month('11');
+		$this->assertEquals(__('November'), $ret);
+		
+		$ret = $this->Datetime->month(1);
+		$this->assertEquals(__('January'), $ret);
+		
+		$ret = $this->Datetime->month(2, true, array('appendDot'=>true));
+		$this->assertEquals(__('Feb').'.', $ret);
+		
+		$ret = $this->Datetime->month(5, true, array('appendDot'=>true));
+		$this->assertEquals(__('May'), $ret);
+	}
+	
+	public function testDays() {
+		$this->out($this->_header(__FUNCTION__));
+		$ret = $this->Datetime->days();
+		$this->assertTrue(count($ret) === 7);
+	}
+	
+	public function testMonths() {
+		$this->out($this->_header(__FUNCTION__));
+		$ret = $this->Datetime->months();
+		$this->assertTrue(count($ret) === 12);
+	}
+	
+	
+	public function testRelLengthOfTime() {
+		$this->out($this->_header(__FUNCTION__));
+		
+		$ret = $this->Datetime->relLengthOfTime('1990-11-20');
+		pr($ret);
+		
+		$ret = $this->Datetime->relLengthOfTime('2012-11-20');
+		pr($ret);
+	}
+	
+	public function testLengthOfTime() {
+		$this->out($this->_header(__FUNCTION__));
+		
+		$ret = $this->Datetime->lengthOfTime(60);
+		pr($ret);
+		
+		# FIX ME! Doesn't work!
+		$ret = $this->Datetime->lengthOfTime(-60);
+		pr($ret);
+		
+		$ret = $this->Datetime->lengthOfTime(-121);
+		pr($ret);
+	}
+	
+	public function testFuzzyFromOffset() {
+		$this->out($this->_header(__FUNCTION__));
+		
+		$ret = $this->Datetime->fuzzyFromOffset(MONTH);
+		pr($ret);
+		
+		$ret = $this->Datetime->fuzzyFromOffset(120);
+		pr($ret);
+		
+		$ret = $this->Datetime->fuzzyFromOffset(DAY);
+		pr($ret);
+		
+		$ret = $this->Datetime->fuzzyFromOffset(DAY+2*MINUTE);
+		pr($ret);
+		
+		# FIX ME! Doesn't work!
+		$ret = $this->Datetime->fuzzyFromOffset(-DAY);
+		pr($ret);
+	}	
+	
+	public function testCweekMod() {
+	
+	}
+
+	public function testCweekDay() {
+		$this->out($this->_header(__FUNCTION__));
+		
+		# wednesday
+		$ret = $this->Datetime->cweekDay(51, 2011, 2);
+		$this->out('51, 2011, 2');
+		$this->out(date(FORMAT_DB_DATETIME, $ret));
+		$this->assertEquals(1324422000, $ret);
+	}
+	
+	public function testCweeks() {
+		$this->out($this->_header(__FUNCTION__));
+		$ret = $this->Datetime->cweeks('2004');
+		$this->assertEquals($ret, 53);
+		
+		$ret = $this->Datetime->cweeks('2010');
+		$this->assertEquals($ret, 52);
+		
+		$ret = $this->Datetime->cweeks('2006');
+		$this->assertEquals($ret, 52);
+		
+		$ret = $this->Datetime->cweeks('2007');
+		$this->assertEquals($ret, 52);
+		/*
+		for ($i = 1990; $i < 2020; $i++) {
+			$this->out($this->Datetime->cweeks($i).BR;
+		}
+		*/
+	}
+	
+	public function testCweekBeginning() {
+		$this->out($this->_header(__FUNCTION__));
+		$values = array(
+			'2001' => 978303600, # Mon 01.01.2001, 00:00
+			'2006' => 1136156400, # Mon 02.01.2006, 00:00
+			'2010' => 1262559600, # Mon 04.01.2010, 00:00
+			'2013' => 1356908400, # Mon 31.12.2012, 00:00
+		);
+		foreach ($values as $year => $expected) {
+			$ret = $this->Datetime->cweekBeginning($year);
+			$this->out($ret);
+			$this->out($this->Datetime->niceDate($ret, 'D').' '.$this->Datetime->niceDate($ret, FORMAT_NICE_YMDHMS));
+			$this->assertEquals($ret, $expected, null, $year);
+		}
+		
+		$values = array(
+			array('2001', '1', 978303600), # Mon 01.01.2001, 00:00:00
+			array('2001', '2', 978908400), # Mon 08.01.2001, 00:00:00
+			array('2001', '5', 980722800), # Mon 29.01.2001, 00:00:00
+			array('2001', '52', 1009148400), # Mon 24.12.2001, 00:00:00
+			array('2013', '11', 1362956400), # Mon 11.03.2013, 00:00:00
+			array('2006', '3', 1137366000), # Mon 16.01.2006, 00:00:00
+		);
+		foreach ($values as $v) {
+			$ret = $this->Datetime->cweekBeginning($v[0], $v[1]);
+			$this->out($ret);
+			$this->out($this->Datetime->niceDate($ret, 'D').' '.$this->Datetime->niceDate($ret, FORMAT_NICE_YMDHMS));
+			$this->assertEquals($ret, $v[2], null, $v[1].'/'.$v[0]);
+		}
+	}
+	
+	public function testCweekEnding() {
+		$this->out($this->_header(__FUNCTION__));
+
+		$values = array(
+			'2001' => 1009753199, # Sun 30.12.2001, 23:59:59
+			'2006' => 1167605999, # Sun 31.12.2006, 23:59:59
+			'2010' => 1294009199, # Sun 02.01.2011, 23:59:59
+			'2013' => 1388357999, # Sun 29.12.2013, 23:59:59
+		);
+		foreach ($values as $year => $expected) {
+			$ret = $this->Datetime->cweekEnding($year);
+			$this->out($ret);
+			$this->out($this->Datetime->niceDate($ret, 'D').' '.$this->Datetime->niceDate($ret, FORMAT_NICE_YMDHMS));
+			$this->assertEquals($ret, $expected);
+		}
+		
+		$values = array(
+			array('2001', '1', 978908399), # Sun 07.01.2001, 23:59:59
+			array('2001', '2', 979513199), # Sun 14.01.2001, 23:59:59
+			array('2001', '5', 981327599), # Sun 04.02.2001, 23:59:59
+			array('2001', '52', 1009753199), # Sun 30.12.2001, 23:59:59
+			array('2013', '11', 1363561199), # Sun 17.03.2013, 23:59:59
+			array('2006', '3', 1137970799), # Sun 22.01.2006, 23:59:59
+		);
+		foreach ($values as $v) {
+			$ret = $this->Datetime->cweekEnding($v[0], $v[1]);
+			$this->out($ret);
+			$this->out($this->Datetime->niceDate($ret, 'D').' '.$this->Datetime->niceDate($ret, FORMAT_NICE_YMDHMS));
+			$this->assertEquals($ret, $v[2], null, $v[1].'/'.$v[0]);
+		}
+	}
+
+	public function testAgeByHoroscop() {
+		App::uses('ZodiacLib', 'Tools.Misc');
+		$zodiac = new ZodiacLib();
+		$is = $this->Datetime->ageByHoroscope(2000, ZodiacLib::SIGN_VIRGO);
+		pr($is);
+		$this->assertEquals($is, 11);
+		$is = $this->Datetime->ageByHoroscope(1991, ZodiacLib::SIGN_LIBRA);
+		pr($is);
+		$this->assertEquals($is, 20);
+		$is = $this->Datetime->ageByHoroscope(1986, ZodiacLib::SIGN_CAPRICORN);
+		pr($is);
+		$this->assertEquals($is, array(24, 25));
+		$is = $this->Datetime->ageByHoroscope(2000, ZodiacLib::SIGN_SCORPIO);
+		pr($is);
+		$this->assertEquals($is, array(10, 11));
+	}
+	
+	public function testAgeRange() {
+		$is = $this->Datetime->ageRange(2000);
+		pr($is);
+		$this->assertEquals($is, 10);
+		$is = $this->Datetime->ageRange(2002, null, null, 5);
+		pr($is);
+		$this->assertEquals($is, array(6, 10));
+		$is = $this->Datetime->ageRange(2000,  null, null, 5);
+		pr($is);
+		$this->assertEquals($is, array(6, 10));
+		$is = $this->Datetime->ageRange(1985, 23, 11);
+		pr($is);
+		$this->assertEquals($is, 25);
+		$is = $this->Datetime->ageRange(1985, null, null, 6);
+		pr($is);
+		$this->assertEquals($is, array(25, 30));
+		$is = $this->Datetime->ageRange(1985,  21, 11, 7);
+		pr($is);
+		$this->assertEquals($is, array(22, 28));
+	}
+}

+ 248 - 0
Test/Case/Lib/GeocodeLibTest.php

@@ -0,0 +1,248 @@
+<?php
+
+App::uses('GeocodeLib', 'Tools.Lib');
+
+# google maps
+Configure::write('Google', array(
+	'key' => 'ABQIAAAAk-aSeht5vBRyVc9CjdBKLRRnhS8GMCOqu88EXp1O-QqtMSdzHhQM4y1gkHFQdUvwiZgZ6jaKlW40kw',	//local
+	'api' => '2.x',
+	'zoom' => 16,
+	'lat' => null,
+	'lng' => null,
+	'type' => 'G_NORMAL_MAP'
+));
+
+class GeocodeLibTest extends CakeTestCase {
+
+	public function setUp() {
+		$this->GeocodeLib = new GeocodeLib();
+	}
+
+	public function TearDown() {
+		unset($this->GeocodeLib);
+	}
+	
+	public function testObject() {
+		$this->assertTrue(is_object($this->GeocodeLib));
+		$this->assertTrue(is_a($this->GeocodeLib, 'GeocodeLib'));
+	}
+
+
+	public function testDistance() {
+		$coords = array(
+			array('name'=>'MUC/Pforzheim (269km road, 2:33h)', 'x'=>array('lat'=>48.1391, 'lng'=>11.5802), 'y'=>array('lat'=>48.8934, 'lng'=>8.70492), 'd'=>228),
+			array('name'=>'MUC/London (1142km road, 11:20h)', 'x'=>array('lat'=>48.1391, 'lng'=>11.5802), 'y'=>array('lat'=>51.508, 'lng'=>-0.124688), 'd'=>919),
+			array('name'=>'MUC/NewYork (--- road, ---h)', 'x'=>array('lat'=>48.1391, 'lng'=>11.5802), 'y'=>array('lat'=>40.700943, 'lng'=>-73.853531), 'd'=>6479)
+		);
+
+		foreach ($coords as $coord) {
+			$is = $this->GeocodeLib->distance($coord['x'], $coord['y']);
+			echo $coord['name'].':';
+			pr('is: '.$is.' - expected: '.$coord['d']);
+			$this->assertEquals($coord['d'], $is);
+		}
+
+	}
+
+	public function testConvert() {
+		$values = array(
+			array(3, 'M', 'K', 4.828032),
+			array(3, 'K', 'M', 1.86411358),
+			array(100000, 'I', 'K', 2.54),
+		);
+		foreach ($values as $value) {
+			$is = $this->GeocodeLib->convert($value[0], $value[1], $value[2]);
+			echo $value[0].$value[1].' in '.$value[2].':';
+			pr('is: '.returns($is).' - expected: '.$value[3]);
+			$this->assertEquals($value[3], round($is, 8));
+		}
+	}
+
+
+	public function testUrl() {
+		$is = $this->GeocodeLib->url();
+		pr($is);
+		$this->assertTrue(!empty($is) && startsWith($is, 'http://maps.google.de/maps/api/geocode/xml?'));
+	}
+
+
+	// not possible with protected method
+	public function _testFetch() {
+		$url = 'http://maps.google.com/maps/api/geocode/xml?sensor=false&address=74523';
+		$is = $this->GeocodeLib->_fetch($url);
+		//echo returns($is);
+
+		$this->assertTrue(!empty($is) && substr($is, 0, 38) == '<?xml version="1.0" encoding="UTF-8"?>');
+
+		$url = 'http://maps.google.com/maps/api/geocode/json?sensor=false&address=74523';
+		$is = $this->GeocodeLib->_fetch($url);
+		//echo returns($is);
+		$this->assertTrue(!empty($is) && substr($is, 0, 1) == '{');
+
+	}
+
+	public function testSetParams() {
+
+	}
+
+
+	public function testSetOptions() {
+		$this->GeocodeLib->setOptions(array('host'=>'xx'));
+		# should remain ".com"
+		$res = $this->GeocodeLib->url();
+		pr($res);
+
+		$this->GeocodeLib->setOptions(array('host'=>'de'));
+		# should now be ".de"
+		$res = $this->GeocodeLib->url();
+		pr($res);
+
+		# now DE
+
+	}
+
+
+	public function testGeocode() {
+		$address = '74523 Deutschland';
+		echo '<h2>'.$address.'</h2>';
+		$is = $this->GeocodeLib->geocode($address);
+		echo returns($is);
+		$this->assertTrue($is);
+
+		$is = $this->GeocodeLib->getResult();
+		echo returns($is);
+		$this->assertTrue(!empty($is));
+
+		$is = $this->GeocodeLib->error();
+		echo returns($is);
+		$this->assertTrue(empty($is));
+
+
+		$address = 'Leopoldstraße 100, München';
+		echo '<h2>'.$address.'</h2>';
+		$is = $this->GeocodeLib->geocode($address);
+		echo returns($is);
+		$this->assertTrue($is);
+
+		pr($this->GeocodeLib->debug());
+
+		$is = $this->GeocodeLib->getResult();
+		echo returns($is);
+		$this->assertTrue(!empty($is));
+
+		$is = $this->GeocodeLib->error();
+		echo returns($is);
+		$this->assertTrue(empty($is));
+
+
+		$address = 'Oranienburger Straße 87, 10178 Berlin, Deutschland';
+		echo '<h2>'.$address.'</h2>';
+		$is = $this->GeocodeLib->geocode($address);
+		echo returns($is);
+		$this->assertTrue($is);
+
+		pr($this->GeocodeLib->debug());
+
+		$is = $this->GeocodeLib->getResult();
+		echo returns($is);
+		$this->assertTrue(!empty($is));
+
+		$is = $this->GeocodeLib->error();
+		echo returns($is);
+		$this->assertTrue(empty($is));
+
+	}
+
+	public function testGeocodeInvalid() {
+		$address = 'Hjfjosdfhosj, 78878 Mdfkufsdfk';
+		echo '<h2>'.$address.'</h2>';
+		$is = $this->GeocodeLib->geocode($address);
+		echo returns($is);
+		$this->assertFalse($is);
+
+		pr($this->GeocodeLib->debug());
+
+		$is = $this->GeocodeLib->error();
+		echo returns($is);
+		$this->assertTrue(!empty($is));
+	}
+
+
+	public function testGeocodeMinAcc() {
+		$address = 'Deutschland';
+		echo '<h2>'.$address.'</h2>';
+		$this->GeocodeLib->setOptions(array('min_accuracy'=>3));
+		$is = $this->GeocodeLib->geocode($address);
+		echo returns($is);
+		$this->assertFalse($is);
+
+		$is = $this->GeocodeLib->error();
+		echo returns($is);
+		$this->assertTrue(!empty($is));
+	}
+
+
+	public function testGeocodeInconclusive() {
+		// seems like there is no inconclusive result anymore!!!
+
+
+		$address = 'Neustadt';
+		echo '<h2>'.$address.'</h2>';
+
+		# allow_inconclusive = TRUE
+		$this->GeocodeLib->setOptions(array('allow_inconclusive'=>true));
+		$is = $this->GeocodeLib->geocode($address);
+		echo 'debug:';
+		pr($this->GeocodeLib->debug());
+		echo 'debug end';
+		$this->assertTrue($is);
+
+		$res = $this->GeocodeLib->getResult();
+		pr($res);
+		$this->assertTrue(count($res) > 4);
+
+		$is = $this->GeocodeLib->isInconclusive();
+		$this->assertTrue($is);
+
+
+		# allow_inconclusive = FALSE
+		$this->GeocodeLib->setOptions(array('allow_inconclusive'=>false));
+		$is = $this->GeocodeLib->geocode($address);
+		echo returns($is);
+		$this->assertFalse($is);
+
+		$is = $this->GeocodeLib->error();
+		echo returns($is);
+		$this->assertTrue(!empty($is));
+
+	}
+
+
+	public function testReverseGeocode() {
+		$coords = array(
+			array(-34.594445, -58.37446, 'Florida 1134-1200, Buenos Aires, Capital Federal, Argentinien'),
+			array(48.8934, 8.70492, 'B294, 75175 Pforzheim, Deutschland')
+		);
+
+		foreach ($coords as $coord) {
+			$is = $this->GeocodeLib->reverseGeocode($coord[0], $coord[1]);
+			echo returns($is);
+			$this->assertTrue($is);
+
+			$is = $this->GeocodeLib->getResult();
+			$this->assertTrue(!empty($is));
+			echo returns($is);
+			$address = isset($is[0]) ? $is[0]['formatted_address'] : $is['formatted_address'];
+			$this->assertEquals($coord[2], $address);
+		}
+
+	}
+
+
+
+
+	public function testGetResult() {
+
+	}
+
+}

+ 10 - 10
Test/Case/Lib/DangerLibTest.php

@@ -1,12 +1,12 @@
 <?php
 
-App::uses('DangerLib', 'Tools.Lib');
+App::uses('HazardLib', 'Tools.Lib');
 
-class DangerLibTest extends CakeTestCase {
+class HazardLibTest extends CakeTestCase {
 
 
 	public function setUp() {
-		$this->DangerLib = new DangerLib();
+		$this->HazardLib = new HazardLib();
 	}
 
 
@@ -15,10 +15,10 @@ class DangerLibTest extends CakeTestCase {
 	 */
 	public function _testParse() {
 
-		$is = $this->DangerLib->_parseXml(DangerLib::URL);
+		$is = $this->HazardLib->_parseXml(HazardLib::URL);
 		pr(h($is));
 		$this->assertTrue(!empty($is));
-		$this->assertEqual(count($is), 113);
+		$this->assertEquals(count($is), 113);
 	}
 
 
@@ -27,30 +27,30 @@ class DangerLibTest extends CakeTestCase {
 	 */
 	public function testXssStrings() {
 
-		$is = $this->DangerLib->xssStrings(false);
+		$is = $this->HazardLib->xssStrings(false);
 		pr(h($is));
 		$this->assertTrue(!empty($is));
 
 		# cached
 		Cache::delete('security_lib_texts');
 
-		$is = $this->DangerLib->xssStrings();
+		$is = $this->HazardLib->xssStrings();
 		pr(h($is));
 		$this->assertTrue(!empty($is) && count($is), 113);
 
-		$is = $this->DangerLib->xssStrings();
+		$is = $this->HazardLib->xssStrings();
 		pr(h($is));
 		$this->assertTrue(!empty($is) && count($is), 113);
 
 	}
 	
 	public function testPhp() {
-		$is = $this->DangerLib->phpStrings();
+		$is = $this->HazardLib->phpStrings();
 		pr(h($is));
 	}
 	
 	public function testSql() {
-		$is = $this->DangerLib->sqlStrings();
+		$is = $this->HazardLib->sqlStrings();
 		pr(h($is));
 	}
 

+ 21 - 0
Test/Case/Lib/MyHelperTest.php

@@ -0,0 +1,21 @@
+<?php
+
+App::uses('MyHelper', 'Tools.Lib');
+App::uses('View', 'View');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+
+class MyHelperTest extends MyCakeTestCase {
+
+	public $MyHelper;
+
+	public function startTest() {
+		$this->MyHelper = new MyHelper(new View(null));
+	}
+
+	public function testObject() {
+		$this->assertTrue(is_object($this->MyHelper));
+		$this->assertIsA($this->MyHelper, 'MyHelper');
+	}
+
+	//TODO
+}

+ 20 - 0
Test/Case/Lib/MyModelTest.php

@@ -0,0 +1,20 @@
+<?php
+
+App::uses('MyModel', 'Tools.Lib');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+
+class MyModelTest extends MyCakeTestCase {
+
+	public $MyModel;
+
+	public function startTest() {
+		$this->MyModel = new MyModel();
+	}
+
+	public function testObject() {
+		$this->assertTrue(is_object($this->MyModel));
+		$this->assertIsA($this->MyModel, 'MyModel');
+	}
+
+	//TODO
+}

+ 267 - 0
Test/Case/Lib/NumberLibTest.php

@@ -0,0 +1,267 @@
+<?php
+
+App::uses('NumberLib', 'Tools.Lib');
+App::uses('MyCakeTestCase', 'Tools.Lib');
+
+class NumberLibTest extends MyCakeTestCase {
+
+	public $NumberLib = null;
+
+	public function startTest() {
+		//$this->NumberLib = new NumberLib();
+	}
+
+	/**
+	 *2011-04-14 lb
+	 */
+	public function testRoundTo() {
+		//increment = 10
+		$values = array(
+			'22' => 20,
+			'15' => 20,
+			'3.4' => 0,
+			'6' => 10,
+			'-3.12' => 0,
+			'-10' => -10
+		);
+		foreach ($values as $was => $expected) {
+			$is = NumberLib::roundTo($was, 10);
+			$this->assertEquals($is, $expected, null, $was);
+		}
+		//increment = 0.1
+		$values2 = array(
+			'22' => 22,
+			'15.234' => 15.2,
+			'3.4' => 3.4,
+			'6.131' => 6.1,
+			'-3.17' => -3.2,
+			'-10.99' => -11
+		);
+		foreach ($values2 as $was => $expected) {
+			$is = NumberLib::roundTo($was, 0.1);
+			$this->assertEquals($is, $expected, null, $was);
+		}
+	}
+
+	/**
+	 *2011-04-14 lb
+	 */
+	public function testRoundUpTo() {
+		//increment = 10
+		$values = array(
+			'22.765' => 30,
+			'15.22' => 20,
+			'3.4' => 10,
+			'6' => 10,
+			'-3.12' => 0,
+			'-10' => -10
+		);
+		foreach ($values as $was => $expected) {
+			$is = NumberLib::roundUpTo($was, 10);
+			$this->assertEquals($is, $expected, null, $was);
+		}
+		//increment = 5
+		$values = array(
+			'22' => 25,
+			'15.234' => 20,
+			'3.4' => 5,
+			'6.131' => 10,
+			'-3.17' => 0,
+			'-10.99' => -10
+		);
+		foreach ($values as $was => $expected) {
+			$is = NumberLib::roundUpTo($was, 5);
+			$this->assertEquals($is, $expected, null, $was);
+		}
+	}
+
+
+	/**
+	 *2011-04-14 lb
+	 */
+	public function testRoundDownTo() {
+		//increment = 10
+		$values = array(
+			'22.765' => 20,
+			'15.22' => 10,
+			'3.4' => 0,
+			'6' => 0,
+			'-3.12' => -10,
+			'-10' => -10
+		);
+		foreach ($values as $was => $expected) {
+			$is = NumberLib::roundDownTo($was, 10);
+			$this->assertEquals($is, $expected, null, $was);
+		}
+		//increment = 3
+		$values = array(
+			'22' => 21,
+			'15.234' => 15,
+			'3.4' => 3,
+			'6.131' => 6,
+			'-3.17' => -6,
+			'-10.99' => -12
+		);
+		foreach ($values as $was => $expected) {
+			$is = NumberLib::roundDownTo($was, 3);
+			$this->assertEquals($is, $expected, null, $was);
+		}
+	}
+
+	/**
+	 *2011-04-15 lb
+	 */
+	public function testGetDecimalPlaces() {
+		$values = array(
+			'100' => -2,
+			'0.0001' => 4,
+			'10' => -1,
+			'0.1' => 1,
+			'1' => 0,
+			'0.001' => 3
+		);
+		foreach ($values as $was => $expected) {
+			$is = NumberLib::getDecimalPlaces($was, 10);
+			$this->assertEquals($is, $expected, null, $was);
+		}
+	}
+
+
+	public function testParseDate() {
+		echo $this->_header(__FUNCTION__);
+		$tests = array(
+			'2010-12-11' => 1292022000,
+			'2010-01-02' => 1262386800,
+			'10-01-02' => 1262386800,
+			'2.1.2010' => 1262386800,
+			'2.1.10' => 1262386800,
+			'02.01.10' => 1262386800,
+			'02.01.2010' => 1262386800,
+			'02.01.2010 22:11' => 1262386800,
+			'2010-01-02 22:11' => 1262386800,
+		);
+		foreach ($tests as $was => $expected) {
+			$is = NumberLib::parseDate($was);
+			//pr($is);
+			pr(date(FORMAT_NICE_YMDHMS, $is));
+			$this->assertEquals($is, $expected, null, $was);
+		}
+	}
+
+
+	public function testParseTime() {
+		echo $this->_header(__FUNCTION__);
+		$tests = array(
+			'2:4' => 7440,
+			'2:04' => 7440,
+			'2' => 7200,
+			'1,5' => 3600+1800,
+			'1.5' => 3600+1800,
+			'1.50' => 3600+1800,
+			'1.01' => 3660,
+			':4' => 240,
+			':04' => 240,
+			':40' => 40*MINUTE,
+			'1:2:4' => 1*HOUR+2*MINUTE+4*SECOND,
+			'01:2:04' => 1*HOUR+2*MINUTE+4*SECOND,
+			'0:2:04' => 2*MINUTE+4*SECOND,
+			'::4' => 4*SECOND,
+			'::04' => 4*SECOND,
+			'::40' => 40*SECOND,
+			'2011-11-12 10:10:10' => 10*HOUR+10*MINUTE+10*SECOND,
+		);
+
+		# positive
+		foreach ($tests as $was => $expected) {
+			$is = NumberLib::parseTime($was);
+			//pr($is);
+			$this->assertEquals($is, $expected, null, $was);
+		}
+
+		unset($tests['2011-11-12 10:10:10']);
+		# negative
+		foreach ($tests as $was => $expected) {
+			$is = NumberLib::parseTime('-'.$was);
+			//pr($is);
+			$this->assertEquals($is, -$expected, null, '-'.$was.' ['.$is.' => '.(-$expected).']');
+		}
+	}
+
+	public function testBuildTime() {
+		echo $this->_header(__FUNCTION__);
+		$tests = array(
+			7440 => '2:04',
+			7220 => '2:00', # 02:00:20 => rounded to 2:00:00
+			5400 => '1:30',
+			3660 => '1:01',
+		);
+
+		# positive
+		foreach ($tests as $was => $expected) {
+			$is = NumberLib::buildTime($was);
+			pr($is);
+			$this->assertEquals($is, $expected);
+		}
+
+		# negative
+		foreach ($tests as $was => $expected) {
+			$is = NumberLib::buildTime(-$was);
+			pr($is);
+			$this->assertEquals($is, '-'.$expected);
+		}
+	}
+
+	public function testBuildDefaultTime() {
+		echo $this->_header(__FUNCTION__);
+		$tests = array(
+			7440 => '02:04:00',
+			7220 => '02:00:20',
+			5400 => '01:30:00',
+			3660 => '01:01:00',
+			1*HOUR+2*MINUTE+4*SECOND => '01:02:04',
+		);
+
+		foreach ($tests as $was => $expected) {
+			$is = NumberLib::buildDefaultTime($was);
+			pr($is);
+			$this->assertEquals($is, $expected);
+		}
+	}
+
+	/**
+	 * basic
+	 */
+	public function testStandardDecimal() {
+		echo $this->_header(__FUNCTION__);
+		$value = '9.30';
+		$is = NumberLib::standardToDecimalTime($value);
+		$this->assertEquals(round($is, 2), '9.50');
+
+		$value = '9.3';
+		$is = NumberLib::standardToDecimalTime($value);
+		$this->assertEquals(round($is, 2), '9.50');
+	}
+
+
+	public function testDecimalStandard() {
+		echo $this->_header(__FUNCTION__);
+		$value = '9.50';
+		$is = NumberLib::decimalToStandardTime($value);
+		$this->assertEquals(round($is, 2), '9.3');
+
+		$value = '9.5';
+		$is = NumberLib::decimalToStandardTime($value);
+		pr($is);
+		$this->assertEquals($is, '9.3');
+
+		$is = NumberLib::decimalToStandardTime($value, 2);
+		pr($is);
+		$this->assertEquals($is, '9.30');
+
+		$is = NumberLib::decimalToStandardTime($value, 2, ':');
+		pr($is);
+		$this->assertEquals($is, '9:30');
+	}
+
+
+}

+ 148 - 0
Test/Case/Lib/TextLibTest.php

@@ -0,0 +1,148 @@
+<?php
+
+App::uses('TextLib', 'Tools.Lib');
+
+/**
+ * 2010-07-14 ms
+ */
+class TextLibTest extends CakeTestCase {
+
+	public function startTest() {
+		$this->TextLib = new TextLib(null);
+	}
+	
+	public function testScreamFont() {
+		$strings = array(
+			'Some Äext' => false,
+			'SOME ÄEXT' => true,
+			'ST' => true,
+			'SOme TExt' => true,
+			'SOme Text' => false,
+		);
+		
+		foreach ($strings as $string => $expected) {
+			$this->TextLib = new TextLib($string);
+			$is = $this->TextLib->isScreamFont();
+			//pr($is);
+			$this->assertSame($expected, $is);
+		}
+	}
+	
+
+	public function testConvertToOrd() {
+		$this->TextLib = new TextLib('h H');
+		$is = $this->TextLib->convertToOrd();
+		pr($is);
+		$this->assertEquals($is, '0-104-32-72-0');
+
+		$is = $this->TextLib->convertToOrd('x'.NL.'x'.LF.'x'.PHP_EOL.'x'.CR.'x'.TB.'x');
+		pr($is);
+	}
+
+	public function testConvertToOrdTable() {
+		$is = $this->TextLib->convertToOrdTable('x'.NL.'x'.LF.'x'.PHP_EOL.'x'.CR.'x'.TB.'x');
+		pr($is);
+	}
+
+
+	public function testWords() {
+		$this->TextLib = new TextLib('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.');
+		$is = $this->TextLib->words(array('min_char'=>3));
+		pr($is);
+		$this->assertTrue(!empty($is) && is_array($is) && count($is) === 9);
+
+	}
+
+	public function testWordCount() {
+		$this->TextLib = new TextLib('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.');
+		$is = $this->TextLib->wordCount(array('min_char'=>3));
+		pr($is);
+		$this->assertTrue(!empty($is) && is_array($is) && count($is) === 9);
+
+
+		$this->TextLib = new TextLib('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.');
+		$is = $this->TextLib->wordCount(array('min_char'=>3, 'sort'=>'DESC', 'limit'=>5));
+		pr($is);
+		$this->assertTrue(!empty($is) && is_array($is) && count($is) === 5);
+
+	}
+
+/** Start **/
+
+	public function testOccurances() {
+		$this->TextLib = new TextLib('Hochhaus');
+		$is = $this->TextLib->occurrences();
+		pr($is);
+		$this->assertTrue(!empty($is) && is_array($is) && count($is) === 6);
+
+		$is = $this->TextLib->occurrences(null, true);
+		pr($is);
+		$this->assertTrue(!empty($is) && is_array($is) && count($is) === 7);
+
+		$is = $this->TextLib->occurrences('h');
+		pr($is);
+		$expected = 3;
+		$this->assertEquals($is, $expected);
+
+		$is = $this->TextLib->occurrences('h', true);
+		pr($is);
+		$expected = 2;
+		$this->assertEquals($is, $expected);
+	}
+
+	public function testMaxOccurances() {
+		$is = $this->TextLib->maxOccurrences();
+		pr($is);
+		$this->assertTrue(!empty($is) && is_array($is) && count($is) === 1);
+
+		$this->TextLib = new TextLib('Radfahren');
+		$is = $this->TextLib->maxOccurrences();
+		pr($is);
+		$this->assertTrue(!empty($is) && is_array($is) && count($is) === 2);
+
+	}
+
+	//TODO: rest of the test functions
+
+
+/*
+//give it the text
+$text = new TextParse(
+"PHP:Hypertext             Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages... .. .. For this purpose,PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document.
+
+
+
+
+As a general-purpose programming language, PHP code(PHP CODE)is processed by an interpreter application in command-line mode performing desired operating system operations and producing program output on its standard output channel.It may also function as a graphical application...... PHP is available as a processor for most modern web servers and as standalone interpreter on most operating systems and computing platforms."
+);
+
+echo "Lenght:".		$text->getLenght()		."\n";	//the Lenght
+
+echo "Character:".	$text->getCharacter()	."\n";	//Character count
+
+echo "Letter:".		$text->getLetter()		."\n";	//Letter count
+
+echo "Space:".		$text->getSpace()		."\n";	//Space count
+
+echo "Symbol:".		$text->getSymbol()		."\n";	//Symbol count(non letter / space / \n / \r)
+
+echo "Word:".		$text->getWord()		."\n";	//Word count
+echo "The Words:";
+print_r($text->getWord(1));	//the Words
+echo "\n";
+
+echo "Sentence:".		$text->getSentence()		."\n";	//Sentence count
+echo "The Sentences:";
+print_r($text->getSentence(1));	//the Sentences
+echo "\n";
+
+echo "Paragraph:".		$text->getParagraph()		."\n";	//Paragraph count
+echo "The Paragraphs:";
+print_r($text->getParagraph(1));	//the Paragraphs
+echo "\n";
+
+echo "Beautified Text:\n".	$text->beautify(80);	//beautify the text, wordwrap=80
+*/
+
+}
+

+ 157 - 0
View/Helper/NumericHelper.php

@@ -0,0 +1,157 @@
+<?php
+
+App::import('Helper', 'Number');
+
+class NumericHelper extends NumberHelper {
+	public $helpers = array('Session');
+
+	protected $_settings = array(
+	
+	);
+
+	protected $code = null;
+	protected $places = 0;
+	protected $symbolRight = null;
+	protected $symbolLeft = null;
+	protected $decimalPoint = '.';
+	protected $thousandsPoint = ',';
+
+	public function __construct($View = null, $settings = array()) {
+		parent::__construct($View, $settings);	
+			
+		$i18n = Configure::read('Currency');
+		if (!empty($i18n['code'])) {
+			$this->code = $i18n['code'];
+		}
+		if (!empty($i18n['places'])) {
+			$this->places = $i18n['places'];
+		}
+		if (!empty($i18n['symbolRight'])) {
+			$this->symbolRight = $i18n['symbolRight'];
+		}
+		if (!empty($i18n['symbolLeft'])) {
+			$this->symbolLeft = $i18n['symbolLeft'];
+		}
+		if (isset($i18n['decimals'])) {
+			$this->decimalPoint = $i18n['decimals'];
+		}
+		if (isset($i18n['thousands'])) {
+			$this->thousandsPoint = $i18n['thousands'];
+		}
+	}
+	
+	/**
+	 * like price but with negative values allowed
+	 * @return string
+	 * 2011-10-05 ms
+	 */
+	public function money($amount, $places = null, $formatOptions = array()) {
+		$formatOptions['allowNegative'] = true;
+		return $this->price($amount, null, $places, $formatOptions);
+	}
+	
+	/**
+	 * @param price
+	 * @param specialPrice (outranks the price)
+	 * @param places
+	 * @param options
+	 * - allowNegative (defaults to false - price needs to be > 0)
+	 * - currency (defaults to true)
+	 * @return string
+	 * 2011-07-30 ms
+	 */
+	public function price($price, $specialPrice = null, $places = null, $formatOptions = array()) {
+		if ($specialPrice !== null && (float)$specialPrice > 0) {
+			$val = $specialPrice;
+		} elseif ((float)$price > 0 || !empty($formatOptions['allowNegative'])) {
+			$val = $price;
+		} else {
+			return '---';
+		}
+
+		if ($places === null) {
+			$places = 2;
+		}
+		$options = array('currency' => true);
+		if (!empty($formatOptions)) {
+			$options = array_merge($options, $formatOptions); # Set::merge not neccessary
+		}
+		
+		
+		return $this->format($val, $places, $options); // ->currency()
+	}
+
+	/**
+	 * format numeric values
+	 * @param float $number
+	 * @param int $places (0 = int, 1..x places after dec, -1..-x places before dec)
+	 * @param array $option : currency=true/false, ... (leave empty for no special treatment)
+	 * //TODO: automize per localeconv() ?
+	 * 2009-04-03 ms
+	 */
+	public function format($number, $places = null, $formatOptions = array()) {
+		if (!is_numeric($number)) {
+			return '---';
+		}
+		if (!is_integer($places)) {
+			$places = 2;
+		}
+		$options = array('before' => '', 'after' => '', 'places' => $places, 'thousands' => $this->thousandsPoint, 'decimals' => $this->
+			decimalPoint, 'escape' => false);
+
+		if (!empty($formatOptions['currency'])) {
+			if (!empty($this->symbolRight)) {
+				$options['after'] = ' ' . $this->symbolRight;
+			} elseif (!empty($this->symbolLeft)) {
+				$options['before'] = $this->symbolLeft . ' ';
+			} else {
+
+			}
+		} else {
+			if (!empty($formatOptions['after'])) {
+				$options['after'] = $formatOptions['after'];
+			}
+			if (!empty($formatOptions['before'])) {
+				$options['before'] = $formatOptions['before'];
+			}
+		}
+
+		if (!empty($formatOptions['thousands'])) {
+			$options['thousands'] = $formatOptions['thousands'];
+		}
+		if (!empty($formatOptions['decimals'])) {
+			$options['decimals'] = $formatOptions['decimals'];
+		}
+		if ($places < 0) {
+			$number = round($number, $places);
+		}
+		return parent::format($number, $options);
+	}
+
+	/**
+	 * Returns the English ordinal suffix (th, st, nd, etc) of a number.
+	 *
+	 *     echo 2, Num::ordinal(2);   // "2nd"
+	 *     echo 10, Num::ordinal(10); // "10th"
+	 *     echo 33, Num::ordinal(33); // "33rd"
+	 *
+	 * @param   integer  number
+	 * @return  string
+	 */
+	public static function ordinal($number) {
+		if ($number % 100 > 10 and $number % 100 < 14) {
+			return 'th';
+		}
+		switch ($number % 10) {
+			case 1:
+				return 'st';
+			case 2:
+				return 'nd';
+			case 3:
+				return 'rd';
+			default:
+				return 'th';
+		}
+	}
+
+}