ImfsTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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-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_Namespace_Imfs
  24. */
  25. require_once 'Zend/Service/Nirvanix/Namespace/Imfs.php';
  26. /**
  27. * @see Zend_Service_Nirvanix_FunctionalTestCase
  28. */
  29. require_once 'Zend/Service/Nirvanix/FunctionalTestCase.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_Namespace_ImfsTest extends Zend_Service_Nirvanix_FunctionalTestCase
  40. {
  41. public function testInheritsFromNirvanixBase()
  42. {
  43. $imfs = new Zend_Service_Nirvanix_Namespace_Imfs();
  44. $this->assertTrue($imfs instanceof Zend_Service_Nirvanix_Namespace_Base);
  45. }
  46. // putContents()
  47. public function testPutContents()
  48. {
  49. $imfs = $this->nirvanix->getService('IMFS');
  50. // response for call to GetStorageNode
  51. $this->httpAdapter->addResponse(
  52. $this->makeNirvanixResponse(
  53. array('ResponseCode' => '0',
  54. 'GetStorageNode' => '<UploadHost>node1.nirvanix.com</UploadHost>
  55. <UploadToken>bar</UploadToken>'))
  56. );
  57. $imfs->putContents('/foo', 'contents for foo');
  58. }
  59. // getContents()
  60. public function testGetContents()
  61. {
  62. $imfs = $this->nirvanix->getService('IMFS');
  63. // response for call to GetOptimalUrlss
  64. $this->httpAdapter->addResponse(
  65. $this->makeNirvanixResponse(
  66. array('ResponseCode' => '0',
  67. 'Download' => '<DownloadURL>http://get-it-here</DownloadURL>'))
  68. );
  69. // response for file download
  70. $this->httpAdapter->addResponse(
  71. $this->makeHttpResponseFrom('contents for foo')
  72. );
  73. $actual = $imfs->getContents('/foo.txt');
  74. $expected = $this->httpClient->getLastResponse()->getBody();
  75. $this->assertEquals($expected, $actual);
  76. }
  77. // unlink()
  78. public function testUnlink()
  79. {
  80. $imfs = $this->nirvanix->getService('IMFS');
  81. // response for call to DeleteFiles
  82. $this->httpAdapter->addResponse(
  83. $this->makeNirvanixResponse(array('ResponseCode' => '0'))
  84. );
  85. $imfs->unlink('foo');
  86. }
  87. /**
  88. * @group ZF-6860
  89. */
  90. public function testDestinationPathFormatSentToServiceAsParameterUsesUnixConvention()
  91. {
  92. $imfs = $this->nirvanix->getService('IMFS');
  93. $this->httpAdapter->addResponse(
  94. $this->makeNirvanixResponse(
  95. array('ResponseCode' => '0',
  96. 'GetStorageNode' => '<UploadHost>node1.nirvanix.com</UploadHost>
  97. <UploadToken>bar</UploadToken>'))
  98. );
  99. // little unix cheat to force a backslash into the IFS path
  100. $imfs->putContents('.\foo/bar', 'contents for foo');
  101. $this->assertContains('./foo', $imfs->getHttpClient()->getLastRequest());
  102. }
  103. }