Adding enclosures now treats type and length parameters as optional for Atom, but...
[zend.git] / tests / Zend / Gdata / WhenTest.php
blobd8a074a71b0c25249ee8486e84ca452b7f56cd07
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Gdata
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id $
23 require_once 'Zend/Gdata/Extension/When.php';
24 require_once 'Zend/Gdata.php';
26 /**
27 * @category Zend
28 * @package Zend_Gdata
29 * @subpackage UnitTests
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
32 * @group Zend_Gdata
34 class Zend_Gdata_WhenTest extends PHPUnit_Framework_TestCase
37 public function setUp() {
38 $this->whenText = file_get_contents(
39 'Zend/Gdata/_files/WhenElementSample1.xml',
40 true);
41 $this->when = new Zend_Gdata_Extension_When();
44 public function testEmptyWhenShouldHaveNoExtensionElements() {
45 $this->assertTrue(is_array($this->when->extensionElements));
46 $this->assertTrue(count($this->when->extensionElements) == 0);
49 public function testEmptyWhenShouldHaveNoExtensionAttributes() {
50 $this->assertTrue(is_array($this->when->extensionAttributes));
51 $this->assertTrue(count($this->when->extensionAttributes) == 0);
54 public function testSampleWhenShouldHaveNoExtensionElements() {
55 $this->when->transferFromXML($this->whenText);
56 $this->assertTrue(is_array($this->when->extensionElements));
57 $this->assertTrue(count($this->when->extensionElements) == 0);
60 public function testSampleWhenShouldHaveNoExtensionAttributes() {
61 $this->when->transferFromXML($this->whenText);
62 $this->assertTrue(is_array($this->when->extensionAttributes));
63 $this->assertTrue(count($this->when->extensionAttributes) == 0);
66 public function testNormalWhenShouldHaveNoExtensionElements() {
67 $this->when->valueString = "Later";
68 $this->when->endTime = "2007-06-21T21:31:56-07:00";
69 $this->when->startTime = "2007-06-19T05:42:19-06:00";
71 $this->assertEquals("Later", $this->when->valueString);
72 $this->assertEquals("2007-06-21T21:31:56-07:00", $this->when->endTime);
73 $this->assertEquals("2007-06-19T05:42:19-06:00", $this->when->startTime);
75 $this->assertEquals(0, count($this->when->extensionElements));
76 $newWhen = new Zend_Gdata_Extension_When();
77 $newWhen->transferFromXML($this->when->saveXML());
78 $this->assertEquals(0, count($newWhen->extensionElements));
79 $newWhen->extensionElements = array(
80 new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
81 $this->assertEquals(1, count($newWhen->extensionElements));
82 $this->assertEquals("Later", $newWhen->valueString);
83 $this->assertEquals("2007-06-21T21:31:56-07:00", $newWhen->endTime);
84 $this->assertEquals("2007-06-19T05:42:19-06:00", $newWhen->startTime);
86 /* try constructing using magic factory */
87 $gdata = new Zend_Gdata();
88 $newWhen2 = $gdata->newWhen();
89 $newWhen2->transferFromXML($newWhen->saveXML());
90 $this->assertEquals(1, count($newWhen2->extensionElements));
91 $this->assertEquals("Later", $newWhen2->valueString);
92 $this->assertEquals("2007-06-21T21:31:56-07:00", $newWhen2->endTime);
93 $this->assertEquals("2007-06-19T05:42:19-06:00", $newWhen2->startTime);
96 public function testEmptyWhenToAndFromStringShouldMatch() {
97 $whenXml = $this->when->saveXML();
98 $newWhen = new Zend_Gdata_Extension_When();
99 $newWhen->transferFromXML($whenXml);
100 $newWhenXml = $newWhen->saveXML();
101 $this->assertTrue($whenXml == $newWhenXml);
104 public function testWhenWithValueToAndFromStringShouldMatch() {
105 $this->when->valueString = "Later";
106 $this->when->endTime = "2007-06-21T21:31:56-07:00";
107 $this->when->startTime = "2007-06-19T05:42:19-06:00";
108 $whenXml = $this->when->saveXML();
109 $newWhen = new Zend_Gdata_Extension_When();
110 $newWhen->transferFromXML($whenXml);
111 $newWhenXml = $newWhen->saveXML();
112 $this->assertTrue($whenXml == $newWhenXml);
113 $this->assertEquals("Later", $this->when->valueString);
114 $this->assertEquals("2007-06-21T21:31:56-07:00", $this->when->endTime);
115 $this->assertEquals("2007-06-19T05:42:19-06:00", $this->when->startTime);
118 public function testExtensionAttributes() {
119 $extensionAttributes = $this->when->extensionAttributes;
120 $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
121 $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
122 $this->when->extensionAttributes = $extensionAttributes;
123 $this->assertEquals('bar', $this->when->extensionAttributes['foo1']['value']);
124 $this->assertEquals('rab', $this->when->extensionAttributes['foo2']['value']);
125 $whenXml = $this->when->saveXML();
126 $newWhen = new Zend_Gdata_Extension_When();
127 $newWhen->transferFromXML($whenXml);
128 $this->assertEquals('bar', $newWhen->extensionAttributes['foo1']['value']);
129 $this->assertEquals('rab', $newWhen->extensionAttributes['foo2']['value']);
132 public function testConvertFullWhenToAndFromString() {
133 $this->when->transferFromXML($this->whenText);
134 $this->assertEquals("Tomorrow @ 5 PM", $this->when->valueString);
135 $this->assertEquals("2005-06-06T18:00:00-08:00", $this->when->endTime);
136 $this->assertEquals("2005-06-06T17:00:00-08:00", $this->when->startTime);
139 public function testToStringCanReturnValueString() {
140 $this->when->transferFromXML($this->whenText);
141 $this->assertEquals('Tomorrow @ 5 PM', $this->when->__toString());