FunctionalTestCase.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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
  23. */
  24. require_once 'Zend/Service/Nirvanix.php';
  25. /**
  26. * @see Zend_Http_Client_Adapter_Test
  27. */
  28. require_once 'Zend/Http/Client/Adapter/Test.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Service
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Service_Nirvanix_FunctionalTestCase extends PHPUnit_Framework_TestCase
  37. {
  38. public function setUp()
  39. {
  40. $this->httpAdapter = new Zend_Http_Client_Adapter_Test();
  41. $this->httpClient = new Zend_Http_Client('http://foo',
  42. array('adapter' => $this->httpAdapter));
  43. $this->auth = array('username' => 'foo', 'password' => 'bar', 'appKey' => 'baz');
  44. $this->options = array('httpClient' => $this->httpClient);
  45. // set first nirvanix response to successful login
  46. $this->httpAdapter->setResponse(
  47. $this->makeNirvanixResponse(array('ResponseCode' => '0',
  48. 'SessionToken' => 'foo'))
  49. );
  50. $this->nirvanix = new Zend_Service_Nirvanix($this->auth, $this->options);
  51. }
  52. public function makeNirvanixResponse($hash)
  53. {
  54. $xml = "<?xml version='1.0'?><Response>";
  55. foreach ($hash as $k => $v) { $xml .= "<$k>$v</$k>"; }
  56. $xml .= "</Response>";
  57. $resp = $this->makeHttpResponseFrom($xml);
  58. return $resp;
  59. }
  60. public function makeHttpResponseFrom($data, $status=200, $message='OK')
  61. {
  62. $headers = array("HTTP/1.1 $status $message",
  63. "Status: $status",
  64. 'Content_Type: text/xml; charset=utf-8',
  65. 'Content-Length: ' . strlen($data)
  66. );
  67. return implode("\r\n", $headers) . "\r\n\r\n$data\r\n\r\n";
  68. }
  69. }