1<?php
2
3namespace Sabre\VObject;
4
5class ParameterTest extends \PHPUnit_Framework_TestCase {
6
7    function testSetup() {
8
9        $cal = new Component\VCalendar();
10
11        $param = new Parameter($cal, 'name','value');
12        $this->assertEquals('NAME',$param->name);
13        $this->assertEquals('value',$param->getValue());
14
15    }
16
17    function testSetupNameLess() {
18
19        $card = new Component\VCard();
20
21        $param = new Parameter($card, null,'URL');
22        $this->assertEquals('VALUE',$param->name);
23        $this->assertEquals('URL',$param->getValue());
24        $this->assertTrue($param->noName);
25
26    }
27
28    function testModify() {
29
30        $cal = new Component\VCalendar();
31
32        $param = new Parameter($cal, 'name', null);
33        $param->addValue(1);
34        $this->assertEquals(array(1), $param->getParts());
35
36        $param->setParts(array(1,2));
37        $this->assertEquals(array(1,2), $param->getParts());
38
39        $param->addValue(3);
40        $this->assertEquals(array(1,2,3), $param->getParts());
41
42        $param->setValue(4);
43        $param->addValue(5);
44        $this->assertEquals(array(4,5), $param->getParts());
45
46    }
47
48    function testCastToString() {
49
50        $cal = new Component\VCalendar();
51        $param = new Parameter($cal, 'name', 'value');
52        $this->assertEquals('value',$param->__toString());
53        $this->assertEquals('value',(string)$param);
54
55    }
56
57    function testCastNullToString() {
58
59        $cal = new Component\VCalendar();
60        $param = new Parameter($cal, 'name', null);
61        $this->assertEquals('',$param->__toString());
62        $this->assertEquals('',(string)$param);
63
64    }
65
66    function testSerialize() {
67
68        $cal = new Component\VCalendar();
69        $param = new Parameter($cal, 'name', 'value');
70        $this->assertEquals('NAME=value',$param->serialize());
71
72    }
73
74    function testSerializeEmpty() {
75
76        $cal = new Component\VCalendar();
77        $param = new Parameter($cal, 'name', null);
78        $this->assertEquals('NAME=',$param->serialize());
79
80    }
81
82    function testSerializeComplex() {
83
84        $cal = new Component\VCalendar();
85        $param = new Parameter($cal, 'name',array("val1", "val2;", "val3^", "val4\n", "val5\""));
86        $this->assertEquals('NAME=val1,"val2;","val3^^","val4^n","val5^\'"',$param->serialize());
87
88    }
89
90    /**
91     * iCal 7.0 (OSX 10.9) has major issues with the EMAIL property, when the
92     * value contains a plus sign, and it's not quoted.
93     *
94     * So we specifically added support for that.
95     */
96    function testSerializePlusSign() {
97
98        $cal = new Component\VCalendar();
99        $param = new Parameter($cal, 'EMAIL',"user+something@example.org");
100        $this->assertEquals('EMAIL="user+something@example.org"',$param->serialize());
101
102    }
103
104    function testIterate() {
105
106        $cal = new Component\VCalendar();
107
108        $param = new Parameter($cal, 'name', array(1,2,3,4));
109        $result = array();
110
111        foreach($param as $value) {
112            $result[] = $value;
113        }
114
115        $this->assertEquals(array(1,2,3,4), $result);
116
117    }
118
119    function testSerializeColon() {
120
121        $cal = new Component\VCalendar();
122        $param = new Parameter($cal, 'name','va:lue');
123        $this->assertEquals('NAME="va:lue"',$param->serialize());
124
125    }
126
127    function testSerializeSemiColon() {
128
129        $cal = new Component\VCalendar();
130        $param = new Parameter($cal, 'name','va;lue');
131        $this->assertEquals('NAME="va;lue"',$param->serialize());
132
133    }
134
135}
136