[Mapbender-commits] r6959 - in trunk/mapbender: lib test/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Sep 29 08:42:27 EDT 2010


Author: christoph
Date: 2010-09-29 12:42:26 +0000 (Wed, 29 Sep 2010)
New Revision: 6959

Modified:
   trunk/mapbender/lib/class_GetApi.php
   trunk/mapbender/test/http/classes/GetApiTest.php
Log:
added WMC case

Modified: trunk/mapbender/lib/class_GetApi.php
===================================================================
--- trunk/mapbender/lib/class_GetApi.php	2010-09-29 12:41:08 UTC (rev 6958)
+++ trunk/mapbender/lib/class_GetApi.php	2010-09-29 12:42:26 UTC (rev 6959)
@@ -13,6 +13,7 @@
 class GetApi {
 	private $layers = array();
 	private $featuretypes = array();
+	private $wmc = array();
 	
 	/**
 	 * @param array $input
@@ -23,11 +24,15 @@
 		}
 		foreach ($input as $key => $value) {
 			switch ($key) {
+				case "WMC":
+					$this->wmc = $this->normalizeWmcInput($value);
+					break;
 				case "LAYER":
 					$this->layers = $this->normalizeLayerInput($value);
 					break;
 				case "FEATURETYPE":
 					$this->featuretypes = $this->normalizeFeaturetypeInput($value);
+					break;
 			}
 		}
 	}
@@ -45,9 +50,42 @@
 	 * @return array
 	 */
 	public function getFeaturetypes () {
-		return $this->featuretypes;	
+		return $this->featuretypes;
 	}
 
+	/**
+	 * Returns an array of wmc
+	 * @return array
+	 */
+	public function getWmc () {
+		return $this->wmc;
+	}
+
+	// for possible inputs see http://www.mapbender.org/GET-Parameter#WMC
+	private function normalizeWmcInput ($input) {
+		// assume WMC=12,13,14
+		$inputArray = split(",", $input);
+		$input = array();
+		$i = 0;
+		foreach ($inputArray as $id) {
+			if (is_numeric($id)) {
+				$input[$i++]["id"] = $id;
+			}
+		}
+
+// check if each layer has at least an id, if not, delete
+		$i = 0;
+		while ($i < count($input)) {
+			if (!is_array($input[$i]) || !isset($input[$i]["id"]) || !is_numeric($input[$i]["id"])) {
+				array_splice($input, $i, 1);
+				continue;
+			}
+			$input[$i]["id"] = intval($input[$i]["id"]);
+			$i++;
+		}
+		return $input;
+	}
+
 	// for possible inputs see http://www.mapbender.org/GET-Parameter#LAYER
 	// for test cases, see http://www.mapbender.org/Talk:GET-Parameter#LAYER
 	private function normalizeLayerInput ($input) {
@@ -83,7 +121,7 @@
 		}
 		else {
 			// assume LAYER=12,13,14
-			$inputArray = split(",", $input); 
+			$inputArray = split(",", $input);
 			$input = array();
 			$i = 0;
 			foreach ($inputArray as $id) {

Modified: trunk/mapbender/test/http/classes/GetApiTest.php
===================================================================
--- trunk/mapbender/test/http/classes/GetApiTest.php	2010-09-29 12:41:08 UTC (rev 6958)
+++ trunk/mapbender/test/http/classes/GetApiTest.php	2010-09-29 12:42:26 UTC (rev 6959)
@@ -106,7 +106,7 @@
 	public function testMultipleFeaturetypesArrayComplex () {
 		parse_str("FEATURETYPE[active]=0&FEATURETYPE[search][firstname]=a&FEATURETYPE[search][lastname]=b&FEATURETYPE[id]=12", $getArray);
 		$apiObject = new GetApi($getArray);
-		
+
 		$expected = array(
 			array(
 				"id" => 12,
@@ -120,5 +120,35 @@
 		$this->assertEquals($expected, $apiObject->getFeaturetypes());
 	}
 
+	public function testWmcSimple () {
+		parse_str("WMC=12", $getArray);
+		$apiObject = new GetApi($getArray);
+
+		$expected = array(
+			array(
+				"id" => 12
+			)
+		);
+		$this->assertEquals($expected, $apiObject->getWmc());
+	}
+
+	public function testWmcSimpleMultiple () {
+		parse_str("WMC=12,13,14", $getArray);
+		$apiObject = new GetApi($getArray);
+
+		$expected = array(
+			array(
+				"id" => 12
+			),
+			array(
+				"id" => 13
+			),
+			array(
+				"id" => 14
+			)
+		);
+		$this->assertEquals($expected, $apiObject->getWmc());
+	}
+
 }
 ?>
\ No newline at end of file



More information about the Mapbender_commits mailing list