Bläddra i källkod

Added some basic unit tests.

Taddes Kroes 14 år sedan
förälder
incheckning
31aaff40ed
6 ändrade filer med 52 tillägg och 8 borttagningar
  1. 2 0
      pquery.array.php
  2. 6 3
      pquery.php
  3. 37 2
      test/test_array.php
  4. 1 1
      test/test_pquery.php
  5. 3 1
      test/test_sql.php
  6. 3 1
      test/test_template.php

+ 2 - 0
pquery.array.php

@@ -9,6 +9,8 @@
  * @todo Documentation
  */
 class pQueryArray extends pQuery implements pQueryExtension {
+	static $accepts = array('array');
+	
 	/**
 	 * Get the value of an array alement at the given index.
 	 * 

+ 6 - 3
pquery.php

@@ -219,13 +219,16 @@ class pQuery {
 		if( isset($accepts[$type]) ) {
 			$convert_method = $accepts[$type];
 			
-			if( !method_exists($this, $convert_method) )
-				return self::error('Plugin "%s" has no conversion method "%s".', $class_name, $convert_method);
+			if( !method_exists($this, $convert_method) ) {
+				return self::error('Plugin "%s" has no conversion method "%s".',
+					$class_name, $convert_method);
+			}
 			
 			$result = $this->$convert_method($variable);
 			$result === null || $this->variable = $result;
 		} else if( !in_array($type, $accepts) ) {
-			return self::error('Variable type "%s" is not accepted by class "%s".', $type, $class_name);
+			return self::error('Variable type "%s" is not accepted by class "%s".',
+				$type, $class_name);
 		}
 	}
 	

+ 37 - 2
test/test_array.php

@@ -1,12 +1,47 @@
 <?php
 
+__p::load_plugin('array');
+
 class pQueryArrayTest extends UnitTestCase {
+	var $variable;
+	var $arr;
+	
 	function __construct() {
-		$this->UnitTestCase('pQuery array plugin test');
+		parent::__construct('pQuery array plugin');
+	}
+	
+	function setUp() {
+		$this->variable = array('test');
+		$this->arr = _arr($this->variable);
+	}
+	
+	function test_constructor() {
+		$this->assertIsA($this->arr, 'pQueryArray', 'constructor does not return pQueryArray object.');
+		$this->assertEqual($this->arr->variable, $this->variable, 'variable is not set correctly.');
+	}
+	
+	function test_get_simple() {
+		$this->assertEqual($this->arr->get(0), $this->variable[0]);
+	}
+	
+	function test_get_non_existent() {
+		$this->assertNull($this->arr->get(count($this->variable)), 'non-existent index should yield NULL.');
+	}
+	
+	function test_is_empty_empty() {
+		$this->assertTrue(_arr(array())->is_empty());
+	}
+	
+	function test_is_empty_non_empty() {
+		$this->assertFalse($this->arr->is_empty());
 	}
 	
-	function test_() {
+	function test_reverse() {
+		$orginal = range(1, 4);
+		$reverse = range(4, 1, -1);
 		
+		$arr = _arr($orginal);
+		$this->assertEqual($arr->reverse()->variable, $reverse, 'reverse is not really reverse...');
 	}
 }
 

+ 1 - 1
test/test_pquery.php

@@ -2,7 +2,7 @@
 
 class pQueryTest extends UnitTestCase {
 	function __construct() {
-		$this->UnitTestCase('pQuery base test');
+		parent::__construct('pQuery base');
 	}
 	
 	function test_() {

+ 3 - 1
test/test_sql.php

@@ -1,8 +1,10 @@
 <?php
 
+__p::load_plugin('sql');
+
 class pQuerySqlTest extends UnitTestCase {
 	function __construct() {
-		$this->UnitTestCase('pQuery MySQL plugin test');
+		parent::__construct('pQuery MySQL plugin');
 	}
 	
 	function test_() {

+ 3 - 1
test/test_template.php

@@ -1,8 +1,10 @@
 <?php
 
+__p::load_plugin('template');
+
 class pQueryTemplateTest extends UnitTestCase {
 	function __construct() {
-		$this->UnitTestCase('pQuery template plugin test');
+		parent::__construct('pQuery template plugin');
 	}
 	
 	function test_() {