示例#1
0
 function testVCard2()
 {
     $vCard = new vCard();
     $vCard->setOrganization('Testing, Inc.');
     $vCard->setName('Smith', 'John', 'J.', 'Mr.', 'Jr.');
     $vCard->setEmail('*****@*****.**');
     $vCard->setPhoneNumber('612-555-3000', 'CELL');
     $vCard->setTitle('Senior Tester');
     $vCard->setAddress('555 Testing Dr', 'Suite 100', 'Testertown', 'TN', '12345', '', 'USA', '', 'HOME');
     $vCard->setNote('Test note.');
     $vCard->setURL('http://www.slashdot.org');
     $output = trim($vCard->getVCard());
     $outputLines = explode("\n", $output);
     $outputLines = array_map('trim', $outputLines);
     $this->assertIdentical($outputLines[0], 'BEGIN:VCARD');
     $this->assertIdentical($outputLines[1], 'VERSION:2.1');
     $this->assertIdentical($outputLines[2], 'ORG;ENCODING=QUOTED-PRINTABLE:Testing, Inc.');
     $this->assertIdentical($outputLines[3], 'N:Smith;John;J.;Mr.;Jr.');
     $this->assertIdentical($outputLines[4], 'FN:Mr. John J. Smith Jr.');
     $this->assertIdentical($outputLines[5], 'EMAIL;INTERNET:test@testerson.org');
     $this->assertIdentical($outputLines[6], 'TEL;CELL:612-555-3000');
     $this->assertIdentical($outputLines[7], 'TITLE;ENCODING=QUOTED-PRINTABLE:Senior Tester');
     $this->assertIdentical($outputLines[8], 'ADR;HOME;ENCODING=QUOTED-PRINTABLE:;Suite 100;555 Testing Dr;Testertown;TN;12345;USA');
     $this->assertIdentical($outputLines[9], 'ORG;ENCODING=QUOTED-PRINTABLE:Test note.');
     $this->assertIdentical($outputLines[10], 'URL:http://www.slashdot.org');
     /* Test revision timestamp. */
     $this->assertPatternIn('/^REV:\\d{8}T\\d{6}$/', $outputLines[11]);
     $currentREVNumeric = date('YmdHis');
     $vCardREVNumeric = preg_replace('/REV:|T/', '', $outputLines[11]);
     $this->assertTrue($vCardREVNumeric >= $currentREVNumeric - 5 && $vCardREVNumeric <= $currentREVNumeric + 5, 'REV is within +/-5 seconds of current timestamp');
     $this->assertIdentical($outputLines[12], 'MAILER:CATS');
     $this->assertIdentical($outputLines[13], 'END:VCARD');
     $this->assertIdentical($vCard->getFilename(), 'John Smith.vcf');
 }