浏览代码

more tests

euromark 13 年之前
父节点
当前提交
c75684d3c3
共有 2 个文件被更改,包括 76 次插入9 次删除
  1. 6 8
      Test/Case/Model/Behavior/SluggedBehaviorTest.php
  2. 70 1
      Test/Case/View/Helper/TreeHelperTest.php

+ 6 - 8
Test/Case/Model/Behavior/SluggedBehaviorTest.php

@@ -156,7 +156,7 @@ class SluggedBehaviorTest extends CakeTestCase {
 
 		$this->Model->create(array('name' => 'Some & More'));
 		$result = $this->Model->save();
-		$this->assertEquals('Some-'.__('and').'-More', $result[$this->Model->alias]['slug']);
+		$this->assertEquals('Some-' . __('and') . '-More', $result[$this->Model->alias]['slug']);
 	}
 
 /**
@@ -430,7 +430,7 @@ class SluggedBehaviorTest extends CakeTestCase {
 			$suffix = dechex($hex1) . dechex($hex2Start) . '_' . dechex($hex1) . dechex($hex2Limit -1);
 			$full = TMP . 'tests' . DS . 'slug_' . $mode . '_' . $suffix . '.html';
 			$file = new File($full, true);
-			$this->__writeHeader($file, $hex1);
+			$this->_writeHeader($file, $hex1);
 			for($hex2 = $hex2Start; $hex2 < $hex2Limit; $hex2++) {
 				$part = file_get_contents($this->_createTestFile(dechex($hex1) . dechex($hex2), $mode));
 				preg_match('@<table>(.*)</table>@Us', $part, $test);
@@ -543,7 +543,7 @@ class SluggedBehaviorTest extends CakeTestCase {
 	protected function _createTestFile($section, $mode = 'display') {
 		$path = TMP . 'tests' . DS . '_slug_' . $mode . '_' . $section . '.html';
 		$file = new File($path, true);
-		$this->__writeHeader($file, $section);
+		$this->_writeHeader($file, $section);
 		for($hex1 = -1; $hex1 < 16; $hex1++) {
 			if ($hex1 == -1) {
 				$row = array('<b>' . $section . '</b>');
@@ -556,7 +556,7 @@ class SluggedBehaviorTest extends CakeTestCase {
 				} else {
 					$hexCode = $section . dechex($hex1) . dechex($hex2);
 					$decCode = hexdec($hexCode);
-					$row[] = $this->__renderChar($hexCode, $mode);
+					$row[] = $this->_renderChar($hexCode, $mode);
 				}
 			}
 			$file->append('<tr><td>' . implode($row, "</td>\n<td>") . "</td></tr>\n");
@@ -574,9 +574,8 @@ class SluggedBehaviorTest extends CakeTestCase {
  * @param mixed $file
  * @param mixed $title
  * @return void
- * @access private
  */
-	private function __writeHeader($file, $title) {
+	protected function _writeHeader($file, $title) {
 		$file->write('<!DOCTYPE html>');
 		$file->append('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">' . "\n");
 		$file->append('<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><style type="text/css">table {width:100%}.slugged{background:yellow}.illegal{background:red}</style>');
@@ -592,9 +591,8 @@ class SluggedBehaviorTest extends CakeTestCase {
  * @param mixed $hexCode
  * @param string $mode
  * @return string
- * @access private
  */
-	private function __renderChar($hexCode, $mode = 'id') {
+	protected function _renderChar($hexCode, $mode = 'id') {
 		$decCode = hexdec($hexCode);
 		$display = $char = html_entity_decode('&#' . $decCode . ';', ENT_NOQUOTES, 'UTF-8');
 		$char = $this->Model->slug($char, false);

+ 70 - 1
Test/Case/View/Helper/TreeHelperTest.php

@@ -87,7 +87,76 @@ TEXT;
 		$this->assertTrue(substr_count($output, '<li>') === substr_count($output, '</li>'));
 	}
 
-	//TODO: fixme: the root ul/li elements should also be marked active...
+	public function testGenerateWithSettings() {
+		$tree = $this->Model->find('threaded');
+
+		$output = $this->Tree->generate($tree, array('class' => 'navi', 'id' => 'main', 'type' => 'ol'));
+		$expected = <<<TEXT
+
+<ol class="navi" id="main">
+	<li>One
+	<ol>
+		<li>One-SubA</li>
+	</ol>
+	</li>
+	<li>Two
+	<ol>
+		<li>Two-SubA
+		<ol>
+			<li>Two-SubA-1
+			<ol>
+				<li>Two-SubA-1-1</li>
+			</ol>
+			</li>
+		</ol>
+		</li>
+	</ol>
+	</li>
+	<li>Three</li>
+	<li>Four
+	<ol>
+		<li>Four-SubA</li>
+	</ol>
+	</li>
+</ol>
+
+TEXT;
+		$this->assertTextEquals($expected, $output);
+	}
+
+	public function testGenerateWithMaxDepth() {
+		$tree = $this->Model->find('threaded');
+
+		$output = $this->Tree->generate($tree, array('maxDepth' => 2));
+		$expected = <<<TEXT
+
+<ul>
+	<li>One
+	<ul>
+		<li>One-SubA</li>
+	</ul>
+	</li>
+	<li>Two
+	<ul>
+		<li>Two-SubA
+		<ul>
+			<li>Two-SubA-1</li>
+		</ul>
+		</li>
+	</ul>
+	</li>
+	<li>Three</li>
+	<li>Four
+	<ul>
+		<li>Four-SubA</li>
+	</ul>
+	</li>
+</ul>
+
+TEXT;
+		$this->assertTextEquals($expected, $output);
+	}
+
 	public function testGenerateWithAutoPath() {
 		$tree = $this->Model->find('threaded');
 		debug($tree);