GbaseOnlineTest.php 6.4 KB

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