Browse Source

fixed warnings and failure of fortunes test per issue #782

Jason Hinkle 11 years ago
parent
commit
998c5105c1

+ 1 - 1
phreeze/benchmark_config

@@ -5,7 +5,7 @@
       "setup_file": "setup",
       "setup_file": "setup",
       "json_url": "/index.php?json",
       "json_url": "/index.php?json",
       "db_url": "/index.php?db",
       "db_url": "/index.php?db",
-      "query_url": "/index.php?db&queries=",
+      "query_url": "/index.php?query&queries=",
       "fortune_url": "/index.php?fortunes",
       "fortune_url": "/index.php?fortunes",
       "update_url": "/index.php?updates&queries=",
       "update_url": "/index.php?updates&queries=",
       "plaintext_url": "/index.php?plaintext",
       "plaintext_url": "/index.php?plaintext",

+ 1 - 0
phreeze/index.php

@@ -23,6 +23,7 @@ $route_map = array(
 		'GET:' => array('route' => 'Test.JSON'),
 		'GET:' => array('route' => 'Test.JSON'),
 		'GET:json' => array('route' => 'Test.JSON'),
 		'GET:json' => array('route' => 'Test.JSON'),
 		'GET:db' => array('route' => 'Test.DB'),
 		'GET:db' => array('route' => 'Test.DB'),
+		'GET:query' => array('route' => 'Test.Query'),
 		'GET:fortunes' => array('route' => 'Test.Fortunes'),
 		'GET:fortunes' => array('route' => 'Test.Fortunes'),
 		'GET:updates' => array('route' => 'Test.Updates'),
 		'GET:updates' => array('route' => 'Test.Updates'),
 		'GET:plaintext' => array('route' => 'Test.PlainText')
 		'GET:plaintext' => array('route' => 'Test.PlainText')

+ 37 - 15
phreeze/libs/Controller/TestController.php

@@ -40,24 +40,46 @@ class TestController extends Controller
 	public function DB()
 	public function DB()
 	{
 	{
 		require_once("Model/World.php");
 		require_once("Model/World.php");
-		
-		// Read number of queries to run from URL parameter
+
+		$id = mt_rand(1, 10000);
+		$world = $this->Phreezer->Get("World",$id);
+		$this->RenderJSON($world);
+	}
+	
+	
+	/**
+	 * Test route that connects to the database and outputs
+	 * the number of rows specified in the querystring argument "queries"
+	 */
+	public function Query()
+	{
+		require_once("Model/World.php");
+	
+		// Read number of queries to run from URL parameter
 		$query_count = RequestUtil::Get('queries',1);
 		$query_count = RequestUtil::Get('queries',1);
-
-		$arr = array();
-		
-		for ($i = 0; $i < $query_count; $i++) {
 		
 		
-			$id = mt_rand(1, 10000);
-			
-			$world = $this->Phreezer->Get("World",$id);
-			
-			// convert the Phreezable object into a simple structure for output
-			$arr[] = array('id'=>$world->Id,'randomNumber'=>$world->Randomnumber);
+		// make sure the query count paramter is in range
+		if (!is_numeric($query_count)) {
+			$query_count = 1;
 		}
 		}
-		
-		$this->RenderJSON($arr);
-
+		else {
+			$query_count = max(1,min($query_count,500));
+		}
+		
+		$arr = array();
+			
+		for ($i = 0; $i < $query_count; $i++) {
+				
+			$id = mt_rand(1, 10000);
+
+			$world = $this->Phreezer->Get("World",$id);
+
+			// convert the Phreezable object into a simple structure for output
+			$arr[] = array('id'=>$world->Id,'randomNumber'=>$world->Randomnumber);
+		}
+			
+		$this->RenderJSON($arr);
+	
 	}
 	}
 	
 	
 	/**
 	/**

+ 3 - 8
phreeze/templates/TestFortunes.php

@@ -1,16 +1,11 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
 <html>
 <html>
-<head>
-<title>Fortunes</title>
-</head>
+<head><title>Fortunes</title></head>
 <body>
 <body>
 <table>
 <table>
-<tr>
-<th>id</th>
-<th>message</th>
-</tr>
+<tr><th>id</th><th>message</th></tr>
 <?php foreach ($model['fortunes'] as $fortune) {
 <?php foreach ($model['fortunes'] as $fortune) {
-	echo '<tr><td>' . $fortune->Id . '</td><td>' . htmlspecialchars($fortune->Message) . '</td></tr>' . "\n";
+	echo '<tr><td>' . $fortune->Id . '</td><td>' . htmlspecialchars($fortune->Message, ENT_QUOTES | ENT_HTML5) . '</td></tr>';
 } ?>
 } ?>
 </table>
 </table>
 </body>
 </body>