1<?php 2/** 3 * Basic Turba test case. 4 * 5 * PHP version 5 6 * 7 * @category Horde 8 * @package Turba 9 * @subpackage UnitTests 10 * @author Gunnar Wrobel <wrobel@pardus.de> 11 * @link http://www.horde.org/apps/turba 12 * @license http://www.horde.org/licenses/apache Apache-like 13 */ 14 15require __DIR__ . '/Stub/Hooks.php'; 16 17/** 18 * Basic Turba test case. 19 * 20 * Copyright 2011-2017 Horde LLC (http://www.horde.org/) 21 * 22 * See the enclosed file LICENSE for license information (ASL). If you did 23 * did not receive this file, see http://www.horde.org/licenses/apache. 24 * 25 * @category Horde 26 * @package Turba 27 * @subpackage UnitTests 28 * @author Gunnar Wrobel <wrobel@pardus.de> 29 * @link http://www.horde.org/apps/turba 30 * @license http://www.horde.org/licenses/apache Apache-like 31 */ 32class Turba_TestCase extends PHPUnit_Framework_TestCase 33{ 34 protected function getInjector() 35 { 36 return new Horde_Injector(new Horde_Injector_TopLevel()); 37 } 38 39 static protected function createBasicTurbaSetup(Horde_Test_Setup $setup) 40 { 41 $setup->setup( 42 array( 43 '_PARAMS' => array( 44 'user' => 'test@example.com', 45 'app' => 'turba' 46 ), 47 'Horde_Cache' => 'Cache', 48 'Horde_Group' => 'Group', 49 'Horde_History' => 'History', 50 'Horde_Perms' => 'Perms', 51 'Horde_Prefs' => 'Prefs', 52 'Horde_Registry' => 'Registry', 53 ) 54 ); 55 $setup->makeGlobal( 56 array( 57 'prefs' => 'Horde_Prefs', 58 'registry' => 'Horde_Registry', 59 'injector' => 'Horde_Injector', 60 ) 61 ); 62 $GLOBALS['session'] = new Horde_Session(); 63 $GLOBALS['conf']['prefs']['driver'] = 'Null'; 64 putenv('HORDE_UNIT_TEST=1'); 65 } 66 67 static protected function tearDownBasicTurbaSetup() 68 { 69 unset( 70 $GLOBALS['session'], 71 $GLOBALS['prefs'], 72 $GLOBALS['injector'], 73 $GLOBALS['registry'], 74 $GLOBALS['conf'] 75 ); 76 } 77 78 static protected function createSqlPdoSqlite(Horde_Test_Setup $setup) 79 { 80 $setup->setup( 81 array( 82 'Horde_Db_Adapter' => array( 83 'factory' => 'Db', 84 'params' => array( 85 'migrations' => array( 86 'migrationsPath' => __DIR__ . '/../../migration', 87 'schemaTableName' => 'turba_test_schema' 88 ) 89 ) 90 ), 91 ) 92 ); 93 } 94 95 static protected function createSqlShares(Horde_Test_Setup $setup) 96 { 97 $setup->getInjector()->setInstance( 98 'Horde_Core_Factory_Db', 99 new Horde_Test_Stub_Factory( 100 $setup->getInjector()->getInstance('Horde_Db_Adapter') 101 ) 102 ); 103 $setup->setup( 104 array( 105 'Turba_Shares' => 'Share', 106 ) 107 ); 108 $GLOBALS['cfgSources']['test']['type'] = 'Sql'; 109 $GLOBALS['cfgSources']['test']['title'] = 'SQL'; 110 $GLOBALS['cfgSources']['test']['map'] = self::_getSqlMap(); 111 } 112 113 static protected function createKolabShares(Horde_Test_Setup $setup) 114 { 115 $setup->setup( 116 array( 117 'Horde_Kolab_Storage' => array( 118 'factory' => 'KolabStorage', 119 'params' => array( 120 'imapuser' => 'test', 121 ) 122 ), 123 'Turba_Shares' => array( 124 'factory' => 'Share', 125 'method' => 'Kolab', 126 ), 127 ) 128 ); 129 $setup->getInjector()->setInstance( 130 'Horde_Core_Factory_Share', 131 new Horde_Test_Stub_Factory( 132 $setup->getInjector()->getInstance('Turba_Shares') 133 ) 134 ); 135 $GLOBALS['cfgSources']['test']['type'] = 'Kolab'; 136 $GLOBALS['cfgSources']['test']['title'] = 'Kolab'; 137 $GLOBALS['cfgSources']['test']['map'] = self::_getKolabMap(); 138 } 139 140 static protected function tearDownShares() 141 { 142 unset( 143 $GLOBALS['cfgSources'] 144 ); 145 } 146 147 static protected function getKolabDriver() 148 { 149 $setup = new Horde_Test_Setup(); 150 self::createBasicTurbaSetup($setup); 151 return self::createKolabDriverWithShares(); 152 } 153 154 static protected function createKolabDriverWithShares($setup) 155 { 156 self::createKolabShares($setup); 157 list($share, $other_share) = self::_createDefaultShares(); 158 159 $GLOBALS['cfgSources'][$share->getName()]['type'] = 'Kolab'; 160 $GLOBALS['cfgSources'][$share->getName()]['title'] = $share->get('name'); 161 $GLOBALS['cfgSources'][$share->getName()]['map'] = self::_getKolabMap(); 162 return $GLOBALS['injector']->getInstance('Turba_Factory_Driver') 163 ->create($share->getName()); 164 } 165 166 static protected function createSqlDriverWithShares($setup) 167 { 168 self::createSqlShares($setup); 169 list($share, $other_share) = self::_createDefaultShares(); 170 171 $GLOBALS['cfgSources'][$share->getName()]['type'] = 'Sql'; 172 $GLOBALS['cfgSources'][$share->getName()]['title'] = $share->get('name'); 173 $GLOBALS['cfgSources'][$share->getName()]['map'] = self::_getSqlMap(); 174 $GLOBALS['cfgSources'][$share->getName()]['params']['table'] = 'turba_objects'; 175 return $GLOBALS['injector']->getInstance('Turba_Factory_Driver') 176 ->create($share->getName()); 177 } 178 179 static protected function _createDefaultShares() 180 { 181 $share = self::_createShare( 182 'Address book of Tester', 'test@example.com' 183 ); 184 $other_share = self::_createShare( 185 'Other address book of Tester', 'test@example.com' 186 ); 187 return array($share, $other_share); 188 } 189 190 static private function _createShare($name, $owner) 191 { 192 $turba_shares = $GLOBALS['injector']->getInstance('Turba_Shares'); 193 $share = $turba_shares->newShare( 194 $owner, strval(new Horde_Support_Randomid()), $name 195 ); 196 $turba_shares->addShare($share); 197 return $share; 198 } 199 200 static private function _getKolabMap() 201 { 202 return array( 203 '__key' => 'uid', 204 '__uid' => 'uid', 205 '__type' => '__type', 206 '__members' => '__members', 207 /* Personal */ 208 'name' => array( 209 'fields' => array('firstname', 'middlenames', 'lastname'), 210 'format' => '%s %s %s', 211 'parse' => array( 212 array( 213 'fields' => array( 214 'firstname', 'middlenames', 'lastname' 215 ), 216 'format' => '%s %s %s' 217 ), 218 array( 219 'fields' => array('lastname', 'firstname'), 220 'format' => '%s, %s' 221 ), 222 array( 223 'fields' => array('firstname', 'lastname'), 224 'format' => '%s %s' 225 ), 226 ) 227 ), 228 'firstname' => 'given-name', 229 'lastname' => 'last-name', 230 'middlenames' => 'middle-names', 231 'namePrefix' => 'prefix', 232 'nameSuffix' => 'suffix', 233 'initials' => 'initials', 234 'nickname' => 'nick-name', 235 'photo' => 'photo', 236 'phototype' => 'phototype', 237 'gender' => 'gender', 238 'birthday' => 'birthday', 239 'spouse' => 'spouse-name', 240 'anniversary' => 'anniversary', 241 'children' => 'children', 242 /* Location */ 243 'workStreet' => 'addr-business-street', 244 'workCity' => 'addr-business-locality', 245 'workProvince' => 'addr-business-region', 246 'workPostalCode' => 'addr-business-postal-code', 247 'workCountry' => 'addr-business-country', 248 'homeStreet' => 'addr-home-street', 249 'homeCity' => 'addr-home-locality', 250 'homeProvince' => 'addr-home-region', 251 'homePostalCode' => 'addr-home-postal-code', 252 'homeCountry' => 'addr-home-country', 253 /* Communications */ 254 'emails' => 'emails', 255 'homePhone' => 'phone-home1', 256 'workPhone' => 'phone-business1', 257 'cellPhone' => 'phone-mobile', 258 'fax' => 'phone-businessfax', 259 'imaddress' => 'im-address', 260 /* Organization */ 261 'title' => 'job-title', 262 'role' => 'profession', 263 'company' => 'organization', 264 'department' => 'department', 265 'office' => 'office-location', 266 'manager' => 'manager-name', 267 'assistant' => 'assistant', 268 /* Other */ 269 'notes' => 'body', 270 'website' => 'web-page', 271 'freebusyUrl' => 'free-busy-url', 272 'language' => 'language', 273 'latitude' => 'latitude', 274 'longitude' => 'longitude', 275 /* Invisible */ 276 'email' => 'email', 277 'pgpPublicKey' => 'pgp-publickey', 278 ); 279 } 280 281 static private function _getSqlMap() 282 { 283 return array( 284 '__key' => 'object_id', 285 '__owner' => 'owner_id', 286 '__type' => 'object_type', 287 '__members' => 'object_members', 288 '__uid' => 'object_uid', 289 'firstname' => 'object_firstname', 290 'lastname' => 'object_lastname', 291 'middlenames' => 'object_middlenames', 292 'namePrefix' => 'object_nameprefix', 293 'nameSuffix' => 'object_namesuffix', 294 'name' => array('fields' => array('namePrefix', 'firstname', 295 'middlenames', 'lastname', 296 'nameSuffix'), 297 'format' => '%s %s %s %s %s', 298 'parse' => array( 299 array('fields' => array('firstname', 'middlenames', 300 'lastname'), 301 'format' => '%s %s %s'), 302 array('fields' => array('firstname', 'lastname'), 303 'format' => '%s %s'))), 304 // This is a shorter version of a "name" composite field which only 305 // consists of the first name and last name. 306 // 'name' => array('fields' => array('firstname', 'lastname'), 307 // 'format' => '%s %s'), 308 'alias' => 'object_alias', 309 'birthday' => 'object_bday', 310 'anniversary' => 'object_anniversary', 311 'spouse' => 'object_spouse', 312 'photo' => 'object_photo', 313 'phototype' => 'object_phototype', 314 'homeStreet' => 'object_homestreet', 315 'homePOBox' => 'object_homepob', 316 'homeCity' => 'object_homecity', 317 'homeProvince' => 'object_homeprovince', 318 'homePostalCode' => 'object_homepostalcode', 319 'homeCountry' => 'object_homecountry', 320 'homeAddress' => array('fields' => array('homeStreet', 'homeCity', 321 'homeProvince', 322 'homePostalCode'), 323 'format' => "%s \n %s, %s %s"), 324 'workStreet' => 'object_workstreet', 325 'workPOBox' => 'object_workpob', 326 'workCity' => 'object_workcity', 327 'workProvince' => 'object_workprovince', 328 'workPostalCode' => 'object_workpostalcode', 329 'workCountry' => 'object_workcountry', 330 'workAddress' => array('fields' => array('workStreet', 'workCity', 331 'workProvince', 332 'workPostalCode'), 333 'format' => "%s \n %s, %s %s"), 334 'department' => 'object_department', 335 'timezone' => 'object_tz', 336 'email' => 'object_email', 337 'homePhone' => 'object_homephone', 338 'homeFax' => 'object_homefax', 339 'workPhone' => 'object_workphone', 340 'cellPhone' => 'object_cellphone', 341 'assistPhone' => 'object_assistantphone', 342 'fax' => 'object_fax', 343 'pager' => 'object_pager', 344 'title' => 'object_title', 345 'role' => 'object_role', 346 'company' => 'object_company', 347 'logo' => 'object_logo', 348 'logotype' => 'object_logotype', 349 'notes' => 'object_notes', 350 'website' => 'object_url', 351 'freebusyUrl' => 'object_freebusyurl', 352 'pgpPublicKey' => 'object_pgppublickey', 353 'smimePublicKey' => 'object_smimepublickey', 354 'imaddress' => 'object_imaddress', 355 'imaddress2' => 'object_imaddress2', 356 'imaddress3' => 'object_imaddress3' 357 ); 358 } 359} 360