QuotedPrintableTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace Sabre\VObject\Parser;
  3. use
  4. Sabre\VObject\Reader;
  5. class QuotedPrintableTest extends \PHPUnit_Framework_TestCase {
  6. function testReadQuotedPrintableSimple() {
  7. $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aach=65n\r\nEND:VCARD";
  8. $result = Reader::read($data);
  9. $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
  10. $this->assertEquals('VCARD', $result->name);
  11. $this->assertEquals(1, count($result->children()));
  12. $this->assertEquals("Aachen", $this->getPropertyValue($result->label));
  13. }
  14. function testReadQuotedPrintableNewlineSoft() {
  15. $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aa=\r\n ch=\r\n en\r\nEND:VCARD";
  16. $result = Reader::read($data);
  17. $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
  18. $this->assertEquals('VCARD', $result->name);
  19. $this->assertEquals(1, count($result->children()));
  20. $this->assertEquals("Aachen", $this->getPropertyValue($result->label));
  21. }
  22. function testReadQuotedPrintableNewlineHard() {
  23. $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aachen=0D=0A=\r\n Germany\r\nEND:VCARD";
  24. $result = Reader::read($data);
  25. $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
  26. $this->assertEquals('VCARD', $result->name);
  27. $this->assertEquals(1, count($result->children()));
  28. $this->assertEquals("Aachen\r\nGermany", $this->getPropertyValue($result->label));
  29. }
  30. function testReadQuotedPrintableCompatibilityMS() {
  31. $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aachen=0D=0A=\r\nDeutschland:okay\r\nEND:VCARD";
  32. $result = Reader::read($data, Reader::OPTION_FORGIVING);
  33. $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
  34. $this->assertEquals('VCARD', $result->name);
  35. $this->assertEquals(1, count($result->children()));
  36. $this->assertEquals("Aachen\r\nDeutschland:okay", $this->getPropertyValue($result->label));
  37. }
  38. function testReadQuotesPrintableCompoundValues() {
  39. $data = <<<VCF
  40. BEGIN:VCARD
  41. VERSION:2.1
  42. N:Doe;John;;;
  43. FN:John Doe
  44. ADR;WORK;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;;M=C3=BCnster =
  45. Str. 1;M=C3=BCnster;;48143;Deutschland
  46. END:VCARD
  47. VCF;
  48. $result = Reader::read($data, Reader::OPTION_FORGIVING);
  49. $this->assertEquals(array(
  50. '','','Münster Str. 1','Münster','','48143','Deutschland'
  51. ), $result->ADR->getParts());
  52. }
  53. private function getPropertyValue(\Sabre\VObject\Property $property) {
  54. return (string)$property;
  55. /*
  56. $param = $property['encoding'];
  57. if ($param !== null) {
  58. $encoding = strtoupper((string)$param);
  59. if ($encoding === 'QUOTED-PRINTABLE') {
  60. $value = quoted_printable_decode($value);
  61. } else {
  62. throw new Exception();
  63. }
  64. }
  65. $param = $property['charset'];
  66. if ($param !== null) {
  67. $charset = strtoupper((string)$param);
  68. if ($charset !== 'UTF-8') {
  69. $value = mb_convert_encoding($value, 'UTF-8', $charset);
  70. }
  71. } else {
  72. $value = StringUtil::convertToUTF8($value);
  73. }
  74. return $value;
  75. */
  76. }
  77. }