2
0

GbaseOnlineTest.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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_Gdata_Gbase
  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. * @version $Id $
  21. */
  22. require_once 'Zend/Gdata/Gbase.php';
  23. require_once 'Zend/Http/Client.php';
  24. require_once 'Zend/Gdata/ClientLogin.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Gdata_Gbase
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @group Zend_Gdata
  32. * @group Zend_Gdata_Gbase
  33. */
  34. class Zend_Gdata_GbaseOnlineTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function setUp()
  37. {
  38. $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
  39. $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
  40. $service = Zend_Gdata_Gbase::AUTH_SERVICE_NAME;
  41. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  42. $this->gdata = new Zend_Gdata_Gbase($client);
  43. }
  44. public function testGetGbaseItemFeed()
  45. {
  46. $feed = $this->gdata->getGbaseItemFeed();
  47. $this->assertTrue($feed instanceof Zend_Gdata_Gbase_ItemFeed);
  48. foreach ($feed->entries as $entry) {
  49. $this->assertTrue($entry instanceof Zend_Gdata_Gbase_ItemEntry);
  50. $this->assertEquals($entry->getHttpClient(), $feed->getHttpClient());
  51. }
  52. $query = new Zend_Gdata_Gbase_ItemQuery();
  53. $feed = $this->gdata->getGbaseItemFeed($query);
  54. $this->assertTrue($feed instanceof Zend_Gdata_Gbase_ItemFeed);
  55. foreach ($feed->entries as $entry) {
  56. $this->assertTrue($entry instanceof Zend_Gdata_Gbase_ItemEntry);
  57. $this->assertEquals($entry->getHttpClient(), $feed->getHttpClient());
  58. }
  59. $uri = $query->getQueryUrl();
  60. $feed = $this->gdata->getGbaseItemFeed($uri);
  61. $this->assertTrue($feed instanceof Zend_Gdata_Gbase_ItemFeed);
  62. foreach ($feed->entries as $entry) {
  63. $this->assertTrue($entry instanceof Zend_Gdata_Gbase_ItemEntry);
  64. $this->assertEquals($entry->getHttpClient(), $feed->getHttpClient());
  65. }
  66. }
  67. public function testGetGbaseItemEntry()
  68. {
  69. $newEntry = $this->gdata->newItemEntry();
  70. $title = 'PHP Developer Handbook';
  71. $newEntry->title = $this->gdata->newTitle(trim($title));
  72. $desc = 'This is a test item';
  73. $newEntry->content = $this->gdata->newContent($desc);
  74. $newEntry->content->type = 'text';
  75. $itemType = 'Products';
  76. $newEntry->itemType = $itemType;
  77. $newEntry->itemType->type = 'text';
  78. $newEntry->addGbaseAttribute('product_type', 'book', 'text');
  79. $newEntry->addGbaseAttribute('price', '12.99 usd', 'floatUnit');
  80. $newEntry->addGbaseAttribute('quantity', '10', 'int');
  81. $createdEntry = $this->gdata->insertGbaseItem($newEntry, false);
  82. $itemId = $createdEntry->id->text;
  83. $entry = $this->gdata->getGbaseItemEntry($itemId);
  84. $this->assertTrue($entry instanceof Zend_Gdata_Gbase_ItemEntry);
  85. }
  86. public function testInsertGbaseItem()
  87. {
  88. $newEntry = $this->gdata->newItemEntry();
  89. $title = 'PHP Developer Handbook';
  90. $newEntry->title = $this->gdata->newTitle(trim($title));
  91. $desc = 'Essential handbook for PHP developers.';
  92. $newEntry->content = $this->gdata->newContent($desc);
  93. $newEntry->content->type = 'text';
  94. $itemType = 'Products';
  95. $newEntry->itemType = $itemType;
  96. $newEntry->itemType->type = 'text';
  97. $newEntry->addGbaseAttribute('product_type', 'book', 'text');
  98. $newEntry->addGbaseAttribute('price', '12.99 usd', 'floatUnit');
  99. $newEntry->addGbaseAttribute('quantity', '10', 'int');
  100. $createdEntry = $this->gdata->insertGbaseItem($newEntry, true);
  101. $this->assertEquals($title, $createdEntry->title->text);
  102. $this->assertEquals($desc, $createdEntry->content->text);
  103. $this->assertEquals($itemType, $createdEntry->itemType->text);
  104. $baseAttribute = $createdEntry->getGbaseAttribute('product_type');
  105. $this->assertEquals('product_type', $baseAttribute[0]->name);
  106. $this->assertEquals('book', $baseAttribute[0]->text);
  107. $this->assertEquals('text', $baseAttribute[0]->type);
  108. $baseAttribute = $createdEntry->getGbaseAttribute('price');
  109. $this->assertEquals('price', $baseAttribute[0]->name);
  110. $this->assertEquals('12.99 usd', $baseAttribute[0]->text);
  111. $this->assertEquals('floatUnit', $baseAttribute[0]->type);
  112. $baseAttribute = $createdEntry->getGbaseAttribute('quantity');
  113. $this->assertEquals('quantity', $baseAttribute[0]->name);
  114. $this->assertEquals('10', $baseAttribute[0]->text);
  115. $this->assertEquals('int', $baseAttribute[0]->type);
  116. }
  117. public function testGetGbaseSnippetFeed()
  118. {
  119. $feed = $this->gdata->getGbaseSnippetFeed();
  120. $this->assertTrue($feed instanceof Zend_Gdata_Gbase_SnippetFeed);
  121. foreach ($feed->entries as $entry) {
  122. $this->assertTrue($entry instanceof Zend_Gdata_Gbase_SnippetEntry);
  123. $this->assertEquals($entry->getHttpClient(), $feed->getHttpClient());
  124. }
  125. $query = new Zend_Gdata_Gbase_SnippetQuery();
  126. $feed = $this->gdata->getGbaseSnippetFeed($query);
  127. $this->assertTrue($feed instanceof Zend_Gdata_Gbase_SnippetFeed);
  128. foreach ($feed->entries as $entry) {
  129. $this->assertTrue($entry instanceof Zend_Gdata_Gbase_SnippetEntry);
  130. $this->assertEquals($entry->getHttpClient(), $feed->getHttpClient());
  131. }
  132. $uri = $query->getQueryUrl();
  133. $feed = $this->gdata->getGbaseSnippetFeed($uri);
  134. $this->assertTrue($feed instanceof Zend_Gdata_Gbase_SnippetFeed);
  135. foreach ($feed->entries as $entry) {
  136. $this->assertTrue($entry instanceof Zend_Gdata_Gbase_SnippetEntry);
  137. $this->assertEquals($entry->getHttpClient(), $feed->getHttpClient());
  138. }
  139. }
  140. }