| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * Unit tests for class rcube_vcard |
|---|
| 5 | * |
|---|
| 6 | * @package Tests |
|---|
| 7 | */ |
|---|
| 8 | class rcube_test_vcards extends UnitTestCase |
|---|
| 9 | { |
|---|
| 10 | |
|---|
| 11 | function __construct() |
|---|
| 12 | { |
|---|
| 13 | $this->UnitTestCase('Vcard encoding/decoding tests'); |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | function _srcpath($fn) |
|---|
| 17 | { |
|---|
| 18 | return realpath(dirname(__FILE__) . '/src/' . $fn); |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | function test_parse_one() |
|---|
| 22 | { |
|---|
| 23 | $vcard = new rcube_vcard(file_get_contents($this->_srcpath('apple.vcf'))); |
|---|
| 24 | |
|---|
| 25 | $this->assertEqual(true, $vcard->business, "Identify as business record"); |
|---|
| 26 | $this->assertEqual("Apple Computer AG", $vcard->displayname, "FN => displayname"); |
|---|
| 27 | $this->assertEqual("", $vcard->firstname, "No person name set"); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | function test_parse_two() |
|---|
| 31 | { |
|---|
| 32 | $vcard = new rcube_vcard(file_get_contents($this->_srcpath('johndoe.vcf')), null); |
|---|
| 33 | |
|---|
| 34 | $this->assertEqual(false, $vcard->business, "Identify as private record"); |
|---|
| 35 | $this->assertEqual("John Doë", $vcard->displayname, "Decode according to charset attribute"); |
|---|
| 36 | $this->assertEqual("roundcube.net", $vcard->organization, "Test organization field"); |
|---|
| 37 | $this->assertEqual(2, count($vcard->email), "List two e-mail addresses"); |
|---|
| 38 | $this->assertEqual("roundcube@gmail.com", $vcard->email[0], "Use PREF e-mail as primary"); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | function test_import() |
|---|
| 42 | { |
|---|
| 43 | $input = file_get_contents($this->_srcpath('apple.vcf')); |
|---|
| 44 | $input .= file_get_contents($this->_srcpath('johndoe.vcf')); |
|---|
| 45 | |
|---|
| 46 | $vcards = rcube_vcard::import($input); |
|---|
| 47 | |
|---|
| 48 | $this->assertEqual(2, count($vcards), "Detected 2 vcards"); |
|---|
| 49 | $this->assertEqual("Apple Computer AG", $vcards[0]->displayname, "FN => displayname"); |
|---|
| 50 | $this->assertEqual("John Doë", $vcards[1]->displayname, "Displayname with correct charset"); |
|---|
| 51 | |
|---|
| 52 | // http://trac.roundcube.net/ticket/1485542 |
|---|
| 53 | $vcards2 = rcube_vcard::import(file_get_contents($this->_srcpath('thebat.vcf'))); |
|---|
| 54 | $this->assertEqual("Iksiñski", $vcards2[0]->surname, "Detect charset in encoded values"); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | function test_encodings() |
|---|
| 58 | { |
|---|
| 59 | $input = file_get_contents($this->_srcpath('utf-16_sample.vcf')); |
|---|
| 60 | |
|---|
| 61 | $vcards = rcube_vcard::import($input); |
|---|
| 62 | $this->assertEqual("njgean ĜdaMonté", $vcards[0]->displayname, "Decoded from UTF-16"); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | } |
|---|