1<?php 2/** 3 * @author Jan Schneider <jan@horde.org> 4 * @license http://www.horde.org/licenses/apache Apache-like 5 * @category Horde 6 * @package Turba 7 * @subpackage UnitTests 8 */ 9class Turba_Unit_ExportTest extends Turba_TestCase 10{ 11 public static function setUpBeforeClass() 12 { 13 self::createBasicTurbaSetup(new Horde_Test_Setup()); 14 parent::setUpBeforeClass(); 15 setlocale(LC_MESSAGES, 'C'); 16 } 17 18 public static function tearDownAfterClass() 19 { 20 self::tearDownBasicTurbaSetup(); 21 parent::tearDownAfterClass(); 22 setlocale(LC_MESSAGES, null); 23 } 24 25 public function setUp() 26 { 27 $GLOBALS['injector']->setInstance( 28 'Turba_Tagger', 29 $this->getMockBuilder('Turba_Tagger') 30 ->disableOriginalConstructor() 31 ->setMethods(null) 32 ->getMock() 33 ); 34 $this->contact = array( 35 'name' => 'Jan Schneiderö', 36 'namePrefix' => 'Mr.', 37 'firstname' => 'Jan', 38 'middlenames' => 'K.', 39 'lastname' => 'Schneiderö', 40 'email' => 'jan@horde.org', 41 'alias' => 'yunosh', 42 'homeAddress' => 'Schönestr. 15 4333604 Bielefeld', 44 'workStreet' => 'Hübschestr. 19', 45 'workCity' => 'Köln', 46 'workProvince' => 'Allgäu', 47 'workPostalcode' => '33602', 48 'workCountry' => 'DK', 49 'homePhone' => '+49 521 555123', 50 'workPhone' => '+49 521 555456', 51 'cellPhone' => '+49 177 555123', 52 'fax' => '+49 521 555789', 53 'pager' => '+49 123 555789', 54 'birthday' => '1971-10-01', 55 'title' => 'Senior Developer (äöü)', 56 'role' => 'Developer (äöü)', 57 'company' => 'Horde Project', 58 'department' => 'äöü', 59 'notes' => 'A German guy (äöü)', 60 'website' => 'http://janschneider.de', 61 'timezone' => 'Europe/Berlin', 62 'latitude' => '52.516276', 63 'longitude' => '13.377778', 64 'photo' => file_get_contents(__DIR__ . '/../fixtures/az.png'), 65 'phototype' => 'image/png', 66 '__tags' => 'Foo,Foo;Bar,Bar', 67 ); 68 $this->driver = new Turba_Driver(); 69 $this->driver->map = array_fill_keys(array_diff(array_keys($this->contact), array('__tags')), true); 70 $this->object = new Turba_Object($this->driver, $this->contact); 71 } 72 73 public function testExportVcard21() 74 { 75 $vcard = $this->driver->tovCard($this->object, '2.1'); 76 $this->assertStringEqualsFile( 77 __DIR__ . '/../fixtures/export_21.vcf', 78 $vcard->exportvCalendar()); 79 } 80 81 public function testExportVcard30() 82 { 83 $vcard = $this->driver->tovCard($this->object, '3.0'); 84 $this->assertStringEqualsFile( 85 __DIR__ . '/../fixtures/export_30.vcf', 86 $vcard->exportvCalendar()); 87 } 88 89 public function testExportBug9207() 90 { 91 $driver = clone $this->driver; 92 $driver->alternativeName = 'company'; 93 $driver->map['name'] = array( 94 'fields' => array('namePrefix', 'firstname', 'middlenames', 95 'lastname', 'nameSuffix'), 96 'format' => '%s %s %s %s %s'); 97 $contact = $this->contact; 98 unset($contact['name']); 99 $object = new Turba_Object($driver, $contact); 100 $vcard = $this->driver->tovCard($object, '3.0'); 101 $this->assertStringEqualsFile( 102 __DIR__ . '/../fixtures/bug_9207.vcf', 103 $vcard->exportvCalendar()); 104 } 105} 106