FactoryTest.php 6.2 KB

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