2
0

OnlineTest.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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_Rackspace
  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. */
  21. require_once 'Zend/Service/Rackspace/Files.php';
  22. require_once 'Zend/Http/Client/Adapter/Socket.php';
  23. /**
  24. * Test helper
  25. */
  26. /**
  27. * @category Zend
  28. * @package Zend_Service_Rackspace_Files
  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_Rackspace_Files
  33. */
  34. class Zend_Service_Rackspace_Files_OnlineTest extends PHPUnit_Framework_TestCase
  35. {
  36. /**
  37. * Reference to Rackspace Files object
  38. *
  39. * @var Zend_Service_Rackspace_Files
  40. */
  41. protected $rackspace;
  42. /**
  43. * Socket based HTTP client adapter
  44. *
  45. * @var Zend_Http_Client_Adapter_Socket
  46. */
  47. protected $httpClientAdapterSocket;
  48. /**
  49. * Metadata for container/object test
  50. *
  51. * @var array
  52. */
  53. protected $metadata;
  54. /**
  55. * Another metadata for container/object test
  56. *
  57. * @var array
  58. */
  59. protected $metadata2;
  60. /**
  61. * Set up the test case
  62. *
  63. * @return void
  64. */
  65. public function setUp()
  66. {
  67. if (!constant('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_ENABLED')) {
  68. $this->markTestSkipped('Zend_Service_Rackspace_Files_OnlineTest tests are not enabled');
  69. }
  70. if(!defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_USER') || !defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_KEY')) {
  71. $this->markTestSkipped('Constants User and Key have to be set.');
  72. }
  73. $this->rackspace = new Zend_Service_Rackspace_Files(TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_USER,
  74. TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_KEY);
  75. $this->httpClientAdapterSocket = new Zend_Http_Client_Adapter_Socket();
  76. $this->rackspace->getHttpClient()
  77. ->setAdapter(self::$httpClientAdapterSocket);
  78. $this->metadata = array (
  79. 'foo' => 'bar',
  80. 'foo2' => 'bar2'
  81. );
  82. $this->metadata2 = array (
  83. 'hello' => 'world'
  84. );
  85. // terms of use compliance: safe delay between each test
  86. sleep(2);
  87. }
  88. public function testCreateContainer()
  89. {
  90. $container= $this->rackspace->createContainer(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,$this->metadata);
  91. $this->assertTrue($container!==false);
  92. $this->assertEquals($container->getName(),TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
  93. }
  94. public function testGetCountContainers()
  95. {
  96. $num= $this->rackspace->getCountContainers();
  97. $this->assertTrue($num>0);
  98. }
  99. public function testGetContainer()
  100. {
  101. $container= $this->rackspace->getContainer(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
  102. $this->assertTrue($container!==false);
  103. $this->assertEquals($container->getName(),TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
  104. }
  105. public function testGetContainers()
  106. {
  107. $containers= $this->rackspace->getContainers();
  108. $this->assertTrue($containers!==false);
  109. $found=false;
  110. foreach ($containers as $container) {
  111. if ($container->getName()==TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME) {
  112. $found=true;
  113. break;
  114. }
  115. }
  116. $this->assertTrue($found);
  117. }
  118. public function testGetMetadataContainer()
  119. {
  120. $data= $this->rackspace->getMetadataContainer(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
  121. $this->assertTrue($data!==false);
  122. $this->assertEquals($data['name'],TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
  123. $this->assertEquals($data['metadata'],$this->metadata);
  124. }
  125. public function testGetInfoAccount()
  126. {
  127. $data= $this->rackspace->getInfoAccount();
  128. $this->assertTrue($data!==false);
  129. $this->assertTrue($data['tot_containers']>0);
  130. }
  131. public function testStoreObject()
  132. {
  133. $content= 'This is a test!';
  134. $result= $this->rackspace->storeObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
  135. TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME,
  136. $content,
  137. $this->metadata);
  138. $this->assertTrue($result);
  139. }
  140. public function testGetObject()
  141. {
  142. $object= $this->rackspace->getObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
  143. TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME);
  144. $this->assertTrue($object!==false);
  145. $this->assertEquals($object->getName(),TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME);
  146. }
  147. public function testCopyObject()
  148. {
  149. $result= $this->rackspace->copyObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
  150. TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME,
  151. TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
  152. TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME.'-copy');
  153. $this->assertTrue($result);
  154. }
  155. public function testGetObjects()
  156. {
  157. $objects= $this->rackspace->getObjects(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
  158. $this->assertTrue($objects!==false);
  159. $this->assertEquals($objects[0]->getName(),TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME);
  160. $this->assertEquals($objects[1]->getName(),TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME.'-copy');
  161. }
  162. public function testGetSizeContainers()
  163. {
  164. $size= $this->rackspace->getSizeContainers();
  165. $this->assertTrue($size!==false);
  166. $this->assertTrue(is_numeric($size));
  167. }
  168. public function testGetCountObjects()
  169. {
  170. $count= $this->rackspace->getCountObjects();
  171. $this->assertTrue($count!==false);
  172. $this->assertTrue(is_numeric($count));
  173. }
  174. public function testSetMetadataObject()
  175. {
  176. $result= $this->rackspace->setMetadataObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
  177. TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME,
  178. $this->metadata2);
  179. $this->assertTrue($result);
  180. }
  181. public function testGetMetadataObject()
  182. {
  183. $data= $this->rackspace->getMetadataObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
  184. TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME);
  185. $this->assertTrue($data!==false);
  186. $this->assertEquals($data['metadata'],$this->metadata2);
  187. }
  188. public function testEnableCdnContainer()
  189. {
  190. $data= $this->rackspace->enableCdnContainer(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
  191. $this->assertTrue($data!==false);
  192. $this->assertTrue(is_array($data));
  193. $this->assertTrue(!empty($data['cdn_uri']));
  194. $this->assertTrue(!empty($data['cdn_uri_ssl']));
  195. }
  196. public function testGetCdnContainers()
  197. {
  198. $containers= $this->rackspace->getCdnContainers();
  199. $this->assertTrue($containers!==false);
  200. $found= false;
  201. foreach ($containers as $container) {
  202. if ($container->getName()==TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME) {
  203. $found= true;
  204. break;
  205. }
  206. }
  207. $this->assertTrue($found);
  208. }
  209. public function testUpdateCdnContainer()
  210. {
  211. $data= $this->rackspace->updateCdnContainer(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,null,false);
  212. $this->assertTrue($data!==false);
  213. }
  214. public function testDeleteObject()
  215. {
  216. $this->assertTrue($this->rackspace->deleteObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
  217. TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME));
  218. }
  219. public function testDeleteObject2()
  220. {
  221. $this->assertTrue($this->rackspace->deleteObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
  222. TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME.'-copy'));
  223. }
  224. public function testDeleteContainer()
  225. {
  226. $this->assertTrue($this->rackspace->deleteContainer(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME));
  227. }
  228. }