Projet

Général

Profil

Révision 32700c57

Ajouté par Assos Assos il y a environ 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ldap/ldap_user/tests/ldap_user.test
1 1
<?php
2 2

  
3

  
4

  
5 3
/**
6 4
 * @file
7
 * see getInfo() for test summary
8
 *
9
 *  @todo test for ldapUserConf->setSynchMapping()
10
 *  @todo test for ldapUserConf->ldapAssociateDrupalAccount($drupal_username)
5
 * See getInfo() for test summary.
11 6
 *
7
 * @todo test for ldapUserConf->setSynchMapping()
8
 * @todo test for ldapUserConf->ldapAssociateDrupalAccount($drupal_username)
12 9
 */
13 10

  
14 11
module_load_include('php', 'ldap_test', 'LdapTestCase.class');
15

  
12
/**
13
 *
14
 */
16 15
class LdapUserUnitTests extends LdapTestCase {
16

  
17
  /**
18
   *
19
   */
17 20
  public static function getInfo() {
18
    return array(
21
    return [
19 22
      'name' => 'LDAP User Unit Tests',
20 23
      'description' => 'Test functions outside of real contexts.',
21
      'group' => 'LDAP User'
22
    );
24
      'group' => 'LDAP User',
25
    ];
23 26
  }
24 27

  
25
  function __construct($test_id = NULL) {
28
  /**
29
   *
30
   */
31
  public function __construct($test_id = NULL) {
26 32
    parent::__construct($test_id);
27 33
  }
28 34

  
......
30 36
  protected $ldap_test_data;
31 37

  
32 38
  /**
33
   *  create one or more server configurations in such as way
34
   *  that this setUp can be a prerequisite for ldap_authentication and ldap_authorization
39
   * Create one or more server configurations in such as way
40
   *  that this setUp can be a prerequisite for ldap_authentication and ldap_authorization.
35 41
   */
36

  
37
  function setUp() {
38
    parent::setUp(array('ldap_servers', 'ldap_user', 'ldap_authentication', 'ldap_test'));
42
  public function setUp() {
43
    parent::setUp(['ldap_servers', 'ldap_user', 'ldap_authentication', 'ldap_test']);
39 44
    variable_set('ldap_simpletest', 2);
40 45
  }
41 46

  
42
  function tearDown() {
47
  /**
48
   *
49
   */
50
  public function tearDown() {
43 51
    parent::tearDown();
44 52
    variable_del('ldap_help_watchdog_detail');
45 53
    variable_del('ldap_simpletest');
46 54
  }
47 55

  
48 56
  /**
49
   * make sure install succeeds and ldap user functions/methods work
57
   * Make sure install succeeds and ldap user functions/methods work.
50 58
   */
51
  function testUnitTests() {
59
  public function testUnitTests() {
52 60
    // TODO: Fix failing tests, excluding to make branch pass.
53 61
    return;
54 62

  
55
    // just to give warning if setup doesn't succeed.
63
    // Just to give warning if setup doesn't succeed.
56 64
    $setup_success = (
57 65
        module_exists('ldap_user') &&
58 66
        module_exists('ldap_servers') &&
......
60 68
      );
61 69
    $this->assertTrue($setup_success, ' ldap_user setup successful', $this->testId('setup'));
62 70

  
63
    $api_functions = array(
64
      'ldap_user_conf' => array(2, 0),
65
      'ldap_user_synch_to_drupal' => array(3, 1),
66
      'ldap_user_provision_to_drupal' => array(2, 1),
67
      'ldap_user_ldap_provision_semaphore' => array(4, 2),
68
      'ldap_user_token_replace' => array(3, 2),
69
      'ldap_user_token_tokenize_entry' => array(5, 2)
70
    );
71
    $api_functions = [
72
      'ldap_user_conf' => [2, 0],
73
      'ldap_user_synch_to_drupal' => [3, 1],
74
      'ldap_user_provision_to_drupal' => [2, 1],
75
      'ldap_user_ldap_provision_semaphore' => [4, 2],
76
      'ldap_user_token_replace' => [3, 2],
77
      'ldap_user_token_tokenize_entry' => [5, 2],
78
    ];
71 79

  
72 80
    foreach ($api_functions as $api_function_name => $param_count) {
73 81
      $reflector = new ReflectionFunction($api_function_name);
74 82
      $this->assertTrue(
75 83
        function_exists($api_function_name) &&
76 84
        $param_count[1] == $reflector->getNumberOfRequiredParameters() &&
77
        $param_count[0] == $reflector->getNumberOfParameters()
78
        , ' api function ' . $api_function_name . ' parameters and required parameters count unchanged.', $this->testId($api_function_name . ' unchanged'));
85
        $param_count[0] == $reflector->getNumberOfParameters(),
86
         ' api function ' . $api_function_name . ' parameters and required parameters count unchanged.', $this->testId($api_function_name . ' unchanged'));
79 87
    }
80 88

  
81 89
    $this->assertTrue(drupal_cron_run(), t('Cron can run with ldap user enabled.'), $this->testId('cron works'));
82 90

  
83
    // test user token functions
91
    // Test user token functions.
84 92
    $entity = new stdClass();
85 93
    $entity->lname[LANGUAGE_NONE][0]['value'] = 'potter';
86 94
    $entity->house[LANGUAGE_NONE][0]['value'] = 'Gryffindor';
......
93 101
    $this->assertTrue($lname == $entity->lname[LANGUAGE_NONE][0]['value'], t('[field.lname] token worked on ldap_user_token_replace().'), $this->testId('tokens.property.field'));
94 102
    $house1 = ldap_user_token_replace('[field.house:1]', $account, $entity);
95 103
    $this->assertTrue($house1 == $entity->house[LANGUAGE_NONE][1]['value'], t('[field.house:1] token worked on ldap_user_token_replace().'), $this->testId('tokens.property.field.ordinal'));
96
    //@todo need tests for :last and a multivalued attribute.  see http://drupal.org/node/1245736
97

  
104
    // @todo need tests for :last and a multivalued attribute.  see http://drupal.org/node/1245736
98 105

  
99
    $sids = array('activedirectory1');
100
    $this->prepTestData('hogwarts', $sids, 'default'); // prepTestData($sids, 'provisionToDrupal', 'default');
106
    $sids = ['activedirectory1'];
107
    $this->prepTestData('hogwarts', $sids, 'default');
101 108
    $ldap_server = ldap_servers_get_servers('activedirectory1', NULL, TRUE, TRUE);
102 109
    $ldap_user_conf = ldap_user_conf('admin', TRUE);
103 110

  
104 111
    $this->assertTrue(is_object($ldap_user_conf), t('ldap_conf class instantiated'), $this->testId('construct ldapUserConf object'));
105 112

  
106
    $user_edit = array();
113
    $user_edit = [];
107 114
    $ldap_user = ldap_servers_get_user_ldap_data('hpotter', $ldap_user_conf->drupalAcctProvisionServer, 'ldap_user_prov_to_drupal');
108 115

  
109
    $desired_result = array(
116
    $desired_result = [
110 117
      'dn' => 'cn=hpotter,ou=people,dc=hogwarts,dc=edu',
111 118
      'mail' => 'hpotter@hogwarts.edu',
112 119
      'attr' => $ldap_server->entries['cn=hpotter,ou=people,dc=hogwarts,dc=edu'],
113 120
      'sid' => 'activedirectory1',
114
    );
121
    ];
115 122

  
116 123
    if (is_array($ldap_user)) {
117 124
      $array_diff = array_diff($ldap_user, $desired_result);
......
124 131
    $ldap_user_conf->entryToUserEdit($ldap_user, $user_edit, $ldap_todrupal_prov_server);
125 132

  
126 133
    unset($user_edit['pass']);
127
    $desired_result = array(
128
        'mail' => 'hpotter@hogwarts.edu',
129
        'name' => 'hpotter',
130
        'init' => 'hpotter@hogwarts.edu',
131
        'status' => 1,
132
        'signature' => '',
133
        'data' =>
134
        array(
134
    $desired_result = [
135
      'mail' => 'hpotter@hogwarts.edu',
136
      'name' => 'hpotter',
137
      'init' => 'hpotter@hogwarts.edu',
138
      'status' => 1,
139
      'signature' => '',
140
      'data' =>
141
        [
135 142
          'ldap_authentication' =>
136
          array(
143
          [
137 144
            'init' =>
138
            array(
145
            [
139 146
              'sid' => 'activedirectory1',
140 147
              'dn' => 'cn=hpotter,ou=people,dc=hogwarts,dc=edu',
141 148
              'mail' => 'hpotter@hogwarts.edu',
142
            ),
143
          ),
144
        ),
145
        'ldap_user_puid' =>
146
        array(
149
            ],
150
          ],
151
        ],
152
      'ldap_user_puid' =>
153
        [
147 154
          LANGUAGE_NONE =>
148
          array(
155
          [
149 156
            0 =>
150
            array(
157
            [
151 158
              'value' => '101',
152
            ),
153
          ),
154
        ),
155
        'ldap_user_puid_property' =>
156
        array(
159
            ],
160
          ],
161
        ],
162
      'ldap_user_puid_property' =>
163
        [
157 164
          LANGUAGE_NONE =>
158
          array(
165
          [
159 166
            0 =>
160
            array(
167
            [
161 168
              'value' => 'guid',
162
            ),
163
          ),
164
        ),
165
        'ldap_user_puid_sid' =>
166
        array(
169
            ],
170
          ],
171
        ],
172
      'ldap_user_puid_sid' =>
173
        [
167 174
          LANGUAGE_NONE =>
168
          array(
175
          [
169 176
            0 =>
170
            array(
177
            [
171 178
              'value' => 'activedirectory1',
172
            ),
173
          ),
174
        ),
175
        'ldap_user_current_dn' =>
176
        array(
179
            ],
180
          ],
181
        ],
182
      'ldap_user_current_dn' =>
183
        [
177 184
          LANGUAGE_NONE =>
178
          array(
185
          [
179 186
            0 =>
180
            array(
187
            [
181 188
              'value' => 'cn=hpotter,ou=people,dc=hogwarts,dc=edu',
182
            ),
183
          ),
184
        ),
185
      );
189
            ],
190
          ],
191
        ],
192
    ];
186 193
    // @FIXME: Wrapper for failing test.
187
    if(is_array($user_edit)) {
194
    if (is_array($user_edit)) {
188 195
      $array_diff = array_diff($user_edit, $desired_result);
189 196
    }
190
    //@todo need better diff, this will give false positives in most cases
197
    // @todo need better diff, this will give false positives in most cases
191 198
    $this->assertTrue(count($array_diff) == 0, t('ldapUserConf::entryToUserEdit retrieved correct property, field, and data values.'), $this->testId('ldapUserConf::entryToUserEdit'));
192 199
    if (count($array_diff) != 0) {
193 200
      debug('ldapUserConf::entryToUserEdit failed.  resulting user edit array:'); debug($user_edit); debug('desired result:'); debug($desired_result); debug('array_diff:'); debug($array_diff);
194 201
    }
195 202

  
196
    $is_synched_tests = array(
197
      LDAP_USER_EVENT_CREATE_DRUPAL_USER => array(
198
        0 => array('[property.fake]', '[property.data]', '[property.uid]'),
199
        1 => array('[property.mail]', '[property.name]', '[field.ldap_user_puid]', '[field.ldap_user_puid_property]', '[field.ldap_user_puid_sid]', '[field.ldap_user_current_dn]'),
200
      ),
201
      LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER => array(
202
        0 => array('[property.fake]', '[property.data]', '[property.uid]', '[field.ldap_user_puid]', '[field.ldap_user_puid_property]', '[field.ldap_user_puid_sid]'),
203
        1 => array('[property.mail]', '[property.name]', '[field.ldap_user_current_dn]'),
204
      ),
205
    );
206

  
207
    $debug = array();
203
    $is_synched_tests = [
204
      LDAP_USER_EVENT_CREATE_DRUPAL_USER => [
205
        0 => ['[property.fake]', '[property.data]', '[property.uid]'],
206
        1 => ['[property.mail]', '[property.name]', '[field.ldap_user_puid]', '[field.ldap_user_puid_property]', '[field.ldap_user_puid_sid]', '[field.ldap_user_current_dn]'],
207
      ],
208
      LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER => [
209
        0 => ['[property.fake]', '[property.data]', '[property.uid]', '[field.ldap_user_puid]', '[field.ldap_user_puid_property]', '[field.ldap_user_puid_sid]'],
210
        1 => ['[property.mail]', '[property.name]', '[field.ldap_user_current_dn]'],
211
      ],
212
    ];
213

  
214
    $debug = [];
208 215
    $fail = FALSE;
209 216
    foreach ($is_synched_tests as $prov_event => $tests) {
210 217
      foreach ($tests as $boolean_result => $attribute_tokens) {
211 218
        foreach ($attribute_tokens as $attribute_token) {
212
          $is_synched = $ldap_user_conf->isSynched($attribute_token, array($prov_event), LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER);
213
          if ((int)$is_synched !== (int)$boolean_result) {
219
          $is_synched = $ldap_user_conf->isSynched($attribute_token, [$prov_event], LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER);
220
          if ((int) $is_synched !== (int) $boolean_result) {
214 221
            $fail = TRUE;
215 222
            $debug[$attribute_token] = "isSynched($attribute_token, array($prov_event),
216
              LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) returned $is_synched when it should have returned ". (int)$boolean_result;
223
              LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) returned $is_synched when it should have returned " . (int) $boolean_result;
217 224
          }
218 225
        }
219 226
      }
......
229 236

  
230 237
    $ldap_user_required_attributes = $ldap_user_conf->getLdapUserRequiredAttributes(LDAP_USER_PROV_DIRECTION_ALL);
231 238

  
232
    $provision_enabled_truth = (boolean)(
239
    $provision_enabled_truth = (boolean) (
233 240
      $ldap_user_conf->provisionEnabled(LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_DRUPAL_USER_PROV_ON_USER_UPDATE_CREATE)
234 241
      && $ldap_user_conf->provisionEnabled(LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_DRUPAL_USER_PROV_ON_AUTHENTICATE)
235 242
      && !$ldap_user_conf->provisionEnabled(LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY, LDAP_USER_LDAP_ENTRY_PROV_ON_USER_UPDATE_CREATE)
......
242 249
    $ldap_user_conf->provisionEnabled(LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_LDAP_ENTRY_PROV_ON_USER_UPDATE_CREATE));
243 250
    $this->assertFalse($provision_enabled_false, t('provisionEnabled works'), $this->testId('provisionEnabled.2'));
244 251

  
245

  
246 252
    $account = new stdClass();
247 253
    $account->name = 'hpotter';
248
    $params = array('ldap_context' => 'ldap_user_prov_to_drupal', 'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER);
254
    $params = ['ldap_context' => 'ldap_user_prov_to_drupal', 'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER];
249 255
    list($ldap_entry, $error) = $ldap_user_conf->drupalUserToLdapEntry($account, 'activedirectory1', $params);
250 256

  
251 257
    $account = NULL;
252
    $user_edit = array('name' => 'hpotter');
253

  
254
    // test method provisionDrupalAccount()
258
    $user_edit = ['name' => 'hpotter'];
255 259

  
260
    // Test method provisionDrupalAccount()
256 261
    $hpotter = $ldap_user_conf->provisionDrupalAccount($account, $user_edit, NULL, TRUE);
257 262

  
258 263
    $hpotter = user_load_by_name('hpotter');
......
281 286
    if (is_array($hpotter->data['ldap_user'])) {
282 287
      $data_diff = array_diff(
283 288
        $hpotter->data['ldap_user'],
284
        array(
289
        [
285 290
          'init' =>
286
            array(
291
            [
287 292
              'sid' => 'activedirectory1',
288 293
              'dn' => NULL,
289 294
              'mail' => 'hpotter@hogwarts.edu',
290
            ),
291
        )
295
            ],
296
        ]
292 297
      );
293 298
      $this->assertTrue(count($data_diff) == 0, t('user->data array correctly populated for hpotter'), $this->testId());
294 299
    }
295
    // test account exists with correct username, mail, fname, puid, puidfield, dn
296

  
297
    // change some user mock ldap data first, (mail and fname) then synch
300
    // Test account exists with correct username, mail, fname, puid, puidfield, dn
301
    // Change some user mock ldap data first, (mail and fname) then synch.
298 302
    $account = user_load_by_name('hpotter');
299 303

  
300 304
    $user_edit = NULL;
301
    $ldap_user_conf->ldapUserSynchMappings = array();
305
    $ldap_user_conf->ldapUserSynchMappings = [];
302 306
    $sid = 'activedirectory1';
303
    $ldap_user_conf->ldapUserSynchMappings[LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER]['[property.mail]'] = array(
307
    $ldap_user_conf->ldapUserSynchMappings[LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER]['[property.mail]'] = [
304 308
      'sid' => $sid,
305 309
      'ldap_attr' => '[mail]',
306 310
      'user_attr' => '[property.mail]',
307 311
      'convert' => 0,
308 312
      'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
309
      'ldap_contexts' => array('ldap_user_insert_drupal_user', 'ldap_user_update_drupal_user', 'ldap_authentication_authenticate'),
310
      'prov_events' => array(LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER),
313
      'ldap_contexts' => ['ldap_user_insert_drupal_user', 'ldap_user_update_drupal_user', 'ldap_authentication_authenticate'],
314
      'prov_events' => [LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER],
311 315
      'name' => 'Property: Mail',
312 316
      'enabled' => TRUE,
313 317
      'config_module' => 'ldap_servers',
314 318
      'prov_module' => 'ldap_user',
315 319
      'user_tokens' => '',
316
      );
320
    ];
317 321
    $ldap_user_conf->save();
318 322

  
319 323
    $this->testFunctions->setFakeServerUserAttribute($sid, 'cn=hpotter,ou=people,dc=hogwarts,dc=edu', 'mail', 'hpotter@owlcarriers.com', 0);
320
    $ldap_server = ldap_servers_get_servers('activedirectory1', NULL, TRUE, TRUE); // clear server cache;
324
    // Clear server cache.
325
    $ldap_server = ldap_servers_get_servers('activedirectory1', NULL, TRUE, TRUE);
321 326
    $user = $ldap_user_conf->synchToDrupalAccount($account, $user_edit, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER, NULL, TRUE);
322 327

  
323 328
    $hpotter = user_load_by_name('hpotter');
......
340 345

  
341 346
    $this->testFunctions->setFakeServerUserAttribute('activedirectory1', 'cn=hpotter,ou=people,dc=hogwarts,dc=edu', 'samaccountname', 'hpotter-granger', 0);
342 347
    $account = NULL;
343
    $user_edit = array('name' => 'hpotter-granger');
348
    $user_edit = ['name' => 'hpotter-granger'];
344 349
    $hpottergranger = $ldap_user_conf->provisionDrupalAccount($account, $user_edit, NULL, TRUE);
345 350

  
346 351
    $this->testFunctions->setFakeServerUserAttribute('activedirectory1', 'cn=hpotter,ou=people,dc=hogwarts,dc=edu', 'samaccountname', 'hpotter', 0);
......
356 361
    $pass = is_object($hpottergranger) && $hpottergranger->name == 'hpotter-granger';
357 362
    $this->assertTrue($pass, t('provisionDrupalAccount recognized PUID conflict and fixed username.'), $this->testId());
358 363

  
359
    $user_edit = array('name' => 'hpotter');
364
    $user_edit = ['name' => 'hpotter'];
360 365
    $hpotter = user_save($hpottergranger, $user_edit, 'ldap_user');
361 366

  
362

  
363
    // delete and recreate test account to make sure account is in correct state
367
    // Delete and recreate test account to make sure account is in correct state.
364 368
    $ldap_user_conf->deleteDrupalAccount('hpotter');
365 369
    $this->assertFalse(user_load($hpotter_uid, TRUE), t('deleteDrupalAccount deleted hpotter successfully'), $this->testId());
366 370

  
367 371
    $ldap_server = ldap_servers_get_servers('activedirectory1', 'enabled', TRUE, TRUE);
368 372
    $ldap_server->refreshFakeData();
369 373
    $account = NULL;
370
    $user_edit = array('name' => 'hpotter');
374
    $user_edit = ['name' => 'hpotter'];
371 375
    $hpotter = $ldap_user_conf->provisionDrupalAccount($account, $user_edit, NULL, TRUE);
372 376

  
373 377
  }
374 378

  
375
  function testProvisionToDrupal() {
379
  /**
380
   *
381
   */
382
  public function testProvisionToDrupal() {
376 383
    // TODO: Fix failing tests, excluding to make branch pass.
377 384
    return;
378
      /**
385
    /**
379 386
     * test that $ldap_user_conf->synchToDrupalAccount() works for various contexts.
380 387
     * make sure changing when a given field/property is flagged for a particular context, everything works
381 388
     * tests one property (property.mail) and one field (field.field_lname) as well as username, puid
382 389
     */
383 390

  
384
      // just to give warning if setup doesn't succeed.  may want to take these out at some point.
391
    // Just to give warning if setup doesn't succeed.  may want to take these out at some point.
385 392
    $setup_success = (
386 393
        module_exists('ldap_user') &&
387 394
        module_exists('ldap_servers') &&
......
389 396
      );
390 397
    $this->assertTrue($setup_success, ' ldap_user setup successful', $this->testId("setup"));
391 398

  
392

  
393 399
    $sid = 'activedirectory1';
394
    $sids = array($sid);
400
    $sids = [$sid];
395 401
    $this->prepTestData('hogwarts', $sids, 'provisionToDrupal', 'default');
396
    $tests = array();
402
    $tests = [];
397 403

  
398
    $tests[] = array(
404
    $tests[] = [
399 405
      'disabled' => 0,
400 406
      'user' => 'hpotter',
401 407
      'field_name' => 'field_lname',
402
      'field_values' => array(array('sn' => 'Potter'), array('sn' => 'Pottery-Chard')),
403
      'field_results' => array('Potter', 'Pottery-Chard'), // first value is what is desired on synch, second if no sycn
404
      'mapping' => array(
408
      'field_values' => [['sn' => 'Potter'], ['sn' => 'Pottery-Chard']],
409
    // First value is what is desired on synch, second if no sycn.
410
      'field_results' => ['Potter', 'Pottery-Chard'],
411
      'mapping' => [
405 412
        'sid' => $sid,
406 413
        'name' => 'Field: Last Name',
407 414
        'ldap_attr' => '[SN]',
408 415
        'user_attr' => '[field.field_lname]',
409 416
        'convert' => 0,
410 417
        'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
411
        'prov_events' => array(LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER),
418
        'prov_events' => [LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER],
412 419
        'user_tokens' => '',
413 420
        'config_module' => 'ldap_user',
414 421
        'prov_module' => 'ldap_user',
415 422
        'enabled' => TRUE,
416
      ),
417
    );
423
      ],
424
    ];
418 425

  
419
    // test for compound tokens
420
    $tests[] = array(
426
    // Test for compound tokens.
427
    $tests[] = [
421 428
      'disabled' => 0,
422 429
      'user' => 'hpotter',
423 430
      'field_name' => 'field_display_name',
424
      'field_values' => array(array('givenname' => 'Harry', 'sn' => 'Potter'), array('givenname' => 'Sir Harry', 'sn' => 'Potter')),
425
      'field_results' => array('Harry Potter', 'Sir Harry Potter'), // desired results
426
      'mapping' => array(
431
      'field_values' => [['givenname' => 'Harry', 'sn' => 'Potter'], ['givenname' => 'Sir Harry', 'sn' => 'Potter']],
432
    // Desired results.
433
      'field_results' => ['Harry Potter', 'Sir Harry Potter'],
434
      'mapping' => [
427 435
        'sid' => $sid,
428 436
        'ldap_attr' => '[givenName] [sn]',
429 437
        'user_attr' => '[field.field_display_name]',
430 438
        'convert' => 0,
431 439
        'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
432
        'prov_events' => array(LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER),
440
        'prov_events' => [LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER],
433 441
        'name' => 'Field: Display Name',
434 442
        'enabled' => TRUE,
435 443
        'config_module' => 'ldap_user',
436 444
        'prov_module' => 'ldap_user',
437 445
        'user_tokens' => '',
438
      ),
439
    );
446
      ],
447
    ];
440 448

  
441

  
442
    // test for constants in use (e.g. "Smith" and "0") instead of tokens e.g. "[sn]" and "[enabled]"
443
    $tests[] = array(
449
    // Test for constants in use (e.g. "Smith" and "0") instead of tokens e.g. "[sn]" and "[enabled]".
450
    $tests[] = [
444 451
      'disabled' => 0,
445 452
      'user' => 'hpotter',
446 453
      'field_name' => 'field_lname',
447
      'field_values' => array(array('sn' => 'Potter1'), array('sn' => 'Potter2')),
448
      'field_results' => array('Smith', 'Smith'),
449
      'mapping' => array(
454
      'field_values' => [['sn' => 'Potter1'], ['sn' => 'Potter2']],
455
      'field_results' => ['Smith', 'Smith'],
456
      'mapping' => [
450 457
        'sid' => $sid,
451 458
        'name' => 'Field: Last Name',
452
        'ldap_attr' => 'Smith', // testing of a constant mapped to a field.  that is everyone should have last name smith
459
    // Testing of a constant mapped to a field.  that is everyone should have last name smith.
460
        'ldap_attr' => 'Smith',
453 461
        'user_attr' => '[field.field_lname]',
454 462
        'convert' => 0,
455 463
        'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
456
        'prov_events' => array(LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER),
464
        'prov_events' => [LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER],
457 465
        'user_tokens' => '',
458 466
        'config_module' => 'ldap_user',
459 467
        'prov_module' => 'ldap_user',
460 468
        'enabled' => TRUE,
461 469

  
462
      ),
463
    );
470
      ],
471
    ];
464 472

  
465
    // test for compound tokens
466
    $tests[] = array(
473
    // Test for compound tokens.
474
    $tests[] = [
467 475
      'disabled' => 0,
468 476
      'user' => 'hpotter',
469 477
      'property_name' => 'signature',
470
      'property_values' => array(array('cn' => 'hpotter'), array('cn' => 'hpotter2')),
471
      'property_results' => array('hpotter@hogwarts.edu', 'hpotter2@hogwarts.edu'),
472
      'mapping' => array(
478
      'property_values' => [['cn' => 'hpotter'], ['cn' => 'hpotter2']],
479
      'property_results' => ['hpotter@hogwarts.edu', 'hpotter2@hogwarts.edu'],
480
      'mapping' => [
473 481
        'sid' => $sid,
474 482
        'ldap_attr' => '[cn]@hogwarts.edu',
475 483
        'user_attr' => '[property.signature]',
476 484
        'convert' => 0,
477 485
        'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
478
        'prov_events' => array(LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER),
486
        'prov_events' => [LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER],
479 487
        'name' => 'Property: Signature',
480 488
        'enabled' => TRUE,
481 489
        'config_module' => 'ldap_servers',
482 490
        'prov_module' => 'ldap_user',
483 491
        'user_tokens' => '',
484
      ),
485
    );
492
      ],
493
    ];
486 494

  
487
    $tests[] = array(
495
    $tests[] = [
488 496
      'disabled' => 0,
489 497
      'user' => 'hpotter',
490 498
      'property_name' => 'mail',
491
      'property_values' => array(array('mail' => 'hpotter@hogwarts.edu'), array('mail' => 'hpotter@owlmail.com')),
492
      'property_results' => array('hpotter@hogwarts.edu', 'hpotter@owlmail.com'),
493
      'mapping' => array(
499
      'property_values' => [['mail' => 'hpotter@hogwarts.edu'], ['mail' => 'hpotter@owlmail.com']],
500
      'property_results' => ['hpotter@hogwarts.edu', 'hpotter@owlmail.com'],
501
      'mapping' => [
494 502
        'sid' => $sid,
495 503
        'ldap_attr' => '[mail]',
496 504
        'user_attr' => '[property.mail]',
497 505
        'convert' => 0,
498 506
        'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
499
        'prov_events' => array(LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER),
507
        'prov_events' => [LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER],
500 508
        'name' => 'Property: Mail',
501 509
        'enabled' => TRUE,
502 510
        'config_module' => 'ldap_servers',
503 511
        'prov_module' => 'ldap_user',
504 512
        'user_tokens' => '',
505
      ),
506
    );
513
      ],
514
    ];
507 515

  
508
    $tests[] = array(
516
    $tests[] = [
509 517
      'disabled' => 0,
510 518
      'user' => 'hpotter',
511 519
      'property_name' => 'status',
512
      'property_values' => array(array(0 => 'z'), array(0 => 'z')),
513
      'property_results' => array(0, 0),
514
      'mapping' => array(
520
      'property_values' => [[0 => 'z'], [0 => 'z']],
521
      'property_results' => [0, 0],
522
      'mapping' => [
515 523
        'sid' => $sid,
516 524
        'ldap_attr' => '0',
517
        'user_attr' => '[property.status]', // testing of a constant mapped to property
525
    // Testing of a constant mapped to property.
526
        'user_attr' => '[property.status]',
518 527
        'convert' => 0,
519 528
        'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
520
        'prov_events' => array(LDAP_USER_EVENT_CREATE_DRUPAL_USER),
529
        'prov_events' => [LDAP_USER_EVENT_CREATE_DRUPAL_USER],
521 530
        'name' => 'Property: Status',
522 531
        'enabled' => TRUE,
523 532
        'config_module' => 'ldap_servers',
524 533
        'prov_module' => 'ldap_user',
525 534
        'user_tokens' => '',
526
      ),
527
    );
535
      ],
536
    ];
528 537

  
529 538
    // @todo test with binary field
530 539
    // @todo case sensitivity in tokens and user_attr in mappings
531 540

  
532
    $test_prov_events = array(
533
      LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER => array(
541
    $test_prov_events = [
542
      LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER => [
534 543
        LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER,
535 544
        LDAP_USER_EVENT_CREATE_DRUPAL_USER,
536
      ),
545
      ],
537 546

  
538
      LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY => array(
547
      LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY => [
539 548
        LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY,
540 549
        LDAP_USER_EVENT_CREATE_LDAP_ENTRY,
541
      ),
542
    );
550
      ],
551
    ];
543 552

  
544
    $this->privileged_user = $this->drupalCreateUser(array(
553
    $this->privileged_user = $this->drupalCreateUser([
545 554
      'administer site configuration',
546
      'administer users'
547
      ));
548
    
555
      'administer users',
556
    ]);
557

  
549 558
    /** Tests for various synch contexts **/
550 559
    foreach ($tests as $j => $test) {
551 560

  
552 561
      $field_name = isset($test['field_name']) ? $test['field_name'] : FALSE;
553 562
      $property_name = isset($test['property_name']) ? $test['property_name'] : FALSE;
554 563
      $direction = ($property_name) ? $test['mapping']['direction'] : $test['mapping']['direction'];
555
      foreach ($test_prov_events[$direction] as $i => $prov_event) {  // test for each provision event
564
      // Test for each provision event.
565
      foreach ($test_prov_events[$direction] as $i => $prov_event) {
556 566

  
557 567
        // 1. set fake ldap values for field and property in fake ldap server
558
        // and clear out mappings and set to provision account with test field and prop[0] on provision
568
        // and clear out mappings and set to provision account with test field and prop[0] on provision.
559 569
        $ldap_server = ldap_servers_get_servers('activedirectory1', 'enabled', TRUE);
560 570
        $this->prepTestData('hogwarts', $sids, 'provisionToDrupal', 'default');
561 571
        $ldap_user_conf = ldap_user_conf('admin', TRUE);
562 572
        if ($property_name) {
563
          $token_attributes = array();
573
          $token_attributes = [];
564 574
          ldap_servers_token_extract_attributes($token_attributes, $test['mapping']['ldap_attr']);
565 575
          foreach ($token_attributes as $attr_name => $attr_parts) {
566 576
            $this->testFunctions->setFakeServerUserAttribute(
......
574 584
          $ldap_user_conf->ldapUserSynchMappings[$direction][$property_token] = $test['mapping'];
575 585
        }
576 586
        if ($field_name) {
577
          $token_attributes = array();
587
          $token_attributes = [];
578 588
          ldap_servers_token_extract_attributes($token_attributes, $test['mapping']['ldap_attr']);
579
          foreach ($token_attributes as $attr_name => $attr_parts ) {
589
          foreach ($token_attributes as $attr_name => $attr_parts) {
580 590
            $this->testFunctions->setFakeServerUserAttribute(
581 591
              'activedirectory1',
582 592
              'cn=hpotter,ou=people,dc=hogwarts,dc=edu',
......
593 603
        ldap_user_ldap_provision_semaphore(NULL, NULL, NULL, TRUE);
594 604
        ldap_servers_flush_server_cache();
595 605

  
596
        // 2. delete user
606
        // 2. delete user.
597 607
        $username = $test['user'];
598 608
        $user_object = user_load_by_name($username);
599 609
        if (is_object($user_object)) {
600
          user_delete($user_object->uid); // watch out for this.
610
          // Watch out for this.
611
          user_delete($user_object->uid);
601 612
        }
602 613

  
603
        // 3. create new user with provisionDrupalAccount
614
        // 3. create new user with provisionDrupalAccount.
604 615
        $account = NULL;
605
        $user_edit = array('name' => $username);
606
       // $this->ldapTestId = $this->module_name . ': provisionDrupalAccount function test';
616
        $user_edit = ['name' => $username];
607 617
        $result = $ldap_user_conf->provisionDrupalAccount($account, $user_edit, NULL, TRUE);
608 618
        list($user_object, $user_entity) = ldap_user_load_user_acct_and_entity($username);
609 619
        if ($property_name) {
610
          if (in_array($prov_event, $ldap_user_conf->ldapUserSynchMappings[$direction][$property_token]['prov_events'])) { // if intended to synch
620
          // If intended to synch.
621
          if (in_array($prov_event, $ldap_user_conf->ldapUserSynchMappings[$direction][$property_token]['prov_events'])) {
611 622
            $property_success = ($user_object->{$property_name} == $test['property_results'][0]);
612 623
            $this->assertTrue($property_success, t("provisionDrupalAccount worked for property $property_name"), $this->testId(":provisionDrupalAccount.i=$j.prov_event=$prov_event"));
613 624
            if (!$property_success) {
614
              debug('field fail,' . $property_name); debug($user_entity->{$property_name}); debug($test['property_results'][0]); //debug($user_entity);
625
              debug('field fail,' . $property_name); debug($user_entity->{$property_name}); debug($test['property_results'][0]);
615 626
            }
616 627
          }
617 628
        }
618 629
        if ($field_name) {
619 630

  
620
          if (in_array($prov_event, $ldap_user_conf->ldapUserSynchMappings[$direction][$field_token]['prov_events'])) { // if intended to synch
631
          // If intended to synch.
632
          if (in_array($prov_event, $ldap_user_conf->ldapUserSynchMappings[$direction][$field_token]['prov_events'])) {
621 633
            $field_success = isset($user_entity->{$field_name}[LANGUAGE_NONE][0]['value']) &&
622 634
              $user_entity->{$field_name}[LANGUAGE_NONE][0]['value'] == $test['field_results'][0];
623 635
            $this->assertTrue($field_success, t("provisionDrupalAccount worked for field $field_name"), $this->testId(":provisionDrupalAccount.i=$j.prov_event=$prov_event"));
624 636
            if (!$field_success) {
625
              debug('field fail,' . $field_name); debug($user_entity->{$field_name}); debug($test['field_results'][0]); //debug($user_entity);
637
              // debug($user_entity);
638
              debug('field fail,' . $field_name); debug($user_entity->{$field_name}); debug($test['field_results'][0]);
626 639
            }
627 640
          }
628 641
          else {
......
631 644
        }
632 645
        ldap_user_ldap_provision_semaphore(NULL, NULL, NULL, TRUE);
633 646
      }
634
      
635
            /**
647

  
648
      /**
636 649
        * manually create drupal user with option of not ldap associated checked
637 650
        */
638
   
651

  
639 652
      if ($hpotter = user_load_by_name('hpotter')) {
640 653
        user_delete($hpotter->uid);
641 654
      }
642 655
      $this->assertFalse(user_load_by_name('hpotter'), t('hpotter removed before manual account creation test'), $this->testId('manual non ldap account created'));
643
      
656

  
644 657
      $this->drupalLogout();
645 658
      $this->drupalLogin($this->privileged_user);
646 659
      $this->drupalGet('admin/people/create');
647
      $edit = array(
660
      $edit = [
648 661
        'name' => 'hpotter',
649 662
        'mail' => 'hpotter@hogwarts.edu',
650 663
        'pass[pass1]' => 'goodpwd',
651 664
        'pass[pass2]' => 'goodpwd',
652 665
        'notify' => FALSE,
653 666
        'ldap_user_association' => LDAP_USER_MANUAL_ACCT_CONFLICT_NO_LDAP_ASSOCIATE,
654
      );
667
      ];
655 668
      $this->drupalPost('admin/people/create', $edit, t('Create new account'));
656
      
669

  
657 670
      $hpotter = user_load_by_name('hpotter');
658 671
      $this->assertTrue($hpotter, t('hpotter created via ui form'), $this->testId('manual non ldap account created'));
659 672
      $this->assertTrue($hpotter && !ldap_user_is_ldap_associated($hpotter), t('hpotter not ldap associated'), $this->testId('manual non ldap account created'));
660
       
661
     
662
     
663
    }
664
         /**
665
     * $entry = $servers['activedirectory1']->dnExists($desired_dn, 'ldap_entry');
666 673

  
667
     * $this->assertFalse($entry, t("Corresponding LDAP entry deleted when Drupal Account deleted for " . $username), $this->ldapTestId);
668
     */
674
    }
669 675
  }
670 676

  
671 677
}
672

  
678
/**
679
 *
680
 */
673 681
class LdapUserIntegrationTests extends LdapTestCase {
674 682

  
683
  /**
684
   *
685
   */
675 686
  public static function getInfo() {
676
    return array(
687
    return [
677 688
      'name' => 'LDAP User Integration Tests',
678 689
      'description' => 'Test provisioning and synching in real contexts such as account creation on logon, synching on user edit, etc.',
679
      'group' => 'LDAP User'
680
    );
690
      'group' => 'LDAP User',
691
    ];
681 692
  }
682 693

  
683
  function __construct($test_id = NULL) {
694
  /**
695
   *
696
   */
697
  public function __construct($test_id = NULL) {
684 698
    parent::__construct($test_id);
685 699
  }
686 700

  
......
688 702
  protected $ldap_test_data;
689 703

  
690 704
  /**
691
   *  create one or more server configurations in such as way
692
   *  that this setUp can be a prerequisite for ldap_authentication and ldap_authorization
705
   * Create one or more server configurations in such as way
706
   *  that this setUp can be a prerequisite for ldap_authentication and ldap_authorization.
693 707
   */
694

  
695
  function setUp() {
696
    parent::setUp(array('ldap_user', 'ldap_test'));
708
  public function setUp() {
709
    parent::setUp(['ldap_user', 'ldap_test']);
697 710
    variable_set('ldap_simpletest', 2);
698 711
  }
699 712

  
700
  function tearDown() {
713
  /**
714
   *
715
   */
716
  public function tearDown() {
701 717
    parent::tearDown();
702 718
    variable_del('ldap_help_watchdog_detail');
703 719
    variable_del('ldap_simpletest');
704 720
  }
705 721

  
706
 /**
707
   * integration tests for provisioning to ldap
722
  /**
723
   * Integration tests for provisioning to ldap.
708 724
   */
709
  function testProvisionToLdap() {
725
  public function testProvisionToLdap() {
710 726

  
711
    // just to give warning if setup doesn't succeed.  may want to take these out at some point.
727
    // Just to give warning if setup doesn't succeed.  may want to take these out at some point.
712 728
    $setup_success = (
713 729
        module_exists('ldap_user') &&
714 730
        module_exists('ldap_servers') &&
......
716 732
      );
717 733
    $this->assertTrue($setup_success, ' ldap_user setup successful', $this->testId("setup"));
718 734

  
719
    foreach (array('activedirectory1', 'openldap1') as $test_sid) {
720
      $sids = array($test_sid);
721
      $this->prepTestData('hogwarts', $sids, 'provisionToLdap_' . $test_sid); // this will create the proper ldap_user configuration from ldap_test/ldap_user.conf.inc
735
    foreach (['activedirectory1', 'openldap1'] as $test_sid) {
736
      $sids = [$test_sid];
737
      // This will create the proper ldap_user configuration from ldap_test/ldap_user.conf.inc.
738
      $this->prepTestData('hogwarts', $sids, 'provisionToLdap_' . $test_sid);
722 739
      $ldap_user_conf = ldap_user_conf('default', TRUE);
723 740

  
724 741
      // 9.B. Create and approve new user, populating first and last name.
......
726 743
      if ($user = user_load_by_name($username)) {
727 744
        user_delete($user->uid);
728 745
      }
729
      $user_edit = array(
746
      $user_edit = [
730 747
        'name' => $username,
731 748
        'mail' => $username . '@hogwarts.org',
732 749
        'pass' => user_password(),
733 750
        'status' => 1,
734
      );
751
      ];
735 752
      $user_acct = new stdClass();
736 753
      $user_acct->is_new = TRUE;
737 754
      $user_acct->field_fname[LANGUAGE_NONE][0]['value'] = 'Bercilak';
......
760 777
        debug('ldap_user_conf'); debug($ldap_user_conf);
761 778
      }
762 779

  
763

  
764
      ldap_user_ldap_provision_semaphore(NULL, NULL, NULL, TRUE);  // need to reset for simpletests
780
      // Need to reset for simpletests.
781
      ldap_user_ldap_provision_semaphore(NULL, NULL, NULL, TRUE);
765 782

  
766 783
      // Change lastname and first name (in drupal) and save user to test ldapSynch event handler
767
      // confirm that appropriate attributes were changed in ldap entry
784
      // confirm that appropriate attributes were changed in ldap entry.
768 785
      $ldap_entry_pre = $servers[$test_sid]->dnExists($desired_dn, 'ldap_entry');
769 786
      $user_acct_pre = user_load_by_name('bhautdeser');
770
      $edit = array();
787
      $edit = [];
771 788
      $edit['field_fname'][LANGUAGE_NONE][0]['value'] = 'Bredbeddle';
772 789
      $edit['field_lname'][LANGUAGE_NONE][0]['value'] = 'Hautdesert';
773 790
      $user_acct = user_save($user_acct, $edit);
774 791
      $user_acct_post = user_load_by_name('bhautdeser');
775 792

  
776
      $servers = ldap_servers_get_servers(NULL, NULL, FALSE, TRUE); // clear cache
793
      // Clear cache.
794
      $servers = ldap_servers_get_servers(NULL, NULL, FALSE, TRUE);
777 795
      $ldap_entry_post = $servers[$test_sid]->dnExists($desired_dn, 'ldap_entry');
778 796

  
779 797
      $ldap_entry_success = (
......
792 810
        debug('ldap_user_conf'); debug($ldap_user_conf);
793 811
      }
794 812

  
795

  
796
    // Change username and first name (in drupal) and save user to test ldapSynch event handler
797
      // confirm that appropriate attributes were changed in ldap entry
813
      // Change username and first name (in drupal) and save user to test ldapSynch event handler
814
      // confirm that appropriate attributes were changed in ldap entry.
798 815
      $ldap_entry_pre = $servers[$test_sid]->dnExists($desired_dn, 'ldap_entry');
799 816
      $user_acct_pre = user_load_by_name('bhautdeser');
800
      $edit = array();
817
      $edit = [];
801 818
      $edit['field_fname'][LANGUAGE_NONE][0]['value'] = 'Bredbeddle';
802 819
      $edit['field_lname'][LANGUAGE_NONE][0]['value'] = 'Hautdesert';
803 820
      $user_acct = user_save($user_acct, $edit);
804 821
      $user_acct_post = user_load_by_name('bhautdeser');
805 822

  
806
      $servers = ldap_servers_get_servers(NULL, NULL, FALSE, TRUE); // clear cache
823
      // Clear cache.
824
      $servers = ldap_servers_get_servers(NULL, NULL, FALSE, TRUE);
807 825
      $ldap_entry_post = $servers[$test_sid]->dnExists($desired_dn, 'ldap_entry');
808 826

  
809 827
      $ldap_entry_success = (
......
828 846
     * use case where a user self creates and confirms a drupal account and
829 847
     *  a corresponding ldap entry with password is created
830 848
     */
831
    $password_tests = array(
849
    $password_tests = [
832 850
      '[password.user-random]' => 'goodpwd',
833 851
      '[password.random]' => 'random',
834
    );
852
    ];
835 853

  
836 854
    foreach ($password_tests as $password_token => $password_result) {
837 855
      $test_id = "provisionToLdapEmailVerification $password_token, $test_sid";
838
      ldap_user_ldap_provision_semaphore(NULL, NULL, NULL, TRUE); // need to reset for simpletests
856
      // Need to reset for simpletests.
857
      ldap_user_ldap_provision_semaphore(NULL, NULL, NULL, TRUE);
839 858
      /**
840 859
       * provisionToLdapEmailVerification setup
841 860
       */
842
      $this->prepTestData('hogwarts', $sids, 'provisionToLdap_' . $test_sid); // this will create the proper ldap_user configuration from ldap_test/ldap_user.conf.inc
861
      // This will create the proper ldap_user configuration from ldap_test/ldap_user.conf.inc.
862
      $this->prepTestData('hogwarts', $sids, 'provisionToLdap_' . $test_sid);
843 863
      $ldap_user_conf = ldap_user_conf('admin', TRUE);
844
      $ldap_user_conf->drupalAcctProvisionServer = 0; // turn off provisioning to drupal
864
      // Turn off provisioning to drupal.
865
      $ldap_user_conf->drupalAcctProvisionServer = 0;
845 866
      $ldap_user_conf->ldapEntryProvisionServer = $test_sid;
846
      $ldap_user_conf->ldapEntryProvisionTriggers = array(
867
      $ldap_user_conf->ldapEntryProvisionTriggers = [
847 868
        LDAP_USER_LDAP_ENTRY_PROV_ON_USER_UPDATE_CREATE,
848
        LDAP_USER_LDAP_ENTRY_PROV_ON_AUTHENTICATE
849
      );
869
        LDAP_USER_LDAP_ENTRY_PROV_ON_AUTHENTICATE,
870
      ];
850 871

  
851
      $ldap_user_conf->ldapUserSynchMappings[LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY]['[password]'] = array(
872
      $ldap_user_conf->ldapUserSynchMappings[LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY]['[password]'] = [
852 873
        'sid' => $test_sid,
853 874
        'ldap_attr' => '[password]',
854 875
        'user_attr' => 'user_tokens',
......
857 878
        'config_module' => 'ldap_user',
858 879
        'synch_module' => 'ldap_user',
859 880
        'enabled' => 1,
860
        'prov_events' => array(LDAP_USER_EVENT_CREATE_LDAP_ENTRY, LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY),
861
      );
881
        'prov_events' => [LDAP_USER_EVENT_CREATE_LDAP_ENTRY, LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY],
882
      ];
862 883

  
863 884
      $ldap_user_conf->save();
864 885
      $ldap_user_conf = ldap_user_conf('default', TRUE);
865 886

  
866 887
      variable_set('user_email_verification', TRUE);
867
      variable_set('user_register', USER_REGISTER_VISITORS); // or USER_REGISTER_ADMINISTRATORS_ONLY, USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL
868
      variable_set('user_cancel_method', 'user_cancel_block'); // user_cancel_block_unpublish, user_cancel_reassign, user_cancel_delete
888
      // Or USER_REGISTER_ADMINISTRATORS_ONLY, USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL.
889
      variable_set('user_register', USER_REGISTER_VISITORS);
890
      // user_cancel_block_unpublish, user_cancel_reassign, user_cancel_delete.
891
      variable_set('user_cancel_method', 'user_cancel_block');
869 892
      $username = 'sstephens';
870 893
      $this->drupalLogout();
871 894
      if ($sstephens = user_load_by_name($username)) {
......
875 898
      /**
876 899
       * provisionToLdapEmailVerification test
877 900
       */
878
      $this->drupalGet('user/register');  // user register form
879
      $edit = array(
901
      // User register form.
902
      $this->drupalGet('user/register');
903
      $edit = [
880 904
        'name' => $username,
881 905
        'mail' => $username . '@hogwarts.edu',
882
        );
906
      ];
883 907

  
884
      $this->createTestUserFields(); // this will create last and first name fields
908
      // This will create last and first name fields.
909
      $this->createTestUserFields();
885 910

  
886 911
      $this->drupalPost('user/register', $edit, t('Create new account'));
887 912

  
888 913
      $sstephens = user_load_by_name($username);
889 914

  
890

  
891
       //can't derive login url, must get it from outgoing email because timestamp in hash is not stored in user_mail_tokens()
892

  
915
      // can't derive login url, must get it from outgoing email because timestamp in hash is not stored in user_mail_tokens()
893 916
      $emails = $this->drupalGetMails();
894
      $email_body = $emails[count($emails) - 1]['body']; // most recent email is the one of interest
895
      $result = array();
917
      // Most recent email is the one of interest.
918
      $email_body = $emails[count($emails) - 1]['body'];
919
      $result = [];
896 920
      preg_match_all('/(user\/reset\/.*)This link can only be/s', $email_body, $result, PREG_PATTERN_ORDER);
897 921
      if (count($result == 2)) {
898 922
        $login_path = trim($result[1][0]);
899
        $this->drupalGet($login_path);  // user login form
923
        // User login form.
924
        $this->drupalGet($login_path);
900 925
        $sstephens = user_load_by_name($username);
901
        $this->drupalPost($login_path, array(), t('Log in'));
926
        $this->drupalPost($login_path, [], t('Log in'));
902 927
        $sstephens = user_load_by_name($username);
903 928

  
904
        $edit = array(
929
        $edit = [
905 930
          'mail' => $username . '@hogwarts.edu',
906 931
          'pass[pass1]' => 'goodpwd',
907 932
          'pass[pass2]' => 'goodpwd',
908 933
          'field_fname[und][0][value]' => 'Samantha',
909
          'field_lname[und][0][value]' => 'Stephens'
910
        );
934
          'field_lname[und][0][value]' => 'Stephens',
935
        ];
911 936

  
912 937
        $this->drupalPost(NULL, $edit, t('Save'));
913 938
        $sstephens = user_load_by_name($username);
914
        $servers = ldap_servers_get_servers(NULL, NULL, FALSE, TRUE); // clear cache
939
        // Clear cache.
940
        $servers = ldap_servers_get_servers(NULL, NULL, FALSE, TRUE);
915 941
        $desired_dn = "cn=$username,ou=people,dc=hogwarts,dc=edu";
916 942
        $ldap_entry_post = $servers[$test_sid]->dnExists($desired_dn, 'ldap_entry');
917 943

  
......
946 972
      }
947 973
      /**
948 974
       * @todo functional tests
949

  
950
       do a password reset of some sort
951
       try to add a drupal user that conflicts with an ldap user
952
       try a binary fields such as a user profile image
975
       *
976
       * do a password reset of some sort
977
       * try to add a drupal user that conflicts with an ldap user
978
       * try a binary fields such as a user profile image
953 979
       */
954 980

  
955 981
    }
956 982

  
957
    // test deletion of drupal entry on deletion of drupal user
958
    foreach (array('activedirectory1', 'openldap1') as $test_sid) {
983
    // Test deletion of drupal entry on deletion of drupal user.
984
    foreach (['activedirectory1', 'openldap1'] as $test_sid) {
959 985
      $test_id = $test_sid;
960
      // 1. setup
961
      $sids = array($test_sid);
962
      $this->prepTestData('hogwarts', $sids, 'provisionToLdap_' . $test_sid); // this will create the proper ldap_user configuration from ldap_test/ldap_user.conf.inc
986
      // 1. setup.
987
      $sids = [$test_sid];
988
      // This will create the proper ldap_user configuration from ldap_test/ldap_user.conf.inc.
989
      $this->prepTestData('hogwarts', $sids, 'provisionToLdap_' . $test_sid);
963 990
      $ldap_user_conf = ldap_user_conf('admin', TRUE);
964 991
      if (!in_array(LDAP_USER_LDAP_ENTRY_DELETE_ON_USER_DELETE, $ldap_user_conf->ldapEntryProvisionTriggers)) {
965 992
        $ldap_user_conf->ldapEntryProvisionTriggers[] = LDAP_USER_LDAP_ENTRY_DELETE_ON_USER_DELETE;
......
971 998
      if ($user = user_load_by_name($username)) {
972 999
        user_delete($user->uid);
973 1000
      }
974
      $user_edit = array(
1001
      $user_edit = [
975 1002
        'name' => $username,
976 1003
        'mail' => $username . '@hogwarts.org',
977 1004
        'pass' => user_password(),
978 1005
        'status' => 1,
979
      );
1006
      ];
980 1007
      $user_acct = new stdClass();
981 1008
      $user_acct->is_new = TRUE;
982 1009
      $user_acct->field_fname[LANGUAGE_NONE][0]['value'] = 'Bercilak';
......
991 1018

  
992 1019
      $ldap_entry = $ldap_user_conf->getProvisionRelatedLdapEntry($drupal_account);
993 1020

  
994
      // 2. test
1021
      // 2. test.
995 1022
      user_delete($drupal_account->uid);
996 1023
      $ldap_server = ldap_servers_get_servers($test_sid, 'all', TRUE, TRUE);
997 1024
      $ldap_entry_post_delete = $ldap_server->dnExists($desired_dn, 'ldap_entry');
998 1025

  
999

  
1000 1026
      $success = (!$ldap_entry_post_delete);
1001 1027
      $this->assertTrue($success, t("ldap entry removed for $username on drupal user delete with deletion enabled."), $this->testId($test_id));
1002 1028

  
......
1007 1033
    }
1008 1034
  }
1009 1035

  
1010
   /**
1011
   * test cron function for dealing with ldap associated users who no longer have
1036
  /**
1037
   * Test cron function for dealing with ldap associated users who no longer have
1012 1038
   * ldap entries
1013
   *  - fix search in fake server to deal with general or queries
1014
  *
1015
  *  simpletest approach:
1016
  *  - loop through all options for user_cancel
1017
  *      ldap_user_orphan_email
1018
          user_cancel_block, user_cancel_block_unpublish,
1019
           user_cancel_reassign, user_cancel_delete
1020
  *    - automatically generate 70 ldap users with cns hpotter1-hpotter300
1021
  *    - create 75 corresponding drupal uses that are ldap identified
1022
  *    - delete 10 of the ldap entries
1023
  *    - run cron
1024
  *    - test for drupal accounts being dealt with correctly and or email sent
1039
   *  - fix search in fake server to deal with general or queries.
1040
   *
1041
   *  Simpletest approach:
1042
   *  - loop through all options for user_cancel
1043
   *      ldap_user_orphan_email
1044
   * user_cancel_block, user_cancel_block_unpublish,
1045
   * user_cancel_reassign, user_cancel_delete
1046
   *    - automatically generate 70 ldap users with cns hpotter1-hpotter300
1047
   *    - create 75 corresponding drupal uses that are ldap identified
1048
   *    - delete 10 of the ldap entries
1049
   *    - run cron
1050
   *    - test for drupal accounts being dealt with correctly and or email sent.
1025 1051
   */
1026
  function testDrupalAccountsOrphaned() {
1052
  public function testDrupalAccountsOrphaned() {
1027 1053
    // TODO: Fix failing tests, excluding to make branch pass.
1028 1054
    return;
1029
  // just to give warning if setup doesn't succeed.  may want to take these out at some point.
1055
    // Just to give warning if setup doesn't succeed.  may want to take these out at some point.
1030 1056
    $setup_success = (
1031 1057
        module_exists('ldap_user') &&
1032 1058
        module_exists('ldap_servers') &&
......
1034 1060
      );
1035 1061
    $this->assertTrue($setup_success, ' ldap_user setup successful', $this->testId('orphaned entries tests'));
1036 1062

  
1037
    $sids = array('activedirectory1');
1063
    $sids = ['activedirectory1'];
1038 1064
    $this->prepTestData('hogwarts', $sids, 'provisionToDrupal', 'default');
1039 1065

  
1040 1066
    $ldap_user_conf = ldap_user_conf('admin');
1041 1067
    $drupal_form = $ldap_user_conf->drupalForm();
1042 1068
    $account_options = $drupal_form['basic_to_drupal']['orphanedDrupalAcctBehavior']['#options'];
1043
    $cn_to_account = array();
1069
    $cn_to_account = [];
1044 1070
    $ldap_server = ldap_servers_get_servers('activedirectory1', NULL, TRUE, TRUE);
1045 1071

  
1046 1072
    foreach ($account_options as $account_option => $account_option_text) {
1047
      $sids = array('activedirectory1');
1073
      $sids = ['activedirectory1'];
1048 1074
      $this->prepTestData('hogwarts', $sids, 'provisionToDrupal', 'default');
1049 1075
      $ldap_user_conf->orphanedDrupalAcctBehavior = $account_option;
1050 1076
      $ldap_user_conf->save();
......
1052 1078
      $test_text = "Test of orphaned Drupal account option: $account_option_text";
1053 1079
      $success = FALSE;
1054 1080

  
1055
      // create 70 drupal accounts (clone0 to clone69) based on corresponding ldap entries
1081
      // Create 70 drupal accounts (clone0 to clone69) based on corresponding ldap entries.
1056 1082
      $first_clone_username = 'clone0';
1057 1083
      $last_clone_username = 'clone' . (LDAP_TEST_USER_ORPHAN_CLONE_COUNT - 1);
1058
      for ($i = 0; $i < LDAP_TEST_USER_ORPHAN_CLONE_COUNT; $i++) { // 70
1084
      // 70.
1085
      for ($i = 0; $i < LDAP_TEST_USER_ORPHAN_CLONE_COUNT; $i++) {
1059 1086
        $name = "clone" . $i;
1060 1087
        $account = $this->createLdapIdentifiedDrupalAccount(
1061 1088
          $ldap_user_conf,
......
1065 1092
        $cn_to_account[$name] = $account;
1066 1093
      }
1067 1094

  
1068
      // delete 10 ldap entries
1095
      // Delete 10 ldap entries.
1069 1096
      // @FIXME: Wrapper for broken test.
1070 1097
      if (is_object($cn_to_account[$first_clone_username])) {
1071 1098
        $clone_first_uid = $cn_to_account[$first_clone_username]->uid;
......
1090 1117
      switch ($account_option) {
1091 1118

  
1092 1119
        case 'ldap_user_orphan_do_not_check':
1093
          $test_uids = array();
1094
          for ($i = 0; $i < LDAP_TEST_USER_ORPHAN_CLONE_COUNT; $i++) { // 70
1120
          $test_uids = [];
1121
          // 70.
1122
          for ($i = 0; $i < LDAP_TEST_USER_ORPHAN_CLONE_COUNT; $i++) {
1095 1123
            $name = "clone" . $i;
1096 1124
            $test_uids[] = @$cn_to_account[$name]->uid;
1097 1125
          }
......
1107 1135
            $success = ($clone_last && $clone_last->status == 1);
1108 1136
          }
1109 1137

  
1110
        break;
1138
          break;
1111 1139

  
1112
        case 'ldap_user_orphan_email' :
1113
          // test is if email has 10 users and was sent
1140
        case 'ldap_user_orphan_email':
1141
          // Test is if email has 10 users and was sent.
1114 1142
          $emails = $this->drupalGetMails();
1115 1143
          if (count($emails)) {
1116
            $email_body = $emails[count($emails) - 1]['body']; // most recent email is the one of interest
1144
            // Most recent email is the one of interest.
1145
            $email_body = $emails[count($emails) - 1]['body'];
1117 1146
            $success = (strpos($email_body, "The following $delete Drupal users") !== FALSE);
1118 1147
          }
1119 1148
          else {
1120 1149
            $success = FALSE;
1121 1150
          }
1122 1151

  
1123
        break;
1152
          break;
1124 1153

  
1125 1154
        case 'user_cancel_block':
1126 1155
        case 'user_cancel_block_unpublish':
1127
          // test is if clone0-clone9 have a status of 0
1128
          // and clone12,11... have a status of 1
1129
          $test_uids = array();
1130
          for ($i = 0; $i < $delete; $i++) { // 70
1156
          // Test is if clone0-clone9 have a status of 0
1157
          // and clone12,11... have a status of 1.
1158
          $test_uids = [];
1159
          // 70.
1160
          for ($i = 0; $i < $delete; $i++) {
1131 1161
            $name = "clone" . $i;
1132 1162
            $test_uids[] = @$cn_to_account[$name]->uid;
1133 1163
          }
......
1143 1173
            $clone_last = user_load($clone_last_uid, TRUE);
1144 1174
            $success = ($clone_last && $clone_last->status == 1);
1145 1175
          }
1146
        break;
1176
          break;
1147 1177

  
1148 1178
        case 'user_cancel_reassign':
1149 1179
        case 'user_cancel_delete':
1150
          // test is if clone0-clone9 are deleted
1151
          // and clone12,11... have a status of 1
1152
          $test_uids = array();
1153
          for ($i = 0; $i < $delete; $i++) { // 70
1180
          // Test is if clone0-clone9 are deleted
1181
          // and clone12,11... have a status of 1.
1182
          $test_uids = [];
1183
          // 70.
1184
          for ($i = 0; $i < $delete; $i++) {
1154 1185
            $name = "clone" . $i;
1155 1186
            $test_uids[] = @$cn_to_account[$name]->uid;
1156 1187
          }
......
1162 1193
            $clone_last = user_load($clone_last_uid, TRUE);
1163 1194
            $success = ($clone_last && $clone_last->status == 1);
1164 1195
          }
1165
        break;
1196
          break;
1166 1197
      }
1167 1198

  
1168 1199
      $this->assertTrue($success, $test_id, $test_text);
1169 1200

  
1170
      // remove all drupal users except 1 for next test
1201
      // Remove all drupal users except 1 for next test.
1171 1202
      foreach ($cn_to_account as $cn => $account) {
1172 1203
        @user_delete($account->uid);
1173 1204
      }
......
1176 1207

  
1177 1208
  }
1178 1209

  
1179
  function createLdapIdentifiedDrupalAccount($ldap_user_conf, $name, $sid) {
1210
  /**
1211
   *
1212
   */
1213
  public function createLdapIdentifiedDrupalAccount($ldap_user_conf, $name, $sid) {
1180 1214

  
1181 1215
    $account = NULL;
1182
    $user_edit = array('name' => $name);
1216
    $user_edit = ['name' => $name];
1183 1217
    $user = $ldap_user_conf->provisionDrupalAccount($account, $user_edit, NULL, TRUE);
1184 1218

  
1185 1219
    return user_load($user->uid, TRUE);
1186 1220
  }
1187 1221

  
1188 1222
}
1189

  
1223
/**
1224
 *
1225
 */
1190 1226
class LdapUserUITests extends LdapTestCase {
1191 1227

  
1228
  /**
1229
   *
1230
   */
1192 1231
  public static function getInfo() {
1193
    return array(
1232
    return [
1194 1233
      'name' => 'LDAP User User Interface',
1195 1234
      'description' => 'Test ldap user admin interface.',
1196
      'group' => 'LDAP User'
1197
    );
1235
      'group' => 'LDAP User',
1236
    ];
1198 1237
  }
1199 1238

  
1200
  function __construct($test_id = NULL) {
1239
  /**
1240
   *
1241
   */
1242
  public function __construct($test_id = NULL) {
1201 1243
    parent::__construct($test_id);
1202 1244
  }
1203 1245

  
......
1205 1247
  protected $ldap_test_data;
1206 1248

  
1207 1249
  /**
1208
   *  create one or more server configurations in such as way
1209
   *  that this setUp can be a prerequisite for ldap_authentication and ldap_authorization
1250
   * Create one or more server configurations in such as way
1251
   *  that this setUp can be a prerequisite for ldap_authentication and ldap_authorization.
1210 1252
   */
1211

  
1212
  function setUp() {
1213
    parent::setUp(array('ldap_user', 'ldap_test'));
1253
  public function setUp() {
1254
    parent::setUp(['ldap_user', 'ldap_test']);
1214 1255
    variable_set('ldap_simpletest', 2);
1215 1256
  }
1216 1257

  
1217
  function tearDown() {
1258
  /**
1259
   *
1260
   */
1261
  public function tearDown() {
1218 1262
    parent::tearDown();
1219 1263
    variable_del('ldap_help_watchdog_detail');
1220 1264
    variable_del('ldap_simpletest');
1221 1265
  }
1222 1266

  
1223 1267
  /**
1224
   * make sure user admin interface works.  (its a beast)
1268
   * Make sure user admin interface works.  (its a beast)
1225 1269
   */
1226
  function testUI() {
1270
  public function testUI() {
1227 1271

  
1228
    // just to give warning if setup doesn't succeed.  may want to take these out at some point.
1272
    // Just to give warning if setup doesn't succeed.  may want to take these out at some point.
1229 1273
    $setup_success = (
1230 1274
        module_exists('ldap_user') &&
1231 1275
        module_exists('ldap_servers') &&
......
1233 1277
      );
1234 1278
    $this->assertTrue($setup_success, ' ldap_user setup successful', $this->testId('user interface tests'));
1235 1279

  
1236
    $sids = array('activedirectory1');
1280
    $sids = ['activedirectory1'];
1237 1281
    $this->prepTestData('hogwarts', $sids, 'provisionToDrupal', 'default');
1238 1282

  
1239
    $this->privileged_user = $this->drupalCreateUser(array(
1283
    $this->privileged_user = $this->drupalCreateUser([
1240 1284
      'administer site configuration',
1241
      'administer users'
1242
      ));
1285
      'administer users',
1286
    ]);
1243 1287

  
1244 1288
    $this->drupalLogin($this->privileged_user);
1245 1289

  
......
1250 1294
    // Populate the field settings with new settings.
1251 1295
    $sid = 'activedirectory1';
1252 1296

  
1253
    $edit_direct_map = array(
1297
    $edit_direct_map = [
1254 1298

  
1255 1299
      'manualAccountConflict' => LDAP_USER_MANUAL_ACCT_CONFLICT_LDAP_ASSOCIATE,
1256 1300
      'drupalAcctProvisionServer' => $sid,
......
1259 1303
      'orphanedDrupalAcctBehavior' => 'ldap_user_orphan_email',
1260 1304
      'orphanedCheckQty' => '50',
1261 1305
      'ldapEntryProvisionServer' => $sid,
1262
    );
1263
    // 'wsEnabled' => TRUE, 'wsKey' => $wsKey,
1264

  
1265

  
1266
// 'wsUserIps' => join("\n", $wsUserIps),
1267
    $edit = $edit_direct_map + array(
1306
    ];
1307
    $edit = $edit_direct_map + [
1268 1308
      'drupalAcctProvisionTriggers[' . LDAP_USER_DRUPAL_USER_PROV_ON_AUTHENTICATE . ']' => TRUE,
1269 1309
      'drupalAcctProvisionTriggers[' . LDAP_USER_DRUPAL_USER_PROV_ON_USER_UPDATE_CREATE . ']' => TRUE,
1270 1310

  
......
1304 1344
      '2__sm__ldap_attr__2' => '[dn]',
1305 1345
      '2__sm__4__2' => TRUE,
1306 1346
      '2__sm__4__2' => TRUE,
1307
    );
1347
    ];
1308 1348

  
1309 1349
    $this->drupalPost('admin/config/people/ldap/user', $edit, t('Save'));
1310 1350

  
......
1314 1354
      $this->assertTrue($ldap_user_conf->{$property} == $value, $property . ' ' . t('field set correctly'), $this->testId('user interface tests'));
1315 1355
    }
1316 1356

  
1317
   // $this->assertTrue(
1318
   //   ($ldap_user_conf->wsUserIps[0] == $wsUserIps[0] && $ldap_user_conf->wsUserIps[1] == $wsUserIps[1])
1319
    //  , t('webserice ips set correctly'), $this->testId('user interface tests'));
1320

  
1321 1357
    $this->assertTrue(
1322 1358
      isset($ldap_user_conf->drupalAcctProvisionTriggers[LDAP_USER_DRUPAL_USER_PROV_ON_AUTHENTICATE]) &&
1323
      isset($ldap_user_conf->drupalAcctProvisionTriggers[LDAP_USER_DRUPAL_USER_PROV_ON_USER_UPDATE_CREATE])
1324
      , t('drupal provision triggers set correctly'), $this->testId('user interface tests'));
1359
      isset($ldap_user_conf->drupalAcctProvisionTriggers[LDAP_USER_DRUPAL_USER_PROV_ON_USER_UPDATE_CREATE]),
1360
       t('drupal provision triggers set correctly'), $this->testId('user interface tests'));
1325 1361

  
1326 1362
    $this->assertTrue(
1327 1363
      isset($ldap_user_conf->ldapEntryProvisionTriggers[LDAP_USER_LDAP_ENTRY_PROV_ON_USER_UPDATE_CREATE]) &&
1328 1364
      isset($ldap_user_conf->ldapEntryProvisionTriggers[LDAP_USER_LDAP_ENTRY_PROV_ON_AUTHENTICATE]) &&
1329
      isset($ldap_user_conf->ldapEntryProvisionTriggers[LDAP_USER_LDAP_ENTRY_DELETE_ON_USER_DELETE])
1330
      , t('ldap provision triggers  set correctly'), $this->testId('user interface tests'));
1365
      isset($ldap_user_conf->ldapEntryProvisionTriggers[LDAP_USER_LDAP_ENTRY_DELETE_ON_USER_DELETE]),
1366
       t('ldap provision triggers  set correctly'), $this->testId('user interface tests'));
1331 1367

  
1332 1368
    $field_token = '[field.field_lname]';
1333 1369
    $field_lname_set_correctly = (
......
1350 1386
      debug('ldap_user_conf->synchMapping[direction][field.field_lname]'); debug($ldap_user_conf->ldapUserSynchMappings[LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER]['field.field_lname']);
1351 1387
    }
1352 1388

  
1353

  
1354

  
1355
    
1356 1389
  }
1357 1390

  
1358

  
1359

  
1360
  
1361

  
1362 1391
}
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff