| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Service_Rackspace
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- require_once 'Zend/Service/Rackspace/Files.php';
- require_once 'Zend/Http/Client/Adapter/Socket.php';
- /**
- * Test helper
- */
- /**
- * @category Zend
- * @package Zend_Service_Rackspace_Files
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Service_Rackspace_Files
- */
- class Zend_Service_Rackspace_Files_OnlineTest extends PHPUnit_Framework_TestCase
- {
- /**
- * Reference to Rackspace Files object
- *
- * @var Zend_Service_Rackspace_Files
- */
- protected $rackspace;
- /**
- * Socket based HTTP client adapter
- *
- * @var Zend_Http_Client_Adapter_Socket
- */
- protected $httpClientAdapterSocket;
- /**
- * Metadata for container/object test
- *
- * @var array
- */
- protected $metadata;
- /**
- * Another metadata for container/object test
- *
- * @var array
- */
- protected $metadata2;
-
- /**
- * Set up the test case
- *
- * @return void
- */
- public function setUp()
- {
-
- if (!constant('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_ENABLED')) {
- $this->markTestSkipped('Zend_Service_Rackspace_Files_OnlineTest tests are not enabled');
- }
- if(!defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_USER') || !defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_KEY')) {
- $this->markTestSkipped('Constants User and Key have to be set.');
- }
- $this->rackspace = new Zend_Service_Rackspace_Files(TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_USER,
- TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_KEY);
- $this->httpClientAdapterSocket = new Zend_Http_Client_Adapter_Socket();
- $this->rackspace->getHttpClient()
- ->setAdapter(self::$httpClientAdapterSocket);
-
- $this->metadata = array (
- 'foo' => 'bar',
- 'foo2' => 'bar2'
- );
-
- $this->metadata2 = array (
- 'hello' => 'world'
- );
-
- // terms of use compliance: safe delay between each test
- sleep(2);
- }
-
- public function testCreateContainer()
- {
- $container= $this->rackspace->createContainer(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,$this->metadata);
- $this->assertTrue($container!==false);
- $this->assertEquals($container->getName(),TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
- }
- public function testGetCountContainers()
- {
- $num= $this->rackspace->getCountContainers();
- $this->assertTrue($num>0);
- }
-
- public function testGetContainer()
- {
- $container= $this->rackspace->getContainer(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
- $this->assertTrue($container!==false);
- $this->assertEquals($container->getName(),TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
- }
-
- public function testGetContainers()
- {
- $containers= $this->rackspace->getContainers();
- $this->assertTrue($containers!==false);
- $found=false;
- foreach ($containers as $container) {
- if ($container->getName()==TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME) {
- $found=true;
- break;
- }
- }
- $this->assertTrue($found);
- }
-
- public function testGetMetadataContainer()
- {
- $data= $this->rackspace->getMetadataContainer(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
- $this->assertTrue($data!==false);
- $this->assertEquals($data['name'],TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
- $this->assertEquals($data['metadata'],$this->metadata);
-
- }
-
- public function testGetInfoAccount()
- {
- $data= $this->rackspace->getInfoAccount();
- $this->assertTrue($data!==false);
- $this->assertTrue($data['tot_containers']>0);
- }
-
- public function testStoreObject()
- {
- $content= 'This is a test!';
- $result= $this->rackspace->storeObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
- TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME,
- $content,
- $this->metadata);
- $this->assertTrue($result);
- }
-
- public function testGetObject()
- {
- $object= $this->rackspace->getObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
- TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME);
- $this->assertTrue($object!==false);
- $this->assertEquals($object->getName(),TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME);
- }
- public function testCopyObject()
- {
- $result= $this->rackspace->copyObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
- TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME,
- TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
- TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME.'-copy');
- $this->assertTrue($result);
- }
- public function testGetObjects()
- {
- $objects= $this->rackspace->getObjects(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
- $this->assertTrue($objects!==false);
-
- $this->assertEquals($objects[0]->getName(),TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME);
- $this->assertEquals($objects[1]->getName(),TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME.'-copy');
- }
-
- public function testGetSizeContainers()
- {
- $size= $this->rackspace->getSizeContainers();
- $this->assertTrue($size!==false);
- $this->assertTrue(is_numeric($size));
- }
-
- public function testGetCountObjects()
- {
- $count= $this->rackspace->getCountObjects();
- $this->assertTrue($count!==false);
- $this->assertTrue(is_numeric($count));
- }
-
- public function testSetMetadataObject()
- {
- $result= $this->rackspace->setMetadataObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
- TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME,
- $this->metadata2);
- $this->assertTrue($result);
- }
-
- public function testGetMetadataObject()
- {
- $data= $this->rackspace->getMetadataObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
- TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME);
- $this->assertTrue($data!==false);
- $this->assertEquals($data['metadata'],$this->metadata2);
- }
-
- public function testEnableCdnContainer()
- {
- $data= $this->rackspace->enableCdnContainer(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME);
- $this->assertTrue($data!==false);
- $this->assertTrue(is_array($data));
- $this->assertTrue(!empty($data['cdn_uri']));
- $this->assertTrue(!empty($data['cdn_uri_ssl']));
- }
-
- public function testGetCdnContainers()
- {
- $containers= $this->rackspace->getCdnContainers();
- $this->assertTrue($containers!==false);
- $found= false;
- foreach ($containers as $container) {
- if ($container->getName()==TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME) {
- $found= true;
- break;
- }
- }
- $this->assertTrue($found);
- }
-
- public function testUpdateCdnContainer()
- {
- $data= $this->rackspace->updateCdnContainer(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,null,false);
- $this->assertTrue($data!==false);
- }
-
- public function testDeleteObject()
- {
- $this->assertTrue($this->rackspace->deleteObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
- TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME));
- }
-
- public function testDeleteObject2()
- {
- $this->assertTrue($this->rackspace->deleteObject(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME,
- TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME.'-copy'));
- }
-
- public function testDeleteContainer()
- {
- $this->assertTrue($this->rackspace->deleteContainer(TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME));
- }
-
- }
|