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_test/LdapTestCase.class.php
1 1
<?php
2 2

  
3

  
4

  
5 3
/**
6 4
 * @file
7
 * simpletest class for LDAP simpletests
8
 *
5
 * Simpletest class for LDAP simpletests.
9 6
 */
10 7

  
11 8
module_load_include('php', 'ldap_test', 'LdapTestFunctions.class');
12

  
9
/**
10
 *
11
 */
13 12
class LdapTestCase extends DrupalWebTestCase {
14 13

  
15 14
  public $testFunctions;
16 15
  public $module_name;
17 16

  
18
  // storage for test data
17
  /**
18
   * Storage for test data.
19
   */
19 20
  public $useFeatureData;
20 21
  public $featurePath;
21 22
  public $featureName;
......
24 25
  public $ldapTestId;
25 26
  public $authorizationData;
26 27
  public $authenticationData;
27
  public $testData = array();
28
  public $testData = [];
28 29

  
29
  public $sid; // current, or only, sid
30
  /**
31
   * Current, or only, sid.
32
   */
33
  public $sid;
30 34

  
31
  function __construct($test_id = NULL) {
35
  /**
36
   *
37
   */
38
  public function __construct($test_id = NULL) {
32 39
    parent::__construct($test_id);
33 40
    $this->testFunctions = new LdapTestFunctions();
34 41
  }
35 42

  
36
  function setUp() {
43
  /**
44
   *
45
   */
46
  public function setUp() {
37 47
    $modules = func_get_args();
38 48
    if (isset($modules[0]) && is_array($modules[0])) {
39 49
      $modules = $modules[0];
......
45 55

  
46 56
  }
47 57

  
48
  function tearDown() {
58
  /**
59
   *
60
   */
61
  public function tearDown() {
49 62
    parent::tearDown();
50 63
    variable_del('ldap_help_watchdog_detail');
51 64
    variable_del('ldap_simpletest');
52 65
  }
53 66

  
54 67
  /**
55
   * setup configuration and fake test data for all ldap modules
68
   * Setup configuration and fake test data for all ldap modules.
56 69
   *
57
   * @param  string $test_ldap_id name of directory in ldap_test where data is (e.g. hogwarts)
70
   * @param string $test_ldap_id
71
   *   name of directory in ldap_test where data is (e.g. hogwarts)
58 72
   *
59
   * the following params are ids that indicate what config data in /ldap_test/<module_name>.conf.inc to use
60
   * for example if $ldap_user_conf_id = 'ad_authentication', the array /ldap_test/ldap_user.conf.inc with the key
61
   *  'ad_authentication' will be used for the user module cofiguration
73
   *   the following params are ids that indicate what config data in /ldap_test/<module_name>.conf.inc to use
74
   *   for example if $ldap_user_conf_id = 'ad_authentication', the array /ldap_test/ldap_user.conf.inc with the key
75
   *   'ad_authentication' will be used for the user module cofiguration.
62 76
   *
63
   * @param array $sids to setup
77
   * @param array $sids
78
   *   to setup.
64 79
   * @param string $ldap_user_conf_id
65
   * @param string $ldap_authentication_conf_id = NULL,
66
   * @param string $ldap_authorization_conf_id = NULL,
67
   * @param string $ldap_feeds_conf_id = NULL,
68
   * @param string $ldap_query_conf_id = NULL
80
   * @param string $ldap_authentication_conf_id
81
   *   = NULL,.
82
   * @param string $ldap_authorization_conf_id
83
   *   = NULL,.
84
   * @param string $ldap_feeds_conf_id
85
   *   = NULL,.
86
   * @param string $ldap_query_conf_id
87
   *   = NULL.
69 88
   */
70
  function prepTestData(
89
  public function prepTestData(
71 90
      $test_ldap_id,
72 91
      $sids,
73 92
      $ldap_user_conf_id = NULL,
......
102 121
  }
103 122

  
104 123
  /**
105
   * attempt to derive a testid from backtrace
124
   * Attempt to derive a testid from backtrace.
106 125
   */
107 126
  public function testId($description = NULL, $method = NULL) {
108 127

  
......
113 132
      $test_id = NULL;
114 133
      $i = 0;
115 134
    }
116
    elseif ($test_id)  { // default test id
135
    // Default test id.
136
    elseif ($test_id) {
117 137
      $i++;
118 138
      return $test_id . '.' . $i;
119 139
    }
......
127 147
      $method = str_replace('test', '', $method, $count);
128 148
    }
129 149

  
130
    $test_id = join(".", array($this->module_name, $method, $description));
150
    $test_id = join(".", [$this->module_name, $method, $description]);
131 151
    return $test_id;
132 152

  
133 153
  }
154

  
155
  /**
156
   *
157
   */
134 158
  public function removeUserFromGroup(&$test_data, $user_dn, $group_dn, $domain = "dc=hogwarts,dc=edu") {
135 159

  
136
      $filter = "(&(objectClass=group)(member=$user_dn))";
137
      if (!empty($test_data['search_results'][$filter][$domain]) &&
160
    $filter = "(&(objectClass=group)(member=$user_dn))";
161
    if (!empty($test_data['search_results'][$filter][$domain]) &&
138 162
            in_array($group_dn, $test_data['search_results'][$filter][$domain])) {
139
        $test_data['search_results'][$filter][$domain] = array_diff($test_data['search_results'][$filter][$domain], array($group_dn));
140
        $test_data['search_results'][$filter][$domain]['count'] = count($test_data['search_results'][$filter][$domain] - 1);
141
      }
163
      $test_data['search_results'][$filter][$domain] = array_diff($test_data['search_results'][$filter][$domain], [$group_dn]);
164
      $test_data['search_results'][$filter][$domain]['count'] = count($test_data['search_results'][$filter][$domain] - 1);
165
    }
142 166

  
143
      if (!empty($test_data['users'][$user_dn]['attr']['memberof']) && in_array($group_dn, $test_data['users'][$user_dn]['attr']['memberof'])) {
144
        $test_data['users'][$user_dn]['attr']['memberof'] = array_diff($test_data['users'][$user_dn]['attr']['memberof'], array($group_dn));
145
        $test_data['users'][$user_dn]['attr']['memberof']['count'] = count($test_data['users'][$user_dn]['attr']['memberof'] - 1);
146
      }
167
    if (!empty($test_data['users'][$user_dn]['attr']['memberof']) && in_array($group_dn, $test_data['users'][$user_dn]['attr']['memberof'])) {
168
      $test_data['users'][$user_dn]['attr']['memberof'] = array_diff($test_data['users'][$user_dn]['attr']['memberof'], [$group_dn]);
169
      $test_data['users'][$user_dn]['attr']['memberof']['count'] = count($test_data['users'][$user_dn]['attr']['memberof'] - 1);
170
    }
147 171

  
148
      if (!empty($test_data['ldap'][$user_dn]['memberof']) && in_array($group_dn, $test_data['ldap'][$user_dn]['memberof'])) {
149
        $test_data['ldap'][$user_dn]['memberof'] = array_diff($test_data['ldap'][$user_dn]['memberof'], array($group_dn));
150
        $test_data['ldap'][$user_dn]['memberof']['count'] = count($test_data['ldap'][$user_dn]['memberof']) - 1;
151
      }
172
    if (!empty($test_data['ldap'][$user_dn]['memberof']) && in_array($group_dn, $test_data['ldap'][$user_dn]['memberof'])) {
173
      $test_data['ldap'][$user_dn]['memberof'] = array_diff($test_data['ldap'][$user_dn]['memberof'], [$group_dn]);
174
      $test_data['ldap'][$user_dn]['memberof']['count'] = count($test_data['ldap'][$user_dn]['memberof']) - 1;
175
    }
152 176

  
153
      if (!empty($test_data['groups'][$group_dn]['attr']['member']) && in_array($group_dn, $test_data['groups'][$group_dn]['attr']['member']) ) {
154
        $members = array_diff($test_data['groups'][$group_dn]['attr']['member'], array($group_dn));
155
        $test_data['groups'][$group_dn]['attr']['member'] = $members;
156
        $test_data['groups'][$group_dn]['attr']['member'][$i]['count'] = count($members - 1);
157
      }
177
    if (!empty($test_data['groups'][$group_dn]['attr']['member']) && in_array($group_dn, $test_data['groups'][$group_dn]['attr']['member'])) {
178
      $members = array_diff($test_data['groups'][$group_dn]['attr']['member'], [$group_dn]);
179
      $test_data['groups'][$group_dn]['attr']['member'] = $members;
180
      $test_data['groups'][$group_dn]['attr']['member'][$i]['count'] = count($members - 1);
158 181
    }
182
  }
159 183

  
184
  /**
185
   *
186
   */
160 187
  public function AttemptLogonNewUser($name, $goodpwd = TRUE) {
161 188

  
162 189
    $this->drupalLogout();
163 190

  
164
    $edit = array(
191
    $edit = [
165 192
      'name' => $name,
166 193
      'pass' => ($goodpwd) ? "goodpwd" : "badpwd",
167
    );
194
    ];
168 195
    $user = user_load_by_name($name);
169 196
    if ($user) {
170 197
      user_delete($user->uid);
......
173 200
  }
174 201

  
175 202
  /**
176
   * keep user entity fields function for ldap_user
203
   * Keep user entity fields function for ldap_user
177 204
   * in base class instead of user test class in case
178
   * module integration testing is needed
205
   * module integration testing is needed.
179 206
   */
180

  
181
  function createTestUserFields() {
207
  public function createTestUserFields() {
182 208
    foreach ($this->ldap_user_test_entity_fields() as $field_id => $field_conf) {
183 209
      $field_info = field_info_field($field_id);
184 210
      if (!$field_info) {
......
189 215
    }
190 216
  }
191 217

  
192
  function ldap_user_test_entity_fields() {
218
  /**
219
   *
220
   */
221
  public function ldap_user_test_entity_fields() {
193 222

  
194
    $fields = array();
223
    $fields = [];
195 224

  
196
    $fields['field_lname']['field'] = array(
225
    $fields['field_lname']['field'] = [
197 226
      'field_name' => 'field_lname',
198 227
      'type' => 'text',
199
      'settings' => array(
228
      'settings' => [
200 229
        'max_length' => 64,
201
      )
202
    );
230
      ],
231
    ];
203 232

  
204
    $fields['field_lname']['instance'] = array(
233
    $fields['field_lname']['instance'] = [
205 234
      'field_name' => 'field_lname',
206 235
      'entity_type' => 'user',
207 236
      'label' => 'Last Name',
208 237
      'bundle' => 'user',
209 238
      'required' => FALSE,
210
      'widget' => array(
239
      'widget' => [
211 240
        'type' => 'text_textfield',
212
      ),
213
      'display' => array(
214
        'default' => array(
241
      ],
242
      'display' => [
243
        'default' => [
215 244
          'type' => 'text_default',
216
        ),
217
      ),
218
      'settings' => array('user_register_form' => FALSE)
219
    );
245
        ],
246
      ],
247
      'settings' => ['user_register_form' => FALSE],
248
    ];
220 249

  
221
  $fields['field_department']['field'] = array(
250
    $fields['field_department']['field'] = [
222 251
      'field_name' => 'field_department',
223 252
      'type' => 'text',
224
      'settings' => array(
253
      'settings' => [
225 254
        'max_length' => 64,
226
      )
227
    );
255
      ],
256
    ];
228 257

  
229
    $fields['field_department']['instance'] = array(
258
    $fields['field_department']['instance'] = [
230 259
      'field_name' => 'field_department',
231 260
      'entity_type' => 'user',
232 261
      'label' => 'Department',
233 262
      'bundle' => 'user',
234 263
      'required' => FALSE,
235
      'widget' => array(
264
      'widget' => [
236 265
        'type' => 'text_textfield',
237
      ),
238
      'display' => array(
239
        'default' => array(
266
      ],
267
      'display' => [
268
        'default' => [
240 269
          'type' => 'text_default',
241
        ),
242
      ),
243
      'settings' => array('user_register_form' => FALSE)
244
    );
270
        ],
271
      ],
272
      'settings' => ['user_register_form' => FALSE],
273
    ];
245 274

  
246

  
247
    $fields['field_fname']['field'] = array(
275
    $fields['field_fname']['field'] = [
248 276
      'field_name' => 'field_fname',
249 277
      'type' => 'text',
250
      'settings' => array(
278
      'settings' => [
251 279
        'max_length' => 64,
252
      )
253
    );
280
      ],
281
    ];
254 282

  
255
    $fields['field_fname']['instance'] = array(
283
    $fields['field_fname']['instance'] = [
256 284
      'field_name' => 'field_fname',
257 285
      'entity_type' => 'user',
258 286
      'label' => 'Last Name',
259 287
      'bundle' => 'user',
260 288
      'required' => FALSE,
261
      'widget' => array(
289
      'widget' => [
262 290
        'type' => 'text_textfield',
263
      ),
264
      'display' => array(
265
        'default' => array(
291
      ],
292
      'display' => [
293
        'default' => [
266 294
          'type' => 'text_default',
267
        ),
268
      ),
269
      'settings' => array('user_register_form' => FALSE)
270
    );
295
        ],
296
      ],
297
      'settings' => ['user_register_form' => FALSE],
298
    ];
271 299

  
272
    // display name for testing compound tokens
273
    $fields['field_display_name']['field'] = array(
300
    // Display name for testing compound tokens.
301
    $fields['field_display_name']['field'] = [
274 302
      'field_name' => 'field_display_name',
275 303
      'type' => 'text',
276
      'settings' => array(
304
      'settings' => [
277 305
        'max_length' => 64,
278
      )
279
    );
306
      ],
307
    ];
280 308

  
281
    $fields['field_display_name']['instance'] = array(
309
    $fields['field_display_name']['instance'] = [
282 310
      'field_name' => 'field_display_name',
283 311
      'entity_type' => 'user',
284 312
      'label' => 'Display Name',
285 313
      'bundle' => 'user',
286 314
      'required' => FALSE,
287
      'widget' => array(
315
      'widget' => [
288 316
        'type' => 'text_textfield',
289
      ),
290
      'display' => array(
291
        'default' => array(
317
      ],
318
      'display' => [
319
        'default' => [
292 320
          'type' => 'text_default',
293
        ),
294
      ),
295
      'settings' => array('user_register_form' => FALSE)
296
    );
321
        ],
322
      ],
323
      'settings' => ['user_register_form' => FALSE],
324
    ];
297 325

  
298
    // display name for testing compound tokens
299
    $fields['field_binary_test']['field'] = array(
326
    // Display name for testing compound tokens.
327
    $fields['field_binary_test']['field'] = [
300 328
      'field_name' => 'field_binary_test',
301 329
      'type' => 'text',
302 330
      'size' => 'big',
303
    );
331
    ];
304 332

  
305
    $fields['field_binary_test']['instance'] = array(
333
    $fields['field_binary_test']['instance'] = [
306 334
      'field_name' => 'field_binary_test',
307 335
      'entity_type' => 'user',
308 336
      'label' => 'Binary Field',
309 337
      'bundle' => 'user',
310 338
      'required' => FALSE,
311
      'widget' => array(
339
      'widget' => [
312 340
        'type' => 'text_textfield',
313
      ),
314
      'display' => array(
315
        'default' => array(
341
      ],
342
      'display' => [
343
        'default' => [
316 344
          'type' => 'text_default',
317
        ),
318
      ),
319
      'settings' => array('user_register_form' => FALSE)
320
    );
345
        ],
346
      ],
347
      'settings' => ['user_register_form' => FALSE],
348
    ];
321 349

  
322 350
    return $fields;
323 351

  
324 352
  }
325 353

  
354
  /**
355
   *
356
   */
326 357
  public function checkConsumerConfSetup($conf_id) {
327 358

  
328 359
    $authorization_data = ldap_test_ldap_authorization_data();
329 360
    $props_set_correctly = TRUE;
330 361

  
331 362
    foreach ($authorization_data[$conf_id] as $consumer_type => $conf) {
332
      $props_set_display = array();
363
      $props_set_display = [];
333 364
      foreach ($conf as $prop => $values) {
334 365
        if (!property_exists($this->consumerAdminConf[$consumer_type], $prop)) {
335 366
          $props_set_correctly = FALSE;
......
347 378
      }
348 379
    }
349 380

  
350
    return array($props_set_display, $props_set_correctly);
381
    return [$props_set_display, $props_set_correctly];
351 382
  }
352 383

  
353

  
384
  /**
385
   *
386
   */
354 387
  public function compareFormToProperties($object, $data, $item_id, $map, $lcase_transformed) {
355 388

  
356
    $mismatches = array();
389
    $mismatches = [];
357 390
    foreach ($data as $field_id => $values) {
358 391
      $field_id = drupal_strtolower($field_id);
359 392
      if (!isset($map[$field_id])) {
......
365 398
      }
366 399
      $property_value = $object->{$property};
367 400

  
368
      $field_value = isset($values[$item_id + 2]) ? $values[$item_id + 2] : $values[$item_id]; // for cases where string input is not same as array.
401
      // For cases where string input is not same as array.
402
      $field_value = isset($values[$item_id + 2]) ? $values[$item_id + 2] : $values[$item_id];
369 403

  
370 404
      if (in_array($field_id, $lcase_transformed) && is_scalar($field_value)) {
371 405
        $field_value = drupal_strtolower($field_value);

Formats disponibles : Unified diff