ソースを参照

Added some tests for array plugin.

Taddeus Kroes 14 年 前
コミット
593e7f77b6
3 ファイル変更18 行追加7 行削除
  1. 10 4
      pquery.array.php
  2. 8 2
      test/test_array.php
  3. 0 1
      todo.txt

+ 10 - 4
pquery.array.php

@@ -30,6 +30,15 @@ class pQueryArray extends pQuery implements pQueryExtension {
 		return !$this->count();
 	}
 	
+	/**
+	 * Get the number of elementsin the array.
+	 * 
+	 * @returns int The number of elements.
+	 */
+	function count() {
+		return count($this->variable);
+	}
+	
 	/**
 	 * Reverse the array.
 	 * 
@@ -58,10 +67,7 @@ class pQueryArray extends pQuery implements pQueryExtension {
 			return call_user_func_array($function, $args);
 		}
 		
-		if( in_array($method, array('count')) )
-			return $method($this->variable);
-		
-		if( in_array($method, array('shuffle')) ) {
+		if( in_array($method, array('shuffle', 'sort')) ) {
 			$method($this->variable);
 			return $this;
 		}

+ 8 - 2
test/test_array.php

@@ -43,8 +43,14 @@ class pQueryArrayTest extends UnitTestCase {
 		$this->assertEqual($arr->reverse()->variable, $reverse, 'reverse is not really reverse...');
 	}
 	
-	function test_call() {
-		
+	function test_call_count() {
+		$this->assertEqual($this->arr->count(), count($this->variable));
+	}
+	
+	function test_call_sort() {
+		$arr = range(1, 8);
+		shuffle($arr);
+		$this->assertEqual(_arr($arr)->sort()->variable, range(1, 8));
 	}
 }
 

+ 0 - 1
todo.txt

@@ -1,5 +1,4 @@
 - Extend array plugin with stack/collection functions.
-- Unit test array plugin
 - Unit test base
 - Unit test cache plugin
 - Unit test css plugin