1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\VObject; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse 6*a1a3b679SAndreas Boehler Sabre\VObject\Component\VCalendar, 7*a1a3b679SAndreas Boehler Sabre\VObject\Component\VCard; 8*a1a3b679SAndreas Boehler 9*a1a3b679SAndreas Boehlerclass PropertyTest extends \PHPUnit_Framework_TestCase { 10*a1a3b679SAndreas Boehler 11*a1a3b679SAndreas Boehler function testToString() { 12*a1a3b679SAndreas Boehler 13*a1a3b679SAndreas Boehler $cal = new VCalendar(); 14*a1a3b679SAndreas Boehler 15*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue'); 16*a1a3b679SAndreas Boehler $this->assertEquals('PROPNAME', $property->name); 17*a1a3b679SAndreas Boehler $this->assertEquals('propvalue', $property->__toString()); 18*a1a3b679SAndreas Boehler $this->assertEquals('propvalue', (string)$property); 19*a1a3b679SAndreas Boehler $this->assertEquals('propvalue', $property->getValue()); 20*a1a3b679SAndreas Boehler 21*a1a3b679SAndreas Boehler } 22*a1a3b679SAndreas Boehler 23*a1a3b679SAndreas Boehler function testCreate() { 24*a1a3b679SAndreas Boehler 25*a1a3b679SAndreas Boehler $cal = new VCalendar(); 26*a1a3b679SAndreas Boehler 27*a1a3b679SAndreas Boehler $params = array( 28*a1a3b679SAndreas Boehler 'param1' => 'value1', 29*a1a3b679SAndreas Boehler 'param2' => 'value2', 30*a1a3b679SAndreas Boehler ); 31*a1a3b679SAndreas Boehler 32*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue', $params); 33*a1a3b679SAndreas Boehler 34*a1a3b679SAndreas Boehler $this->assertEquals('value1', $property['param1']->getValue()); 35*a1a3b679SAndreas Boehler $this->assertEquals('value2', $property['param2']->getValue()); 36*a1a3b679SAndreas Boehler 37*a1a3b679SAndreas Boehler } 38*a1a3b679SAndreas Boehler 39*a1a3b679SAndreas Boehler function testSetValue() { 40*a1a3b679SAndreas Boehler 41*a1a3b679SAndreas Boehler $cal = new VCalendar(); 42*a1a3b679SAndreas Boehler 43*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue'); 44*a1a3b679SAndreas Boehler $property->setValue('value2'); 45*a1a3b679SAndreas Boehler 46*a1a3b679SAndreas Boehler $this->assertEquals('PROPNAME', $property->name); 47*a1a3b679SAndreas Boehler $this->assertEquals('value2', $property->__toString()); 48*a1a3b679SAndreas Boehler 49*a1a3b679SAndreas Boehler } 50*a1a3b679SAndreas Boehler 51*a1a3b679SAndreas Boehler function testParameterExists() { 52*a1a3b679SAndreas Boehler 53*a1a3b679SAndreas Boehler $cal = new VCalendar(); 54*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue'); 55*a1a3b679SAndreas Boehler $property['paramname'] = 'paramvalue'; 56*a1a3b679SAndreas Boehler 57*a1a3b679SAndreas Boehler $this->assertTrue(isset($property['PARAMNAME'])); 58*a1a3b679SAndreas Boehler $this->assertTrue(isset($property['paramname'])); 59*a1a3b679SAndreas Boehler $this->assertFalse(isset($property['foo'])); 60*a1a3b679SAndreas Boehler 61*a1a3b679SAndreas Boehler } 62*a1a3b679SAndreas Boehler 63*a1a3b679SAndreas Boehler function testParameterGet() { 64*a1a3b679SAndreas Boehler 65*a1a3b679SAndreas Boehler $cal = new VCalendar(); 66*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue'); 67*a1a3b679SAndreas Boehler $property['paramname'] = 'paramvalue'; 68*a1a3b679SAndreas Boehler 69*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\VObject\\Parameter',$property['paramname']); 70*a1a3b679SAndreas Boehler 71*a1a3b679SAndreas Boehler } 72*a1a3b679SAndreas Boehler 73*a1a3b679SAndreas Boehler function testParameterNotExists() { 74*a1a3b679SAndreas Boehler 75*a1a3b679SAndreas Boehler $cal = new VCalendar(); 76*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue'); 77*a1a3b679SAndreas Boehler $property['paramname'] = 'paramvalue'; 78*a1a3b679SAndreas Boehler 79*a1a3b679SAndreas Boehler $this->assertInternalType('null',$property['foo']); 80*a1a3b679SAndreas Boehler 81*a1a3b679SAndreas Boehler } 82*a1a3b679SAndreas Boehler 83*a1a3b679SAndreas Boehler function testParameterMultiple() { 84*a1a3b679SAndreas Boehler 85*a1a3b679SAndreas Boehler $cal = new VCalendar(); 86*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue'); 87*a1a3b679SAndreas Boehler $property['paramname'] = 'paramvalue'; 88*a1a3b679SAndreas Boehler $property->add('paramname', 'paramvalue'); 89*a1a3b679SAndreas Boehler 90*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\VObject\\Parameter',$property['paramname']); 91*a1a3b679SAndreas Boehler $this->assertEquals(2,count($property['paramname']->getParts())); 92*a1a3b679SAndreas Boehler 93*a1a3b679SAndreas Boehler } 94*a1a3b679SAndreas Boehler 95*a1a3b679SAndreas Boehler function testSetParameterAsString() { 96*a1a3b679SAndreas Boehler 97*a1a3b679SAndreas Boehler $cal = new VCalendar(); 98*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue'); 99*a1a3b679SAndreas Boehler $property['paramname'] = 'paramvalue'; 100*a1a3b679SAndreas Boehler 101*a1a3b679SAndreas Boehler $this->assertEquals(1,count($property->parameters())); 102*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\VObject\\Parameter', $property->parameters['PARAMNAME']); 103*a1a3b679SAndreas Boehler $this->assertEquals('PARAMNAME',$property->parameters['PARAMNAME']->name); 104*a1a3b679SAndreas Boehler $this->assertEquals('paramvalue',$property->parameters['PARAMNAME']->getValue()); 105*a1a3b679SAndreas Boehler 106*a1a3b679SAndreas Boehler } 107*a1a3b679SAndreas Boehler 108*a1a3b679SAndreas Boehler function testUnsetParameter() { 109*a1a3b679SAndreas Boehler 110*a1a3b679SAndreas Boehler $cal = new VCalendar(); 111*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue'); 112*a1a3b679SAndreas Boehler $property['paramname'] = 'paramvalue'; 113*a1a3b679SAndreas Boehler 114*a1a3b679SAndreas Boehler unset($property['PARAMNAME']); 115*a1a3b679SAndreas Boehler $this->assertEquals(0,count($property->parameters())); 116*a1a3b679SAndreas Boehler 117*a1a3b679SAndreas Boehler } 118*a1a3b679SAndreas Boehler 119*a1a3b679SAndreas Boehler function testSerialize() { 120*a1a3b679SAndreas Boehler 121*a1a3b679SAndreas Boehler $cal = new VCalendar(); 122*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue'); 123*a1a3b679SAndreas Boehler 124*a1a3b679SAndreas Boehler $this->assertEquals("PROPNAME:propvalue\r\n",$property->serialize()); 125*a1a3b679SAndreas Boehler 126*a1a3b679SAndreas Boehler } 127*a1a3b679SAndreas Boehler 128*a1a3b679SAndreas Boehler function testSerializeParam() { 129*a1a3b679SAndreas Boehler 130*a1a3b679SAndreas Boehler $cal = new VCalendar(); 131*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue', array( 132*a1a3b679SAndreas Boehler 'paramname' => 'paramvalue', 133*a1a3b679SAndreas Boehler 'paramname2' => 'paramvalue2', 134*a1a3b679SAndreas Boehler )); 135*a1a3b679SAndreas Boehler 136*a1a3b679SAndreas Boehler $this->assertEquals("PROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propvalue\r\n",$property->serialize()); 137*a1a3b679SAndreas Boehler 138*a1a3b679SAndreas Boehler } 139*a1a3b679SAndreas Boehler 140*a1a3b679SAndreas Boehler function testSerializeNewLine() { 141*a1a3b679SAndreas Boehler 142*a1a3b679SAndreas Boehler $cal = new VCalendar(); 143*a1a3b679SAndreas Boehler $property = $cal->createProperty('SUMMARY',"line1\nline2"); 144*a1a3b679SAndreas Boehler 145*a1a3b679SAndreas Boehler $this->assertEquals("SUMMARY:line1\\nline2\r\n",$property->serialize()); 146*a1a3b679SAndreas Boehler 147*a1a3b679SAndreas Boehler } 148*a1a3b679SAndreas Boehler 149*a1a3b679SAndreas Boehler function testSerializeLongLine() { 150*a1a3b679SAndreas Boehler 151*a1a3b679SAndreas Boehler $cal = new VCalendar(); 152*a1a3b679SAndreas Boehler $value = str_repeat('!',200); 153*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname',$value); 154*a1a3b679SAndreas Boehler 155*a1a3b679SAndreas Boehler $expected = "PROPNAME:" . str_repeat('!',66) . "\r\n " . str_repeat('!',74) . "\r\n " . str_repeat('!',60) . "\r\n"; 156*a1a3b679SAndreas Boehler 157*a1a3b679SAndreas Boehler $this->assertEquals($expected,$property->serialize()); 158*a1a3b679SAndreas Boehler 159*a1a3b679SAndreas Boehler } 160*a1a3b679SAndreas Boehler 161*a1a3b679SAndreas Boehler function testSerializeUTF8LineFold() { 162*a1a3b679SAndreas Boehler 163*a1a3b679SAndreas Boehler $cal = new VCalendar(); 164*a1a3b679SAndreas Boehler $value = str_repeat('!',65) . "\xc3\xa4bla"; // inserted umlaut-a 165*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname', $value); 166*a1a3b679SAndreas Boehler $expected = "PROPNAME:" . str_repeat('!',65) . "\r\n \xc3\xa4bla\r\n"; 167*a1a3b679SAndreas Boehler $this->assertEquals($expected, $property->serialize()); 168*a1a3b679SAndreas Boehler 169*a1a3b679SAndreas Boehler } 170*a1a3b679SAndreas Boehler 171*a1a3b679SAndreas Boehler function testGetIterator() { 172*a1a3b679SAndreas Boehler 173*a1a3b679SAndreas Boehler $cal = new VCalendar(); 174*a1a3b679SAndreas Boehler $it = new ElementList(array()); 175*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue'); 176*a1a3b679SAndreas Boehler $property->setIterator($it); 177*a1a3b679SAndreas Boehler $this->assertEquals($it,$property->getIterator()); 178*a1a3b679SAndreas Boehler 179*a1a3b679SAndreas Boehler } 180*a1a3b679SAndreas Boehler 181*a1a3b679SAndreas Boehler 182*a1a3b679SAndreas Boehler function testGetIteratorDefault() { 183*a1a3b679SAndreas Boehler 184*a1a3b679SAndreas Boehler $cal = new VCalendar(); 185*a1a3b679SAndreas Boehler $property = $cal->createProperty('propname','propvalue'); 186*a1a3b679SAndreas Boehler $it = $property->getIterator(); 187*a1a3b679SAndreas Boehler $this->assertTrue($it instanceof ElementList); 188*a1a3b679SAndreas Boehler $this->assertEquals(1,count($it)); 189*a1a3b679SAndreas Boehler 190*a1a3b679SAndreas Boehler } 191*a1a3b679SAndreas Boehler 192*a1a3b679SAndreas Boehler function testAddScalar() { 193*a1a3b679SAndreas Boehler 194*a1a3b679SAndreas Boehler $cal = new VCalendar(); 195*a1a3b679SAndreas Boehler $property = $cal->createProperty('EMAIL'); 196*a1a3b679SAndreas Boehler 197*a1a3b679SAndreas Boehler $property->add('myparam','value'); 198*a1a3b679SAndreas Boehler 199*a1a3b679SAndreas Boehler $this->assertEquals(1, count($property->parameters())); 200*a1a3b679SAndreas Boehler 201*a1a3b679SAndreas Boehler $this->assertTrue($property->parameters['MYPARAM'] instanceof Parameter); 202*a1a3b679SAndreas Boehler $this->assertEquals('MYPARAM',$property->parameters['MYPARAM']->name); 203*a1a3b679SAndreas Boehler $this->assertEquals('value',$property->parameters['MYPARAM']->getValue()); 204*a1a3b679SAndreas Boehler 205*a1a3b679SAndreas Boehler } 206*a1a3b679SAndreas Boehler 207*a1a3b679SAndreas Boehler function testAddParameter() { 208*a1a3b679SAndreas Boehler 209*a1a3b679SAndreas Boehler $cal = new VCalendar(); 210*a1a3b679SAndreas Boehler $prop = $cal->createProperty('EMAIL'); 211*a1a3b679SAndreas Boehler 212*a1a3b679SAndreas Boehler $prop->add('MYPARAM','value'); 213*a1a3b679SAndreas Boehler 214*a1a3b679SAndreas Boehler $this->assertEquals(1, count($prop->parameters())); 215*a1a3b679SAndreas Boehler $this->assertEquals('MYPARAM',$prop['myparam']->name); 216*a1a3b679SAndreas Boehler 217*a1a3b679SAndreas Boehler } 218*a1a3b679SAndreas Boehler 219*a1a3b679SAndreas Boehler function testAddParameterTwice() { 220*a1a3b679SAndreas Boehler 221*a1a3b679SAndreas Boehler $cal = new VCalendar(); 222*a1a3b679SAndreas Boehler $prop = $cal->createProperty('EMAIL'); 223*a1a3b679SAndreas Boehler 224*a1a3b679SAndreas Boehler $prop->add('MYPARAM', 'value1'); 225*a1a3b679SAndreas Boehler $prop->add('MYPARAM', 'value2'); 226*a1a3b679SAndreas Boehler 227*a1a3b679SAndreas Boehler $this->assertEquals(1, count($prop->parameters)); 228*a1a3b679SAndreas Boehler $this->assertEquals(2, count($prop->parameters['MYPARAM']->getParts())); 229*a1a3b679SAndreas Boehler 230*a1a3b679SAndreas Boehler $this->assertEquals('MYPARAM',$prop['MYPARAM']->name); 231*a1a3b679SAndreas Boehler 232*a1a3b679SAndreas Boehler } 233*a1a3b679SAndreas Boehler 234*a1a3b679SAndreas Boehler 235*a1a3b679SAndreas Boehler function testClone() { 236*a1a3b679SAndreas Boehler 237*a1a3b679SAndreas Boehler $cal = new VCalendar(); 238*a1a3b679SAndreas Boehler $property = $cal->createProperty('EMAIL','value'); 239*a1a3b679SAndreas Boehler $property['FOO'] = 'BAR'; 240*a1a3b679SAndreas Boehler 241*a1a3b679SAndreas Boehler $property2 = clone $property; 242*a1a3b679SAndreas Boehler 243*a1a3b679SAndreas Boehler $property['FOO'] = 'BAZ'; 244*a1a3b679SAndreas Boehler $this->assertEquals('BAR', (string)$property2['FOO']); 245*a1a3b679SAndreas Boehler 246*a1a3b679SAndreas Boehler } 247*a1a3b679SAndreas Boehler 248*a1a3b679SAndreas Boehler function testCreateParams() { 249*a1a3b679SAndreas Boehler 250*a1a3b679SAndreas Boehler $cal = new VCalendar(); 251*a1a3b679SAndreas Boehler $property = $cal->createProperty('X-PROP','value', array( 252*a1a3b679SAndreas Boehler 'param1' => 'value1', 253*a1a3b679SAndreas Boehler 'param2' => array('value2', 'value3') 254*a1a3b679SAndreas Boehler )); 255*a1a3b679SAndreas Boehler 256*a1a3b679SAndreas Boehler $this->assertEquals(1, count($property['PARAM1']->getParts())); 257*a1a3b679SAndreas Boehler $this->assertEquals(2, count($property['PARAM2']->getParts())); 258*a1a3b679SAndreas Boehler 259*a1a3b679SAndreas Boehler } 260*a1a3b679SAndreas Boehler 261*a1a3b679SAndreas Boehler function testValidateNonUTF8() { 262*a1a3b679SAndreas Boehler 263*a1a3b679SAndreas Boehler $calendar = new VCalendar(); 264*a1a3b679SAndreas Boehler $property = $calendar->createProperty('X-PROP', "Bla\x00"); 265*a1a3b679SAndreas Boehler $result = $property->validate(Property::REPAIR); 266*a1a3b679SAndreas Boehler 267*a1a3b679SAndreas Boehler $this->assertEquals('Property contained a control character (0x00)', $result[0]['message']); 268*a1a3b679SAndreas Boehler $this->assertEquals('Bla', $property->getValue()); 269*a1a3b679SAndreas Boehler 270*a1a3b679SAndreas Boehler } 271*a1a3b679SAndreas Boehler 272*a1a3b679SAndreas Boehler function testValidateControlChars() { 273*a1a3b679SAndreas Boehler 274*a1a3b679SAndreas Boehler $s = "chars["; 275*a1a3b679SAndreas Boehler foreach (array( 276*a1a3b679SAndreas Boehler 0x7F, 0x5E, 0x5C, 0x3B, 0x3A, 0x2C, 0x22, 0x20, 277*a1a3b679SAndreas Boehler 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 278*a1a3b679SAndreas Boehler 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 279*a1a3b679SAndreas Boehler 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 280*a1a3b679SAndreas Boehler 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 281*a1a3b679SAndreas Boehler ) as $c) { 282*a1a3b679SAndreas Boehler $s .= sprintf('%02X(%c)', $c, $c); 283*a1a3b679SAndreas Boehler } 284*a1a3b679SAndreas Boehler $s .= "]end"; 285*a1a3b679SAndreas Boehler 286*a1a3b679SAndreas Boehler $calendar = new VCalendar(); 287*a1a3b679SAndreas Boehler $property = $calendar->createProperty('X-PROP', $s); 288*a1a3b679SAndreas Boehler $result = $property->validate(Property::REPAIR); 289*a1a3b679SAndreas Boehler 290*a1a3b679SAndreas Boehler $this->assertEquals('Property contained a control character (0x7f)', $result[0]['message']); 291*a1a3b679SAndreas Boehler $this->assertEquals("chars[7F()5E(^)5C(\\\\)3B(\\;)3A(:)2C(\\,)22(\")20( )1F()1E()1D()1C()1B()1A()19()18()17()16()15()14()13()12()11()10()0F()0E()0D()0C()0B()0A(\\n)09( )08()07()06()05()04()03()02()01()00()]end", $property->getRawMimeDirValue()); 292*a1a3b679SAndreas Boehler 293*a1a3b679SAndreas Boehler } 294*a1a3b679SAndreas Boehler 295*a1a3b679SAndreas Boehler function testValidateBadPropertyName() { 296*a1a3b679SAndreas Boehler 297*a1a3b679SAndreas Boehler $calendar = new VCalendar(); 298*a1a3b679SAndreas Boehler $property = $calendar->createProperty("X_*&PROP*", "Bla"); 299*a1a3b679SAndreas Boehler $result = $property->validate(Property::REPAIR); 300*a1a3b679SAndreas Boehler 301*a1a3b679SAndreas Boehler $this->assertEquals($result[0]['message'], 'The propertyname: X_*&PROP* contains invalid characters. Only A-Z, 0-9 and - are allowed'); 302*a1a3b679SAndreas Boehler $this->assertEquals('X-PROP', $property->name); 303*a1a3b679SAndreas Boehler 304*a1a3b679SAndreas Boehler } 305*a1a3b679SAndreas Boehler 306*a1a3b679SAndreas Boehler function testGetValue() { 307*a1a3b679SAndreas Boehler 308*a1a3b679SAndreas Boehler $calendar = new VCalendar(); 309*a1a3b679SAndreas Boehler $property = $calendar->createProperty("SUMMARY", null); 310*a1a3b679SAndreas Boehler $this->assertEquals(array(), $property->getParts()); 311*a1a3b679SAndreas Boehler $this->assertNull($property->getValue()); 312*a1a3b679SAndreas Boehler 313*a1a3b679SAndreas Boehler $property->setValue(array()); 314*a1a3b679SAndreas Boehler $this->assertEquals(array(), $property->getParts()); 315*a1a3b679SAndreas Boehler $this->assertNull($property->getValue()); 316*a1a3b679SAndreas Boehler 317*a1a3b679SAndreas Boehler $property->setValue(array(1)); 318*a1a3b679SAndreas Boehler $this->assertEquals(array(1), $property->getParts()); 319*a1a3b679SAndreas Boehler $this->assertEquals(1, $property->getValue()); 320*a1a3b679SAndreas Boehler 321*a1a3b679SAndreas Boehler $property->setValue(array(1,2)); 322*a1a3b679SAndreas Boehler $this->assertEquals(array(1,2), $property->getParts()); 323*a1a3b679SAndreas Boehler $this->assertEquals('1,2', $property->getValue()); 324*a1a3b679SAndreas Boehler 325*a1a3b679SAndreas Boehler $property->setValue('str'); 326*a1a3b679SAndreas Boehler $this->assertEquals(array('str'), $property->getParts()); 327*a1a3b679SAndreas Boehler $this->assertEquals('str', $property->getValue()); 328*a1a3b679SAndreas Boehler } 329*a1a3b679SAndreas Boehler 330*a1a3b679SAndreas Boehler /** 331*a1a3b679SAndreas Boehler * ElementList should reject this. 332*a1a3b679SAndreas Boehler * 333*a1a3b679SAndreas Boehler * @expectedException \LogicException 334*a1a3b679SAndreas Boehler */ 335*a1a3b679SAndreas Boehler function testArrayAccessSetInt() { 336*a1a3b679SAndreas Boehler 337*a1a3b679SAndreas Boehler $calendar = new VCalendar(); 338*a1a3b679SAndreas Boehler $property = $calendar->createProperty("X-PROP", null); 339*a1a3b679SAndreas Boehler 340*a1a3b679SAndreas Boehler $calendar->add($property); 341*a1a3b679SAndreas Boehler $calendar->{'X-PROP'}[0] = 'Something!'; 342*a1a3b679SAndreas Boehler 343*a1a3b679SAndreas Boehler } 344*a1a3b679SAndreas Boehler 345*a1a3b679SAndreas Boehler /** 346*a1a3b679SAndreas Boehler * ElementList should reject this. 347*a1a3b679SAndreas Boehler * 348*a1a3b679SAndreas Boehler * @expectedException \LogicException 349*a1a3b679SAndreas Boehler */ 350*a1a3b679SAndreas Boehler function testArrayAccessUnsetInt() { 351*a1a3b679SAndreas Boehler 352*a1a3b679SAndreas Boehler $calendar = new VCalendar(); 353*a1a3b679SAndreas Boehler $property = $calendar->createProperty("X-PROP", null); 354*a1a3b679SAndreas Boehler 355*a1a3b679SAndreas Boehler $calendar->add($property); 356*a1a3b679SAndreas Boehler unset($calendar->{'X-PROP'}[0]); 357*a1a3b679SAndreas Boehler 358*a1a3b679SAndreas Boehler } 359*a1a3b679SAndreas Boehler 360*a1a3b679SAndreas Boehler function testValidateBadEncoding() { 361*a1a3b679SAndreas Boehler 362*a1a3b679SAndreas Boehler $document = new VCalendar(); 363*a1a3b679SAndreas Boehler $property = $document->add('X-FOO','value'); 364*a1a3b679SAndreas Boehler $property['ENCODING'] = 'invalid'; 365*a1a3b679SAndreas Boehler 366*a1a3b679SAndreas Boehler $result = $property->validate(); 367*a1a3b679SAndreas Boehler 368*a1a3b679SAndreas Boehler $this->assertEquals('ENCODING=INVALID is not valid for this document type.', $result[0]['message']); 369*a1a3b679SAndreas Boehler $this->assertEquals(1, $result[0]['level']); 370*a1a3b679SAndreas Boehler 371*a1a3b679SAndreas Boehler } 372*a1a3b679SAndreas Boehler 373*a1a3b679SAndreas Boehler function testValidateBadEncodingVCard4() { 374*a1a3b679SAndreas Boehler 375*a1a3b679SAndreas Boehler $document = new VCard(array('VERSION' => '4.0')); 376*a1a3b679SAndreas Boehler $property = $document->add('X-FOO','value'); 377*a1a3b679SAndreas Boehler $property['ENCODING'] = 'BASE64'; 378*a1a3b679SAndreas Boehler 379*a1a3b679SAndreas Boehler $result = $property->validate(); 380*a1a3b679SAndreas Boehler 381*a1a3b679SAndreas Boehler $this->assertEquals('ENCODING parameter is not valid in vCard 4.', $result[0]['message']); 382*a1a3b679SAndreas Boehler $this->assertEquals(1, $result[0]['level']); 383*a1a3b679SAndreas Boehler 384*a1a3b679SAndreas Boehler } 385*a1a3b679SAndreas Boehler 386*a1a3b679SAndreas Boehler function testValidateBadEncodingVCard3() { 387*a1a3b679SAndreas Boehler 388*a1a3b679SAndreas Boehler $document = new VCard(array('VERSION' => '3.0')); 389*a1a3b679SAndreas Boehler $property = $document->add('X-FOO','value'); 390*a1a3b679SAndreas Boehler $property['ENCODING'] = 'BASE64'; 391*a1a3b679SAndreas Boehler 392*a1a3b679SAndreas Boehler $result = $property->validate(); 393*a1a3b679SAndreas Boehler 394*a1a3b679SAndreas Boehler $this->assertEquals('ENCODING=BASE64 is not valid for this document type.', $result[0]['message']); 395*a1a3b679SAndreas Boehler $this->assertEquals(1, $result[0]['level']); 396*a1a3b679SAndreas Boehler 397*a1a3b679SAndreas Boehler } 398*a1a3b679SAndreas Boehler 399*a1a3b679SAndreas Boehler function testValidateBadEncodingVCard21() { 400*a1a3b679SAndreas Boehler 401*a1a3b679SAndreas Boehler $document = new VCard(array('VERSION' => '2.1')); 402*a1a3b679SAndreas Boehler $property = $document->add('X-FOO','value'); 403*a1a3b679SAndreas Boehler $property['ENCODING'] = 'B'; 404*a1a3b679SAndreas Boehler 405*a1a3b679SAndreas Boehler $result = $property->validate(); 406*a1a3b679SAndreas Boehler 407*a1a3b679SAndreas Boehler $this->assertEquals('ENCODING=B is not valid for this document type.', $result[0]['message']); 408*a1a3b679SAndreas Boehler $this->assertEquals(1, $result[0]['level']); 409*a1a3b679SAndreas Boehler 410*a1a3b679SAndreas Boehler } 411*a1a3b679SAndreas Boehler} 412