HttpTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. // Call Zend_XmlRpc_Request_HttpTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_XmlRpc_Request_HttpTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. require_once 'Zend/XmlRpc/Request/Http.php';
  8. /**
  9. * Test case for Zend_XmlRpc_Request_Http
  10. *
  11. * @package Zend_XmlRpc
  12. * @subpackage UnitTests
  13. * @version $Id$
  14. */
  15. class Zend_XmlRpc_Request_HttpTest extends PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * Runs the test methods of this class.
  19. *
  20. * @return void
  21. */
  22. public static function main()
  23. {
  24. $suite = new PHPUnit_Framework_TestSuite("Zend_XmlRpc_Request_HttpTest");
  25. $result = PHPUnit_TextUI_TestRunner::run($suite);
  26. }
  27. /**
  28. * Setup environment
  29. */
  30. public function setUp()
  31. {
  32. $this->xml =<<<EOX
  33. <?xml version="1.0" encoding="UTF-8"?>
  34. <methodCall>
  35. <methodName>test.userUpdate</methodName>
  36. <params>
  37. <param>
  38. <value><string>blahblahblah</string></value>
  39. </param>
  40. <param>
  41. <value><struct>
  42. <member>
  43. <name>salutation</name>
  44. <value><string>Felsenblöcke</string></value>
  45. </member>
  46. <member>
  47. <name>firstname</name>
  48. <value><string>Lépiné</string></value>
  49. </member>
  50. <member>
  51. <name>lastname</name>
  52. <value><string>Géranté</string></value>
  53. </member>
  54. <member>
  55. <name>company</name>
  56. <value><string>Zend Technologies, Inc.</string></value>
  57. </member>
  58. </struct></value>
  59. </param>
  60. </params>
  61. </methodCall>
  62. EOX;
  63. $this->request = new Zend_XmlRpc_Request_Http();
  64. $this->request->loadXml($this->xml);
  65. $this->server = $_SERVER;
  66. foreach ($_SERVER as $key => $value) {
  67. if ('HTTP_' == substr($key, 0, 5)) {
  68. unset($_SERVER[$key]);
  69. }
  70. }
  71. $_SERVER['HTTP_USER_AGENT'] = 'Zend_XmlRpc_Client';
  72. $_SERVER['HTTP_HOST'] = 'localhost';
  73. $_SERVER['HTTP_CONTENT_TYPE'] = 'text/xml';
  74. $_SERVER['HTTP_CONTENT_LENGTH'] = strlen($this->xml) + 1;
  75. }
  76. /**
  77. * Teardown environment
  78. */
  79. public function tearDown()
  80. {
  81. $_SERVER = $this->server;
  82. unset($this->request);
  83. }
  84. public function testGetRawRequest()
  85. {
  86. $this->assertEquals($this->xml, $this->request->getRawRequest());
  87. }
  88. public function testGetHeaders()
  89. {
  90. $expected = array(
  91. 'User-Agent' => 'Zend_XmlRpc_Client',
  92. 'Host' => 'localhost',
  93. 'Content-Type' => 'text/xml',
  94. 'Content-Length' => 958
  95. );
  96. $this->assertEquals($expected, $this->request->getHeaders());
  97. }
  98. public function testGetFullRequest()
  99. {
  100. $expected =<<<EOT
  101. User-Agent: Zend_XmlRpc_Client
  102. Host: localhost
  103. Content-Type: text/xml
  104. Content-Length: 958
  105. EOT;
  106. $expected .= $this->xml;
  107. $this->assertEquals($expected, $this->request->getFullRequest());
  108. }
  109. public function testCanPassInMethodAndParams()
  110. {
  111. try {
  112. $request = new Zend_XmlRpc_Request_Http('foo', array('bar', 'baz'));
  113. } catch (Exception $e) {
  114. $this->fail('Should be able to pass in methods and params to request');
  115. }
  116. }
  117. public function testExtendingClassShouldBeAbleToReceiveMethodAndParams()
  118. {
  119. try {
  120. $request = new Zend_XmlRpc_Request_HttpTest_Extension('foo', array('bar', 'baz'));
  121. } catch (Exception $e) {
  122. $this->fail('Should be able to pass in methods and params to request');
  123. }
  124. $this->assertEquals('foo', $request->method);
  125. $this->assertEquals(array('bar', 'baz'), $request->params);
  126. }
  127. }
  128. class Zend_XmlRpc_Request_HttpTest_Extension extends Zend_XmlRpc_Request_Http
  129. {
  130. public function __construct($method = null, $params = null)
  131. {
  132. $this->method = $method;
  133. $this->params = (array) $params;
  134. }
  135. }
  136. // Call Zend_XmlRpc_Request_HttpTest::main() if this source file is executed directly.
  137. if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_Request_HttpTest::main") {
  138. Zend_XmlRpc_Request_HttpTest::main();
  139. }