test_pens_response.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 PENSResponse class
  20. *
  21. * This class provides unit tests for the PENSResponse 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(dirname(__FILE__)."/../pens.php");
  30. /**
  31. * Unit tests for the PENSResponse class
  32. *
  33. * This class provides unit tests for the PENSResponse 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 TestPENSResponse extends UnitTestCase {
  41. public function testCreationFromPENSException() {
  42. $object = new PENSResponse(new PENSException(1101));
  43. $this->assertEqual($object->getError(), 1101);
  44. $this->assertNotNull($object->getErrorText());
  45. }
  46. public function testCreationFromArguments() {
  47. $object = new PENSResponse(0, "collect command received and understood");
  48. $this->assertIdentical($object->getError(), 0);
  49. $this->assertEqual($object->getErrorText(), "collect command received and understood");
  50. }
  51. public function testCreationFromHTTPResponse() {
  52. $eol = PENSConfig::$eol;
  53. $response = "error=1101".$eol."error-text=unable to parse PENS command".$eol."version=1.0.0".$eol."pens-data=".$eol;
  54. $object = new PENSResponse($response);
  55. $this->assertIdentical($object->getError(), 1101);
  56. $this->assertIdentical($object->getErrorText(), "unable to parse PENS command");
  57. $this->assertIdentical($object->getVersion(), "1.0.0");
  58. $this->assertNull($object->getPensData());
  59. }
  60. }