PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Service/Rackspace/Files/OfflineTest.php

https://github.com/ajgarlag/zf1
PHP | 358 lines | 236 code | 41 blank | 81 comment | 4 complexity | c74fd2458ce3c3126da75c90f5063491 MD5 | raw file
  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-2012 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/Test.php';
  23. /**
  24. * Test helper
  25. */
  26. /**
  27. * @category Zend
  28. * @package Zend_Service_Rackspace_Files
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2012 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_OfflineTest
  35. extends PHPUnit_Framework_TestCase
  36. {
  37. /**
  38. * Reference to RackspaceFiles
  39. *
  40. * @var Zend_Service_Rackspace_Files
  41. */
  42. protected $rackspace;
  43. /**
  44. * HTTP client adapter for testing
  45. *
  46. * @var Zend_Http_Client_Adapter_Test
  47. */
  48. protected $httpClientAdapterTest;
  49. /**
  50. * Metadata for container/object test
  51. *
  52. * @var array
  53. */
  54. protected $metadata;
  55. /**
  56. * Another metadata for container/object test
  57. *
  58. * @var array
  59. */
  60. protected $metadata2;
  61. /**
  62. * Reference to Container
  63. *
  64. * @var Zend_Service_Rackspace_Files_Container
  65. */
  66. protected $container;
  67. /**
  68. * Set up the test case
  69. *
  70. * @return void
  71. */
  72. public function setUp()
  73. {
  74. $this->rackspace = new Zend_Service_Rackspace_Files('foo', 'bar');
  75. $this->container = new Zend_Service_Rackspace_Files_Container(
  76. $this->rackspace,
  77. array(
  78. 'name' => TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME
  79. )
  80. );
  81. $this->httpClientAdapterTest = new Zend_Http_Client_Adapter_Test();
  82. $this->rackspace->getHttpClient()->setAdapter(
  83. $this->httpClientAdapterTest
  84. );
  85. // authentication (from a file)
  86. $this->httpClientAdapterTest->setResponse(
  87. self::loadResponse('../../_files/testAuthenticate')
  88. );
  89. $this->assertTrue(
  90. $this->rackspace->authenticate(), 'Authentication failed'
  91. );
  92. $this->metadata = array(
  93. 'foo' => 'bar',
  94. 'foo2' => 'bar2'
  95. );
  96. $this->metadata2 = array(
  97. 'hello' => 'world'
  98. );
  99. // load the HTTP response (from a file)
  100. $this->httpClientAdapterTest->setResponse(
  101. $this->loadResponse($this->getName())
  102. );
  103. }
  104. /**
  105. * Utility method for returning a string HTTP response, which is loaded from a file
  106. *
  107. * @param string $name
  108. *
  109. * @return string
  110. */
  111. protected function loadResponse($name)
  112. {
  113. return file_get_contents(__DIR__ . '/_files/' . $name . '.response');
  114. }
  115. public function testCreateContainer()
  116. {
  117. $container =
  118. $this->rackspace->createContainer('zf-unit-test', $this->metadata);
  119. $this->assertTrue($container !== false);
  120. $this->assertEquals($container->getName(), 'zf-unit-test');
  121. }
  122. public function testGetCountContainers()
  123. {
  124. $num = $this->rackspace->getCountContainers();
  125. $this->assertTrue($num > 0);
  126. }
  127. public function testGetContainer()
  128. {
  129. $container = $this->rackspace->getContainer('zf-unit-test');
  130. $this->assertTrue($container !== false);
  131. $this->assertEquals($container->getName(), 'zf-unit-test');
  132. }
  133. public function testGetContainers()
  134. {
  135. $containers = $this->rackspace->getContainers();
  136. $this->assertTrue($containers !== false);
  137. $found = false;
  138. foreach ($containers as $container) {
  139. if ($container->getName() == 'zf-unit-test') {
  140. $found = true;
  141. break;
  142. }
  143. }
  144. $this->assertTrue($found);
  145. }
  146. public function testGetMetadataContainer()
  147. {
  148. $data = $this->rackspace->getMetadataContainer('zf-unit-test');
  149. $this->assertTrue($data !== false);
  150. $this->assertEquals($data['name'], 'zf-unit-test');
  151. $this->assertEquals($data['metadata'], $this->metadata);
  152. }
  153. public function testGetInfoAccount()
  154. {
  155. $data = $this->rackspace->getInfoAccount();
  156. $this->assertTrue($data !== false);
  157. $this->assertTrue($data['tot_containers'] > 0);
  158. }
  159. public function testStoreObject()
  160. {
  161. $content = 'This is a test!';
  162. $result = $this->rackspace->storeObject(
  163. 'zf-unit-test',
  164. 'zf-object-test',
  165. $content,
  166. $this->metadata
  167. );
  168. $this->assertTrue($result);
  169. }
  170. public function testGetObject()
  171. {
  172. $object = $this->rackspace->getObject(
  173. 'zf-unit-test',
  174. 'zf-object-test'
  175. );
  176. $this->assertTrue($object !== false);
  177. $this->assertEquals($object->getName(), 'zf-object-test');
  178. $this->assertEquals($object->getSize(), 15);
  179. $this->assertEquals($object->getMetadata(), $this->metadata);
  180. }
  181. public function testCopyObject()
  182. {
  183. $result = $this->rackspace->copyObject(
  184. 'zf-unit-test',
  185. 'zf-object-test',
  186. 'zf-unit-test',
  187. 'zf-object-test' . '-copy'
  188. );
  189. $this->assertTrue($result);
  190. }
  191. public function testGetObjects()
  192. {
  193. $objects = $this->rackspace->getObjects('zf-unit-test');
  194. $this->assertTrue($objects !== false);
  195. $this->assertEquals($objects[0]->getName(), 'zf-object-test');
  196. $this->assertEquals($objects[1]->getName(), 'zf-object-test' . '-copy');
  197. }
  198. public function testGetSizeContainers()
  199. {
  200. $size = $this->rackspace->getSizeContainers();
  201. $this->assertTrue($size !== false);
  202. $this->assertTrue(is_numeric($size));
  203. }
  204. public function testGetCountObjects()
  205. {
  206. $count = $this->rackspace->getCountObjects();
  207. $this->assertTrue($count !== false);
  208. $this->assertTrue(is_numeric($count));
  209. }
  210. public function testSetMetadataObject()
  211. {
  212. $result = $this->rackspace->setMetadataObject(
  213. 'zf-unit-test',
  214. 'zf-object-test',
  215. $this->metadata2
  216. );
  217. $this->assertTrue($result);
  218. }
  219. public function testGetMetadataObject()
  220. {
  221. $data = $this->rackspace->getMetadataObject(
  222. 'zf-unit-test',
  223. 'zf-object-test'
  224. );
  225. $this->assertTrue($data !== false);
  226. $this->assertEquals($data['metadata'], $this->metadata2);
  227. }
  228. public function testEnableCdnContainer()
  229. {
  230. $data = $this->rackspace->enableCdnContainer('zf-unit-test');
  231. $this->assertTrue($data !== false);
  232. $this->assertTrue(is_array($data));
  233. $this->assertTrue(!empty($data['cdn_uri']));
  234. $this->assertTrue(!empty($data['cdn_uri_ssl']));
  235. }
  236. public function testGetCdnContainers()
  237. {
  238. $containers = $this->rackspace->getCdnContainers();
  239. $this->assertTrue($containers !== false);
  240. $found = false;
  241. foreach ($containers as $container) {
  242. if ($container->getName() == 'zf-unit-test') {
  243. $found = true;
  244. break;
  245. }
  246. }
  247. $this->assertTrue($found);
  248. }
  249. public function testUpdateCdnContainer()
  250. {
  251. $data =
  252. $this->rackspace->updateCdnContainer('zf-unit-test', null, false);
  253. $this->assertTrue($data !== false);
  254. }
  255. public function testDeleteObject()
  256. {
  257. $this->assertTrue(
  258. $this->rackspace->deleteObject(
  259. 'zf-unit-test',
  260. 'zf-object-test'
  261. )
  262. );
  263. }
  264. public function testDeleteObject2()
  265. {
  266. $this->assertTrue(
  267. $this->rackspace->deleteObject(
  268. 'zf-unit-test',
  269. 'zf-object-test' . '-copy'
  270. )
  271. );
  272. }
  273. public function testDeleteContainer()
  274. {
  275. $this->assertTrue($this->rackspace->deleteContainer('zf-unit-test'));
  276. }
  277. /**
  278. * @group ZF-12542
  279. */
  280. public function testGetInfoCdnContainer()
  281. {
  282. $info = $this->rackspace->getInfoCdnContainer(
  283. TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME
  284. );
  285. $this->assertTrue($info !== false);
  286. $this->assertTrue(is_array($info));
  287. $this->assertTrue(!empty($info['ttl']));
  288. $this->assertTrue(!empty($info['cdn_uri']));
  289. $this->assertTrue(!empty($info['cdn_uri_ssl']));
  290. $this->assertTrue($info['cdn_enabled']);
  291. $this->assertTrue($info['log_retention']);
  292. }
  293. /**
  294. * @group ZF-12542
  295. */
  296. public function testGetCdnTtl()
  297. {
  298. $ttl = $this->container->getCdnTtl();
  299. $this->assertTrue($ttl !== false);
  300. }
  301. /**
  302. * @group ZF-12542
  303. */
  304. public function testGetCdnUri()
  305. {
  306. $uri = $this->container->getCdnUri();
  307. $this->assertTrue($uri !== false);
  308. }
  309. /**
  310. * @group ZF-12542
  311. */
  312. public function testGetCdnUriSsl()
  313. {
  314. $uri = $this->container->getCdnUriSsl();
  315. $this->assertTrue($uri !== false);
  316. }
  317. }