SimpleDbTest.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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_DocumentService
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 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_DocumentService_Adapter_SimpleDbTest::main() if this source file is executed directly.
  22. if (!defined("PHPUnit_MAIN_METHOD")) {
  23. define("PHPUnit_MAIN_METHOD", "Zend_Cloud_DocumentService_Adapter_SimpleDbTest::main");
  24. }
  25. /**
  26. * @see Zend_Cloud_DocumentServiceTestCase
  27. */
  28. require_once 'Zend/Cloud/DocumentService/TestCase.php';
  29. /** @see Zend_Cloud_DocumenteService_Factory */
  30. require_once 'Zend/Cloud/DocumentService/Factory.php';
  31. /** @see Zend_Cloud_DocumenteService_Adapter_SimpleDb */
  32. require_once 'Zend/Cloud/DocumentService/Adapter/SimpleDb.php';
  33. /** @see Zend_Config */
  34. require_once 'Zend/Config.php';
  35. /**
  36. * @category Zend
  37. * @package Zend_Cloud
  38. * @subpackage UnitTests
  39. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  40. * @license http://framework.zend.com/license/new-bsd New BSD License
  41. */
  42. class Zend_Cloud_DocumentService_Adapter_SimpleDbTest
  43. extends Zend_Cloud_DocumentService_TestCase
  44. {
  45. /**
  46. * Period to wait for propagation in seconds
  47. * Should be set by adapter
  48. *
  49. * @var int
  50. */
  51. protected $_waitPeriod = 10;
  52. protected $_clientType = 'Zend_Service_Amazon_SimpleDb';
  53. /**
  54. * Runs the test methods of this class.
  55. *
  56. * @access public
  57. * @static
  58. */
  59. public static function main()
  60. {
  61. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  62. $result = PHPUnit_TextUI_TestRunner::run($suite);
  63. }
  64. public function testUpdateDocumentMergeAll()
  65. {
  66. $data = $this->_getDocumentData();
  67. $name = $this->_collectionName("testMerge");
  68. $this->_commonDocument->createCollection($name);
  69. $doc = $this->_makeDocument($data[0]);
  70. $this->_commonDocument->insertDocument($name, $doc);
  71. $doc1 = $this->_makeDocument($data[1]);
  72. $this->_wait();
  73. $this->_commonDocument->updateDocument($name, $doc->getID(), $doc1,
  74. array(Zend_Cloud_DocumentService_Adapter_SimpleDb::MERGE_OPTION => true));
  75. $this->_wait();
  76. $fetchdoc = $this->_commonDocument->fetchDocument($name, $doc->getID());
  77. $this->assertTrue($fetchdoc instanceof Zend_Cloud_DocumentService_Document, "New document not found");
  78. $this->assertContains($doc->name, $fetchdoc->name, "Name field did not update: " . var_export($fetchdoc->getFields(), 1));
  79. $this->assertContains($doc1->name, $fetchdoc->name, "Name field did not update: " . var_export($fetchdoc->getFields(), 1));
  80. $this->assertContains((string) $doc->year, $fetchdoc->year, "Year field did not update: " . var_export($fetchdoc->getFields(), 1));
  81. $this->assertContains((string) $doc1->year, $fetchdoc->year, "Year field did not update: " . var_export($fetchdoc->getFields(), 1));
  82. $this->_commonDocument->deleteCollection($name);
  83. }
  84. public function testUpdateDocumentMergeSome()
  85. {
  86. $data = $this->_getDocumentData();
  87. $name = $this->_collectionName("testMerge");
  88. $this->_commonDocument->createCollection($name);
  89. $doc = $this->_makeDocument($data[0]);
  90. $this->_commonDocument->insertDocument($name, $doc);
  91. $doc1 = $this->_makeDocument($data[1]);
  92. $this->_wait();
  93. $this->_commonDocument->updateDocument($name, $doc->getID(), $doc1,
  94. array(Zend_Cloud_DocumentService_Adapter_SimpleDb::MERGE_OPTION =>
  95. array("year" => true, "pages" => true)));
  96. $this->_wait();
  97. $fetchdoc = $this->_commonDocument->fetchDocument($name, $doc->getID());
  98. $this->assertTrue($fetchdoc instanceof Zend_Cloud_DocumentService_Document, "New document not found");
  99. $this->assertEquals($doc1->name, $fetchdoc->name, "Name field did not update");
  100. $this->assertContains((string) $doc1->pages, $fetchdoc->pages, "Page field did not update");
  101. $this->assertContains((string) $doc->pages, $fetchdoc->pages, "Page field did not update");
  102. $this->assertContains((string) $doc1->year, $fetchdoc->year, "Year field did not update");
  103. $this->assertContains((string) $doc->year, $fetchdoc->year, "Year field did not update");
  104. $this->_commonDocument->deleteCollection($name);
  105. }
  106. static function getConfigArray()
  107. {
  108. return array(
  109. Zend_Cloud_DocumentService_Factory::DOCUMENT_ADAPTER_KEY => 'Zend_Cloud_DocumentService_Adapter_SimpleDb',
  110. Zend_Cloud_DocumentService_Adapter_SimpleDb::AWS_ACCESS_KEY => constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'),
  111. Zend_Cloud_DocumentService_Adapter_SimpleDb::AWS_SECRET_KEY => constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY'),
  112. );
  113. }
  114. protected function _getConfig()
  115. {
  116. if (!defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED') ||
  117. !constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED') ||
  118. !defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID') ||
  119. !defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY')) {
  120. $this->markTestSkipped("Amazon SimpleDB access not configured, skipping test");
  121. }
  122. $config = new Zend_Config(self::getConfigArray());
  123. return $config;
  124. }
  125. protected function _getDocumentData()
  126. {
  127. return array(
  128. array(
  129. parent::ID_FIELD => "0385333498",
  130. "name" => "The Sirens of Titan",
  131. "author" => "Kurt Vonnegut",
  132. "year" => 1959,
  133. "pages" => 336,
  134. "keyword" => array("Book", "Paperback")
  135. ),
  136. array(
  137. parent::ID_FIELD => "0802131786",
  138. "name" => "Tropic of Cancer",
  139. "author" => "Henry Miller",
  140. "year" => 1934,
  141. "pages" => 318,
  142. "keyword" => array("Book")
  143. ),
  144. array(
  145. parent::ID_FIELD => "B000T9886K",
  146. "name" => "In Between",
  147. "author" => "Paul Van Dyk",
  148. "year" => 2007,
  149. "keyword" => array("CD", "Music")
  150. ),
  151. array(
  152. parent::ID_FIELD => "1579124585",
  153. "name" => "The Right Stuff",
  154. "author" => "Tom Wolfe",
  155. "year" => 1979,
  156. "pages" => 304,
  157. "keyword" => array("American", "Book", "Hardcover")
  158. ),
  159. );
  160. }
  161. protected function _queryString($domain, $s1, $s2)
  162. {
  163. return "select * from $domain where itemName() = '$s1' OR itemName() = '$s2'";
  164. }
  165. }
  166. if (PHPUnit_MAIN_METHOD == 'Zend_Cloud_DocumentService_Adapter_SimpleDbTest::main') {
  167. Zend_Cloud_DocumentService_Adapter_SimpleDbTest::main();
  168. }