test_pens_server.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * This file is part of php-pens.
  4. *
  5. * php-pens is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * php-pens is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with php-pens. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * Functional tests for the PENS Server
  20. *
  21. * This class provides functional testing of the PENS Server
  22. *
  23. * @package PENS
  24. * @subpackage Tests
  25. * @author Guillaume Viguier-Just <guillaume@viguierjust.com>
  26. * @licence http://www.gnu.org/licenses/gpl.txt
  27. */
  28. require_once("simpletest/autorun.php");
  29. require_once("simpletest/web_tester.php");
  30. define(PENS_TEST_SERVER_URL, "http://localhost/pens/pens_server_test.php");
  31. define(PENS_TEST_RECEIPT_MAILTO, "mailto:test@test.com");
  32. /**
  33. * Functional tests for the PENS Server
  34. *
  35. * This class provides functional tests for the PENS Server
  36. *
  37. * @package PENS
  38. * @subpackage Tests
  39. * @author Guillaume Viguier-Just <guillaume@viguierjust.com>
  40. * @licence http://www.gnu.org/licenses/gpl.txt
  41. */
  42. class TestPENSServer extends WebTestCase {
  43. private $_valid_params = array(
  44. "command" => "collect",
  45. "pens-version" => "1.0.0",
  46. "package-type" => "aicc-pkg",
  47. "package-type-version" => "1.0",
  48. "package-format" => "zip",
  49. "package-id" => "http://myurl.com/12345",
  50. "package-url" => "http://www.aicc.org/pens/sample/captivatequiz.zip",
  51. "package-url-expiry" => "2099-04-09T14:17:43Z",
  52. "client" => "test-pens-server",
  53. "receipt" => PENS_TEST_RECEIPT_MAILTO);
  54. public function testEmptyQuery() {
  55. $this->get(PENS_TEST_SERVER_URL);
  56. $this->assertText("error=2002");
  57. }
  58. public function testValidQuery() {
  59. $this->get(PENS_TEST_SERVER_URL, $this->_valid_params);
  60. $this->assertText("error=0");
  61. }
  62. private function invalidParameterTest($name, $value, $error) {
  63. $params = $this->_valid_params;
  64. $params[$name] = $value;
  65. $this->get(PENS_TEST_SERVER_URL, $params);
  66. $this->assertText("error=".$error);
  67. }
  68. private function validParameterTest($name, $value) {
  69. $params = $this->_valid_params;
  70. $params[$name] = $value;
  71. $this->get(PENS_TEST_SERVER_URL, $params);
  72. $this->assertText("error=0");
  73. }
  74. public function testInvalidCommand() {
  75. $this->invalidParameterTest("command", "invalid", 2002);
  76. }
  77. public function testInvalidVersion() {
  78. $this->invalidParameterTest("pens-version", "0.8.0", 2001);
  79. }
  80. public function testInvalidPackageType() {
  81. $this->invalidParameterTest("package-type", "invalid", 2003);
  82. }
  83. public function testEmptyPackageTypeVersion() {
  84. $this->invalidParameterTest("package-type-version", null, 2004);
  85. }
  86. public function testInvalidPackageFormat() {
  87. $this->invalidParameterTest("package-format", "invalid", 2005);
  88. }
  89. public function testInvalidPackageId() {
  90. $this->invalidParameterTest("package-id", "invalid", 2007);
  91. }
  92. public function testInvalidPackageUrl() {
  93. $this->invalidParameterTest("package-url", "invalid", 2008);
  94. }
  95. public function testInvalidPackageUrlExpiry() {
  96. $this->invalidParameterTest("package-url-expiry", "invalid", 2009);
  97. }
  98. public function testValidPackageUrlExpiry() {
  99. $this->validParameterTest("package-url-expiry", "2099-01-01");
  100. }
  101. }