浏览代码

add tests

euromark 11 年之前
父节点
当前提交
4bd3674a83
共有 3 个文件被更改,包括 99 次插入0 次删除
  1. 1 0
      Console/Command/PwdShell.php
  2. 53 0
      Test/Case/Console/Command/PwdShellTest.php
  3. 45 0
      Test/Case/View/Helper/LoremHelperTest.php

+ 1 - 0
Console/Command/PwdShell.php

@@ -44,6 +44,7 @@ class PwdShell extends AppShell {
 			$passwordHasher = new $className();
 			$pw = $passwordHasher->hash($pwToHash);
 		} else {
+			$class = new $class(new ComponentCollection());
 			$pw = $class->password($pwToHash);
 		}
 

+ 53 - 0
Test/Case/Console/Command/PwdShellTest.php

@@ -0,0 +1,53 @@
+<?php
+
+App::uses('PwdShell', 'Tools.Console/Command');
+App::uses('MyCakeTestCase', 'Tools.TestSuite');
+App::uses('TestConsoleOutput', 'Tools.TestSuite');
+
+class PwdShellTest extends MyCakeTestCase {
+
+	public $PwdShell;
+
+	/**
+	 * PwdShellTest::setUp()
+	 *
+	 * @return void
+	 */
+	public function setUp() {
+		parent::setUp();
+
+		$output = new TestConsoleOutput();
+		$error = $this->getMock('ConsoleOutput', array(), array(), '', false);
+		$input = $this->getMock('ConsoleInput', array(), array(), '', false);
+
+		$this->PwdShell = new PwdShell($output, $error, $input);
+	}
+
+	/**
+	 * PwdShellTest::testObject()
+	 *
+	 * @return void
+	 */
+	public function testObject() {
+		$this->assertTrue(is_object($this->PwdShell));
+		$this->assertInstanceOf('PwdShell', $this->PwdShell);
+	}
+
+	/**
+	 * PwdShellTest::testHash()
+	 *
+	 * @return void
+	 */
+	public function testHash() {
+		$this->PwdShell->stdin->expects($this->at(0))
+			->method('read')
+			->will($this->returnValue('123'));
+
+		$this->PwdShell->startup();
+		$this->PwdShell->hash();
+
+		$output = $this->PwdShell->stdout->output();
+		$this->assertNotEmpty($output);
+	}
+
+}

+ 45 - 0
Test/Case/View/Helper/LoremHelperTest.php

@@ -0,0 +1,45 @@
+<?php
+
+App::uses('LoremHelper', 'Tools.View/Helper');
+App::uses('MyCakeTestCase', 'Tools.TestSuite');
+App::uses('View', 'View');
+
+class LoremHelperTest extends MyCakeTestCase {
+
+	/**
+	 * LoremHelperTest::setUp()
+	 *
+	 * @return void
+	 */
+	public function setUp() {
+		parent::setUp();
+
+		$this->Lorem = new LoremHelper(new View(null));
+	}
+
+	/**
+	 * LoremHelperTest::testObject()
+	 *
+	 * @return void
+	 */
+	public function testObject() {
+		$this->assertInstanceOf('LoremHelper', $this->Lorem);
+	}
+
+	/**
+	 * LoremHelperTest::testIpsum()
+	 *
+	 * @return void
+	 */
+	public function testIpsum() {
+		$is = $this->Lorem->ipsum();
+		$this->assertTextContains('<p>', $is);
+		$this->assertTextContains('</p>', $is);
+		$this->assertTrue(strlen($is) > 50);
+
+		$is = $this->Lorem->ipsum(6, 'w');
+		$words = explode(' ', $is);
+		$this->assertSame(6, count($words));
+	}
+
+}