. */ /** * Functional tests for the PENS Server * * This class provides functional testing of the PENS Server * * @package PENS * @subpackage Tests * @author Guillaume Viguier-Just * @licence http://www.gnu.org/licenses/gpl.txt */ require_once("simpletest/autorun.php"); require_once("simpletest/web_tester.php"); define(PENS_TEST_SERVER_URL, "http://localhost/pens/pens_server_test.php"); define(PENS_TEST_RECEIPT_MAILTO, "mailto:test@test.com"); /** * Functional tests for the PENS Server * * This class provides functional tests for the PENS Server * * @package PENS * @subpackage Tests * @author Guillaume Viguier-Just * @licence http://www.gnu.org/licenses/gpl.txt */ class TestPENSServer extends WebTestCase { private $_valid_params = array( "command" => "collect", "pens-version" => "1.0.0", "package-type" => "aicc-pkg", "package-type-version" => "1.0", "package-format" => "zip", "package-id" => "http://myurl.com/12345", "package-url" => "http://www.aicc.org/pens/sample/captivatequiz.zip", "package-url-expiry" => "2099-04-09T14:17:43Z", "client" => "test-pens-server", "receipt" => PENS_TEST_RECEIPT_MAILTO); public function testEmptyQuery() { $this->get(PENS_TEST_SERVER_URL); $this->assertText("error=2002"); } public function testValidQuery() { $this->get(PENS_TEST_SERVER_URL, $this->_valid_params); $this->assertText("error=0"); } private function invalidParameterTest($name, $value, $error) { $params = $this->_valid_params; $params[$name] = $value; $this->get(PENS_TEST_SERVER_URL, $params); $this->assertText("error=".$error); } private function validParameterTest($name, $value) { $params = $this->_valid_params; $params[$name] = $value; $this->get(PENS_TEST_SERVER_URL, $params); $this->assertText("error=0"); } public function testInvalidCommand() { $this->invalidParameterTest("command", "invalid", 2002); } public function testInvalidVersion() { $this->invalidParameterTest("pens-version", "0.8.0", 2001); } public function testInvalidPackageType() { $this->invalidParameterTest("package-type", "invalid", 2003); } public function testEmptyPackageTypeVersion() { $this->invalidParameterTest("package-type-version", null, 2004); } public function testInvalidPackageFormat() { $this->invalidParameterTest("package-format", "invalid", 2005); } public function testInvalidPackageId() { $this->invalidParameterTest("package-id", "invalid", 2007); } public function testInvalidPackageUrl() { $this->invalidParameterTest("package-url", "invalid", 2008); } public function testInvalidPackageUrlExpiry() { $this->invalidParameterTest("package-url-expiry", "invalid", 2009); } public function testValidPackageUrlExpiry() { $this->validParameterTest("package-url-expiry", "2099-01-01"); } }