~clinton-collins/familyproject/trunk

« back to all changes in this revision

Viewing changes to ZendFramework/tests/Zend/Gdata/Calendar/SelectedTest.php

  • Committer: Clinton Collins
  • Date: 2009-06-26 19:54:58 UTC
  • Revision ID: clinton.collins@gmail.com-20090626195458-5ebba0qcvo15xlpy
Initial Import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
7
 * This source file is subject to the new BSD license that is bundled
 
8
 * with this package in the file LICENSE.txt.
 
9
 * It is also available through the world-wide-web at this URL:
 
10
 * http://framework.zend.com/license/new-bsd
 
11
 * If you did not receive a copy of the license and are unable to
 
12
 * obtain it through the world-wide-web, please send an email
 
13
 * to license@zend.com so we can send you a copy immediately.
 
14
 *
 
15
 * @category     Zend
 
16
 * @package      Zend_Gdata_Calendar
 
17
 * @subpackage   UnitTests
 
18
 * @copyright    Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com);
 
19
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
20
 */
 
21
 
 
22
require_once 'Zend/Gdata/Calendar/Extension/Selected.php';
 
23
require_once 'Zend/Gdata/Calendar.php';
 
24
 
 
25
/**
 
26
 * @package    Zend_Gdata_Calendar
 
27
 * @subpackage UnitTests
 
28
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
29
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
30
 */
 
31
class Zend_Gdata_Calendar_SelectedTest extends PHPUnit_Framework_TestCase
 
32
{
 
33
 
 
34
    public function setUp() {
 
35
        $this->selectedText = file_get_contents(
 
36
                'Zend/Gdata/Calendar/_files/SelectedElementSample1.xml',
 
37
                true);
 
38
        $this->selected = new Zend_Gdata_Calendar_Extension_Selected();
 
39
    }
 
40
      
 
41
    public function testEmptySelectedShouldHaveNoExtensionElements() {
 
42
        $this->assertTrue(is_array($this->selected->extensionElements));
 
43
        $this->assertTrue(count($this->selected->extensionElements) == 0);
 
44
    }
 
45
 
 
46
    public function testEmptySelectedShouldHaveNoExtensionAttributes() {
 
47
        $this->assertTrue(is_array($this->selected->extensionAttributes));
 
48
        $this->assertTrue(count($this->selected->extensionAttributes) == 0);
 
49
    }
 
50
 
 
51
    public function testSampleSelectedShouldHaveNoExtensionElements() {
 
52
        $this->selected->transferFromXML($this->selectedText);
 
53
        $this->assertTrue(is_array($this->selected->extensionElements));
 
54
        $this->assertTrue(count($this->selected->extensionElements) == 0);
 
55
    }
 
56
 
 
57
    public function testSampleSelectedShouldHaveNoExtensionAttributes() {
 
58
        $this->selected->transferFromXML($this->selectedText);
 
59
        $this->assertTrue(is_array($this->selected->extensionAttributes));
 
60
        $this->assertTrue(count($this->selected->extensionAttributes) == 0);
 
61
    }
 
62
    
 
63
    public function testNormalSelectedShouldHaveNoExtensionElements() {
 
64
        $this->selected->value = true;
 
65
        $this->assertEquals($this->selected->value, true);
 
66
        $this->assertEquals(count($this->selected->extensionElements), 0);
 
67
        $newSelected = new Zend_Gdata_Calendar_Extension_Selected(); 
 
68
        $newSelected->transferFromXML($this->selected->saveXML());
 
69
        $this->assertEquals(count($newSelected->extensionElements), 0);
 
70
        $newSelected->extensionElements = array(
 
71
                new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
 
72
        $this->assertEquals(count($newSelected->extensionElements), 1);
 
73
        $this->assertEquals($newSelected->value, true);
 
74
 
 
75
        /* try constructing using magic factory */
 
76
        $cal = new Zend_Gdata_Calendar();
 
77
        $newSelected2 = $cal->newSelected();
 
78
        $newSelected2->transferFromXML($newSelected->saveXML());
 
79
        $this->assertEquals(count($newSelected2->extensionElements), 1);
 
80
        $this->assertEquals($newSelected2->value, true);
 
81
    }
 
82
 
 
83
    public function testEmptySelectedToAndFromStringShouldMatch() {
 
84
        $selectedXml = $this->selected->saveXML();
 
85
        $newSelected = new Zend_Gdata_Calendar_Extension_Selected();
 
86
        $newSelected->transferFromXML($selectedXml);
 
87
        $newSelectedXml = $newSelected->saveXML();
 
88
        $this->assertTrue($selectedXml == $newSelectedXml);
 
89
    }
 
90
 
 
91
    public function testSelectedWithValueToAndFromStringShouldMatch() {
 
92
        $this->selected->value = true;
 
93
        $selectedXml = $this->selected->saveXML();
 
94
        $newSelected = new Zend_Gdata_Calendar_Extension_Selected();
 
95
        $newSelected->transferFromXML($selectedXml);
 
96
        $newSelectedXml = $newSelected->saveXML();
 
97
        $this->assertTrue($selectedXml == $newSelectedXml);
 
98
        $this->assertEquals(true, $newSelected->value);
 
99
    }
 
100
 
 
101
    public function testExtensionAttributes() {
 
102
        $extensionAttributes = $this->selected->extensionAttributes;
 
103
        $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
 
104
        $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
 
105
        $this->selected->extensionAttributes = $extensionAttributes;
 
106
        $this->assertEquals('bar', $this->selected->extensionAttributes['foo1']['value']);
 
107
        $this->assertEquals('rab', $this->selected->extensionAttributes['foo2']['value']);
 
108
        $selectedXml = $this->selected->saveXML();
 
109
        $newSelected = new Zend_Gdata_Calendar_Extension_Selected();
 
110
        $newSelected->transferFromXML($selectedXml);
 
111
        $this->assertEquals('bar', $newSelected->extensionAttributes['foo1']['value']);
 
112
        $this->assertEquals('rab', $newSelected->extensionAttributes['foo2']['value']);
 
113
    }
 
114
 
 
115
    public function testConvertFullSelectedToAndFromString() {
 
116
        $this->selected->transferFromXML($this->selectedText);
 
117
        $this->assertEquals($this->selected->value, false);
 
118
    }
 
119
 
 
120
}