FunctionalTestCase.php 2.7 KB

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