FactoryTest.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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_Cloud
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. // Call Zend_Cloud_StorageService_FactoryTest::main() if this source file is executed directly.
  22. if (!defined("PHPUnit_MAIN_METHOD")) {
  23. define("PHPUnit_MAIN_METHOD", "Zend_Cloud_StorageService_FactoryTest::main");
  24. }
  25. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  26. /**
  27. * @see Zend_Config_Ini
  28. */
  29. require_once 'Zend/Config/Ini.php';
  30. /**
  31. * @see Zend_Cloud_StorageService_Factory
  32. */
  33. require_once 'Zend/Cloud/StorageService/Factory.php';
  34. require_once 'Zend/Cloud/StorageService/Adapter/FileSystem.php';
  35. require_once 'Zend/Cloud/StorageService/Adapter/Nirvanix.php';
  36. require_once 'Zend/Cloud/StorageService/Adapter/S3.php';
  37. require_once 'Zend/Cloud/StorageService/Adapter/WindowsAzure.php';
  38. require_once 'Zend/Http/Client/Adapter/Test.php';
  39. /**
  40. * Test class for Zend_Cloud_StorageService_Factory
  41. *
  42. * @category Zend
  43. * @package Zend_Cloud
  44. * @subpackage UnitTests
  45. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  46. * @license http://framework.zend.com/license/new-bsd New BSD License
  47. * @group Zend_Cloud
  48. */
  49. class Zend_Cloud_StorageService_FactoryTest extends PHPUnit_Framework_TestCase
  50. {
  51. /**
  52. * Runs the test methods of this class.
  53. *
  54. * @return void
  55. */
  56. public static function main()
  57. {
  58. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  59. $result = PHPUnit_TextUI_TestRunner::run($suite);
  60. }
  61. public function testGetStorageAdapterKey()
  62. {
  63. $this->assertTrue(is_string(Zend_Cloud_StorageService_Factory::STORAGE_ADAPTER_KEY));
  64. }
  65. public function testGetAdapterWithConfig()
  66. {
  67. $httptest = new Zend_Http_Client_Adapter_Test();
  68. // Nirvanix adapter
  69. $nirvanixConfig = new Zend_Config_Ini(realpath(dirname(__FILE__) . '/_files/config/nirvanix.ini'));
  70. $nirvanixConfig = $nirvanixConfig->toArray();
  71. $nirvanixConfig[Zend_Cloud_StorageService_Adapter_Nirvanix::HTTP_ADAPTER] = $httptest;
  72. $doc = new DOMDocument('1.0', 'utf-8');
  73. $root = $doc->createElement('Response');
  74. $responseCode = $doc->createElement('ResponseCode', 0);
  75. $sessionTok = $doc->createElement('SessionToken', '54592180-7060-4D4B-BC74-2566F4B2F943');
  76. $root->appendChild($responseCode);
  77. $root->appendChild($sessionTok);
  78. $doc->appendChild($root);
  79. $body = $doc->saveXML();
  80. $resp = new Zend_Http_Response(200, array('Date' => 0), $body);
  81. $httptest->setResponse($resp);
  82. $nirvanixAdapter = Zend_Cloud_StorageService_Factory::getAdapter(
  83. $nirvanixConfig
  84. );
  85. $this->assertEquals('Zend_Cloud_StorageService_Adapter_Nirvanix', get_class($nirvanixAdapter));
  86. // S3 adapter
  87. $s3Config = new Zend_Config_Ini(realpath(dirname(__FILE__) . '/_files/config/s3.ini'));
  88. $s3Adapter = Zend_Cloud_StorageService_Factory::getAdapter($s3Config);
  89. $this->assertEquals('Zend_Cloud_StorageService_Adapter_S3', get_class($s3Adapter));
  90. // file system adapter
  91. $fileSystemConfig = new Zend_Config_Ini(realpath(dirname(__FILE__) . '/_files/config/filesystem.ini'));
  92. $fileSystemAdapter = Zend_Cloud_StorageService_Factory::getAdapter($fileSystemConfig);
  93. $this->assertEquals('Zend_Cloud_StorageService_Adapter_FileSystem', get_class($fileSystemAdapter));
  94. // Azure adapter
  95. $azureConfig = new Zend_Config_Ini(realpath(dirname(__FILE__) . '/_files/config/windowsazure.ini'));
  96. $azureConfig = $azureConfig->toArray();
  97. $azureContainer = $azureConfig[Zend_Cloud_StorageService_Adapter_WindowsAzure::CONTAINER];
  98. $azureConfig[Zend_Cloud_StorageService_Adapter_WindowsAzure::HTTP_ADAPTER] = $httptest;
  99. $q = "?";
  100. $doc = new DOMDocument('1.0', 'utf-8');
  101. $root = $doc->createElement('EnumerationResults');
  102. $acctName = $doc->createAttribute('AccountName');
  103. $acctName->value = 'http://myaccount.blob.core.windows.net';
  104. $root->appendChild($acctName);
  105. $maxResults = $doc->createElement('MaxResults', 1);
  106. $containers = $doc->createElement('Containers');
  107. $container = $doc->createElement('Container');
  108. $containerName = $doc->createElement('Name', $azureContainer);
  109. $container->appendChild($containerName);
  110. $containers->appendChild($container);
  111. $root->appendChild($maxResults);
  112. $root->appendChild($containers);
  113. $doc->appendChild($root);
  114. $body = $doc->saveXML();
  115. $resp = new Zend_Http_Response(200, array('x-ms-request-id' => 0), $body);
  116. $httptest->setResponse($resp);
  117. $azureAdapter = Zend_Cloud_StorageService_Factory::getAdapter($azureConfig);
  118. $this->assertEquals('Zend_Cloud_StorageService_Adapter_WindowsAzure', get_class($azureAdapter));
  119. }
  120. public function testGetAdapterWithArray()
  121. {
  122. // No need to overdo it; we'll test the array config with just one adapter.
  123. $fileSystemConfig = array(
  124. Zend_Cloud_StorageService_Factory::STORAGE_ADAPTER_KEY => 'Zend_Cloud_StorageService_Adapter_FileSystem',
  125. Zend_Cloud_StorageService_Adapter_FileSystem::LOCAL_DIRECTORY => dirname(__FILE__) ."/_files/data",
  126. );
  127. $fileSystemAdapter = Zend_Cloud_StorageService_Factory::getAdapter($fileSystemConfig);
  128. $this->assertEquals('Zend_Cloud_StorageService_Adapter_FileSystem', get_class($fileSystemAdapter));
  129. }
  130. }
  131. // Call Zend_Cloud_StorageService_FactoryTest::main() if this source file is executed directly.
  132. if (PHPUnit_MAIN_METHOD == "Zend_Cloud_StorageService_FactoryTest::main") {
  133. Zend_Cloud_StorageService_FactoryTest::main();
  134. }