Skip to content

Commit

Permalink
Fix datatime value return value of to_string.
Browse files Browse the repository at this point in the history
  • Loading branch information
melroy89 committed Mar 7, 2019
1 parent 51ecc1b commit 9985584
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/Property/Value/DateTimeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function __construct(\DateTime $value)

public function __toString(): string
{
// TODO: possibly not in line with rfc6350
return $this->value->format('u');
// According to the Timestamp rfc6350 standard in Zulu zone (UTC)
return $this->value->format('Ymd\THis\Z');
}

public function getValue(): \DateTime
Expand Down
121 changes: 73 additions & 48 deletions tests/VCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,54 +431,79 @@ public function testKindGroup(): void
$this->assertEquals($vcard->getParameters(), $parser->getVCards()[0]->getParameters());
}

/**
* Test the Revision Parameter.
*/
public function testRevisionParameter(): void
{
// Given
$expectedContent = "BEGIN:VCARD\r\n" .
"VERSION:4.0\r\n" .
"KIND:individual\r\n" .
"REV:19951031T222710Z\r\n" .
"FN:Test\r\n" .
"END:VCARD\r\n";

$formatter = new Formatter(new VcfFormatter(), '');
$vcard = (new Vcard())
->add(new FullName("Test"))
->add(new Revision(new \DateTime('19951031T222710Z')));

// When
$formatter->addVCard($vcard);

// Then
$this->assertEquals($expectedContent, $formatter->getContent());
}

/**
* Verify if multiple telephone numbers are correctly formatted
*/
public function testTelephonePropertyContent(): void
{
// Given
$expectedContent = "BEGIN:VCARD\r\n" .
"VERSION:4.0\r\n" .
"KIND:individual\r\n" .
"FN:Bob\r\n" .
"TEL;TYPE=home;VALUE=uri:tel:+33-01-23-45-67\r\n" .
"TEL;TYPE=work;VALUE=uri:tel:+33-05-42-41-96\r\n" .
"END:VCARD\r\n";

$formatter = new Formatter(new VcfFormatter(), '');
$vcard = (new VCard())
->add(new FullName('Bob'))
->add(new Telephone('+33 01 23 45 67'))
->add(new Telephone('+33-05-42-41-96', Type::work()));
// Given
$expectedContent = "BEGIN:VCARD\r\n" .
"VERSION:4.0\r\n" .
"KIND:individual\r\n" .
"FN:Bob\r\n" .
"TEL;TYPE=home;VALUE=uri:tel:+33-01-23-45-67\r\n" .
"TEL;TYPE=work;VALUE=uri:tel:+33-05-42-41-96\r\n" .
"END:VCARD\r\n";

$formatter = new Formatter(new VcfFormatter(), '');
$vcard = (new VCard())
->add(new FullName('Bob'))
->add(new Telephone('+33 01 23 45 67'))
->add(new Telephone('+33-05-42-41-96', Type::work()));

// When
$formatter->addVCard($vcard);
// When
$formatter->addVCard($vcard);

// Then
$this->assertEquals($expectedContent, $formatter->getContent());
// Then
$this->assertEquals($expectedContent, $formatter->getContent());
}

/**
* Verify if a full name gets correctly formatted
*/
public function testNamePropertyContent(): void
{
// Given
$expectedContent = "BEGIN:VCARD\r\n" .
"VERSION:4.0\r\n" .
"KIND:individual\r\n" .
"FN:Mr. Melroy Antoine van den Berg\r\n" .
"N:van den Berg;Melroy;Antoine;Mr.;\r\n" .
"END:VCARD\r\n";
// Given
$expectedContent = "BEGIN:VCARD\r\n" .
"VERSION:4.0\r\n" .
"KIND:individual\r\n" .
"FN:Mr. Melroy Antoine van den Berg\r\n" .
"N:van den Berg;Melroy;Antoine;Mr.;\r\n" .
"END:VCARD\r\n";

$formatter = new Formatter(new VcfFormatter(), '');
$vcard = (new VCard())->add(new Name('van den Berg', 'Melroy', 'Antoine', 'Mr.'));
$formatter = new Formatter(new VcfFormatter(), '');
$vcard = (new VCard())->add(new Name('van den Berg', 'Melroy', 'Antoine', 'Mr.'));

// When
$formatter->addVCard($vcard);
// When
$formatter->addVCard($vcard);

// Then
$this->assertEquals($expectedContent, $formatter->getContent());
// Then
$this->assertEquals($expectedContent, $formatter->getContent());
}

/**
Expand All @@ -487,24 +512,24 @@ public function testNamePropertyContent(): void
*/
public function testAddressPropertyContentWithLineBreak() : void
{
// Given
$expectedContent = "BEGIN:VCARD\r\n" .
"VERSION:4.0\r\n" .
"KIND:individual\r\n" .
"FN:Bob\r\n" .
"ADR;TYPE=home:42;Villa;Main Street 500;London;Barnet;EN4 0AG;United Kingd\r\n" .
// Line break because of 75 octets width limit, immediately followed by a single white space.
" om\r\n" .
"END:VCARD\r\n";
$formatter = new Formatter(new VcfFormatter(), '');
$vcard = (new VCard())
->add(new FullName('Bob'))
->add(new Address('42', 'Villa', 'Main Street 500', 'London', 'Barnet', 'EN4 0AG', 'United Kingdom'));
// Given
$expectedContent = "BEGIN:VCARD\r\n" .
"VERSION:4.0\r\n" .
"KIND:individual\r\n" .
"FN:Bob\r\n" .
"ADR;TYPE=home:42;Villa;Main Street 500;London;Barnet;EN4 0AG;United Kingd\r\n" .
// Line break because of 75 octets width limit, immediately followed by a single white space.
" om\r\n" .
"END:VCARD\r\n";
$formatter = new Formatter(new VcfFormatter(), '');
$vcard = (new VCard())
->add(new FullName('Bob'))
->add(new Address('42', 'Villa', 'Main Street 500', 'London', 'Barnet', 'EN4 0AG', 'United Kingdom'));

// When
$formatter->addVCard($vcard);
// When
$formatter->addVCard($vcard);

// Then
$this->assertEquals($expectedContent, $formatter->getContent());
// Then
$this->assertEquals($expectedContent, $formatter->getContent());
}
}

0 comments on commit 9985584

Please sign in to comment.