Skip to content

Instantly share code, notes, and snippets.

@tjdett
Created January 22, 2012 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjdett/1655346 to your computer and use it in GitHub Desktop.
Save tjdett/1655346 to your computer and use it in GitHub Desktop.
<phpunit colors="true">
<testsuite name="Code Test Suite">
<directory>./</directory>
<file>RequestTest.php</file>
</testsuite>
<php>
<includePath>.:../..:.:/opt/apps/zendtest/code/local/code/</includePath>
<post name="ASSESSMENT_TYPE" value="ENDSEMCENTRAL"/>
<post name="ASSESSMENT_TITLE" value="End of Semester Open Book Examination"/>
<post name="ASSESSMENT_WEIGHT" value="66.7"/>
<post name="OBJECTIVES" value="array(240385, 240386, 240387)"/>
</php>
<logging>
<log type="coverage-html" target="./log/report" charset="UTF-8" yui="true" highlight="true" lowupperbound="50" highlowerbound="80"/>
<log type="testdox-html" target="./log/testdox.html"/>
</logging>
</phpunit>
<?php
/*
* Static Class to handle getting information from the request better
*
* @author D.Holborow
* @version 1.0 2006/04/03
*
*/
class Request {
//--------------------------------------------------------------------------
// Method
// get
// Description
// Gets a parameter passed to the page through the request, handles an optional value if request parameter not set
// Params
//
public static function get($paramName, $optValue = "") {
foreach (array($_POST, $_GET) as $params) {
$param = self::checkParam($params, $paramName);
if ($param !== null)
return $param;
}
return $optValue;
}
public static function checkParam($globalArray, $paramName) {
if (!isset($globalArray[$paramName]))
return null;
$testValue = $globalArray[$paramName];
if (is_string($testValue) && strlen($testValue) == 0)
return null;
return $testValue;
}
}
?>
<?php
date_default_timezone_set("Australia/Brisbane");
require_once('./Request.class');
class RequestTest extends PHPUnit_Framework_TestCase {
public function testReturnsPost() {
$_GET["ASSESSMENT_ID"] = 9461;
$_POST["QUESTIONTYPES"] = array(3,4,9);
$this->assertEquals("ENDSEMCENTRAL", Request::get("ASSESSMENT_TYPE"));
$this->assertEquals(0, Request::get("profileid", 0));
$this->assertEquals(9461, Request::get("ASSESSMENT_ID"));
$this->assertEquals(array(3,4,9), Request::get("QUESTIONTYPES"));
}
public function testFavoursPostOverGet() {
$_GET["hot"] = "coffee";
$_POST["hot"] = "chocolate";
$this->assertEquals("chocolate", Request::get("hot"));
}
public function testConsidersEmptyStringToBeAbsentValue() {
$_GET["a"] = "1";
$_GET["b"] = "";
$this->assertEquals("1", Request::get("a", "default"));
$this->assertEquals("default", Request::get("b", "default"));
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment