浏览代码

more tests

euromark 11 年之前
父节点
当前提交
bacf51a7bc
共有 2 个文件被更改,包括 207 次插入13 次删除
  1. 186 0
      tests/TestCase/BootstrapTest.php
  2. 21 13
      tests/TestCase/View/Helper/NumberHelperTest.php

+ 186 - 0
tests/TestCase/BootstrapTest.php

@@ -0,0 +1,186 @@
+<?php
+namespace Tools\Test\TestCase;
+
+use Cake\Routing\Router;
+use Cake\Controller\Controller;
+use Cake\Network\Request;
+use Cake\Network\Response;
+use Cake\TestSuite\TestCase;
+use Tools\View\RssView;
+
+/**
+ * RssViewTest
+ *
+ */
+class BootstrapTest extends TestCase {
+
+	/**
+	 * @return void
+	 */
+	public function testIsEmpty() {
+		$result = isEmpty(new \DateTime(date(FORMAT_DB_DATE)));
+		$this->assertFalse($result);
+	}
+
+	/**
+	 * BootstrapTest::testStartsWith()
+	 *
+	 * return void
+	 */
+	public function testStartsWith() {
+		$strings = array(
+			array(
+				'auto',
+				'au',
+				true
+			),
+			array(
+				'auto',
+				'ut',
+				false
+			),
+			array(
+				'Auto',
+				'au',
+				true
+			),
+			array(
+				'auto',
+				'Ut',
+				false
+			),
+		);
+
+		foreach ($strings as $string) {
+			$is = startsWith($string[0], $string[1]);
+			//pr(returns($is). ' - expected '.returns($string[2]));
+			$this->assertEquals($string[2], $is);
+		}
+
+		$is = startsWith('Auto', 'aut', true);
+		$this->assertEquals(false, $is);
+	}
+
+	/**
+	 * BootstrapTest::testEndsWith()
+	 *
+	 * @return void
+	 */
+	public function testEndsWith() {
+		$strings = array(
+			array(
+				'auto',
+				'to',
+				true
+			),
+			array(
+				'auto',
+				'ut',
+				false
+			),
+			array(
+				'auto',
+				'To',
+				true
+			),
+			array(
+				'auto',
+				'Ut',
+				false
+			),
+		);
+
+		foreach ($strings as $string) {
+			$is = endsWith($string[0], $string[1]);
+			//pr(returns($is). ' - expected '.returns($string[2]));
+			$this->assertEquals($string[2], $is);
+		}
+
+		$is = endsWith('Auto', 'To', true);
+		$this->assertEquals(false, $is);
+	}
+
+	/**
+	 * BootstrapTest::testContains()
+	 *
+	 * @return void
+	 */
+	public function testContains() {
+		$strings = array(
+			array(
+				'auto',
+				'to',
+				true
+			),
+			array(
+				'auto',
+				'ut',
+				true
+			),
+			array(
+				'auto',
+				'To',
+				true
+			),
+			array(
+				'auto',
+				'ot',
+				false
+			),
+		);
+
+		foreach ($strings as $string) {
+			$is = contains($string[0], $string[1]);
+			//pr(returns($is). ' - expected '.returns($string[2]));
+			$this->assertEquals($string[2], $is);
+		}
+
+		$is = contains('Auto', 'To', true);
+		$this->assertEquals(false, $is);
+	}
+
+	public function testEnt() {
+		//$this->assertEquals($expected, $is);
+	}
+
+	public function testEntDec() {
+		//$this->assertEquals($expected, $is);
+	}
+
+	public function testReturns() {
+		//$this->assertEquals($expected, $is);
+	}
+
+	/**
+	 * BootstrapTest::testExtractPathInfo()
+	 *
+	 * @return void
+	 */
+	public function testExtractPathInfo() {
+		$result = extractPathInfo('somefile.jpg', 'ext');
+		$this->assertEquals('jpg', $result);
+
+		$result = extractPathInfo('somefile.jpg', 'base');
+		$this->assertEquals('somefile.jpg', $result);
+
+		$result = extractPathInfo('somefile.jpg', 'file');
+		$this->assertEquals('somefile', $result);
+
+		$result = extractPathInfo('somefile.jpg?foo=bar#something', 'ext', true);
+		$this->assertEquals('jpg', $result);
+	}
+
+	/**
+	 * BootstrapTest::testExtractFileInfo()
+	 *
+	 * @return void
+	 */
+	public function testExtractFileInfo() {
+		$result = extractFileInfo('/some/path/to/filename.ext', 'file');
+		$this->assertEquals('filename', $result);
+
+		$result = extractFileInfo('/some/path/to/filename.x.y.z.ext', 'file');
+		$this->assertEquals('filename.x.y.z', $result);
+	}
+
+}

+ 21 - 13
tests/TestCase/View/Helper/NumberHelperTest.php

@@ -8,7 +8,7 @@ use Cake\Core\Configure;
 use Tools\Utility\Number;
 
 /**
- * Numeric Test Case
+ * Number Test Case
  */
 class NumberHelperTest extends TestCase {
 
@@ -20,7 +20,7 @@ class NumberHelperTest extends TestCase {
 			'thousands' => '.'
 		));
 		Number::config();
-		$this->Numeric = new NumberHelper(new View(null));
+		$this->Number = new NumberHelper(new View(null));
 	}
 
 	/**
@@ -31,47 +31,55 @@ class NumberHelperTest extends TestCase {
 	 * @return void
 	 */
 	public function testFormat() {
+		$is = $this->Number->format('22');
+		$expected = '22';
+		$this->assertEquals($expected, $is);
+
+		$is = $this->Number->format('22.01');
+		$expected = '22,01';
+		$this->assertEquals($expected, $is);
+
 		$this->skipIf(true, 'FIXME');
 
-		$is = $this->Numeric->format('22');
+		$is = $this->Number->format('22');
 		$expected = '22,00';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Numeric->format('22.30', array('places' => 1));
+		$is = $this->Number->format('22.30', array('places' => 1));
 		$expected = '22,3';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Numeric->format('22.30', array('places' => -1));
+		$is = $this->Number->format('22.30', array('places' => -1));
 		$expected = '20';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Numeric->format('22.30', array('places' => -2));
+		$is = $this->Number->format('22.30', array('places' => -2));
 		$expected = '0';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Numeric->format('22.30', array('places' => 3));
+		$is = $this->Number->format('22.30', array('places' => 3));
 		$expected = '22,300';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Numeric->format('abc', array('places' => 2));
+		$is = $this->Number->format('abc', array('places' => 2));
 		$expected = '---';
 		$this->assertEquals($expected, $is);
 
 		/*
-		$is = $this->Numeric->format('12.2', array('places'=>'a'));
+		$is = $this->Number->format('12.2', array('places'=>'a'));
 		$expected = '12,20';
 		$this->assertEquals($expected, $is);
 		*/
 
-		$is = $this->Numeric->format('22.3', array('places' => 2, 'before' => 'EUR '));
+		$is = $this->Number->format('22.3', array('places' => 2, 'before' => 'EUR '));
 		$expected = 'EUR 22,30';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Numeric->format('22.3', array('places' => 2, 'after' => ' EUR'));
+		$is = $this->Number->format('22.3', array('places' => 2, 'after' => ' EUR'));
 		$expected = '22,30 EUR';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Numeric->format('22.3', array('places' => 2, 'after' => 'x', 'before' => 'v'));
+		$is = $this->Number->format('22.3', array('places' => 2, 'after' => 'x', 'before' => 'v'));
 		$expected = 'v22,30x';
 		$this->assertEquals($expected, $is);
 
@@ -82,6 +90,6 @@ class NumberHelperTest extends TestCase {
 	public function tearDown() {
 		parent::tearDown();
 
-		unset($this->Numeric);
+		unset($this->Number);
 	}
 }