[Mapbender-commits] r6869 - trunk/mapbender/test/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Sep 2 04:41:18 EDT 2010


Author: christoph
Date: 2010-09-02 08:41:17 +0000 (Thu, 02 Sep 2010)
New Revision: 6869

Modified:
   trunk/mapbender/test/http/classes/FilterTest.php
Log:
extended filter testing

Modified: trunk/mapbender/test/http/classes/FilterTest.php
===================================================================
--- trunk/mapbender/test/http/classes/FilterTest.php	2010-09-02 08:38:28 UTC (rev 6868)
+++ trunk/mapbender/test/http/classes/FilterTest.php	2010-09-02 08:41:17 UTC (rev 6869)
@@ -4,10 +4,30 @@
 
 class FilterTest extends PHPUnit_Framework_TestCase {
 
+	public function testConstructorEmpty () {
+		$filter = new Filter();
+		
+		$sqlObject = new stdClass();
+		$sqlObject->sql = "";
+		$sqlObject->v = array();
+		$sqlObject->t = array();
+		$this->assertEquals($sqlObject, $filter->toSql());
+	}
+
+	public function testOperatorLike () {
+		$filter = new Filter("LIKE", "a", "%a");
+		
+		$sqlObject = new stdClass();
+		$sqlObject->sql = "a LIKE $1";
+		$sqlObject->v = array("%a");
+		$sqlObject->t = array("s");
+		$this->assertEquals($sqlObject, $filter->toSql());
+	}
+
 	public function testConstructorOperatorKeyValue () {
 		$filter = new Filter("=", "a", "b");
 		$sqlObject = new stdClass();
-		$sqlObject->sql = "a=$1";
+		$sqlObject->sql = "a = $1";
 		$sqlObject->v = array("b");
 		$sqlObject->t = array("s");
 		$this->assertEquals($sqlObject, $filter->toSql());
@@ -28,7 +48,7 @@
 
 		$filter = new Filter("AND", array($filterA, $filterB));
 		$sqlObject = new stdClass();
-		$sqlObject->sql = "(a=$1 AND b>=$2)";
+		$sqlObject->sql = "(a = $1 AND b >= $2)";
 		$sqlObject->v = array("b", 3);
 		$sqlObject->t = array("s", "i");
 		$this->assertEquals($sqlObject, $filter->toSql());
@@ -45,10 +65,72 @@
 
 		$filter = new Filter("AND", array($filter1all, $filter2all));
 		$sqlObject = new stdClass();
-		$sqlObject->sql = "((a=$1 AND b>=$2) AND (c=$3 AND e>=$4))";
+		$sqlObject->sql = "((a = $1 AND b >= $2) AND (c = $3 AND e >= $4))";
 		$sqlObject->v = array("b", 3, "d", 4);
 		$sqlObject->t = array("s", "i","s", "i");
 		$this->assertEquals($sqlObject, $filter->toSql());
 	}
+	
+	public function testConstructorOneFilter () {
+		$filterA = new Filter("=", "a", "b");
+		$filterB = new Filter("AND", array($filterA));
+
+		$sqlObject = new stdClass();
+		$sqlObject->sql = "(a = $1)";
+		$sqlObject->v = array("b");
+		$sqlObject->t = array("s");
+		
+		$this->assertEquals($sqlObject, $filterB->toSql());
+	}
+
+	public function testConstructorTwoFiltersOneEmpty () {
+		$filterA = new Filter("=", "a", "b");
+		$filterB = new Filter();
+		$filterC = new Filter("AND", array($filterA, $filterB));
+
+		$sqlObject = new stdClass();
+		$sqlObject->sql = "(a = $1)";
+		$sqlObject->v = array("b");
+		$sqlObject->t = array("s");
+		
+		$this->assertEquals($sqlObject, $filterC->toSql());
+	}
+
+	public function testConstructorTwoFiltersOneEmptyReordered () {
+		$filterA = new Filter("AND", array(new Filter()));
+		$filterB = new Filter("=", "a", "b");
+		$filterC = new Filter("AND", array($filterA, $filterB));
+
+		$sqlObject = new stdClass();
+		$sqlObject->sql = "(a = $1)";
+		$sqlObject->v = array("b");
+		$sqlObject->t = array("s");
+		
+		$this->assertEquals($sqlObject, $filterC->toSql());
+	}
+
+	public function testContructorFalse () {
+		$filterA = new Filter("FALSE");
+
+		$sqlObject = new stdClass();
+		$sqlObject->sql = "FALSE";
+		$sqlObject->v = array();
+		$sqlObject->t = array();
+		
+		$this->assertEquals($sqlObject, $filterA->toSql());
+	}
+
+	public function testContructorFalseMultiple () {
+		$filterA = new Filter("FALSE");
+		$filterB = new Filter("=", "b", 6);
+		$filterAnd = new Filter("AND", array($filterA, $filterB));
+		
+		$sqlObject = new stdClass();
+		$sqlObject->sql = "(FALSE AND b = $1)";
+		$sqlObject->v = array(6);
+		$sqlObject->t = array("i");
+		
+		$this->assertEquals($sqlObject, $filterAnd->toSql());
+	}
 }
 ?>
\ No newline at end of file



More information about the Mapbender_commits mailing list