';
+ $this->content->type = 'xhtml';
+ $contentXml = $this->content->saveXML();
+ $newContent = new Zend_Gdata_App_Extension_Content();
+ $newContent->transferFromXML($contentXml);
+ $newContentXml = $newContent->saveXML();
+ $this->assertEquals($newContentXml, $contentXml);
+ $this->assertEquals('
', $newContent->text);
+ $this->assertEquals('xhtml', $newContent->type);
+ }
+
+ public function testContentWithSrcAndTypeToAndFromStringShouldMatch() {
+ $this->content->src = 'http://www.example.com/image.png';
+ $this->content->type = 'image/png';
+ $contentXml = $this->content->saveXML();
+ $newContent = new Zend_Gdata_App_Extension_Content();
+ $newContent->transferFromXML($contentXml);
+ $newContentXml = $newContent->saveXML();
+ $this->assertEquals($newContentXml, $contentXml);
+ $this->assertEquals('http://www.example.com/image.png', $newContent->src);
+ $this->assertEquals('image/png', $newContent->type);
+ }
+
+ public function testConvertContentWithSrcAndTypeToAndFromString() {
+ $this->content->transferFromXML($this->contentText);
+ $this->assertEquals('http://www.example.com/image.png', $this->content->src);
+ $this->assertEquals('image/png', $this->content->type);
+ }
+
+ public function testConvertContentWithTextAndTypeToAndFromString() {
+ $this->content->transferFromXML($this->contentText2);
+ $this->assertEquals('xhtml', $this->content->type);
+ $this->assertEquals(1, count($this->content->extensionElements));
+ }
+
+}
diff --git a/zend/tests/Zend/Gdata/App/ControlTest.php b/zend/tests/Zend/Gdata/App/ControlTest.php
new file mode 100644
index 0000000..b41b361
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/ControlTest.php
@@ -0,0 +1,75 @@
+controlText = file_get_contents(
+ 'Zend/Gdata/App/_files/ControlElementSample1.xml',
+ true);
+ $this->control = new Zend_Gdata_App_Extension_Control();
+ }
+
+ public function testEmptyControlShouldHaveEmptyExtensionsList() {
+ $this->assertTrue(is_array($this->control->extensionElements));
+ $this->assertTrue(count($this->control->extensionElements) == 0);
+ }
+
+ public function testEmptyControlToAndFromStringShouldMatch() {
+ $controlXml = $this->control->saveXML();
+ $newControl = new Zend_Gdata_App_Extension_Control();
+ $newControl->transferFromXML($controlXml);
+ $newControlXml = $newControl->saveXML();
+ $this->assertTrue($controlXml == $newControlXml);
+ }
+
+ public function testControlWithDraftToAndFromStringShouldMatch() {
+ $draft = new Zend_Gdata_App_Extension_Draft('yes');
+ $this->control->draft = $draft;
+ $controlXml = $this->control->saveXML();
+ $newControl = new Zend_Gdata_App_Extension_Control();
+ $newControl->transferFromXML($controlXml);
+ $newControlXml = $newControl->saveXML();
+ $this->assertEquals($newControlXml, $controlXml);
+ $this->assertEquals('yes', $newControl->draft->text);
+ }
+
+ public function testConvertControlWithDraftToAndFromString() {
+ $this->control->transferFromXML($this->controlText);
+ $this->assertEquals('yes', $this->control->draft->text);
+ }
+
+}
diff --git a/zend/tests/Zend/Gdata/App/EntryTest.php b/zend/tests/Zend/Gdata/App/EntryTest.php
new file mode 100644
index 0000000..5d9ed9b
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/EntryTest.php
@@ -0,0 +1,614 @@
+enryText = file_get_contents(
+ 'Zend/Gdata/App/_files/EntrySample1.xml',
+ true);
+ $this->httpEntrySample = file_get_contents(
+ 'Zend/Gdata/App/_files/EntrySampleHttp1.txt',
+ true);
+ $this->enry = new Zend_Gdata_App_Entry();
+
+ $this->adapter = new Test_Zend_Gdata_MockHttpClient();
+ $this->client = new Zend_Gdata_HttpClient();
+ $this->client->setAdapter($this->adapter);
+ $this->service = new Zend_Gdata_App($this->client);
+ }
+
+ public function testEmptyEntryShouldHaveEmptyExtensionsList()
+ {
+ $this->assertTrue(is_array($this->enry->extensionElements));
+ $this->assertTrue(count($this->enry->extensionElements) == 0);
+ }
+
+ public function testEmptyEntryToAndFromStringShouldMatch()
+ {
+ $enryXml = $this->enry->saveXML();
+ $newEntry = new Zend_Gdata_App_Entry();
+ $newEntry->transferFromXML($enryXml);
+ $newEntryXml = $newEntry->saveXML();
+ $this->assertTrue($enryXml == $newEntryXml);
+ }
+
+ public function testConvertEntryToAndFromString()
+ {
+ $this->enry->transferFromXML($this->enryText);
+ $enryXml = $this->enry->saveXML();
+ $newEntry = new Zend_Gdata_App_Entry();
+ $newEntry->transferFromXML($enryXml);
+/*
+ $this->assertEquals(1, count($newEntry->entry));
+ $this->assertEquals('dive into mark', $newEntry->title->text);
+ $this->assertEquals('text', $newEntry->title->type);
+ $this->assertEquals('2005-07-31T12:29:29Z', $newEntry->updated->text);
+ $this->assertEquals('tag:example.org,2003:3', $newEntry->id->text);
+ $this->assertEquals(2, count($newEntry->link));
+ $this->assertEquals('http://example.org/',
+ $newEntry->getAlternateLink()->href);
+ $this->assertEquals('en',
+ $newEntry->getAlternateLink()->hrefLang);
+ $this->assertEquals('text/html',
+ $newEntry->getAlternateLink()->type);
+ $this->assertEquals('http://example.org/enry.atom',
+ $newEntry->getSelfLink()->href);
+ $this->assertEquals('application/atom+xml',
+ $newEntry->getSelfLink()->type);
+ $this->assertEquals('Copyright (c) 2003, Mark Pilgrim',
+ $newEntry->rights->text);
+ $entry = $newEntry->entry[0];
+ $this->assertEquals('Atom draft-07 snapshot', $entry->title->text);
+ $this->assertEquals('tag:example.org,2003:3.2397',
+ $entry->id->text);
+ $this->assertEquals('2005-07-31T12:29:29Z', $entry->updated->text);
+ $this->assertEquals('2003-12-13T08:29:29-04:00',
+ $entry->published->text);
+ $this->assertEquals('Mark Pilgrim',
+ $entry->author[0]->name->text);
+ $this->assertEquals('http://example.org/',
+ $entry->author[0]->uri->text);
+ $this->assertEquals(2, count($entry->contributor));
+ $this->assertEquals('Sam Ruby',
+ $entry->contributor[0]->name->text);
+ $this->assertEquals('Joe Gregorio',
+ $entry->contributor[1]->name->text);
+ $this->assertEquals('xhtml', $entry->content->type);
+*/
+ }
+
+ public function testCanSetAndGetEtag()
+ {
+ $data = "W/&FooBarBaz&";
+ $this->enry->setEtag($data);
+ $this->assertEquals($this->enry->getEtag(), $data);
+ }
+
+ public function testCanSetAndgetService()
+ {
+ $data = new Zend_Gdata_App();
+ $this->enry->setService($data);
+ $this->assertEquals($this->enry->getService(), $data);
+
+ $data = null;
+ $this->enry->setService($data);
+ $this->assertEquals($this->enry->getService(), $data);
+ }
+
+ public function testsetServiceProvidesFluentInterface()
+ {
+ $result = $this->enry->setService(null);
+ $this->assertEquals($this->enry, $result);
+ }
+
+ public function testGetHttpClientPullsFromServiceInstance()
+ {
+ $s = new Zend_Gdata_App();
+ $this->enry->setService($s);
+
+ $c = new Zend_Gdata_HttpClient();
+ $s->setHttpClient($c);
+ $this->assertEquals($this->enry->getHttpClient(),
+ $s->getHttpClient());
+
+ $c = new Zend_Http_Client();
+ $s->setHttpClient($c);
+ $this->assertEquals($this->enry->getHttpClient(),
+ $s->getHttpClient($c));
+ }
+
+ public function testSetHttpClientPushesIntoServiceInstance()
+ {
+ $s = new Zend_Gdata_App();
+ $this->enry->setService($s);
+
+ $c = new Zend_Gdata_HttpClient();
+ $this->enry->setHttpClient($c);
+ $this->assertEquals(get_class($s->getHttpClient()),
+ 'Zend_Gdata_HttpClient');
+
+ $c = new Zend_Http_Client();
+ $this->enry->setHttpClient($c);
+ $this->assertEquals(get_class($s->getHttpClient()),
+ 'Zend_Http_Client');
+ }
+
+ public function testSaveSupportsGdataV2()
+ {
+ // Prepare mock response
+ $this->adapter->setResponse("HTTP/1.1 201 Created");
+
+ // Make sure that we're using protocol v2
+ $this->service->setMajorProtocolVersion(2);
+ $this->enry->setService($this->service);
+
+ // Set a URL for posting, so that save() will work
+ $editLink = new Zend_Gdata_App_extension_Link('http://example.com',
+ 'edit');
+ $this->enry->setLink(array($editLink));
+
+ // Perform a (mock) save
+ $this->enry->save();
+
+ // Check to make sure that a v2 header was sent
+ $headers = $this->adapter->popRequest()->headers;
+ $found = false;
+ foreach ($headers as $header) {
+ if ($header == 'GData-Version: 2')
+ $found = true;
+ }
+ $this->assertTrue($found,
+ 'GData-Version header missing or incorrect.');
+ }
+
+ public function testDeleteSupportsGdataV2()
+ {
+ // Prepare mock response
+ $this->adapter->setResponse("HTTP/1.1 200 OK");
+
+ // Make sure that we're using protocol v2
+ $this->service->setMajorProtocolVersion(2);
+ $this->enry->setService($this->service);
+
+ // Set a URL for posting, so that save() will work
+ $editLink = new Zend_Gdata_App_extension_Link('http://example.com',
+ 'edit');
+ $this->enry->setLink(array($editLink));
+
+ // Perform a (mock) save
+ $this->enry->delete();
+
+ // Check to make sure that a v2 header was sent
+ $headers = $this->adapter->popRequest()->headers;
+ $found = false;
+ foreach ($headers as $header) {
+ if ($header == 'GData-Version: 2')
+ $found = true;
+ }
+ $this->assertTrue($found,
+ 'GData-Version header missing or incorrect.');
+ }
+
+ public function testIfMatchHeaderCanBeSetOnSave()
+ {
+ $etagOverride = 'foo';
+ $etag = 'ABCD1234';
+ $this->service->setMajorProtocolVersion(2);
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = $this->service->newEntry();
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ 'http://www.example.com',
+ 'edit',
+ 'application/atom+xml'));
+ $entry->setEtag($etag);
+ $newEntry = $entry->save(null, null,
+ array('If-Match' => $etagOverride));
+ $headers = $this->adapter->popRequest()->headers;
+ $found = false;
+ foreach ($headers as $header) {
+ if ($header == 'If-Match: ' . $etagOverride)
+ $found = true;
+ }
+ $this->assertTrue($found,
+ 'If-Match header not found or incorrect');
+ }
+
+ public function testIfNoneMatchHeaderCanBeSetOnSave()
+ {
+ $etagOverride = 'foo';
+ $etag = 'ABCD1234';
+ $this->service->setMajorProtocolVersion(2);
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = $this->service->newEntry();
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ 'http://www.example.com',
+ 'edit',
+ 'application/atom+xml'));
+ $entry->setEtag($etag);
+ $newEntry = $entry->save(null, null,
+ array('If-None-Match' => $etagOverride));
+ $headers = $this->adapter->popRequest()->headers;
+ $found = false;
+ foreach ($headers as $header) {
+ if ($header == 'If-None-Match: ' . $etagOverride)
+ $found = true;
+ }
+ $this->assertTrue($found,
+ 'If-None-Match header not found or incorrect');
+ }
+
+ public function testCanSetUriOnSave()
+ {
+ $uri = 'http://example.net/foo/bar';
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = $this->service->newEntry();
+ $newEntry = $entry->save($uri);
+ $request = $this->adapter->popRequest();
+ $uriObject = Zend_Uri_Http::fromString($uri);
+ $uriObject->setPort('80');
+ $this->assertEquals($uriObject, $request->uri);
+ }
+
+ public function testCanSetClassnameOnSave()
+ {
+ $className = 'Zend_Gdata_Entry';
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = $this->service->newEntry();
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ 'http://www.example.com',
+ 'edit',
+ 'application/atom+xml'));
+ $newEntry = $entry->save(null, $className);
+ $this->assertEquals($className, get_class($newEntry));
+ }
+
+ public function testIfNoneMatchSetOnReload()
+ {
+ $etag = 'ABCD1234';
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = $this->service->newEntry();
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ 'http://www.example.com',
+ 'edit',
+ 'application/atom+xml'));
+ $entry->setEtag($etag);
+ $newEntry = $entry->reload();
+ $headers = $this->adapter->popRequest()->headers;
+ $found = false;
+ foreach ($headers as $header) {
+ if ($header == 'If-None-Match: ' . $etag)
+ $found = true;
+ }
+ $this->assertTrue($found,
+ 'If-None-Match header not found or incorrect');
+ }
+
+ public function testIfNoneMatchCanBeSetOnReload()
+ {
+ $etagOverride = 'foo';
+ $etag = 'ABCD1234';
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = $this->service->newEntry();
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ 'http://www.example.com',
+ 'edit',
+ 'application/atom+xml'));
+ $entry->setEtag($etag);
+ $newEntry = $entry->reload(null, null,
+ array('If-None-Match' => $etagOverride));
+ $headers = $this->adapter->popRequest()->headers;
+ $found = false;
+ foreach ($headers as $header) {
+ if ($header == 'If-None-Match: ' . $etagOverride)
+ $found = true;
+ }
+ $this->assertTrue($found,
+ 'If-None-Match header not found or incorrect');
+ }
+
+ public function testReloadReturnsEntryObject()
+ {
+ $etag = 'ABCD1234';
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = $this->service->newEntry();
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ 'http://www.example.com',
+ 'edit',
+ 'application/atom+xml'));
+ $entry->setEtag($etag);
+ $newEntry = $entry->reload();
+ $this->assertEquals('Zend_Gdata_App_Entry', get_class($newEntry));
+ }
+
+ public function testReloadPopulatesEntryObject()
+ {
+ $etag = 'ABCD1234';
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = $this->service->newEntry();
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ 'http://www.example.com',
+ 'edit',
+ 'application/atom+xml'));
+ $entry->setEtag($etag);
+ $newEntry = $entry->reload();
+ $this->assertEquals('Hello world', $newEntry->title->text);
+ }
+
+ public function testReloadDoesntThrowExceptionIfNoEtag()
+ {
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = $this->service->newEntry();
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ 'http://www.example.com',
+ 'edit',
+ 'application/atom+xml'));
+ $newEntry = $entry->reload();
+ $this->assertEquals('Zend_Gdata_App_Entry', get_class($newEntry));
+ }
+
+ public function testReloadExtractsURIFromEditLink()
+ {
+ $expectedUri = 'http://www.example.com';
+ $etag = 'ABCD1234';
+ $this->service->setMajorProtocolVersion(2);
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = $this->service->newEntry();
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ $expectedUri,
+ 'edit',
+ 'application/atom+xml'));
+ $entry->setEtag($etag);
+ $newEntry = $entry->reload();
+ $requestUri = $this->adapter->popRequest()->uri;
+ $expectedUriObject = Zend_Uri_Http::fromString($expectedUri);
+ $expectedUriObject->setPort('80');
+ $this->assertEquals($expectedUriObject, $requestUri);
+ }
+
+ public function testReloadAllowsCustomURI()
+ {
+ $uriOverride = 'http://www.example.org';
+ $etag = 'ABCD1234';
+ $this->service->setMajorProtocolVersion(2);
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = $this->service->newEntry();
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ 'http://www.example.com',
+ 'edit',
+ 'application/atom+xml'));
+ $entry->setEtag($etag);
+ $newEntry = $entry->reload($uriOverride);
+ $requestUri = $this->adapter->popRequest()->uri;
+ $uriOverrideObject = Zend_Uri_Http::fromString($uriOverride);
+ $uriOverrideObject->setPort('80');
+ $this->assertEquals($uriOverrideObject, $requestUri);
+ }
+
+ public function testReloadReturnsNullIfEntryNotModified()
+ {
+ $etag = 'ABCD1234';
+ $this->service->setMajorProtocolVersion(2);
+ $this->adapter->setResponse('HTTP/1.1 304 Not Modified');
+ $entry = $this->service->newEntry();
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ 'http://www.example.com',
+ 'edit',
+ 'application/atom+xml'));
+ $entry->setEtag($etag);
+ $newEntry = $entry->reload();
+ $this->assertEquals(null, $newEntry);
+ }
+
+ public function testCanSetReloadReturnClassname()
+ {
+ $className = 'Zend_Gdata_Entry';
+ $etag = 'ABCD1234';
+ $this->service->setMajorProtocolVersion(2);
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = $this->service->newEntry();
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ 'http://www.example.com',
+ 'edit',
+ 'application/atom+xml'));
+ $entry->setEtag($etag);
+ $newEntry = $entry->reload(null, $className);
+ $this->assertEquals($className, get_class($newEntry));
+ }
+
+ public function testReloadInheritsClassname()
+ {
+ $className = 'Zend_Gdata_Entry';
+ $etag = 'ABCD1234';
+ $this->service->setMajorProtocolVersion(2);
+ $this->adapter->setResponse($this->httpEntrySample);
+ $entry = new $className;
+ $entry->setService($this->service);
+ $entry->link = array(new Zend_Gdata_App_Extension_Link(
+ 'http://www.example.com',
+ 'edit',
+ 'application/atom+xml'));
+ $entry->setEtag($etag);
+ $newEntry = $entry->reload();
+ $this->assertEquals($className, get_class($newEntry));
+ }
+
+ public function testCanSetMajorProtocolVersion()
+ {
+ $expectedVersion = 42;
+ $entry = $this->service->newEntry();
+ $entry->setMajorProtocolVersion($expectedVersion);
+ $receivedVersion = $entry->getMajorProtocolVersion();
+ $this->assertEquals($expectedVersion, $receivedVersion);
+ }
+
+ public function testCanSetMinorProtocolVersion()
+ {
+ $expectedVersion = 42;
+ $entry = $this->service->newEntry();
+ $entry->setMinorProtocolVersion($expectedVersion);
+ $receivedVersion = $entry->getMinorProtocolVersion();
+ $this->assertEquals($expectedVersion, $receivedVersion);
+ }
+
+ public function testMajorProtocolVersionCannotBeZero()
+ {
+ $expectedVersion = 0;
+ $entry = $this->service->newEntry();
+ $this->setExpectedException('Zend_Gdata_App_InvalidArgumentException');
+ $entry->setMajorProtocolVersion($expectedVersion);
+ }
+
+ public function testMajorProtocolVersionCannotBeNegative()
+ {
+ $expectedVersion = -1;
+ $entry = $this->service->newEntry();
+ $this->setExpectedException('Zend_Gdata_App_InvalidArgumentException');
+ $entry->setMajorProtocolVersion($expectedVersion);
+ }
+
+ public function testMajorProtocolVersionMayBeNull()
+ {
+ $expectedVersion = null;
+ $entry = $this->service->newEntry();
+ $entry->setMajorProtocolVersion($expectedVersion);
+ $receivedVersion = $entry->getMajorProtocolVersion();
+ $this->assertNull($receivedVersion);
+ }
+
+ public function testMinorProtocolVersionMayBeZero()
+ {
+ $expectedVersion = 0;
+ $entry = $this->service->newEntry();
+ $entry->setMinorProtocolVersion($expectedVersion);
+ $receivedVersion = $entry->getMinorProtocolVersion();
+ $this->assertEquals($expectedVersion, $receivedVersion);
+ }
+
+ public function testMinorProtocolVersionCannotBeNegative()
+ {
+ $expectedVersion = -1;
+ $entry = $this->service->newEntry();
+ $this->setExpectedException('Zend_Gdata_App_InvalidArgumentException');
+ $entry->setMinorProtocolVersion($expectedVersion);
+ }
+
+ public function testMinorProtocolVersionMayBeNull()
+ {
+ $expectedVersion = null;
+ $entry = $this->service->newEntry();
+ $entry->setMinorProtocolVersion($expectedVersion);
+ $receivedVersion = $entry->getMinorProtocolVersion();
+ $this->assertNull($receivedVersion);
+ }
+
+ public function testDefaultMajorProtocolVersionIs1()
+ {
+ $entry = $this->service->newEntry();
+ $this->assertEquals(1, $entry->getMajorProtocolVersion());
+ }
+
+ public function testDefaultMinorProtocolVersionIsNull()
+ {
+ $entry = $this->service->newEntry();
+ $this->assertNull($entry->getMinorProtocolVersion());
+ }
+
+ public function testLookupNamespaceUsesCurrentVersion()
+ {
+ $prefix = 'test';
+ $v1TestString = 'TEST-v1';
+ $v2TestString = 'TEST-v2';
+
+ Zend_Gdata_App_Base::flushNamespaceLookupCache();
+ $entry = $this->service->newEntry();
+ $entry->registerNamespace($prefix, $v1TestString, 1, 0);
+ $entry->registerNamespace($prefix, $v2TestString, 2, 0);
+ $entry->setMajorProtocolVersion(1);
+ $result = $entry->lookupNamespace($prefix);
+ $this->assertEquals($v1TestString, $result);
+ $entry->setMajorProtocolVersion(2);
+ $result = $entry->lookupNamespace($prefix);
+ $this->assertEquals($v2TestString, $result);
+ $entry->setMajorProtocolVersion(null); // Should default to latest
+ $result = $entry->lookupNamespace($prefix);
+ $this->assertEquals($v2TestString, $result);
+ }
+
+ public function testLookupNamespaceObeysParentBehavior()
+ {
+ $prefix = 'test';
+ $testString10 = 'TEST-v1-0';
+ $testString20 = 'TEST-v2-0';
+ $testString11 = 'TEST-v1-1';
+ $testString21 = 'TEST-v2-1';
+ $testString12 = 'TEST-v1-2';
+ $testString22 = 'TEST-v2-2';
+
+ Zend_Gdata_App_Base::flushNamespaceLookupCache();
+ $entry = $this->service->newEntry();
+ $entry->registerNamespace($prefix, $testString10, 1, 0);
+ $entry->registerNamespace($prefix, $testString20, 2, 0);
+ $entry->registerNamespace($prefix, $testString11, 1, 1);
+ $entry->registerNamespace($prefix, $testString21, 2, 1);
+ $entry->registerNamespace($prefix, $testString12, 1, 2);
+ $entry->registerNamespace($prefix, $testString22, 2, 2);
+
+ // Assumes default version (1)
+ $result = $entry->lookupNamespace($prefix, 1, null);
+ $this->assertEquals($testString12, $result);
+ $result = $entry->lookupNamespace($prefix, 2, null);
+ $this->assertEquals($testString22, $result);
+ $result = $entry->lookupNamespace($prefix, 1, 1);
+ $this->assertEquals($testString11, $result);
+ $result = $entry->lookupNamespace($prefix, 2, 1);
+ $this->assertEquals($testString21, $result);
+ $result = $entry->lookupNamespace($prefix, null, null);
+ $this->assertEquals($testString12, $result);
+ $result = $entry->lookupNamespace($prefix, null, 1);
+ $this->assertEquals($testString11, $result);
+
+ // Override to retrieve latest version
+ $entry->setMajorProtocolVersion(null);
+ $result = $entry->lookupNamespace($prefix, null, null);
+ $this->assertEquals($testString22, $result);
+ $result = $entry->lookupNamespace($prefix, null, 1);
+ $this->assertEquals($testString21, $result);
+ }
+
+}
diff --git a/zend/tests/Zend/Gdata/App/FeedTest.php b/zend/tests/Zend/Gdata/App/FeedTest.php
new file mode 100644
index 0000000..a86b6c7
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/FeedTest.php
@@ -0,0 +1,282 @@
+feedText = file_get_contents(
+ 'Zend/Gdata/App/_files/FeedSample1.xml',
+ true);
+ $this->feed = new Zend_Gdata_App_Feed();
+ }
+
+ public function testEmptyFeedShouldHaveEmptyExtensionsList() {
+ $this->assertTrue(is_array($this->feed->extensionElements));
+ $this->assertTrue(count($this->feed->extensionElements) == 0);
+ }
+
+ public function testEmptyFeedToAndFromStringShouldMatch() {
+ $feedXml = $this->feed->saveXML();
+ $newFeed = new Zend_Gdata_App_Feed();
+ $newFeed->transferFromXML($feedXml);
+ $newFeedXml = $newFeed->saveXML();
+ $this->assertTrue($feedXml == $newFeedXml);
+ }
+
+ public function testConvertFeedToAndFromString() {
+ $this->feed->transferFromXML($this->feedText);
+ $feedXml = $this->feed->saveXML();
+ $newFeed = new Zend_Gdata_App_Feed();
+ $newFeed->transferFromXML($feedXml);
+ $this->assertEquals(1, count($newFeed->entry));
+ $this->assertEquals('dive into mark', $newFeed->title->text);
+ $this->assertEquals('text', $newFeed->title->type);
+ $this->assertEquals('2005-07-31T12:29:29Z', $newFeed->updated->text);
+ $this->assertEquals('tag:example.org,2003:3', $newFeed->id->text);
+ $this->assertEquals(2, count($newFeed->link));
+ $this->assertEquals('http://example.org/',
+ $newFeed->getAlternateLink()->href);
+ $this->assertEquals('en',
+ $newFeed->getAlternateLink()->hrefLang);
+ $this->assertEquals('text/html',
+ $newFeed->getAlternateLink()->type);
+ $this->assertEquals('http://example.org/feed.atom',
+ $newFeed->getSelfLink()->href);
+ $this->assertEquals('application/atom+xml',
+ $newFeed->getSelfLink()->type);
+ $this->assertEquals('Copyright (c) 2003, Mark Pilgrim',
+ $newFeed->rights->text);
+ $entry = $newFeed->entry[0];
+ $this->assertEquals('Atom draft-07 snapshot', $entry->title->text);
+ $this->assertEquals('tag:example.org,2003:3.2397',
+ $entry->id->text);
+ $this->assertEquals('2005-07-31T12:29:29Z', $entry->updated->text);
+ $this->assertEquals('2003-12-13T08:29:29-04:00',
+ $entry->published->text);
+ $this->assertEquals('Mark Pilgrim',
+ $entry->author[0]->name->text);
+ $this->assertEquals('http://example.org/',
+ $entry->author[0]->uri->text);
+ $this->assertEquals(2, count($entry->contributor));
+ $this->assertEquals('Sam Ruby',
+ $entry->contributor[0]->name->text);
+ $this->assertEquals('Joe Gregorio',
+ $entry->contributor[1]->name->text);
+ $this->assertEquals('xhtml', $entry->content->type);
+ }
+
+ public function testCanAddIndividualEntries() {
+ $this->feed->transferFromXML($this->feedText);
+ $this->assertEquals(1, count($this->feed->entry));
+ $oldTitle = $this->feed->entry[0]->title->text;
+ $newEntry = new Zend_Gdata_App_Entry();
+ $newEntry->setTitle(new Zend_Gdata_App_Extension_Title("Foo"));
+ $this->feed->addEntry($newEntry);
+ $this->assertEquals(2, count($this->feed->entry));
+ $this->assertEquals($oldTitle, $this->feed->entry[0]->title->text);
+ $this->assertEquals("Foo", $this->feed->entry[1]->title->text);
+ }
+
+ public function testCanSetAndGetEtag() {
+ $data = "W/&FooBarBaz&";
+ $this->feed->setEtag($data);
+ $this->assertEquals($this->feed->getEtag(), $data);
+ }
+
+ public function testSetServicePropagatesToChildren() {
+ // Setup
+ $entries = array(new Zend_Gdata_App_Entry(),
+ new Zend_Gdata_App_Entry());
+ foreach ($entries as $entry) {
+ $this->feed->addEntry($entry);
+ }
+
+ // Set new service instance and test for propagation
+ $s = new Zend_Gdata_App();
+ $this->feed->setService($s);
+
+ $service = $this->feed->getService();
+ if (!is_object($service)) {
+ $this->fail('No feed service received');
+ }
+ $this->assertEquals('Zend_Gdata_App',
+ get_class($service));
+
+ foreach ($entries as $entry) {
+ $service = $entry->getService();
+ if (!is_object($service)) {
+ $this->fail('No entry service received');
+ }
+ $this->assertEquals('Zend_Gdata_App',
+ get_class($service));
+ }
+
+ // Set null service instance and test for propagation
+ $s = null;
+ $this->feed->setService($s);
+ $this->assertFalse(is_object($this->feed->getService()));
+ foreach ($entries as $entry) {
+ $service = $entry->getService();
+ $this->assertFalse(is_object($service));
+ }
+ }
+
+ public function testCanSetMajorProtocolVersion()
+ {
+ $expectedVersion = 42;
+ $this->feed->setMajorProtocolVersion($expectedVersion);
+ $receivedVersion = $this->feed->getMajorProtocolVersion();
+ $this->assertEquals($expectedVersion, $receivedVersion);
+ }
+
+ public function testCanSetMinorProtocolVersion()
+ {
+ $expectedVersion = 42;
+ $this->feed->setMinorProtocolVersion($expectedVersion);
+ $receivedVersion = $this->feed->getMinorProtocolVersion();
+ $this->assertEquals($expectedVersion, $receivedVersion);
+ }
+
+ public function testEntriesInheritFeedVersionOnCreate()
+ {
+ $major = 98;
+ $minor = 12;
+ $this->feed->setMajorProtocolVersion($major);
+ $this->feed->setMinorProtocolVersion($minor);
+ $this->feed->transferFromXML($this->feedText);
+ foreach ($this->feed->entries as $entry) {
+ $this->assertEquals($major, $entry->getMajorProtocolVersion());
+ $this->assertEquals($minor, $entry->getMinorProtocolVersion());
+ }
+ }
+
+ public function testEntriesInheritFeedVersionOnUpdate()
+ {
+ $major = 98;
+ $minor = 12;
+ $this->feed->transferFromXML($this->feedText);
+ $this->feed->setMajorProtocolVersion($major);
+ $this->feed->setMinorProtocolVersion($minor);
+ foreach ($this->feed->entries as $entry) {
+ $this->assertEquals($major, $entry->getMajorProtocolVersion());
+ $this->assertEquals($minor, $entry->getMinorProtocolVersion());
+ }
+ }
+
+ public function testDefaultMajorProtocolVersionIs1()
+ {
+ $this->assertEquals(1, $this->feed->getMajorProtocolVersion());
+ }
+
+ public function testDefaultMinorProtocolVersionIsNull()
+ {
+ $this->assertNull($this->feed->getMinorProtocolVersion());
+ }
+
+ public function testLookupNamespaceUsesCurrentVersion()
+ {
+ $prefix = 'test';
+ $v1TestString = 'TEST-v1';
+ $v2TestString = 'TEST-v2';
+
+ Zend_Gdata_App_Base::flushNamespaceLookupCache();
+ $feed = $this->feed;
+ $feed->registerNamespace($prefix, $v1TestString, 1, 0);
+ $feed->registerNamespace($prefix, $v2TestString, 2, 0);
+ $feed->setMajorProtocolVersion(1);
+ $result = $feed->lookupNamespace($prefix);
+ $this->assertEquals($v1TestString, $result);
+ $feed->setMajorProtocolVersion(2);
+ $result = $feed->lookupNamespace($prefix);
+ $this->assertEquals($v2TestString, $result);
+ $feed->setMajorProtocolVersion(null); // Should default to latest
+ $result = $feed->lookupNamespace($prefix);
+ }
+
+ public function testLookupNamespaceObeysParentBehavior()
+ {
+ $prefix = 'test';
+ $testString10 = 'TEST-v1-0';
+ $testString20 = 'TEST-v2-0';
+ $testString11 = 'TEST-v1-1';
+ $testString21 = 'TEST-v2-1';
+ $testString12 = 'TEST-v1-2';
+ $testString22 = 'TEST-v2-2';
+
+ Zend_Gdata_App_Base::flushNamespaceLookupCache();
+ $feed = $this->feed;
+ $feed->registerNamespace($prefix, $testString10, 1, 0);
+ $feed->registerNamespace($prefix, $testString20, 2, 0);
+ $feed->registerNamespace($prefix, $testString11, 1, 1);
+ $feed->registerNamespace($prefix, $testString21, 2, 1);
+ $feed->registerNamespace($prefix, $testString12, 1, 2);
+ $feed->registerNamespace($prefix, $testString22, 2, 2);
+
+ // Assumes default version (1)
+ $result = $feed->lookupNamespace($prefix, 1, null);
+ $this->assertEquals($testString12, $result);
+ $result = $feed->lookupNamespace($prefix, 2, null);
+ $this->assertEquals($testString22, $result);
+ $result = $feed->lookupNamespace($prefix, 1, 1);
+ $this->assertEquals($testString11, $result);
+ $result = $feed->lookupNamespace($prefix, 2, 1);
+ $this->assertEquals($testString21, $result);
+ $result = $feed->lookupNamespace($prefix, null, null);
+ $this->assertEquals($testString12, $result);
+ $result = $feed->lookupNamespace($prefix, null, 1);
+ $this->assertEquals($testString11, $result);
+
+ // Override to retrieve latest version
+ $feed->setMajorProtocolVersion(null);
+ $result = $feed->lookupNamespace($prefix, null, null);
+ $this->assertEquals($testString22, $result);
+ $result = $feed->lookupNamespace($prefix, null, 1);
+ $this->assertEquals($testString21, $result);
+ }
+
+ /**
+ * @group ZF-10242
+ */
+ public function testCount()
+ {
+ $feed = new Zend_Gdata_App_Feed();
+ $feed->addEntry('foo')
+ ->addEntry('bar');
+
+ $this->assertEquals(2, $feed->count());
+ $this->assertEquals(2, count($feed));
+ }
+}
diff --git a/zend/tests/Zend/Gdata/App/GeneratorTest.php b/zend/tests/Zend/Gdata/App/GeneratorTest.php
new file mode 100644
index 0000000..ac1a02b
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/GeneratorTest.php
@@ -0,0 +1,82 @@
+generatorText = file_get_contents(
+ 'Zend/Gdata/App/_files/GeneratorElementSample1.xml',
+ true);
+ $this->generator = new Zend_Gdata_App_Extension_Generator();
+ }
+
+ public function testEmptyGeneratorShouldHaveEmptyExtensionsList() {
+ $this->assertTrue(is_array($this->generator->extensionElements));
+ $this->assertTrue(count($this->generator->extensionElements) == 0);
+ }
+
+ public function testEmptyGeneratorToAndFromStringShouldMatch() {
+ $generatorXml = $this->generator->saveXML();
+ $newGenerator = new Zend_Gdata_App_Extension_Generator();
+ $newGenerator->transferFromXML($generatorXml);
+ $newGeneratorXml = $newGenerator->saveXML();
+ $this->assertTrue($generatorXml == $newGeneratorXml);
+ }
+
+ public function testGeneratorToAndFromStringShouldMatch() {
+ $this->generator->uri = 'http://code.google.com/apis/gdata/';
+ $this->generator->version = '1.0';
+ $this->generator->text = 'Google data APIs';
+ $generatorXml = $this->generator->saveXML();
+ $newGenerator = new Zend_Gdata_App_Extension_Generator();
+ $newGenerator->transferFromXML($generatorXml);
+ $newGeneratorXml = $newGenerator->saveXML();
+ $this->assertEquals($newGeneratorXml, $generatorXml);
+ $this->assertEquals('http://code.google.com/apis/gdata/',
+ $newGenerator->uri);
+ $this->assertEquals('1.0', $newGenerator->version);
+ $this->assertEquals('Google data APIs', $newGenerator->text);
+ }
+
+ public function testConvertGeneratorWithDraftToAndFromString() {
+ $this->generator->transferFromXML($this->generatorText);
+ $this->assertEquals('http://code.google.com/apis/gdata/',
+ $this->generator->uri);
+ $this->assertEquals('1.0', $this->generator->version);
+ $this->assertEquals('Google data APIs', $this->generator->text);
+ }
+
+}
diff --git a/zend/tests/Zend/Gdata/App/HttpExceptionTest.php b/zend/tests/Zend/Gdata/App/HttpExceptionTest.php
new file mode 100755
index 0000000..eba19da
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/HttpExceptionTest.php
@@ -0,0 +1,71 @@
+sprKey = constant('TESTS_ZEND_GDATA_SPREADSHEETS_SPREADSHEETKEY');
+ $this->wksId = constant('TESTS_ZEND_GDATA_SPREADSHEETS_WORKSHEETID');
+ $service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
+ $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
+ $this->gdata = new Zend_Gdata_Spreadsheets($client);
+ }
+
+ public function testGetRawResponseBody()
+ {
+ try {
+ $rowData = array();
+ $entry = $this->gdata->insertRow($rowData, $this->sprKey);
+ $this->fail('Expecting Zend_Gdata_App_HttpException');
+ } catch (Zend_Gdata_App_HttpException $hExc) {
+ $this->assertThat($hExc,
+ $this->isInstanceOf('Zend_Gdata_App_HttpException'),
+ 'Expecting Zend_Gdata_App_HttpException, got '
+ . get_class($hExc));
+
+ $message = $hExc->getMessage();
+ $this->assertEquals($message, 'Expected response code 200, got 400');
+ $body = $hExc->getRawResponseBody();
+ $this->assertNotNull($body);
+ $this->assertNotEquals(stripos($body,
+ 'Blank rows cannot be written; use delete instead.'), false);
+ }
+ }
+}
diff --git a/zend/tests/Zend/Gdata/App/MockBase.php b/zend/tests/Zend/Gdata/App/MockBase.php
new file mode 100644
index 0000000..581fc99
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/MockBase.php
@@ -0,0 +1,38 @@
+assertEquals('2006-12-01', $date);
+ }
+
+ public function testFormatTimestampFromStringWithTimezone()
+ {
+ // assert that a correctly formatted timestamp is not modified
+ $date = Zend_Gdata_App_Util::formatTimestamp('2007-01-10T13:31:12-04:00');
+ $this->assertEquals('2007-01-10T13:31:12-04:00', $date);
+ }
+
+ public function testFormatTimestampWithMilliseconds()
+ {
+ // assert that a correctly formatted timestamp is not modified
+ $date = Zend_Gdata_App_Util::formatTimestamp('1956-12-14T43:09:54.52376Z');
+ $this->assertEquals('1956-12-14T43:09:54.52376Z', $date);
+ }
+
+ public function testFormatTimestampUsingZuluAsOffset()
+ {
+ // assert that a correctly formatted timestamp is not modified
+ $date = Zend_Gdata_App_Util::formatTimestamp('2024-03-19T01:38:12Z');
+ $this->assertEquals('2024-03-19T01:38:12Z', $date);
+ }
+
+ public function testFormatTimestampUsingLowercaseTAndZ()
+ {
+ // assert that a correctly formatted timestamp is not modified
+ $date = Zend_Gdata_App_Util::formatTimestamp('1945-07-19t12:19:08z');
+ $this->assertEquals('1945-07-19t12:19:08z', $date);
+ }
+
+ public function testFormatTimestampFromStringWithNonCompliantDate()
+ {
+ // assert that a non-compliant date is converted to RFC 3339
+ $date = Zend_Gdata_App_Util::formatTimestamp('2007/07/13');
+ $this->assertEquals('2007-07-13T00:00:00', $date);
+ }
+
+ public function testFormatTimestampFromInteger()
+ {
+ $ts = 1164960000; // Fri Dec 1 00:00:00 PST 2006
+ $date = Zend_Gdata_App_Util::formatTimestamp($ts);
+ $this->assertEquals('2006-12-01T08:00:00+00:00', $date);
+ }
+
+ public function testExceptionFormatTimestampNonsense()
+ {
+ $util = new Zend_Gdata_App_Util();
+ try {
+ $ts = Zend_Gdata_App_Util::formatTimestamp('nonsense string');
+ } catch (Zend_Gdata_App_Exception $e) {
+ $this->assertEquals('Invalid timestamp: nonsense string.', $e->getMessage());
+ return;
+ }
+ // Excetion not thrown, this is bad.
+ $this->fail("Exception not thrown.");
+ }
+
+ public function testExceptionFormatTimestampSemiInvalid()
+ {
+ $util = new Zend_Gdata_App_Util();
+ try {
+ $ts = Zend_Gdata_App_Util::formatTimestamp('2007-06-05adslfkja');
+ } catch (Zend_Gdata_App_Exception $e) {
+ $this->assertEquals('Invalid timestamp: 2007-06-05adslfkja.', $e->getMessage());
+ return;
+ }
+ // Excetion not thrown, this is bad.
+ $this->fail("Exception not thrown.");
+ }
+
+ public function testExceptionFormatTimestampInvalidTime()
+ {
+ $util = new Zend_Gdata_App_Util();
+ try {
+ $ts = Zend_Gdata_App_Util::formatTimestamp('2007-06-05Tadslfkja');
+ } catch (Zend_Gdata_App_Exception $e) {
+ $this->assertEquals('Invalid timestamp: 2007-06-05Tadslfkja.', $e->getMessage());
+ return;
+ }
+ // Excetion not thrown, this is bad.
+ $this->fail("Exception not thrown.");
+ }
+
+ public function testExceptionFormatTimestampInvalidOffset()
+ {
+ $util = new Zend_Gdata_App_Util();
+ try {
+ $ts = Zend_Gdata_App_Util::formatTimestamp('2007-06-05T02:51:12+egg');
+ } catch (Zend_Gdata_App_Exception $e) {
+ $this->assertEquals('Invalid timestamp: 2007-06-05T02:51:12+egg.', $e->getMessage());
+ return;
+ }
+ // Excetion not thrown, this is bad.
+ $this->fail("Exception not thrown.");
+ }
+
+ public function testExceptionFormatTimestampInvalidOffsetHours()
+ {
+ $util = new Zend_Gdata_App_Util();
+ try {
+ $ts = Zend_Gdata_App_Util::formatTimestamp('2007-06-05T02:51:12-ab:00');
+ } catch (Zend_Gdata_App_Exception $e) {
+ $this->assertEquals('Invalid timestamp: 2007-06-05T02:51:12-ab:00.', $e->getMessage());
+ return;
+ }
+ // Excetion not thrown, this is bad.
+ $this->fail("Exception not thrown.");
+ }
+
+ /**
+ * @group ZF-11610
+ */
+ public function testFormatTimestepHandlesSmallUnixTimestampProperly()
+ {
+ $this->assertEquals(
+ '1970-01-01T00:02:03+00:00',
+ Zend_Gdata_App_Util::formatTimestamp(123)
+ );
+ }
+
+ public function testFindGreatestBoundedValueReturnsMax() {
+ $data = array(-1 => null,
+ 0 => null,
+ 1 => null,
+ 2 => null,
+ 3 => null,
+ 5 => null,
+ -2 => null);
+ $result = Zend_Gdata_App_Util::findGreatestBoundedValue(99, $data);
+ $this->assertEquals(5, $result);
+ }
+
+ public function testFindGreatestBoundedValueReturnsMaxWhenBounded() {
+ $data = array(-1 => null,
+ 0 => null,
+ 1 => null,
+ 2 => null,
+ 3 => null,
+ 5 => null,
+ -2 => null);
+ $result = Zend_Gdata_App_Util::findGreatestBoundedValue(4, $data);
+ $this->assertEquals(3, $result);
+ }
+
+ public function testFindGreatestBoundedValueReturnsMaxWhenUnbounded() {
+ $data = array(-1 => null,
+ 0 => null,
+ 1 => null,
+ 2 => null,
+ 3 => null,
+ 5 => null,
+ -2 => null);
+ $result = Zend_Gdata_App_Util::findGreatestBoundedValue(null, $data);
+ $this->assertEquals(5, $result);
+ }
+
+ public function testFindGreatestBoundedValueReturnsZeroWhenZeroBounded() {
+ $data = array(-1 => null,
+ 0 => null,
+ 1 => null,
+ 2 => null,
+ 3 => null,
+ 5 => null,
+ -2 => null);
+ $result = Zend_Gdata_App_Util::findGreatestBoundedValue(0, $data);
+ $this->assertEquals(0, $result);
+ }
+
+ public function testFindGreatestBoundedValueFailsWhenNegativelyBounded() {
+ $data = array(-1 => null,
+ 0 => null,
+ 1 => null,
+ 2 => null,
+ 3 => null,
+ 5 => null,
+ -2 => null);
+ try {
+ $result = Zend_Gdata_App_Util::findGreatestBoundedValue(-1, $data);
+ $failed = true;
+ } catch (Zend_Gdata_App_Exception $e) {
+ $failed = false;
+ }
+ $this->assertFalse($failed, 'Exception not raised.');
+ }
+
+}
diff --git a/zend/tests/Zend/Gdata/App/_files/AuthorElementSample1.xml b/zend/tests/Zend/Gdata/App/_files/AuthorElementSample1.xml
new file mode 100644
index 0000000..772b6f5
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/_files/AuthorElementSample1.xml
@@ -0,0 +1,6 @@
+
+
[Update: The Atom draft is finished.]
+[Update: The Atom draft is finished.]
+