| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- <?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_WindowsAzure
- * @subpackage UnitTests
- * @version $Id$
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- if (!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'Zend_Service_WindowsAzure_BlobStreamTest::main');
- }
- /**
- * Test helpers
- */
- require_once dirname(__FILE__) . '/../../../TestHelper.php';
- require_once dirname(__FILE__) . '/../../../TestConfiguration.php.dist';
- /** Zend_Service_WindowsAzure_Storage_Blob */
- require_once 'Zend/Service/WindowsAzure/Storage/Blob.php';
- /**
- * @category Zend
- * @package Zend_Service_WindowsAzure
- * @subpackage UnitTests
- * @version $Id$
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Service_WindowsAzure_BlobStreamTest extends PHPUnit_Framework_TestCase
- {
- static $path;
-
- public function __construct()
- {
- self::$path = dirname(__FILE__).'/_files/';
- }
-
- public static function main()
- {
- if (TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS) {
- $suite = new PHPUnit_Framework_TestSuite("Zend_Service_WindowsAzure_BlobStreamTest");
- $result = PHPUnit_TextUI_TestRunner::run($suite);
- }
- }
-
- /**
- * Test setup
- */
- protected function setUp()
- {
- }
-
- /**
- * Test teardown
- */
- protected function tearDown()
- {
- $storageClient = $this->createStorageInstance();
- for ($i = 1; $i <= self::$uniqId; $i++)
- {
- try { $storageClient->deleteContainer(TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSTREAM_CONTAINER_PREFIX . $i); } catch (Exception $e) { }
- try { $storageClient->unregisterStreamWrapper('azure'); } catch (Exception $e) { }
- }
- }
- protected function createStorageInstance()
- {
- $storageClient = null;
- if (TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNONPROD) {
- $storageClient = new Zend_Service_WindowsAzure_Storage_Blob(TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_PROD, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_PROD, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_PROD, false, Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250));
- } else {
- $storageClient = new Zend_Service_WindowsAzure_Storage_Blob(TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_DEV, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_DEV, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_DEV, true, Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250));
- }
-
- if (TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_USEPROXY) {
- $storageClient->setProxy(TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_USEPROXY, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_PORT, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_CREDENTIALS);
- }
- return $storageClient;
- }
-
- protected static $uniqId = 0;
-
- protected function generateName()
- {
- self::$uniqId++;
- return TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSTREAM_CONTAINER_PREFIX . self::$uniqId;
- }
-
- /**
- * Test read file
- */
- public function testReadFile()
- {
- if (TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS) {
- $containerName = $this->generateName();
- $fileName = 'azure://' . $containerName . '/test.txt';
-
- $storageClient = $this->createStorageInstance();
- $storageClient->registerStreamWrapper();
-
- $fh = fopen($fileName, 'w');
- fwrite($fh, "Hello world!");
- fclose($fh);
-
- $result = file_get_contents($fileName);
-
- $storageClient->unregisterStreamWrapper();
-
- $this->assertEquals('Hello world!', $result);
- }
- }
-
- /**
- * Test write file
- */
- public function testWriteFile()
- {
- if (TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS) {
- $containerName = $this->generateName();
- $fileName = 'azure://' . $containerName . '/test.txt';
-
- $storageClient = $this->createStorageInstance();
- $storageClient->registerStreamWrapper();
-
- $fh = fopen($fileName, 'w');
- fwrite($fh, "Hello world!");
- fclose($fh);
-
- $storageClient->unregisterStreamWrapper();
-
- $instance = $storageClient->getBlobInstance($containerName, 'test.txt');
- $this->assertEquals('test.txt', $instance->Name);
- }
- }
-
- /**
- * Test unlink file
- */
- public function testUnlinkFile()
- {
- if (TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS) {
- $containerName = $this->generateName();
- $fileName = 'azure://' . $containerName . '/test.txt';
-
- $storageClient = $this->createStorageInstance();
- $storageClient->registerStreamWrapper();
-
- $fh = fopen($fileName, 'w');
- fwrite($fh, "Hello world!");
- fclose($fh);
-
- unlink($fileName);
-
- $storageClient->unregisterStreamWrapper();
-
- $result = $storageClient->listBlobs($containerName);
- $this->assertEquals(0, count($result));
- }
- }
-
- /**
- * Test copy file
- */
- public function testCopyFile()
- {
- if (TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS) {
- $containerName = $this->generateName();
- $sourceFileName = 'azure://' . $containerName . '/test.txt';
- $destinationFileName = 'azure://' . $containerName . '/test2.txt';
-
- $storageClient = $this->createStorageInstance();
- $storageClient->registerStreamWrapper();
-
- $fh = fopen($sourceFileName, 'w');
- fwrite($fh, "Hello world!");
- fclose($fh);
- copy($sourceFileName, $destinationFileName);
- $storageClient->unregisterStreamWrapper();
-
- $instance = $storageClient->getBlobInstance($containerName, 'test2.txt');
- $this->assertEquals('test2.txt', $instance->Name);
- }
- }
-
- /**
- * Test rename file
- */
- public function testRenameFile()
- {
- if (TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS) {
- $containerName = $this->generateName();
- $sourceFileName = 'azure://' . $containerName . '/test.txt';
- $destinationFileName = 'azure://' . $containerName . '/test2.txt';
-
- $storageClient = $this->createStorageInstance();
- $storageClient->registerStreamWrapper();
-
- $fh = fopen($sourceFileName, 'w');
- fwrite($fh, "Hello world!");
- fclose($fh);
-
- rename($sourceFileName, $destinationFileName);
-
- $storageClient->unregisterStreamWrapper();
-
- $instance = $storageClient->getBlobInstance($containerName, 'test2.txt');
- $this->assertEquals('test2.txt', $instance->Name);
- }
- }
-
- /**
- * Test mkdir
- */
- public function testMkdir()
- {
- if (TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS) {
- $containerName = $this->generateName();
-
- $storageClient = $this->createStorageInstance();
- $storageClient->registerStreamWrapper();
-
- mkdir('azure://' . $containerName);
-
- $storageClient->unregisterStreamWrapper();
-
- $result = $storageClient->listContainers();
-
- $this->assertEquals(1, count($result));
- $this->assertEquals($containerName, $result[0]->Name);
- }
- }
-
- /**
- * Test rmdir
- */
- public function testRmdir()
- {
- if (TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS) {
- $containerName = $this->generateName();
-
- $storageClient = $this->createStorageInstance();
- $storageClient->registerStreamWrapper();
-
- mkdir('azure://' . $containerName);
- rmdir('azure://' . $containerName);
-
- $storageClient->unregisterStreamWrapper();
-
- $result = $storageClient->listContainers();
-
- $this->assertEquals(0, count($result));
- }
- }
-
- /**
- * Test opendir
- */
- public function testOpendir()
- {
- if (TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS) {
- $containerName = $this->generateName();
- $storageClient = $this->createStorageInstance();
- $storageClient->createContainer($containerName);
-
- $storageClient->putBlob($containerName, 'images/WindowsAzure1.gif', self::$path . 'WindowsAzure.gif');
- $storageClient->putBlob($containerName, 'images/WindowsAzure2.gif', self::$path . 'WindowsAzure.gif');
- $storageClient->putBlob($containerName, 'images/WindowsAzure3.gif', self::$path . 'WindowsAzure.gif');
- $storageClient->putBlob($containerName, 'images/WindowsAzure4.gif', self::$path . 'WindowsAzure.gif');
- $storageClient->putBlob($containerName, 'images/WindowsAzure5.gif', self::$path . 'WindowsAzure.gif');
-
- $result1 = $storageClient->listBlobs($containerName);
-
- $storageClient->registerStreamWrapper();
-
- $result2 = array();
- if ($handle = opendir('azure://' . $containerName)) {
- while (false !== ($file = readdir($handle))) {
- $result2[] = $file;
- }
- closedir($handle);
- }
-
- $storageClient->unregisterStreamWrapper();
-
- $result = $storageClient->listContainers();
-
- $this->assertEquals(count($result1), count($result2));
- }
- }
- }
- // Call Zend_Service_WindowsAzure_BlobStreamTest::main() if this source file is executed directly.
- if (PHPUnit_MAIN_METHOD == "Zend_Service_WindowsAzure_BlobStreamTest::main") {
- Zend_Service_WindowsAzure_BlobStreamTest::main();
- }
|