summaryrefslogtreecommitdiff
path: root/zend/tests/Zend/Gdata/App
diff options
context:
space:
mode:
authorHorus32014-02-24 16:42:14 +0100
committerHorus32014-02-24 16:42:14 +0100
commit06f945f27840b53e57795dadbc38e76f7e11ab1c (patch)
tree689d5c7f4ffa15460c7e90f47c6a7dd59ce4e8bd /zend/tests/Zend/Gdata/App
downloadrandom-06f945f27840b53e57795dadbc38e76f7e11ab1c.tar.gz
init
Diffstat (limited to 'zend/tests/Zend/Gdata/App')
-rw-r--r--zend/tests/Zend/Gdata/App/AuthorTest.php118
-rw-r--r--zend/tests/Zend/Gdata/App/BaseTest.php133
-rw-r--r--zend/tests/Zend/Gdata/App/CaptchaRequiredExceptionTest.php58
-rw-r--r--zend/tests/Zend/Gdata/App/CategoryTest.php114
-rw-r--r--zend/tests/Zend/Gdata/App/ContentTest.php97
-rw-r--r--zend/tests/Zend/Gdata/App/ControlTest.php75
-rw-r--r--zend/tests/Zend/Gdata/App/EntryTest.php614
-rw-r--r--zend/tests/Zend/Gdata/App/FeedTest.php282
-rw-r--r--zend/tests/Zend/Gdata/App/GeneratorTest.php82
-rwxr-xr-xzend/tests/Zend/Gdata/App/HttpExceptionTest.php71
-rw-r--r--zend/tests/Zend/Gdata/App/MockBase.php38
-rw-r--r--zend/tests/Zend/Gdata/App/UtilTest.php229
-rw-r--r--zend/tests/Zend/Gdata/App/_files/AuthorElementSample1.xml6
-rw-r--r--zend/tests/Zend/Gdata/App/_files/CategoryElementSample1.xml4
-rw-r--r--zend/tests/Zend/Gdata/App/_files/ContentElementSample1.xml3
-rw-r--r--zend/tests/Zend/Gdata/App/_files/ContentElementSample2.xml2
-rw-r--r--zend/tests/Zend/Gdata/App/_files/ControlElementSample1.xml4
-rw-r--r--zend/tests/Zend/Gdata/App/_files/EntrySample1.xml28
-rw-r--r--zend/tests/Zend/Gdata/App/_files/EntrySampleHttp1.txt29
-rw-r--r--zend/tests/Zend/Gdata/App/_files/FeedSample1.xml45
-rw-r--r--zend/tests/Zend/Gdata/App/_files/GeneratorElementSample1.xml2
21 files changed, 2034 insertions, 0 deletions
diff --git a/zend/tests/Zend/Gdata/App/AuthorTest.php b/zend/tests/Zend/Gdata/App/AuthorTest.php
new file mode 100644
index 0000000..b1fde22
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/AuthorTest.php
@@ -0,0 +1,118 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id $
+ */
+
+require_once 'Zend/Gdata/App/Extension/Author.php';
+require_once 'Zend/Gdata/App.php';
+
+/**
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Gdata
+ * @group Zend_Gdata_App
+ */
+class Zend_Gdata_App_AuthorTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp() {
+ $this->authorText = file_get_contents(
+ 'Zend/Gdata/App/_files/AuthorElementSample1.xml',
+ true);
+ $this->author = new Zend_Gdata_App_Extension_Author();
+ }
+
+ public function testEmptyAuthorShouldHaveEmptyExtensionsList() {
+ $this->assertTrue(is_array($this->author->extensionElements));
+ $this->assertTrue(count($this->author->extensionElements) == 0);
+ }
+
+ public function testNormalAuthorShouldHaveNoExtensionElements() {
+ $this->author->name = new Zend_Gdata_App_Extension_Name('Jeff Scudder');
+ $this->assertEquals($this->author->name->text, 'Jeff Scudder');
+ $this->assertEquals(count($this->author->extensionElements), 0);
+ $newAuthor = new Zend_Gdata_App_Extension_Author();
+ $newAuthor->transferFromXML($this->author->saveXML());
+ $this->assertEquals(count($newAuthor->extensionElements), 0);
+ $newAuthor->extensionElements = array(
+ new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
+ $this->assertEquals(count($newAuthor->extensionElements), 1);
+ $this->assertEquals($newAuthor->name->text, 'Jeff Scudder');
+
+ /* try constructing using magic factory */
+ $app = new Zend_Gdata_App();
+ $newAuthor2 = $app->newAuthor();
+ $newAuthor2->transferFromXML($newAuthor->saveXML());
+ $this->assertEquals(count($newAuthor2->extensionElements), 1);
+ $this->assertEquals($newAuthor2->name->text, 'Jeff Scudder');
+ }
+
+ public function testEmptyAuthorToAndFromStringShouldMatch() {
+ $authorXml = $this->author->saveXML();
+ $newAuthor = new Zend_Gdata_App_Extension_Author();
+ $newAuthor->transferFromXML($authorXml);
+ $newAuthorXml = $newAuthor->saveXML();
+ $this->assertTrue($authorXml == $newAuthorXml);
+ }
+
+ public function testAuthorWithNameEmailToAndFromStringShouldMatch() {
+ $this->author->name = new Zend_Gdata_App_Extension_Name('Jeff Scudder');
+ $this->author->email = new Zend_Gdata_App_Extension_Email(
+ 'api.jscudder@gmail.com');
+ $this->author->uri = new Zend_Gdata_App_Extension_Uri(
+ 'http://code.google.com/apis/gdata/');
+ $authorXml = $this->author->saveXML();
+ $newAuthor = new Zend_Gdata_App_Extension_Author();
+ $newAuthor->transferFromXML($authorXml);
+ $newAuthorXml = $newAuthor->saveXML();
+ $this->assertTrue($authorXml == $newAuthorXml);
+ $this->assertEquals('Jeff Scudder', $newAuthor->name->text);
+ $this->assertEquals('api.jscudder@gmail.com', $newAuthor->email->text);
+ $this->assertEquals('http://code.google.com/apis/gdata/', $newAuthor->uri->text);
+ }
+
+ public function testExtensionAttributes() {
+ $extensionAttributes = $this->author->extensionAttributes;
+ $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
+ $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
+ $this->author->extensionAttributes = $extensionAttributes;
+ $this->assertEquals('bar', $this->author->extensionAttributes['foo1']['value']);
+ $this->assertEquals('rab', $this->author->extensionAttributes['foo2']['value']);
+ $authorXml = $this->author->saveXML();
+ $newAuthor = new Zend_Gdata_App_Extension_Author();
+ $newAuthor->transferFromXML($authorXml);
+ //var_dump($this->author);
+ //print $authorXml;
+ $this->assertEquals('bar', $newAuthor->extensionAttributes['foo1']['value']);
+ $this->assertEquals('rab', $newAuthor->extensionAttributes['foo2']['value']);
+ }
+
+ public function testConvertFullAuthorToAndFromString() {
+ $this->author->transferFromXML($this->authorText);
+ $this->assertEquals($this->author->name->text, 'John Doe');
+ $this->assertEquals($this->author->email->text,
+ 'johndoes@someemailadress.com');
+ $this->assertEquals($this->author->uri->text, 'http://www.google.com');
+ }
+
+}
diff --git a/zend/tests/Zend/Gdata/App/BaseTest.php b/zend/tests/Zend/Gdata/App/BaseTest.php
new file mode 100644
index 0000000..6fae63d
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/BaseTest.php
@@ -0,0 +1,133 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id $
+ */
+
+require_once 'Zend/Gdata/App/MockBase.php';
+
+/**
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Gdata
+ * @group Zend_Gdata_App
+ */
+class Zend_Gdata_App_BaseTest extends PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ $this->fileName = 'Zend/Gdata/App/_files/FeedSample1.xml';
+ $this->base = new Zend_Gdata_App_MockBase();
+ }
+
+ public function testUnknownNamespaceReturnsInput() {
+ $this->assertEquals('example',
+ $this->base->lookupNamespace('example'));
+ }
+ public function testAtomV1NamespaceReturnedByDefault() {
+ $this->assertEquals('http://www.w3.org/2005/Atom',
+ $this->base->lookupNamespace('atom'));
+ }
+
+ public function testAtomPubV1NamespaceReturnedByDefault() {
+ $this->assertEquals('http://purl.org/atom/app#',
+ $this->base->lookupNamespace('app'));
+ }
+
+ public function testAtomV1NamespaceReturnedWhenSpecifyingMajorVersion() {
+ $this->assertEquals('http://www.w3.org/2005/Atom',
+ $this->base->lookupNamespace('atom',
+ 1));
+ }
+
+ public function testAtomV1NamespaceReturnedWhenSpecifyingMajorAndMinorVersion() {
+ $this->assertEquals('http://www.w3.org/2005/Atom',
+ $this->base->lookupNamespace('atom',
+ 1, 0));
+ }
+
+ public function testAtomPubV1NamespaceReturnedWhenSpecifyingMajorVersion() {
+ $this->assertEquals('http://purl.org/atom/app#',
+ $this->base->lookupNamespace('app',
+ 1));
+ }
+
+ public function testAtomPubV1NamespaceReturnedWhenSpecifyingMajorAndMinorVersion() {
+ $this->assertEquals('http://purl.org/atom/app#',
+ $this->base->lookupNamespace('app',
+ 1, 0));
+ }
+
+ public function testAtomPubV2NamespaceReturnedWhenSpecifyingMajorVersion() {
+ $this->assertEquals('http://www.w3.org/2007/app',
+ $this->base->lookupNamespace('app',
+ 2));
+ }
+
+ public function testAtomPubV2NamespaceReturnedWhenSpecifyingMajorAndMinorVersion() {
+ $this->assertEquals('http://www.w3.org/2007/app',
+ $this->base->lookupNamespace('app',
+ 2, 0));
+ }
+
+ public function testNullReturnsLatestVersion() {
+ $this->assertEquals('http://www.w3.org/2007/app',
+ $this->base->lookupNamespace('app',
+ null, null));
+ }
+
+ public function testRegisterNamespaceWorksWithoutVersion() {
+ $ns = 'http://example.net/namespaces.foo';
+ $prefix = 'foo';
+ $this->base->registerNamespace($prefix, $ns);
+ $result = $this->base->lookupNamespace($prefix);
+ $this->assertEquals($ns, $result);
+ }
+
+ public function testRegisterNamespaceAllowsSettingMajorVersion() {
+ $ns = 'http://example.net/namespaces.foo';
+ $prefix = 'foo';
+ $this->base->registerNamespace($prefix, 'wrong-1', 1);
+ $this->base->registerNamespace($prefix, $ns, 2);
+ $this->base->registerNamespace($prefix, 'wrong-3', 3);
+ $this->base->registerNamespace($prefix, 'wrong-4', 4);
+ $result = $this->base->lookupNamespace($prefix, 2);
+ $this->assertEquals($ns, $result);
+ }
+
+ public function testRegisterNamespaceAllowsSettingMinorVersion() {
+ $ns = 'http://example.net/namespaces.foo';
+ $prefix = 'foo';
+ $this->base->registerNamespace($prefix, 'wrong-1', 1);
+ $this->base->registerNamespace($prefix, 'wrong-2-0', 2,0);
+ $this->base->registerNamespace($prefix, 'wrong-2-1', 2,1);
+ $this->base->registerNamespace($prefix, 'wrong-2-2', 2,2);
+ $this->base->registerNamespace($prefix, $ns, 2, 3);
+ $this->base->registerNamespace($prefix, 'wrong-2-4', 2,4);
+ $this->base->registerNamespace($prefix, 'wrong-3-0', 3-0);
+ $this->base->registerNamespace($prefix, 'wrong-3-1', 3-1);
+ $this->base->registerNamespace($prefix, 'wrong-4', 4);
+ $result = $this->base->lookupNamespace($prefix, 2, 3);
+ $this->assertEquals($ns, $result);
+ }
+
+}
diff --git a/zend/tests/Zend/Gdata/App/CaptchaRequiredExceptionTest.php b/zend/tests/Zend/Gdata/App/CaptchaRequiredExceptionTest.php
new file mode 100644
index 0000000..c4ada6b
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/CaptchaRequiredExceptionTest.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id $
+ */
+
+ require_once 'Zend/Gdata/App/CaptchaRequiredException.php';
+
+/**
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Gdata
+ * @group Zend_Gdata_App
+ */
+class Zend_Gdata_App_CaptchaRequiredExceptionTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp() {
+ $this->exampleException = new Zend_Gdata_App_CaptchaRequiredException('testtoken', 'Captcha?ctoken=testtoken');
+ }
+
+ public function testExceptionContainsValidInformation() {
+ $this->assertEquals('testtoken', $this->exampleException->getCaptchaToken());
+ $this->assertEquals('https://www.google.com/accounts/Captcha?ctoken=testtoken', $this->exampleException->getCaptchaUrl());
+ }
+
+ public function testExceptionIsThrowable() {
+ $caught = false;
+ try {
+ throw $this->exampleException;
+ }
+ catch(Zend_Gdata_App_CaptchaRequiredException $e) {
+ $caught = true;
+ }
+
+ $this->assertTrue($caught);
+ }
+
+}
diff --git a/zend/tests/Zend/Gdata/App/CategoryTest.php b/zend/tests/Zend/Gdata/App/CategoryTest.php
new file mode 100644
index 0000000..289af56
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/CategoryTest.php
@@ -0,0 +1,114 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id $
+ */
+
+require_once 'Zend/Gdata/App/Extension/Category.php';
+require_once 'Zend/Gdata/App.php';
+
+/**
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Gdata
+ * @group Zend_Gdata_App
+ */
+class Zend_Gdata_App_CategoryTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp() {
+ $this->categoryText = file_get_contents(
+ 'Zend/Gdata/App/_files/CategoryElementSample1.xml',
+ true);
+ $this->category = new Zend_Gdata_App_Extension_Category();
+ }
+
+ public function testEmptyCategoryShouldHaveEmptyExtensionsList() {
+ $this->assertTrue(is_array($this->category->extensionElements));
+ $this->assertTrue(count($this->category->extensionElements) == 0);
+ }
+
+ public function testNormalCategoryShouldHaveNoExtensionElements() {
+
+ $this->category->scheme = 'http://schemas.google.com/g/2005#kind';
+ $this->assertEquals($this->category->scheme, 'http://schemas.google.com/g/2005#kind');
+ $this->assertEquals(count($this->category->extensionElements), 0);
+ $newCategory = new Zend_Gdata_App_Extension_Category();
+ $newCategory->transferFromXML($this->category->saveXML());
+ $this->assertEquals(0, count($newCategory->extensionElements));
+ $newCategory->extensionElements = array(
+ new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
+ $this->assertEquals(count($newCategory->extensionElements), 1);
+ $this->assertEquals($newCategory->scheme, 'http://schemas.google.com/g/2005#kind');
+
+ /* try constructing using magic factory */
+ $app = new Zend_Gdata_App();
+ $newCategory2 = $app->newCategory();
+ $newCategory2->transferFromXML($newCategory->saveXML());
+ $this->assertEquals(count($newCategory2->extensionElements), 1);
+ $this->assertEquals($newCategory2->scheme, 'http://schemas.google.com/g/2005#kind');
+ }
+
+ public function testEmptyCategoryToAndFromStringShouldMatch() {
+ $categoryXml = $this->category->saveXML();
+ $newCategory = new Zend_Gdata_App_Extension_Category();
+ $newCategory->transferFromXML($categoryXml);
+ $newCategoryXml = $newCategory->saveXML();
+ $this->assertTrue($categoryXml == $newCategoryXml);
+ }
+
+ public function testCategoryWithSchemeAndTermToAndFromStringShouldMatch() {
+ $this->category->scheme = 'http://schemas.google.com/g/2005#kind';
+ $this->category->term = 'http://schemas.google.com/g/2005#event';
+ $this->category->label = 'event kind';
+ $categoryXml = $this->category->saveXML();
+ $newCategory = new Zend_Gdata_App_Extension_Category();
+ $newCategory->transferFromXML($categoryXml);
+ $newCategoryXml = $newCategory->saveXML();
+ $this->assertTrue($categoryXml == $newCategoryXml);
+ $this->assertEquals('http://schemas.google.com/g/2005#kind', $newCategory->scheme);
+ $this->assertEquals('http://schemas.google.com/g/2005#event', $newCategory->term);
+ $this->assertEquals('event kind', $newCategory->label);
+ }
+
+ public function testExtensionAttributes() {
+ $extensionAttributes = $this->category->extensionAttributes;
+ $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
+ $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
+ $this->category->extensionAttributes = $extensionAttributes;
+ $this->assertEquals('bar', $this->category->extensionAttributes['foo1']['value']);
+ $this->assertEquals('rab', $this->category->extensionAttributes['foo2']['value']);
+ $categoryXml = $this->category->saveXML();
+ $newCategory = new Zend_Gdata_App_Extension_Category();
+ $newCategory->transferFromXML($categoryXml);
+ $this->assertEquals('bar', $newCategory->extensionAttributes['foo1']['value']);
+ $this->assertEquals('rab', $newCategory->extensionAttributes['foo2']['value']);
+ }
+
+ public function testConvertFullCategoryToAndFromString() {
+ $this->category->transferFromXML($this->categoryText);
+ $this->assertEquals('http://schemas.google.com/g/2005#kind', $this->category->scheme);
+ $this->assertEquals('http://schemas.google.com/g/2005#event', $this->category->term);
+ $this->assertEquals('event kind', $this->category->label);
+ }
+
+}
diff --git a/zend/tests/Zend/Gdata/App/ContentTest.php b/zend/tests/Zend/Gdata/App/ContentTest.php
new file mode 100644
index 0000000..eec6d7c
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/ContentTest.php
@@ -0,0 +1,97 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id $
+ */
+
+require_once 'Zend/Gdata/App/Extension/Content.php';
+require_once 'Zend/Gdata/App.php';
+
+/**
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Gdata
+ * @group Zend_Gdata_App
+ */
+class Zend_Gdata_App_ContentTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp() {
+ $this->contentText = file_get_contents(
+ 'Zend/Gdata/App/_files/ContentElementSample1.xml',
+ true);
+ $this->contentText2 = file_get_contents(
+ 'Zend/Gdata/App/_files/ContentElementSample2.xml',
+ true);
+ $this->content = new Zend_Gdata_App_Extension_Content();
+ }
+
+ public function testEmptyContentShouldHaveEmptyExtensionsList() {
+ $this->assertTrue(is_array($this->content->extensionElements));
+ $this->assertTrue(count($this->content->extensionElements) == 0);
+ }
+
+ public function testEmptyContentToAndFromStringShouldMatch() {
+ $contentXml = $this->content->saveXML();
+ $newContent = new Zend_Gdata_App_Extension_Content();
+ $newContent->transferFromXML($contentXml);
+ $newContentXml = $newContent->saveXML();
+ $this->assertTrue($contentXml == $newContentXml);
+ }
+
+ public function testContentWithTextAndTypeToAndFromStringShouldMatch() {
+ $this->content->text = '<img src="http://www.example.com/image.jpg"/>';
+ $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('<img src="http://www.example.com/image.jpg"/>', $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 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id $
+ */
+
+require_once 'Zend/Gdata/App/Extension/Control.php';
+require_once 'Zend/Gdata/App/Extension/Draft.php';
+require_once 'Zend/Gdata/App.php';
+
+/**
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Gdata
+ * @group Zend_Gdata_App
+ */
+class Zend_Gdata_App_ControlTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp() {
+ $this->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 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id $
+ */
+
+require_once 'Zend/Gdata/App/Entry.php';
+require_once 'Zend/Gdata/App.php';
+require_once 'Zend/Gdata/TestUtility/MockHttpClient.php';
+require_once 'Zend/Gdata/HttpClient.php';
+
+/**
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Gdata
+ * @group Zend_Gdata_App
+ */
+class Zend_Gdata_App_EntryTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp()
+ {
+ $this->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/&amp;FooBarBaz&amp;";
+ $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 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @feed Zend
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id $
+ */
+
+require_once 'Zend/Gdata/App/Feed.php';
+require_once 'Zend/Gdata/App.php';
+
+/**
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Gdata
+ * @group Zend_Gdata_App
+ */
+class Zend_Gdata_App_FeedTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp() {
+ $this->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/&amp;FooBarBaz&amp;";
+ $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 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id $
+ */
+
+require_once 'Zend/Gdata/App/Extension/Generator.php';
+require_once 'Zend/Gdata/App/Extension/Draft.php';
+require_once 'Zend/Gdata/App.php';
+
+/**
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Gdata
+ * @group Zend_Gdata_App
+ */
+class Zend_Gdata_App_GeneratorTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp() {
+ $this->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 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id $
+ */
+
+require_once 'Zend/Gdata/App.php';
+require_once 'Zend/Gdata/Spreadsheets.php';
+require_once 'Zend/Http/Client.php';
+require_once 'Zend/Gdata/ClientLogin.php';
+
+/**
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Gdata
+ * @group Zend_Gdata_App
+ */
+class Zend_Gdata_App_HttpExceptionTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp()
+ {
+ $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
+ $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
+ $this->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 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id $
+ */
+
+require_once 'Zend/Gdata/App/Base.php';
+
+/**
+ * Minimal implementation of Zend_Gdata_App_Base
+ *
+ * @category Zend
+ * @package Zend_Gdata
+ * @subpackage Unittests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+
+class Zend_Gdata_App_MockBase extends Zend_Gdata_App_Base
+{
+ // This space intentionally left blank.
+}
diff --git a/zend/tests/Zend/Gdata/App/UtilTest.php b/zend/tests/Zend/Gdata/App/UtilTest.php
new file mode 100644
index 0000000..9d97a53
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/UtilTest.php
@@ -0,0 +1,229 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id $
+ */
+
+require_once 'Zend/Http/Client.php';
+require_once 'Zend/Gdata/App/Util.php';
+require_once 'Zend/Gdata/App/Exception.php';
+
+/**
+ * @category Zend
+ * @package Zend_Gdata_App
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Gdata
+ * @group Zend_Gdata_App
+ */
+class Zend_Gdata_App_UtilTest extends PHPUnit_Framework_TestCase
+{
+
+ public function testFormatTimestampFromString()
+ {
+ // assert that a correctly formatted timestamp is not modified
+ $date = Zend_Gdata_App_Util::formatTimestamp('2006-12-01');
+ $this->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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<author xmlns="http://www.w3.org/2005/Atom">
+ <name xmlns="http://www.w3.org/2005/Atom">John Doe</name>
+ <email xmlns="http://www.w3.org/2005/Atom">johndoes@someemailadress.com</email>
+ <uri xmlns="http://www.w3.org/2005/Atom">http://www.google.com</uri>
+</author>
diff --git a/zend/tests/Zend/Gdata/App/_files/CategoryElementSample1.xml b/zend/tests/Zend/Gdata/App/_files/CategoryElementSample1.xml
new file mode 100644
index 0000000..2a8b609
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/_files/CategoryElementSample1.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<category scheme="http://schemas.google.com/g/2005#kind"
+ term="http://schemas.google.com/g/2005#event"
+ label="event kind"></category>
diff --git a/zend/tests/Zend/Gdata/App/_files/ContentElementSample1.xml b/zend/tests/Zend/Gdata/App/_files/ContentElementSample1.xml
new file mode 100644
index 0000000..91acb5b
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/_files/ContentElementSample1.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8"?>
+<content type="image/png"
+ src="http://www.example.com/image.png"/>
diff --git a/zend/tests/Zend/Gdata/App/_files/ContentElementSample2.xml b/zend/tests/Zend/Gdata/App/_files/ContentElementSample2.xml
new file mode 100644
index 0000000..18cdfc1
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/_files/ContentElementSample2.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<content type="xhtml"><img src="http://www.example.com/image.jpg"/></content>
diff --git a/zend/tests/Zend/Gdata/App/_files/ControlElementSample1.xml b/zend/tests/Zend/Gdata/App/_files/ControlElementSample1.xml
new file mode 100644
index 0000000..5fbd7ef
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/_files/ControlElementSample1.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<control xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://purl.org/atom/app#">
+ <app:draft>yes</app:draft>
+</control>
diff --git a/zend/tests/Zend/Gdata/App/_files/EntrySample1.xml b/zend/tests/Zend/Gdata/App/_files/EntrySample1.xml
new file mode 100644
index 0000000..27de402
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/_files/EntrySample1.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<entry xmlns="http://www.w3.org/2005/Atom">
+ <title>Atom draft-07 snapshot</title>
+ <link rel="alternate" type="text/html"
+ href="http://example.org/2005/04/02/atom"/>
+ <link rel="enclosure" type="audio/mpeg" length="1337"
+ href="http://example.org/audio/ph34r_my_podcast.mp3"/>
+ <id>tag:example.org,2003:3.2397</id>
+ <updated>2005-07-31T12:29:29Z</updated>
+ <published>2003-12-13T08:29:29-04:00</published>
+ <author>
+ <name>Mark Pilgrim</name>
+ <uri>http://example.org/</uri>
+ <email>f8dy@example.com</email>
+ </author>
+ <contributor>
+ <name>Sam Ruby</name>
+ </contributor>
+ <contributor>
+ <name>Joe Gregorio</name>
+ </contributor>
+ <content type="xhtml" xml:lang="en"
+ xml:base="http://diveintomark.org/">
+ <div xmlns="http://www.w3.org/1999/xhtml">
+ <p><i>[Update: The Atom draft is finished.]</i></p>
+ </div>
+ </content>
+</entry>
diff --git a/zend/tests/Zend/Gdata/App/_files/EntrySampleHttp1.txt b/zend/tests/Zend/Gdata/App/_files/EntrySampleHttp1.txt
new file mode 100644
index 0000000..33bdd0b
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/_files/EntrySampleHttp1.txt
@@ -0,0 +1,29 @@
+HTTP/1.1 200 OK
+Content-Type: application/atom+xml; charset=UTF-8
+Last-Modified: Sun, 07 Sep 2008 17:53:51 GMT
+Cache-Control: max-age=0 private
+ETag: W/"CkcHQH8_fCp7ImA9WxRTGEw."
+Date: Sun, 07 Sep 2008 21:23:39 GMT
+Content-Length: 1450
+Server: GFE/1.3
+
+<?xml version="1.0" encoding="UTF-8"?>
+<?xml-stylesheet href="http://www.google.com/url?sa=D&amp;q=http://www.blogger.com/styles/atom.css" type="text/css"?>
+<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" gd:etag="W/&quot;CkcHQH8_fCp7ImA9WxRTGEw.&quot;">
+ <id>tag:blogger.com,1999:blog-8273578352962669317.post-6938730899689776686</id>
+ <published>2008-09-07T10:53:00.001-07:00</published>
+ <updated>2008-09-07T10:53:51.144-07:00</updated>
+ <app:edited xmlns:app="http://www.w3.org/2007/app">2008-09-07T10:53:51.144-07:00</app:edited>
+ <title>Hello world</title>
+ <content type="html">&lt;p&gt;Hello world!&lt;/p&gt;</content>
+ <link rel="alternate" type="text/html" href="http://www.google.com/url?sa=D&amp;q=http://example.blogspot.com/2008/09/hello-world.html" title="Hello world"/>
+ <link rel="replies" type="text/html" href="http://www.google.com/url?sa=D&amp;q=http://www.blogger.com/comment.g%3FblogID%3D12345678901234567890%26amp%3BpostID%3D09876543210987654321" title="0 Comments"/>
+ <link rel="replies" type="application/atom+xml" href="http://www.google.com/url?sa=D&amp;q=http://example.blogspot.com/feeds/12345678901234567890/comments/default" title="Post Comments"/>
+ <link rel="self" type="application/atom+xml" href="http://www.google.com/url?sa=D&amp;q=http://example.blogspot.com/feeds/posts/default/12345678901234567890"/>
+ <link rel="edit" type="application/atom+xml" href="http://www.google.com/url?sa=D&amp;q=http://www.blogger.com/feeds/12345678901234567890/posts/default/09876543210987654321%3Fv%3D2"/>
+ <author>
+ <name>John Doe</name>
+ <uri>http://www.blogger.com/profile/12345678901234567890</uri>
+ <email>jdoe@example.com</email>
+ </author>
+</entry>
diff --git a/zend/tests/Zend/Gdata/App/_files/FeedSample1.xml b/zend/tests/Zend/Gdata/App/_files/FeedSample1.xml
new file mode 100644
index 0000000..b1a4b36
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/_files/FeedSample1.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <title type="text">dive into mark</title>
+ <subtitle type="html">
+ A &lt;em&gt;lot&lt;/em&gt; of effort
+ went into making this effortless
+ </subtitle>
+ <updated>2005-07-31T12:29:29Z</updated>
+ <id>tag:example.org,2003:3</id>
+ <link rel="alternate" type="text/html"
+ hreflang="en" href="http://example.org/"/>
+ <link rel="self" type="application/atom+xml"
+ href="http://example.org/feed.atom"/>
+ <rights>Copyright (c) 2003, Mark Pilgrim</rights>
+ <generator uri="http://www.example.com/" version="1.0">
+ Example Toolkit
+ </generator>
+ <entry>
+ <title>Atom draft-07 snapshot</title>
+ <link rel="alternate" type="text/html"
+ href="http://example.org/2005/04/02/atom"/>
+ <link rel="enclosure" type="audio/mpeg" length="1337"
+ href="http://example.org/audio/ph34r_my_podcast.mp3"/>
+ <id>tag:example.org,2003:3.2397</id>
+ <updated>2005-07-31T12:29:29Z</updated>
+ <published>2003-12-13T08:29:29-04:00</published>
+ <author>
+ <name>Mark Pilgrim</name>
+ <uri>http://example.org/</uri>
+ <email>f8dy@example.com</email>
+ </author>
+ <contributor>
+ <name>Sam Ruby</name>
+ </contributor>
+ <contributor>
+ <name>Joe Gregorio</name>
+ </contributor>
+ <content type="xhtml" xml:lang="en"
+ xml:base="http://diveintomark.org/">
+ <div xmlns="http://www.w3.org/1999/xhtml">
+ <p><i>[Update: The Atom draft is finished.]</i></p>
+ </div>
+ </content>
+ </entry>
+</feed>
diff --git a/zend/tests/Zend/Gdata/App/_files/GeneratorElementSample1.xml b/zend/tests/Zend/Gdata/App/_files/GeneratorElementSample1.xml
new file mode 100644
index 0000000..00ae021
--- /dev/null
+++ b/zend/tests/Zend/Gdata/App/_files/GeneratorElementSample1.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<generator xmlns="http://www.w3.org/2005/Atom" uri="http://code.google.com/apis/gdata/" version="1.0">Google data APIs</generator>