ResponseTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_Nirvanix
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Service_Nirvanix_Response
  24. */
  25. require_once 'Zend/Service/Nirvanix/Response.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Service_Nirvanix
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Service
  33. * @group Zend_Service_Nirvanix
  34. */
  35. class Zend_Service_Nirvanix_ResponseTest extends PHPUnit_Framework_TestCase
  36. {
  37. // Constructor
  38. public function testThrowsWhenInputStringIsNotXML()
  39. {
  40. $notXml = 'foo';
  41. try {
  42. new Zend_Service_Nirvanix_Response($notXml);
  43. } catch (Zend_Service_Nirvanix_Exception $e) {
  44. $this->assertRegExp('/xml could not be parsed/i', $e->getMessage());
  45. }
  46. }
  47. public function testThrowsWhenXmlElementNameIsNotResponse()
  48. {
  49. $xml = "<?xml version='1.0'?>
  50. <foo></foo>";
  51. try {
  52. new Zend_Service_Nirvanix_Response($xml);
  53. } catch (Zend_Service_Nirvanix_Exception $e) {
  54. $this->assertRegExp('/expected xml element response/i', $e->getMessage());
  55. }
  56. }
  57. public function testThrowsCodeAndMessageWhenResponseCodeIsNotZero()
  58. {
  59. $xml = "<?xml version='1.0'?>
  60. <Response>
  61. <ResponseCode>42</ResponseCode>
  62. <ErrorMessage>foo</ErrorMessage>
  63. </Response>";
  64. try {
  65. new Zend_Service_Nirvanix_Response($xml);
  66. } catch (Zend_Service_Nirvanix_Exception $e) {
  67. $this->assertEquals(42, $e->getCode());
  68. $this->assertEquals('foo', $e->getMessage());
  69. }
  70. }
  71. // getSxml()
  72. public function testGetSxmlReturnsSimpleXmlElement()
  73. {
  74. $xml = "<?xml version='1.0'?>
  75. <Response>
  76. <ResponseCode>0</ResponseCode>
  77. <foo>bar</foo>
  78. </Response>";
  79. $resp = new Zend_Service_Nirvanix_Response($xml);
  80. $this->assertTrue($resp->getSxml() instanceof SimpleXMLElement);
  81. }
  82. // __get()
  83. public function testUndefinedPropertyIsDelegatedToSimpleXMLElement()
  84. {
  85. $xml = "<?xml version='1.0'?>
  86. <Response>
  87. <ResponseCode>0</ResponseCode>
  88. <foo>bar</foo>
  89. </Response>";
  90. $resp = new Zend_Service_Nirvanix_Response($xml);
  91. $this->assertEquals('bar', (string)$resp->foo);
  92. }
  93. // __call()
  94. public function testUndefinedMethodIsDelegatedToSimpleXMLElement()
  95. {
  96. $xml = "<?xml version='1.0'?>
  97. <Response>
  98. <ResponseCode>0</ResponseCode>
  99. <foo>bar</foo>
  100. </Response>";
  101. $resp = new Zend_Service_Nirvanix_Response($xml);
  102. $this->assertEquals('Response', $resp->getName());
  103. }
  104. }