TextTest.php 2.0 KB

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