test_pens_request.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. * Unit tests for the PENSRequest class
  20. *
  21. * This class provides unit tests for the PENSRequest class
  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 __DIR__.'/../pens.php';
  30. /**
  31. * Unit tests for the PENSRequest class
  32. *
  33. * This class provides unit tests for the PENSRequest class
  34. *
  35. * @package PENS
  36. * @subpackage Tests
  37. * @author Guillaume Viguier-Just <guillaume@viguierjust.com>
  38. * @licence http://www.gnu.org/licenses/gpl.txt
  39. */
  40. class TestPENSRequest extends UnitTestCase {
  41. /**
  42. * Valid arguments to be used for tests
  43. *
  44. * @var array
  45. */
  46. private $args = null;
  47. public function setUp() {
  48. $this->args = array(
  49. "pens-version" => "1.0.0",
  50. "command" => "collect",
  51. "package-type" => "aicc-pkg",
  52. "package-type-version" => "1.0",
  53. "package-format" => "zip",
  54. "package-id" => "http://myurl.com/12345",
  55. "package-url" => "http://myurl.com/mypackage.zip",
  56. "package-url-expiry" => "2006-04-01T06:51:29Z",
  57. "client" => "Authorware7",
  58. "receipt" => "mailto:name@domain.com",
  59. "package-url-user-id" => "guillaumev",
  60. "package-url-account" => "toto",
  61. "package-url-password" => "12345",
  62. "system-user-id" => "guillaumev",
  63. "system-password" => "12345",
  64. "alerts" => "http://myurl.com/alerts",
  65. "vendor-data" => "here are my data");
  66. }
  67. public function createObject($myargs) {
  68. return PENSRequestFactory::createPENSRequest($myargs);
  69. }
  70. public function exceptionTestForValue($key, $value, $code) {
  71. try {
  72. $myargs = $this->args;
  73. if($value === null) {
  74. unset($myargs[$key]);
  75. } else {
  76. $myargs[$key] = $value;
  77. }
  78. $object = $this->createObject($myargs);
  79. $this->fail();
  80. } catch(PENSException $e) {
  81. $this->assertEqual($e->getCode(), $code);
  82. }
  83. }
  84. public function testPensVersionInvalid() {
  85. $this->exceptionTestForValue("pens-version", "0.8.0", 2001);
  86. }
  87. public function testPensVersionNull() {
  88. $this->exceptionTestForValue("pens-version", null, 2001);
  89. }
  90. public function testCommandInvalid() {
  91. $this->exceptionTestForValue("command", "testing", 2002);
  92. }
  93. public function testCommandNull() {
  94. $this->exceptionTestForValue("command", null, 2002);
  95. }
  96. public function testPackageTypeInvalid() {
  97. $this->exceptionTestForValue("package-type", "testing", 2003);
  98. }
  99. public function testPackageTypeNull() {
  100. $this->exceptionTestForValue("package-type", null, 2003);
  101. }
  102. public function testPackageTypeVersionNull() {
  103. $this->exceptionTestForValue("package-type-version", null, 2004);
  104. }
  105. public function testPackageFormatInvalid() {
  106. $this->exceptionTestForValue("package-format", "testing", 2005);
  107. }
  108. public function testPackageFormatNull() {
  109. $this->exceptionTestForValue("package-format", null, 2005);
  110. }
  111. public function testPackageIdInvalid() {
  112. $this->exceptionTestForValue("package-id", "testing", 2007);
  113. }
  114. public function testPackageIdNull() {
  115. $this->exceptionTestForValue("package-id", null, 2007);
  116. }
  117. public function testPackageUrlInvalid() {
  118. $this->exceptionTestForValue("package-url", "testing", 2008);
  119. }
  120. public function testPackageUrlInvalid2() {
  121. $this->exceptionTestForValue("package-url", "http://myurl.com/mypackage", 2008);
  122. }
  123. public function testPackageUrlNull() {
  124. $this->exceptionTestForValue("package-url", null, 2008);
  125. }
  126. public function testPackageUrlExpiryNull() {
  127. $this->exceptionTestForValue("package-url-expiry", null, 2009);
  128. }
  129. public function testPackageUrlExpiryInvalid() {
  130. $this->exceptionTestForValue("package-url-expiry", "testing", 2009);
  131. }
  132. public function testClientNull() {
  133. $this->exceptionTestForValue("client", null, 2010);
  134. }
  135. public function testReceiptNull() {
  136. $this->exceptionTestForValue("receipt", null, 2011);
  137. }
  138. public function testReceiptInvalid() {
  139. $this->exceptionTestForValue("receipt", "testing", 2011);
  140. }
  141. public function testAlertsInvalid() {
  142. $this->exceptionTestForValue("alerts", "testing", 1201);
  143. }
  144. public function testReceiptValid() {
  145. try {
  146. $myargs = $this->args;
  147. $myargs["receipt"] = "mailto:name@domain.com,name2@domain.com";
  148. $object = $this->createObject($myargs);
  149. $this->pass();
  150. } catch(PENSException $e) {
  151. $this->fail();
  152. }
  153. }
  154. public function testValid() {
  155. try {
  156. $object = $this->createObject($this->args);
  157. $this->assertIsA($object, "PENSRequestCollect");
  158. $this->assertEqual($object->getPensVersion(), "1.0.0");
  159. $this->assertEqual($object->getPackageType(), "aicc-pkg");
  160. $this->assertEqual($object->getPackageTypeVersion(), "1.0");
  161. $this->assertEqual($object->getPackageFormat(), "zip");
  162. $this->assertEqual($object->getPackageId(), "http://myurl.com/12345");
  163. $this->assertEqual($object->getPackageUrl(), "http://myurl.com/mypackage.zip");
  164. $this->assertIsA($object->getPackageUrlExpiry(), "DateTime");
  165. $this->assertEqual($object->getClient(), "Authorware7");
  166. $this->assertEqual($object->getReceipt(), "mailto:name@domain.com");
  167. $this->assertEqual($object->getPackageUrlUserId(), "guillaumev");
  168. $this->assertEqual($object->getPackageUrlAccount(), "toto");
  169. $this->assertEqual($object->getPackageUrlPassword(), "12345");
  170. $this->assertEqual($object->getSystemUserId(), "guillaumev");
  171. $this->assertEqual($object->getSystemPassword(), "12345");
  172. $this->assertEqual($object->getAlerts(), "http://myurl.com/alerts");
  173. $this->assertEqual($object->getVendorData(), "here are my data");
  174. } catch(PENSException $e) {
  175. $this->fail();
  176. }
  177. }
  178. }