FactoryTest.php 5.1 KB

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