1<?php 2/** 3 * Test the person object. 4 * 5 * PHP version 5 6 * 7 * @category Kolab 8 * @package Kolab_Server 9 * @author Gunnar Wrobel <wrobel@pardus.de> 10 * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 11 * @link http://pear.horde.org/index.php?package=Kolab_Server 12 */ 13 14/** 15 * Require our basic test case definition 16 */ 17require_once __DIR__ . '/Scenario.php'; 18 19/** 20 * Test the person object. 21 * 22 * Copyright 2009-2016 Horde LLC (http://www.horde.org/) 23 * 24 * See the enclosed file COPYING for license information (LGPL). If you 25 * did not receive this file, see http://www.horde.org/licenses/lgpl21. 26 * 27 * @category Kolab 28 * @package Kolab_Server 29 * @author Gunnar Wrobel <wrobel@pardus.de> 30 * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 31 * @link http://pear.horde.org/index.php?package=Kolab_Server 32 */ 33class Horde_Kolab_Server_Integration_PersonTest extends Horde_Kolab_Server_Integration_Scenario 34{ 35 36 public $cn = 'Kolab_Server_PersonTest'; 37 38 /** 39 * Objects used within this test 40 * 41 * @var array 42 */ 43 private $objects = array( 44 /* Default dummy person */ 45 array( 46 'type' => 'Horde_Kolab_Server_Object_Person', 47 'Cn' => 'Kolab_Server_PersonTest_123', 48 'Sn' => 'Kolab_Server_PersonTest_123', 49 'Userpassword' => 'Kolab_Server_PersonTest_123', 50 ), 51 /* Invalid person (no sn) */ 52 array( 53 'type' => 'Horde_Kolab_Server_Object_Person', 54 'Cn' => 'Kolab_Server_PersonTest_123', 55 'Userpassword' => 'Kolab_Server_PersonTest_123', 56 ), 57 /* Person with problematic characters */ 58 array( 59 'type' => 'Horde_Kolab_Server_Object_Person', 60 'Cn' => 'Kolab_Server_PersonTest_!"$%&()=?', 61 'Sn' => 'Kolab_Server_PersonTest_!"$%&()=?', 62 'Userpassword' => 'Kolab_Server_PersonTest_!"$%&()=?', 63 ), 64 /* Person with difficult encoding */ 65 array( 66 'type' => 'Horde_Kolab_Server_Object_Person', 67 'Cn' => 'Kolab_Server_PersonTest_ügöräߧ', 68 'Sn' => 'Kolab_Server_PersonTest_ügöräߧ', 69 'Userpassword' => 'Kolab_Server_PersonTest_ügöräߧ', 70 ), 71 /* Person with forward slash */ 72 array( 73 'type' => 'Horde_Kolab_Server_Object_Person', 74 'Cn' => 'Kolab_Server_PersonTest_/', 75 'Sn' => 'Kolab_Server_PersonTest_/', 76 'Userpassword' => 'Kolab_Server_PersonTest_/', 77 ), 78 /* Person with double cn */ 79 array( 80 'type' => 'Horde_Kolab_Server_Object_Person', 81 'Cn' => array('Kolab_Server_PersonTest_cn1', 82 'Kolab_Server_PersonTest_cn2'), 83 'Sn' => 'Kolab_Server_PersonTest_cncn', 84 'Userpassword' => 'Kolab_Server_PersonTest_cncn', 85 ), 86 /* Person with name suffix*/ 87 array( 88 'type' => 'Horde_Kolab_Server_Object_Person', 89 'Cn' => 'Kolab_Server_PersonTest_123', 90 'Sn' => 'Kolab_Server_PersonTest_123', 91 'Userpassword' => 'Kolab_Server_PersonTest_123', 92 ), 93 /* Person for telephone number handling*/ 94 array( 95 'type' => 'Horde_Kolab_Server_Object_Person', 96 'Cn' => 'Kolab_Server_PersonTest_123456', 97 'Sn' => 'Kolab_Server_PersonTest_123456', 98 'Userpassword' => 'Kolab_Server_PersonTest_123456', 99 ), 100 /* Person with a creation date*/ 101 array( 102 'type' => 'Horde_Kolab_Server_Object_Person', 103 'Cn' => 'Kolab_Server_PersonTest_123456', 104 'Sn' => 'Kolab_Server_PersonTest_123456', 105 'Userpassword' => 'Kolab_Server_PersonTest_123456', 106 'Creationdate' => '191008030000Z', 107 ), 108 ); 109 110 /** 111 * Set up testing. 112 * 113 * @return NULL 114 */ 115 protected function setUp() 116 { 117 parent::setUp(); 118 119 $this->initializeEnvironments(); 120 $this->servers = $this->getKolabServers(); 121 } 122 123 /** 124 * Test ID generation for a person. 125 * 126 * @return NULL 127 */ 128 public function testGenerateId() 129 { 130 foreach ($this->servers as $server) { 131 $a = new Horde_Kolab_Server_Object_Person($server, null, $this->objects[0]); 132 $this->assertContains('Cn' . '=' . $this->objects[0]['Cn'], 133 $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); 134 } 135 } 136 137 /** 138 * Test adding an invalid person. 139 * 140 * @expectedException Horde_Kolab_Server_Exception 141 * 142 * @return NULL 143 */ 144 public function testAddInvalidPerson() 145 { 146 $this->addToServers($this->objects[1]); 147 } 148 149 /** 150 * Test adding a person. 151 * 152 * @return NULL 153 */ 154 public function testAddPerson() 155 { 156 foreach ($this->servers as $server) { 157 $adds = array(0, 2, 3, 4); 158 foreach ($adds as $add) { 159 $result = $server->add($this->objects[$add]); 160 $this->assertNoError($result); 161 $cn_result = $server->uidForCn($this->objects[$add]['Cn']); 162 $this->assertNoError($cn_result); 163 $dn_parts = Horde_Ldap_Util::explodeDN($cn_result, array('casefold' => 'lower')); 164 $dnpart = Horde_Ldap_Util::unescapeDNValue($dn_parts[0]); 165 /** 166 * @todo: I currently do not really understand why the forward slash 167 * is not correctly converted back but I lack the time to analyse it 168 * in detail. The server entry looks okay. 169 */ 170 $dnpart = str_replace('\/', '/', $dnpart); 171 $this->assertContains('Cn' . '=' . $this->objects[$add]['Cn'], 172 $dnpart[0]); 173 $result = $server->delete($cn_result); 174 $this->assertNoError($result); 175 $cn_result = $server->uidForCn($this->objects[$add]['Cn']); 176 $this->assertNoError($cn_result); 177 $this->assertFalse($server->uidForCn($this->objects[$add]['Cn'])); 178 } 179 } 180 } 181 182 /** 183 * Test modifying the surname of a person. 184 * 185 * @return NULL 186 */ 187 public function testModifyPersonSn() 188 { 189 foreach ($this->servers as $server) { 190 $person = $this->assertAdd($server, $this->objects[2], 191 array('Cn' => $this->objects[2]['Cn'])); 192 $this->assertSimpleSequence($person, $server, 193 'Sn', 194 array('modified', 'modified_again'), true); 195 } 196 } 197 198 /** 199 * Test modifying the cn of a person. This should have an effect on the UID 200 * of the object and needs to rename the object. 201 * 202 * @return NULL 203 */ 204 public function testModifyPersonCn() 205 { 206 foreach ($this->servers as $server) { 207 $person = $server->add($this->objects[2]); 208 $this->assertNoError($person); 209 210 $person = $server->fetch($person->getUid()); 211 212 $this->assertEquals($this->objects[2]['Cn'], 213 $person->get('Cn')); 214 215 $result = $person->save(array('Cn' => 'Kolab_Server_PersonTest_äö')); 216 $cn_result = $server->uidForCn('Kolab_Server_PersonTest_äö'); 217 $person = $server->fetch($cn_result); 218 $this->assertEquals($person->get('Cn'), 219 'Kolab_Server_PersonTest_äö'); 220 $result = $server->delete($cn_result); 221 $this->assertNoError($result); 222 $cn_result = $server->uidForCn('Kolab_Server_PersonTest_äö'); 223 $this->assertNoError($cn_result); 224 $this->assertFalse($cn_result); 225 } 226 } 227 228 /** 229 * Test adding a person with two common names. 230 * 231 * @return NULL 232 */ 233 public function testAddDoubleCnPerson() 234 { 235 foreach ($this->servers as $server) { 236 $person = $this->assertAdd($server, $this->objects[5], 237 array()); 238 239 $cn_result = $server->uidForCn($this->objects[5]['Cn'][0]); 240 $this->assertNoError($cn_result); 241 $dn_parts = Horde_Ldap_Util::explodeDN($cn_result, array('casefold' => 'lower')); 242 $dnpart = Horde_Ldap_Util::unescapeDNValue($dn_parts[0]); 243 $this->assertContains('Cn' . '=' . $this->objects[5]['Cn'][0], 244 $dnpart[0]); 245 } 246 } 247 248 /** 249 * Test handling a phone number. 250 * 251 * @return NULL 252 */ 253 public function testHandlingAPhoneNumaber() 254 { 255 foreach ($this->servers as $server) { 256 $person = $this->assertAdd($server, $this->objects[7], 257 array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_TELNO => '')); 258 $this->assertSimpleSequence($person, $server, 259 Horde_Kolab_Server_Object_Person::ATTRIBUTE_TELNO, 260 array('123456789', '+1234567890', array('1', '2'), null, '0'), true); 261 } 262 } 263 264 /** 265 * Test retrrieving a date. 266 * 267 * @return NULL 268 */ 269 public function testGetDate() 270 { 271 foreach ($this->servers as $server) { 272 $person = $this->assertAdd($server, $this->objects[8], 273 array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_TELNO => '')); 274 $cdate = $person->get(Horde_Kolab_Server_Object_Person::ATTRDATE_CREATIONDATE); 275 $this->assertEquals('Horde_Date', get_class($cdate)); 276 $this->assertEquals('1910-08-03 01:00:00', (string) $cdate); 277 } 278 } 279} 280