Mercurial > hg > rc1
comparison vendor/sabre/vobject/tests/VObject/Parser/QuotedPrintableTest.php @ 7:430dbd5346f7
vendor sabre as distributed
| author | Charlie Root |
|---|---|
| date | Sat, 13 Jan 2018 09:06:10 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 6:cec75ba50afc | 7:430dbd5346f7 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Sabre\VObject\Parser; | |
| 4 | |
| 5 use | |
| 6 Sabre\VObject\Reader; | |
| 7 | |
| 8 class QuotedPrintableTest extends \PHPUnit_Framework_TestCase { | |
| 9 | |
| 10 function testReadQuotedPrintableSimple() { | |
| 11 | |
| 12 $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aach=65n\r\nEND:VCARD"; | |
| 13 | |
| 14 $result = Reader::read($data); | |
| 15 | |
| 16 $this->assertInstanceOf('Sabre\\VObject\\Component', $result); | |
| 17 $this->assertEquals('VCARD', $result->name); | |
| 18 $this->assertEquals(1, count($result->children())); | |
| 19 $this->assertEquals("Aachen", $this->getPropertyValue($result->label)); | |
| 20 | |
| 21 } | |
| 22 | |
| 23 function testReadQuotedPrintableNewlineSoft() { | |
| 24 | |
| 25 $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aa=\r\n ch=\r\n en\r\nEND:VCARD"; | |
| 26 $result = Reader::read($data); | |
| 27 | |
| 28 $this->assertInstanceOf('Sabre\\VObject\\Component', $result); | |
| 29 $this->assertEquals('VCARD', $result->name); | |
| 30 $this->assertEquals(1, count($result->children())); | |
| 31 $this->assertEquals("Aachen", $this->getPropertyValue($result->label)); | |
| 32 | |
| 33 } | |
| 34 | |
| 35 function testReadQuotedPrintableNewlineHard() { | |
| 36 | |
| 37 $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aachen=0D=0A=\r\n Germany\r\nEND:VCARD"; | |
| 38 $result = Reader::read($data); | |
| 39 | |
| 40 $this->assertInstanceOf('Sabre\\VObject\\Component', $result); | |
| 41 $this->assertEquals('VCARD', $result->name); | |
| 42 $this->assertEquals(1, count($result->children())); | |
| 43 $this->assertEquals("Aachen\r\nGermany", $this->getPropertyValue($result->label)); | |
| 44 | |
| 45 | |
| 46 } | |
| 47 | |
| 48 function testReadQuotedPrintableCompatibilityMS() { | |
| 49 | |
| 50 $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aachen=0D=0A=\r\nDeutschland:okay\r\nEND:VCARD"; | |
| 51 $result = Reader::read($data, Reader::OPTION_FORGIVING); | |
| 52 | |
| 53 $this->assertInstanceOf('Sabre\\VObject\\Component', $result); | |
| 54 $this->assertEquals('VCARD', $result->name); | |
| 55 $this->assertEquals(1, count($result->children())); | |
| 56 $this->assertEquals("Aachen\r\nDeutschland:okay", $this->getPropertyValue($result->label)); | |
| 57 | |
| 58 } | |
| 59 | |
| 60 function testReadQuotesPrintableCompoundValues() { | |
| 61 | |
| 62 $data = <<<VCF | |
| 63 BEGIN:VCARD | |
| 64 VERSION:2.1 | |
| 65 N:Doe;John;;; | |
| 66 FN:John Doe | |
| 67 ADR;WORK;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;;M=C3=BCnster = | |
| 68 Str. 1;M=C3=BCnster;;48143;Deutschland | |
| 69 END:VCARD | |
| 70 VCF; | |
| 71 | |
| 72 $result = Reader::read($data, Reader::OPTION_FORGIVING); | |
| 73 $this->assertEquals(array( | |
| 74 '','','Münster Str. 1','Münster','','48143','Deutschland' | |
| 75 ), $result->ADR->getParts()); | |
| 76 | |
| 77 | |
| 78 } | |
| 79 | |
| 80 private function getPropertyValue(\Sabre\VObject\Property $property) { | |
| 81 | |
| 82 return (string)$property; | |
| 83 | |
| 84 /* | |
| 85 $param = $property['encoding']; | |
| 86 if ($param !== null) { | |
| 87 $encoding = strtoupper((string)$param); | |
| 88 if ($encoding === 'QUOTED-PRINTABLE') { | |
| 89 $value = quoted_printable_decode($value); | |
| 90 } else { | |
| 91 throw new Exception(); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 $param = $property['charset']; | |
| 96 if ($param !== null) { | |
| 97 $charset = strtoupper((string)$param); | |
| 98 if ($charset !== 'UTF-8') { | |
| 99 $value = mb_convert_encoding($value, 'UTF-8', $charset); | |
| 100 } | |
| 101 } else { | |
| 102 $value = StringUtil::convertToUTF8($value); | |
| 103 } | |
| 104 | |
| 105 return $value; | |
| 106 */ | |
| 107 } | |
| 108 } |
