1<?php 2 3namespace Sabre\VObject\Property; 4 5use Sabre\VObject\Component\VCard; 6 7class TextTest extends \PHPUnit_Framework_TestCase { 8 9 function assertVCard21Serialization($propValue, $expected) { 10 11 $doc = new VCard([ 12 'VERSION' => '2.1', 13 'PROP' => $propValue 14 ], false); 15 16 // Adding quoted-printable, because we're testing if it gets removed 17 // automatically. 18 $doc->PROP['ENCODING'] = 'QUOTED-PRINTABLE'; 19 $doc->PROP['P1'] = 'V1'; 20 21 22 $output = $doc->serialize(); 23 24 25 $this->assertEquals("BEGIN:VCARD\r\nVERSION:2.1\r\n$expected\r\nEND:VCARD\r\n", $output); 26 27 } 28 29 function testSerializeVCard21() { 30 31 $this->assertVCard21Serialization( 32 'f;oo', 33 'PROP;P1=V1:f;oo' 34 ); 35 36 } 37 38 function testSerializeVCard21Array() { 39 40 $this->assertVCard21Serialization( 41 ['f;oo', 'bar'], 42 'PROP;P1=V1:f\;oo;bar' 43 ); 44 45 } 46 function testSerializeVCard21Fold() { 47 48 $this->assertVCard21Serialization( 49 str_repeat('x', 80), 50 'PROP;P1=V1:' . str_repeat('x', 64) . "\r\n " . str_repeat('x', 16) 51 ); 52 53 } 54 55 56 57 function testSerializeQuotedPrintable() { 58 59 $this->assertVCard21Serialization( 60 "foo\r\nbar", 61 'PROP;P1=V1;ENCODING=QUOTED-PRINTABLE:foo=0D=0Abar' 62 ); 63 } 64 65 function testSerializeQuotedPrintableFold() { 66 67 $this->assertVCard21Serialization( 68 "foo\r\nbarxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 69 "PROP;P1=V1;ENCODING=QUOTED-PRINTABLE:foo=0D=0Abarxxxxxxxxxxxxxxxxxxxxxxxxxx=\r\n xxx" 70 ); 71 72 } 73 74 function testValidateMinimumPropValue() { 75 76 $vcard = <<<IN 77BEGIN:VCARD 78VERSION:4.0 79UID:foo 80FN:Hi! 81N:A 82END:VCARD 83IN; 84 85 $vcard = \Sabre\VObject\Reader::read($vcard); 86 $this->assertEquals(1, count($vcard->validate())); 87 88 $this->assertEquals(1, count($vcard->N->getParts())); 89 90 $vcard->validate(\Sabre\VObject\Node::REPAIR); 91 92 $this->assertEquals(5, count($vcard->N->getParts())); 93 94 } 95 96} 97