alecpl
2010-04-21 93c01888547210f54bd593d0774f9f63ec38f7a7
commit | author | age
5570ad 1 <?php
T 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   
53 }