Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 28 | class Test_User_User extends \Test\TestCase { |
||
| 29 | |||
| 30 | 26 | private function getTestInstances() { |
|
| 31 | 26 | $access = $this->getMock('\OCA\user_ldap\lib\user\IUserTools'); |
|
| 32 | 26 | $config = $this->getMock('\OCP\IConfig'); |
|
| 33 | 26 | $filesys = $this->getMock('\OCA\user_ldap\lib\FilesystemHelper'); |
|
| 34 | 26 | $log = $this->getMock('\OCA\user_ldap\lib\LogWrapper'); |
|
| 35 | 26 | $avaMgr = $this->getMock('\OCP\IAvatarManager'); |
|
| 36 | 26 | $image = $this->getMock('\OCP\Image'); |
|
| 37 | 26 | $dbc = $this->getMock('\OCP\IDBConnection'); |
|
| 38 | |||
| 39 | 26 | return array($access, $config, $filesys, $image, $log, $avaMgr, $dbc); |
|
| 40 | } |
||
| 41 | |||
| 42 | 20 | private function getAdvancedMocks($cfMock, $fsMock, $logMock, $avaMgr, $dbc) { |
|
| 43 | 20 | static $conMethods; |
|
| 44 | 20 | static $accMethods; |
|
| 45 | 20 | static $umMethods; |
|
| 46 | |||
| 47 | 20 | View Code Duplication | if(is_null($conMethods) || is_null($accMethods)) { |
|
|
|||
| 48 | 1 | $conMethods = get_class_methods('\OCA\user_ldap\lib\Connection'); |
|
| 49 | 1 | $accMethods = get_class_methods('\OCA\user_ldap\lib\Access'); |
|
| 50 | //getConnection shall not be replaced |
||
| 51 | 1 | unset($accMethods[array_search('getConnection', $accMethods)]); |
|
| 52 | 1 | $umMethods = get_class_methods('\OCA\user_ldap\lib\user\Manager'); |
|
| 53 | 1 | } |
|
| 54 | 20 | $lw = $this->getMock('\OCA\user_ldap\lib\ILDAPWrapper'); |
|
| 55 | 20 | $im = $this->getMock('\OCP\Image'); |
|
| 56 | 20 | $um = $this->getMock('\OCA\user_ldap\lib\user\Manager', |
|
| 57 | 20 | $umMethods, array($cfMock, $fsMock, $logMock, $avaMgr, $im, $dbc)); |
|
| 58 | 20 | $connector = $this->getMock('\OCA\user_ldap\lib\Connection', |
|
| 59 | 20 | $conMethods, array($lw, null, null)); |
|
| 60 | 20 | $access = $this->getMock('\OCA\user_ldap\lib\Access', |
|
| 61 | 20 | $accMethods, array($connector, $lw, $um)); |
|
| 62 | |||
| 63 | 20 | return array($access, $connector); |
|
| 64 | } |
||
| 65 | |||
| 66 | 1 | View Code Duplication | public function testGetDNandUsername() { |
| 67 | list($access, $config, $filesys, $image, $log, $avaMgr) = |
||
| 68 | 1 | $this->getTestInstances(); |
|
| 69 | |||
| 70 | 1 | $uid = 'alice'; |
|
| 71 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 72 | |||
| 73 | 1 | $user = new User( |
|
| 74 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 75 | |||
| 76 | 1 | $this->assertSame($dn, $user->getDN()); |
|
| 77 | 1 | $this->assertSame($uid, $user->getUsername()); |
|
| 78 | 1 | } |
|
| 79 | |||
| 80 | 1 | public function testUpdateEmailProvided() { |
|
| 81 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 82 | 1 | $this->getTestInstances(); |
|
| 83 | |||
| 84 | list($access, $connection) = |
||
| 85 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 86 | |||
| 87 | 1 | $connection->expects($this->once()) |
|
| 88 | 1 | ->method('__get') |
|
| 89 | 1 | ->with($this->equalTo('ldapEmailAttribute')) |
|
| 90 | 1 | ->will($this->returnValue('email')); |
|
| 91 | |||
| 92 | 1 | $access->expects($this->once()) |
|
| 93 | 1 | ->method('readAttribute') |
|
| 94 | 1 | ->with($this->equalTo('uid=alice,dc=foo,dc=bar'), |
|
| 95 | 1 | $this->equalTo('email')) |
|
| 96 | 1 | ->will($this->returnValue(array('[email protected]'))); |
|
| 97 | |||
| 98 | 1 | $config->expects($this->once()) |
|
| 99 | 1 | ->method('setUserValue') |
|
| 100 | 1 | ->with($this->equalTo('alice'), $this->equalTo('settings'), |
|
| 101 | 1 | $this->equalTo('email'), |
|
| 102 | 1 | $this->equalTo('[email protected]')) |
|
| 103 | 1 | ->will($this->returnValue(true)); |
|
| 104 | |||
| 105 | 1 | $uid = 'alice'; |
|
| 106 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 107 | |||
| 108 | 1 | $user = new User( |
|
| 109 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 110 | |||
| 111 | 1 | $user->updateEmail(); |
|
| 112 | 1 | } |
|
| 113 | |||
| 114 | 1 | public function testUpdateEmailNotProvided() { |
|
| 115 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 116 | 1 | $this->getTestInstances(); |
|
| 117 | |||
| 118 | list($access, $connection) = |
||
| 119 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 120 | |||
| 121 | 1 | $connection->expects($this->once()) |
|
| 122 | 1 | ->method('__get') |
|
| 123 | 1 | ->with($this->equalTo('ldapEmailAttribute')) |
|
| 124 | 1 | ->will($this->returnValue('email')); |
|
| 125 | |||
| 126 | 1 | $access->expects($this->once()) |
|
| 127 | 1 | ->method('readAttribute') |
|
| 128 | 1 | ->with($this->equalTo('uid=alice,dc=foo,dc=bar'), |
|
| 129 | 1 | $this->equalTo('email')) |
|
| 130 | 1 | ->will($this->returnValue(false)); |
|
| 131 | |||
| 132 | 1 | $config->expects($this->never()) |
|
| 133 | 1 | ->method('setUserValue'); |
|
| 134 | |||
| 135 | 1 | $uid = 'alice'; |
|
| 136 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 137 | |||
| 138 | 1 | $user = new User( |
|
| 139 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 140 | |||
| 141 | 1 | $user->updateEmail(); |
|
| 142 | 1 | } |
|
| 143 | |||
| 144 | 2 | public function testUpdateEmailNotConfigured() { |
|
| 145 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 146 | 1 | $this->getTestInstances(); |
|
| 147 | |||
| 148 | 1 | list($access, $connection) = |
|
| 149 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 150 | |||
| 151 | 1 | $connection->expects($this->once()) |
|
| 152 | 1 | ->method('__get') |
|
| 153 | 1 | ->with($this->equalTo('ldapEmailAttribute')) |
|
| 154 | 1 | ->will($this->returnValue('')); |
|
| 155 | |||
| 156 | 1 | $access->expects($this->never()) |
|
| 157 | 1 | ->method('readAttribute'); |
|
| 158 | |||
| 159 | 1 | $config->expects($this->never()) |
|
| 160 | 1 | ->method('setUserValue'); |
|
| 161 | |||
| 162 | 1 | $uid = 'alice'; |
|
| 163 | 2 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 164 | |||
| 165 | 1 | $user = new User( |
|
| 166 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 167 | |||
| 168 | 1 | $user->updateEmail(); |
|
| 169 | 1 | } |
|
| 170 | |||
| 171 | 2 | View Code Duplication | public function testUpdateQuotaAllProvided() { |
| 172 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 173 | 1 | $this->getTestInstances(); |
|
| 174 | |||
| 175 | list($access, $connection) = |
||
| 176 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 177 | |||
| 178 | 1 | $connection->expects($this->at(0)) |
|
| 179 | 1 | ->method('__get') |
|
| 180 | 1 | ->with($this->equalTo('ldapQuotaDefault')) |
|
| 181 | 1 | ->will($this->returnValue('23 GB')); |
|
| 182 | |||
| 183 | 1 | $connection->expects($this->at(1)) |
|
| 184 | 1 | ->method('__get') |
|
| 185 | 1 | ->with($this->equalTo('ldapQuotaAttribute')) |
|
| 186 | 1 | ->will($this->returnValue('myquota')); |
|
| 187 | |||
| 188 | 1 | $connection->expects($this->exactly(2)) |
|
| 189 | 2 | ->method('__get'); |
|
| 190 | |||
| 191 | 1 | $access->expects($this->once()) |
|
| 192 | 1 | ->method('readAttribute') |
|
| 193 | 1 | ->with($this->equalTo('uid=alice,dc=foo,dc=bar'), |
|
| 194 | 1 | $this->equalTo('myquota')) |
|
| 195 | 1 | ->will($this->returnValue(array('42 GB'))); |
|
| 196 | |||
| 197 | 1 | $config->expects($this->once()) |
|
| 198 | 1 | ->method('setUserValue') |
|
| 199 | 1 | ->with($this->equalTo('alice'), |
|
| 200 | 1 | $this->equalTo('files'), |
|
| 201 | 1 | $this->equalTo('quota'), |
|
| 202 | 1 | $this->equalTo('42 GB')) |
|
| 203 | 1 | ->will($this->returnValue(true)); |
|
| 204 | |||
| 205 | 1 | $uid = 'alice'; |
|
| 206 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 207 | |||
| 208 | 1 | $user = new User( |
|
| 209 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 210 | |||
| 211 | 1 | $user->updateQuota(); |
|
| 212 | 1 | } |
|
| 213 | |||
| 214 | 5 | View Code Duplication | public function testUpdateQuotaDefaultProvided() { |
| 215 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 216 | 1 | $this->getTestInstances(); |
|
| 217 | |||
| 218 | list($access, $connection) = |
||
| 219 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 220 | |||
| 221 | 1 | $connection->expects($this->at(0)) |
|
| 222 | 1 | ->method('__get') |
|
| 223 | 1 | ->with($this->equalTo('ldapQuotaDefault')) |
|
| 224 | 1 | ->will($this->returnValue('25 GB')); |
|
| 225 | |||
| 226 | 1 | $connection->expects($this->at(1)) |
|
| 227 | 1 | ->method('__get') |
|
| 228 | 1 | ->with($this->equalTo('ldapQuotaAttribute')) |
|
| 229 | 1 | ->will($this->returnValue('myquota')); |
|
| 230 | |||
| 231 | 1 | $connection->expects($this->exactly(2)) |
|
| 232 | 1 | ->method('__get'); |
|
| 233 | |||
| 234 | 1 | $access->expects($this->once()) |
|
| 235 | 1 | ->method('readAttribute') |
|
| 236 | 1 | ->with($this->equalTo('uid=alice,dc=foo,dc=bar'), |
|
| 237 | 1 | $this->equalTo('myquota')) |
|
| 238 | 1 | ->will($this->returnValue(false)); |
|
| 239 | |||
| 240 | 1 | $config->expects($this->once()) |
|
| 241 | 1 | ->method('setUserValue') |
|
| 242 | 1 | ->with($this->equalTo('alice'), |
|
| 243 | 5 | $this->equalTo('files'), |
|
| 244 | 4 | $this->equalTo('quota'), |
|
| 245 | 1 | $this->equalTo('25 GB')) |
|
| 246 | 3 | ->will($this->returnValue(true)); |
|
| 247 | |||
| 248 | 1 | $uid = 'alice'; |
|
| 249 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 250 | |||
| 251 | 1 | $user = new User( |
|
| 252 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 253 | |||
| 254 | 1 | $user->updateQuota(); |
|
| 255 | 1 | } |
|
| 256 | |||
| 257 | 1 | View Code Duplication | public function testUpdateQuotaIndividualProvided() { |
| 258 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 259 | 1 | $this->getTestInstances(); |
|
| 260 | |||
| 261 | list($access, $connection) = |
||
| 262 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 263 | |||
| 264 | 1 | $connection->expects($this->at(0)) |
|
| 265 | 1 | ->method('__get') |
|
| 266 | 1 | ->with($this->equalTo('ldapQuotaDefault')) |
|
| 267 | 1 | ->will($this->returnValue('')); |
|
| 268 | |||
| 269 | 1 | $connection->expects($this->at(1)) |
|
| 270 | 1 | ->method('__get') |
|
| 271 | 1 | ->with($this->equalTo('ldapQuotaAttribute')) |
|
| 272 | 1 | ->will($this->returnValue('myquota')); |
|
| 273 | |||
| 274 | 1 | $connection->expects($this->exactly(2)) |
|
| 275 | 1 | ->method('__get'); |
|
| 276 | |||
| 277 | 1 | $access->expects($this->once()) |
|
| 278 | 1 | ->method('readAttribute') |
|
| 279 | 1 | ->with($this->equalTo('uid=alice,dc=foo,dc=bar'), |
|
| 280 | 1 | $this->equalTo('myquota')) |
|
| 281 | 1 | ->will($this->returnValue(array('27 GB'))); |
|
| 282 | |||
| 283 | 1 | $config->expects($this->once()) |
|
| 284 | 1 | ->method('setUserValue') |
|
| 285 | 1 | ->with($this->equalTo('alice'), |
|
| 286 | 1 | $this->equalTo('files'), |
|
| 287 | 1 | $this->equalTo('quota'), |
|
| 288 | 1 | $this->equalTo('27 GB')) |
|
| 289 | 1 | ->will($this->returnValue(true)); |
|
| 290 | |||
| 291 | 1 | $uid = 'alice'; |
|
| 292 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 293 | |||
| 294 | 1 | $user = new User( |
|
| 295 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 296 | |||
| 297 | 1 | $user->updateQuota(); |
|
| 298 | 1 | } |
|
| 299 | |||
| 300 | 1 | public function testUpdateQuotaNoneProvided() { |
|
| 301 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 302 | 1 | $this->getTestInstances(); |
|
| 303 | |||
| 304 | list($access, $connection) = |
||
| 305 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 306 | |||
| 307 | 1 | $connection->expects($this->at(0)) |
|
| 308 | 1 | ->method('__get') |
|
| 309 | 1 | ->with($this->equalTo('ldapQuotaDefault')) |
|
| 310 | 1 | ->will($this->returnValue('')); |
|
| 311 | |||
| 312 | 1 | $connection->expects($this->at(1)) |
|
| 313 | 1 | ->method('__get') |
|
| 314 | 1 | ->with($this->equalTo('ldapQuotaAttribute')) |
|
| 315 | 1 | ->will($this->returnValue('myquota')); |
|
| 316 | |||
| 317 | 1 | $connection->expects($this->exactly(2)) |
|
| 318 | 1 | ->method('__get'); |
|
| 319 | |||
| 320 | 1 | $access->expects($this->once()) |
|
| 321 | 1 | ->method('readAttribute') |
|
| 322 | 1 | ->with($this->equalTo('uid=alice,dc=foo,dc=bar'), |
|
| 323 | 1 | $this->equalTo('myquota')) |
|
| 324 | 1 | ->will($this->returnValue(false)); |
|
| 325 | |||
| 326 | 1 | $config->expects($this->never()) |
|
| 327 | 1 | ->method('setUserValue'); |
|
| 328 | |||
| 329 | 1 | $uid = 'alice'; |
|
| 330 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 331 | |||
| 332 | 1 | $user = new User( |
|
| 333 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 334 | |||
| 335 | 1 | $user->updateQuota(); |
|
| 336 | 1 | } |
|
| 337 | |||
| 338 | 1 | public function testUpdateQuotaNoneConfigured() { |
|
| 339 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 340 | 1 | $this->getTestInstances(); |
|
| 341 | |||
| 342 | list($access, $connection) = |
||
| 343 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 344 | |||
| 345 | 1 | $connection->expects($this->at(0)) |
|
| 346 | 1 | ->method('__get') |
|
| 347 | 1 | ->with($this->equalTo('ldapQuotaDefault')) |
|
| 348 | 1 | ->will($this->returnValue('')); |
|
| 349 | |||
| 350 | 1 | $connection->expects($this->at(1)) |
|
| 351 | 1 | ->method('__get') |
|
| 352 | 1 | ->with($this->equalTo('ldapQuotaAttribute')) |
|
| 353 | 1 | ->will($this->returnValue('')); |
|
| 354 | |||
| 355 | 1 | $connection->expects($this->exactly(2)) |
|
| 356 | 1 | ->method('__get'); |
|
| 357 | |||
| 358 | 1 | $access->expects($this->never()) |
|
| 359 | 1 | ->method('readAttribute'); |
|
| 360 | |||
| 361 | 1 | $config->expects($this->never()) |
|
| 362 | 1 | ->method('setUserValue'); |
|
| 363 | |||
| 364 | 1 | $uid = 'alice'; |
|
| 365 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 366 | |||
| 367 | 1 | $user = new User( |
|
| 368 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 369 | |||
| 370 | 1 | $user->updateQuota(); |
|
| 371 | 1 | } |
|
| 372 | |||
| 373 | 1 | public function testUpdateQuotaFromValue() { |
|
| 374 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 375 | 1 | $this->getTestInstances(); |
|
| 376 | |||
| 377 | list($access, $connection) = |
||
| 378 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 379 | |||
| 380 | 1 | $readQuota = '19 GB'; |
|
| 381 | |||
| 382 | 1 | $connection->expects($this->at(0)) |
|
| 383 | 1 | ->method('__get') |
|
| 384 | 1 | ->with($this->equalTo('ldapQuotaDefault')) |
|
| 385 | 1 | ->will($this->returnValue('')); |
|
| 386 | |||
| 387 | 1 | $connection->expects($this->once(1)) |
|
| 388 | 1 | ->method('__get') |
|
| 389 | 1 | ->with($this->equalTo('ldapQuotaDefault')) |
|
| 390 | 1 | ->will($this->returnValue(null)); |
|
| 391 | |||
| 392 | 1 | $access->expects($this->never()) |
|
| 393 | 1 | ->method('readAttribute'); |
|
| 394 | |||
| 395 | 1 | $config->expects($this->once()) |
|
| 396 | 1 | ->method('setUserValue') |
|
| 397 | 1 | ->with($this->equalTo('alice'), |
|
| 398 | 1 | $this->equalTo('files'), |
|
| 399 | 1 | $this->equalTo('quota'), |
|
| 400 | 1 | $this->equalTo($readQuota)) |
|
| 401 | 1 | ->will($this->returnValue(true)); |
|
| 402 | |||
| 403 | 1 | $uid = 'alice'; |
|
| 404 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 405 | |||
| 406 | 1 | $user = new User( |
|
| 407 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 408 | |||
| 409 | 1 | $user->updateQuota($readQuota); |
|
| 410 | 1 | } |
|
| 411 | |||
| 412 | //the testUpdateAvatar series also implicitely tests getAvatarImage |
||
| 413 | 7 | public function testUpdateAvatarJpegPhotoProvided() { |
|
| 461 | |||
| 462 | 1 | public function testUpdateAvatarThumbnailPhotoProvided() { |
|
| 463 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 464 | 1 | $this->getTestInstances(); |
|
| 465 | |||
| 466 | list($access, $connection) = |
||
| 467 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 468 | |||
| 469 | 1 | $access->expects($this->at(0)) |
|
| 470 | 1 | ->method('readAttribute') |
|
| 471 | 1 | ->with($this->equalTo('uid=alice,dc=foo,dc=bar'), |
|
| 472 | 1 | $this->equalTo('jpegPhoto')) |
|
| 473 | 1 | ->will($this->returnValue(false)); |
|
| 474 | |||
| 475 | 1 | $access->expects($this->at(1)) |
|
| 476 | 1 | ->method('readAttribute') |
|
| 477 | 1 | ->with($this->equalTo('uid=alice,dc=foo,dc=bar'), |
|
| 478 | 1 | $this->equalTo('thumbnailPhoto')) |
|
| 479 | 1 | ->will($this->returnValue(array('this is a photo'))); |
|
| 480 | |||
| 481 | 1 | $access->expects($this->exactly(2)) |
|
| 482 | 1 | ->method('readAttribute'); |
|
| 483 | |||
| 484 | 1 | $image->expects($this->once()) |
|
| 485 | 1 | ->method('valid') |
|
| 486 | 1 | ->will($this->returnValue(true)); |
|
| 487 | 1 | $image->expects($this->once()) |
|
| 488 | 1 | ->method('width') |
|
| 489 | 1 | ->will($this->returnValue(128)); |
|
| 490 | 1 | $image->expects($this->once()) |
|
| 491 | 1 | ->method('height') |
|
| 492 | 1 | ->will($this->returnValue(128)); |
|
| 493 | 1 | $image->expects($this->once()) |
|
| 494 | 1 | ->method('centerCrop') |
|
| 495 | 1 | ->will($this->returnValue(true)); |
|
| 496 | |||
| 497 | 1 | $filesys->expects($this->once()) |
|
| 498 | 1 | ->method('isLoaded') |
|
| 499 | 1 | ->will($this->returnValue(true)); |
|
| 500 | |||
| 501 | 1 | $avatar = $this->getMock('\OCP\IAvatar'); |
|
| 502 | 1 | $avatar->expects($this->once()) |
|
| 503 | 1 | ->method('set') |
|
| 504 | 1 | ->with($this->isInstanceOf($image)); |
|
| 505 | |||
| 506 | 1 | $avaMgr->expects($this->once()) |
|
| 507 | 1 | ->method('getAvatar') |
|
| 508 | 1 | ->with($this->equalTo('alice')) |
|
| 509 | 1 | ->will($this->returnValue($avatar)); |
|
| 510 | |||
| 511 | 1 | $uid = 'alice'; |
|
| 512 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 513 | |||
| 514 | 1 | $user = new User( |
|
| 515 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 516 | |||
| 517 | 1 | $user->updateAvatar(); |
|
| 518 | 1 | } |
|
| 519 | |||
| 520 | 1 | public function testUpdateAvatarNotProvided() { |
|
| 521 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 522 | 1 | $this->getTestInstances(); |
|
| 523 | |||
| 524 | list($access, $connection) = |
||
| 525 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 526 | |||
| 527 | 1 | $access->expects($this->at(0)) |
|
| 528 | 1 | ->method('readAttribute') |
|
| 529 | 1 | ->with($this->equalTo('uid=alice,dc=foo,dc=bar'), |
|
| 530 | 1 | $this->equalTo('jpegPhoto')) |
|
| 531 | 1 | ->will($this->returnValue(false)); |
|
| 532 | |||
| 533 | 1 | $access->expects($this->at(1)) |
|
| 534 | 1 | ->method('readAttribute') |
|
| 535 | 1 | ->with($this->equalTo('uid=alice,dc=foo,dc=bar'), |
|
| 536 | 1 | $this->equalTo('thumbnailPhoto')) |
|
| 537 | 1 | ->will($this->returnValue(false)); |
|
| 538 | |||
| 539 | 1 | $access->expects($this->exactly(2)) |
|
| 540 | 1 | ->method('readAttribute'); |
|
| 541 | |||
| 542 | 1 | $image->expects($this->never()) |
|
| 543 | 1 | ->method('valid'); |
|
| 544 | 1 | $image->expects($this->never()) |
|
| 545 | 1 | ->method('width'); |
|
| 546 | 1 | $image->expects($this->never()) |
|
| 547 | 1 | ->method('height'); |
|
| 548 | 1 | $image->expects($this->never()) |
|
| 549 | 1 | ->method('centerCrop'); |
|
| 550 | |||
| 551 | 1 | $filesys->expects($this->never()) |
|
| 552 | 1 | ->method('isLoaded'); |
|
| 553 | |||
| 554 | 1 | $avaMgr->expects($this->never()) |
|
| 555 | 1 | ->method('getAvatar'); |
|
| 556 | |||
| 557 | 1 | $uid = 'alice'; |
|
| 558 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 559 | |||
| 560 | 1 | $user = new User( |
|
| 561 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 562 | |||
| 563 | 1 | $user->updateAvatar(); |
|
| 564 | 1 | } |
|
| 565 | |||
| 566 | 1 | View Code Duplication | public function testUpdateBeforeFirstLogin() { |
| 567 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 568 | 1 | $this->getTestInstances(); |
|
| 569 | |||
| 570 | list($access, $connection) = |
||
| 571 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 572 | |||
| 573 | 1 | $config->expects($this->at(0)) |
|
| 574 | 1 | ->method('getUserValue') |
|
| 575 | 1 | ->with($this->equalTo('alice'), $this->equalTo('user_ldap'), |
|
| 576 | 1 | $this->equalTo(User::USER_PREFKEY_FIRSTLOGIN), |
|
| 577 | 1 | $this->equalTo(0)) |
|
| 578 | 1 | ->will($this->returnValue(0)); |
|
| 579 | |||
| 580 | 1 | $config->expects($this->at(1)) |
|
| 581 | 1 | ->method('getUserValue') |
|
| 582 | 1 | ->with($this->equalTo('alice'), $this->equalTo('user_ldap'), |
|
| 583 | 1 | $this->equalTo(User::USER_PREFKEY_LASTREFRESH), |
|
| 584 | 1 | $this->equalTo(0)) |
|
| 585 | 1 | ->will($this->returnValue(0)); |
|
| 586 | |||
| 587 | 1 | $config->expects($this->exactly(2)) |
|
| 588 | 1 | ->method('getUserValue'); |
|
| 589 | |||
| 590 | 1 | $config->expects($this->never()) |
|
| 591 | 1 | ->method('setUserValue'); |
|
| 592 | |||
| 593 | 1 | $uid = 'alice'; |
|
| 594 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 595 | |||
| 596 | 1 | $user = new User( |
|
| 597 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 598 | |||
| 599 | 1 | $user->update(); |
|
| 600 | 1 | } |
|
| 601 | |||
| 602 | 1 | public function testUpdateAfterFirstLogin() { |
|
| 603 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 604 | 1 | $this->getTestInstances(); |
|
| 605 | |||
| 606 | list($access, $connection) = |
||
| 607 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 608 | |||
| 609 | 1 | $config->expects($this->at(0)) |
|
| 610 | 1 | ->method('getUserValue') |
|
| 611 | 1 | ->with($this->equalTo('alice'), $this->equalTo('user_ldap'), |
|
| 612 | 1 | $this->equalTo(User::USER_PREFKEY_FIRSTLOGIN), |
|
| 613 | 1 | $this->equalTo(0)) |
|
| 614 | 1 | ->will($this->returnValue(1)); |
|
| 615 | |||
| 616 | 1 | $config->expects($this->at(1)) |
|
| 617 | 1 | ->method('getUserValue') |
|
| 618 | 1 | ->with($this->equalTo('alice'), $this->equalTo('user_ldap'), |
|
| 619 | 1 | $this->equalTo(User::USER_PREFKEY_LASTREFRESH), |
|
| 620 | 1 | $this->equalTo(0)) |
|
| 621 | 1 | ->will($this->returnValue(0)); |
|
| 622 | |||
| 623 | 1 | $config->expects($this->exactly(2)) |
|
| 624 | 1 | ->method('getUserValue'); |
|
| 625 | |||
| 626 | 1 | $config->expects($this->once()) |
|
| 627 | 1 | ->method('setUserValue') |
|
| 628 | 1 | ->with($this->equalTo('alice'), $this->equalTo('user_ldap'), |
|
| 629 | 1 | $this->equalTo(User::USER_PREFKEY_LASTREFRESH), |
|
| 630 | 1 | $this->anything()) |
|
| 631 | 1 | ->will($this->returnValue(true)); |
|
| 632 | |||
| 633 | 1 | $uid = 'alice'; |
|
| 634 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 635 | |||
| 636 | 1 | $user = new User( |
|
| 637 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 638 | |||
| 639 | 1 | $user->update(); |
|
| 640 | 1 | } |
|
| 641 | |||
| 642 | 1 | View Code Duplication | public function testUpdateNoRefresh() { |
| 643 | list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 644 | 1 | $this->getTestInstances(); |
|
| 645 | |||
| 646 | list($access, $connection) = |
||
| 647 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 648 | |||
| 649 | 1 | $config->expects($this->at(0)) |
|
| 650 | 1 | ->method('getUserValue') |
|
| 651 | 1 | ->with($this->equalTo('alice'), $this->equalTo('user_ldap'), |
|
| 652 | 1 | $this->equalTo(User::USER_PREFKEY_FIRSTLOGIN), |
|
| 653 | 1 | $this->equalTo(0)) |
|
| 654 | 1 | ->will($this->returnValue(1)); |
|
| 655 | |||
| 656 | 1 | $config->expects($this->at(1)) |
|
| 657 | 1 | ->method('getUserValue') |
|
| 658 | 1 | ->with($this->equalTo('alice'), $this->equalTo('user_ldap'), |
|
| 659 | 1 | $this->equalTo(User::USER_PREFKEY_LASTREFRESH), |
|
| 660 | 1 | $this->equalTo(0)) |
|
| 661 | 1 | ->will($this->returnValue(time())); |
|
| 662 | |||
| 663 | 1 | $config->expects($this->exactly(2)) |
|
| 664 | 1 | ->method('getUserValue'); |
|
| 665 | |||
| 666 | 1 | $config->expects($this->never()) |
|
| 667 | 1 | ->method('setUserValue'); |
|
| 668 | |||
| 669 | 1 | $uid = 'alice'; |
|
| 670 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 671 | |||
| 672 | 1 | $user = new User( |
|
| 673 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 674 | |||
| 675 | 1 | $user->update(); |
|
| 676 | 1 | } |
|
| 677 | |||
| 678 | 1 | public function testMarkLogin() { |
|
| 679 | list($access, $config, $filesys, $image, $log, $avaMgr) = |
||
| 680 | 1 | $this->getTestInstances(); |
|
| 681 | |||
| 682 | 1 | $config->expects($this->once()) |
|
| 683 | 1 | ->method('setUserValue') |
|
| 684 | 1 | ->with($this->equalTo('alice'), |
|
| 685 | 1 | $this->equalTo('user_ldap'), |
|
| 686 | 1 | $this->equalTo(User::USER_PREFKEY_FIRSTLOGIN), |
|
| 687 | 1 | $this->equalTo(1)) |
|
| 688 | 1 | ->will($this->returnValue(true)); |
|
| 689 | |||
| 690 | 1 | $uid = 'alice'; |
|
| 691 | 1 | $dn = 'uid=alice,dc=foo,dc=bar'; |
|
| 692 | |||
| 693 | 1 | $user = new User( |
|
| 694 | 1 | $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr); |
|
| 695 | |||
| 696 | 1 | $user->markLogin(); |
|
| 697 | 1 | } |
|
| 698 | |||
| 699 | 1 | public function testGetAvatarImageProvided() { |
|
| 721 | |||
| 722 | 1 | public function testProcessAttributes() { |
|
| 723 | list(, $config, $filesys, $image, $log, $avaMgr, $dbc) = |
||
| 724 | 1 | $this->getTestInstances(); |
|
| 725 | |||
| 726 | list($access, $connection) = |
||
| 727 | 1 | $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc); |
|
| 728 | |||
| 729 | 1 | $uid = 'alice'; |
|
| 730 | 1 | $dn = 'uid=alice'; |
|
| 731 | |||
| 732 | $requiredMethods = array( |
||
| 733 | 1 | 'markRefreshTime', |
|
| 734 | 1 | 'updateQuota', |
|
| 735 | 1 | 'updateEmail', |
|
| 736 | 1 | 'composeAndStoreDisplayName', |
|
| 737 | 1 | 'storeLDAPUserName', |
|
| 738 | 1 | 'getHomePath', |
|
| 778 | |||
| 779 | public function emptyHomeFolderAttributeValueProvider() { |
||
| 785 | |||
| 786 | /** |
||
| 787 | * @dataProvider emptyHomeFolderAttributeValueProvider |
||
| 788 | */ |
||
| 789 | 2 | public function testGetHomePathNotConfigured($attributeValue) { |
|
| 816 | |||
| 817 | 1 | View Code Duplication | public function testGetHomePathConfiguredNotAvailableAllowed() { |
| 848 | |||
| 849 | /** |
||
| 850 | * @expectedException \Exception |
||
| 851 | */ |
||
| 852 | 1 | View Code Duplication | public function testGetHomePathConfiguredNotAvailableNotAllowed() { |
| 881 | |||
| 882 | View Code Duplication | public function displayNameProvider() { |
|
| 889 | |||
| 890 | /** |
||
| 891 | * @dataProvider displayNameProvider |
||
| 892 | */ |
||
| 893 | 3 | View Code Duplication | public function testComposeAndStoreDisplayName($part1, $part2, $expected) { |
| 906 | } |
||
| 907 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.