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.
16 * @package Zend_Gdata_Gbase
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
23 require_once 'Zend/Gdata/Gbase.php';
24 require_once 'Zend/Http/Client.php';
25 require_once 'Zend/Gdata/ClientLogin.php';
29 * @package Zend_Gdata_Gbase
30 * @subpackage UnitTests
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32 * @license http://framework.zend.com/license/new-bsd New BSD License
34 * @group Zend_Gdata_Gbase
36 class Zend_Gdata_GbaseOnlineTest
extends PHPUnit_Framework_TestCase
39 public function setUp()
41 $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
42 $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
43 $service = Zend_Gdata_Gbase
::AUTH_SERVICE_NAME
;
44 $client = Zend_Gdata_ClientLogin
::getHttpClient($user, $pass, $service);
45 $this->gdata
= new Zend_Gdata_Gbase($client);
48 public function testGetGbaseItemFeed()
50 $feed = $this->gdata
->getGbaseItemFeed();
51 $this->assertTrue($feed instanceof Zend_Gdata_Gbase_ItemFeed
);
52 foreach ($feed->entries
as $entry) {
53 $this->assertTrue($entry instanceof Zend_Gdata_Gbase_ItemEntry
);
54 $this->assertEquals($entry->getHttpClient(), $feed->getHttpClient());
57 $query = new Zend_Gdata_Gbase_ItemQuery();
58 $feed = $this->gdata
->getGbaseItemFeed($query);
59 $this->assertTrue($feed instanceof Zend_Gdata_Gbase_ItemFeed
);
60 foreach ($feed->entries
as $entry) {
61 $this->assertTrue($entry instanceof Zend_Gdata_Gbase_ItemEntry
);
62 $this->assertEquals($entry->getHttpClient(), $feed->getHttpClient());
65 $uri = $query->getQueryUrl();
66 $feed = $this->gdata
->getGbaseItemFeed($uri);
67 $this->assertTrue($feed instanceof Zend_Gdata_Gbase_ItemFeed
);
68 foreach ($feed->entries
as $entry) {
69 $this->assertTrue($entry instanceof Zend_Gdata_Gbase_ItemEntry
);
70 $this->assertEquals($entry->getHttpClient(), $feed->getHttpClient());
74 public function testGetGbaseItemEntry()
76 $newEntry = $this->gdata
->newItemEntry();
78 $title = 'PHP Developer Handbook';
79 $newEntry->title
= $this->gdata
->newTitle(trim($title));
81 $desc = 'This is a test item';
82 $newEntry->content
= $this->gdata
->newContent($desc);
83 $newEntry->content
->type
= 'text';
85 $itemType = 'Products';
86 $newEntry->itemType
= $itemType;
87 $newEntry->itemType
->type
= 'text';
89 $newEntry->addGbaseAttribute('product_type', 'book', 'text');
90 $newEntry->addGbaseAttribute('price', '12.99 usd', 'floatUnit');
91 $newEntry->addGbaseAttribute('quantity', '10', 'int');
93 $createdEntry = $this->gdata
->insertGbaseItem($newEntry, false);
94 $itemId = $createdEntry->id
->text
;
96 $entry = $this->gdata
->getGbaseItemEntry($itemId);
97 $this->assertTrue($entry instanceof Zend_Gdata_Gbase_ItemEntry
);
100 public function testInsertGbaseItem()
102 $newEntry = $this->gdata
->newItemEntry();
104 $title = 'PHP Developer Handbook';
105 $newEntry->title
= $this->gdata
->newTitle(trim($title));
107 $desc = 'Essential handbook for PHP developers.';
108 $newEntry->content
= $this->gdata
->newContent($desc);
109 $newEntry->content
->type
= 'text';
111 $itemType = 'Products';
112 $newEntry->itemType
= $itemType;
113 $newEntry->itemType
->type
= 'text';
115 $newEntry->addGbaseAttribute('product_type', 'book', 'text');
116 $newEntry->addGbaseAttribute('price', '12.99 usd', 'floatUnit');
117 $newEntry->addGbaseAttribute('quantity', '10', 'int');
119 $createdEntry = $this->gdata
->insertGbaseItem($newEntry, true);
121 $this->assertEquals($title, $createdEntry->title
->text
);
122 $this->assertEquals($desc, $createdEntry->content
->text
);
123 $this->assertEquals($itemType, $createdEntry->itemType
->text
);
125 $baseAttribute = $createdEntry->getGbaseAttribute('product_type');
126 $this->assertEquals('product_type', $baseAttribute[0]->name
);
127 $this->assertEquals('book', $baseAttribute[0]->text
);
128 $this->assertEquals('text', $baseAttribute[0]->type
);
130 $baseAttribute = $createdEntry->getGbaseAttribute('price');
131 $this->assertEquals('price', $baseAttribute[0]->name
);
132 $this->assertEquals('12.99 usd', $baseAttribute[0]->text
);
133 $this->assertEquals('floatUnit', $baseAttribute[0]->type
);
135 $baseAttribute = $createdEntry->getGbaseAttribute('quantity');
136 $this->assertEquals('quantity', $baseAttribute[0]->name
);
137 $this->assertEquals('10', $baseAttribute[0]->text
);
138 $this->assertEquals('int', $baseAttribute[0]->type
);
141 public function testGetGbaseSnippetFeed()
143 $feed = $this->gdata
->getGbaseSnippetFeed();
144 $this->assertTrue($feed instanceof Zend_Gdata_Gbase_SnippetFeed
);
145 foreach ($feed->entries
as $entry) {
146 $this->assertTrue($entry instanceof Zend_Gdata_Gbase_SnippetEntry
);
147 $this->assertEquals($entry->getHttpClient(), $feed->getHttpClient());
150 $query = new Zend_Gdata_Gbase_SnippetQuery();
151 $feed = $this->gdata
->getGbaseSnippetFeed($query);
152 $this->assertTrue($feed instanceof Zend_Gdata_Gbase_SnippetFeed
);
153 foreach ($feed->entries
as $entry) {
154 $this->assertTrue($entry instanceof Zend_Gdata_Gbase_SnippetEntry
);
155 $this->assertEquals($entry->getHttpClient(), $feed->getHttpClient());
158 $uri = $query->getQueryUrl();
159 $feed = $this->gdata
->getGbaseSnippetFeed($uri);
160 $this->assertTrue($feed instanceof Zend_Gdata_Gbase_SnippetFeed
);
161 foreach ($feed->entries
as $entry) {
162 $this->assertTrue($entry instanceof Zend_Gdata_Gbase_SnippetEntry
);
163 $this->assertEquals($entry->getHttpClient(), $feed->getHttpClient());