Skip to content

Commit

Permalink
Testing quoted-printable encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed May 24, 2013
1 parent 8d5bb3b commit e1d79db
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 24 deletions.
24 changes: 0 additions & 24 deletions lib/Sabre/VObject/Property/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,6 @@ public function setQuotedPrintableValue($val) {
}
/**
* Returns a quoted-printable encoded string.
*
* @return string
*/
public function getQuotedPrintableValue() {
$val = $this->getParts();
// Imploding multiple parts into a single value, and splitting the
// values with ;.
if (count($val)>1) {
foreach($val as $k=>$v) {
$val[$k] = str_replace(';','\;', $v);
}
$val = implode(';', $val);
}
$val = quoted_printable_decode($val);
return $val;
}
/**
* Returns a raw mime-dir representation of the value.
*
Expand Down
64 changes: 64 additions & 0 deletions tests/Sabre/VObject/Property/TextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Sabre\VObject\Property;

use Sabre\VObject\Component\VCard;

class TextTest extends \PHPUnit_Framework_TestCase {

function assertVCard21serialization($propValue, $expected) {

$doc = new VCard(array(
'VERSION'=>'2.1',
'PROP' => $propValue
), false);

// Adding quoted-printable, because we're testing if it gets removed
// automatically.
$doc->PROP['ENCODING'] = 'QUOTED-PRINTABLE';
$doc->PROP['P1'] = 'V1';


$output = $doc->serialize();


$this->assertEquals("BEGIN:VCARD\r\nVERSION:2.1\r\n$expected\r\nEND:VCARD\r\n", $output);

}

function testSerializeVCard21() {

$this->assertVCard21Serialization(
'f;oo',
'PROP;P1=V1:f;oo'
);

}

function testSerializeVCard21Array() {

$this->assertVCard21Serialization(
array('f;oo','bar'),
'PROP;P1=V1:f\;oo;bar'
);

}


function testSerializeQuotedPrintable() {

$this->assertVCard21Serialization(
"foo\r\nbar",
'PROP;P1=V1;ENCODING=QUOTED-PRINTABLE:foo=0D=0Abar'
);
}

function testSerializeQuotedPrintableFold() {

$this->assertVCard21Serialization(
"foo\r\nbarxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"PROP;P1=V1;ENCODING=QUOTED-PRINTABLE:foo=0D=0Abarxxxxxxxxxxxxxxxxxxxxxxxxxx=\r\n xxx"
);

}
}

0 comments on commit e1d79db

Please sign in to comment.