ResponseTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service
  17. * @subpackage Nirvanix
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Service_Nirvanix_Response
  23. */
  24. require_once 'Zend/Service/Nirvanix/Response.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Service
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Service_Nirvanix_ResponseTest extends PHPUnit_Framework_TestCase
  33. {
  34. // Constructor
  35. public function testThrowsWhenInputStringIsNotXML()
  36. {
  37. $notXml = 'foo';
  38. try {
  39. new Zend_Service_Nirvanix_Response($notXml);
  40. } catch (Zend_Service_Nirvanix_Exception $e) {
  41. $this->assertRegExp('/xml could not be parsed/i', $e->getMessage());
  42. }
  43. }
  44. public function testThrowsWhenXmlElementNameIsNotResponse()
  45. {
  46. $xml = "<?xml version='1.0'?>
  47. <foo></foo>";
  48. try {
  49. new Zend_Service_Nirvanix_Response($xml);
  50. } catch (Zend_Service_Nirvanix_Exception $e) {
  51. $this->assertRegExp('/expected xml element response/i', $e->getMessage());
  52. }
  53. }
  54. public function testThrowsCodeAndMessageWhenResponseCodeIsNotZero()
  55. {
  56. $xml = "<?xml version='1.0'?>
  57. <Response>
  58. <ResponseCode>42</ResponseCode>
  59. <ErrorMessage>foo</ErrorMessage>
  60. </Response>";
  61. try {
  62. new Zend_Service_Nirvanix_Response($xml);
  63. } catch (Zend_Service_Nirvanix_Exception $e) {
  64. $this->assertEquals(42, $e->getCode());
  65. $this->assertEquals('foo', $e->getMessage());
  66. }
  67. }
  68. // getSxml()
  69. public function testGetSxmlReturnsSimpleXmlElement()
  70. {
  71. $xml = "<?xml version='1.0'?>
  72. <Response>
  73. <ResponseCode>0</ResponseCode>
  74. <foo>bar</foo>
  75. </Response>";
  76. $resp = new Zend_Service_Nirvanix_Response($xml);
  77. $this->assertType('SimpleXMLElement', $resp->getSxml());
  78. }
  79. // __get()
  80. public function testUndefinedPropertyIsDelegatedToSimpleXMLElement()
  81. {
  82. $xml = "<?xml version='1.0'?>
  83. <Response>
  84. <ResponseCode>0</ResponseCode>
  85. <foo>bar</foo>
  86. </Response>";
  87. $resp = new Zend_Service_Nirvanix_Response($xml);
  88. $this->assertEquals('bar', (string)$resp->foo);
  89. }
  90. // __call()
  91. public function testUndefinedMethodIsDelegatedToSimpleXMLElement()
  92. {
  93. $xml = "<?xml version='1.0'?>
  94. <Response>
  95. <ResponseCode>0</ResponseCode>
  96. <foo>bar</foo>
  97. </Response>";
  98. $resp = new Zend_Service_Nirvanix_Response($xml);
  99. $this->assertEquals('Response', $resp->getName());
  100. }
  101. }