Projet

Général

Profil

Paste
Télécharger (23,3 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_authorization / tests / BasicTests.test @ 5136ce55

1
<?php
2

    
3
/**
4
 * @file
5
 * ldap_authentication simpletests
6
 *
7
 */
8
module_load_include('php', 'ldap_test', 'LdapTestCase.class');
9

    
10
class LdapAuthorizationBasicTests extends LdapTestCase {
11
  public static function getInfo() {
12
    return array(
13
      'name' => 'LDAP Authorization Basic Tests',
14
      'description' => 'Test ldap authorization.',
15
      'group' => 'LDAP Authorization'
16
    );
17
  }
18

    
19
  function __construct($test_id = NULL) {
20
    parent::__construct($test_id);
21
  }
22

    
23
  public $module_name = 'ldap_authorization';
24
  protected $ldap_test_data;
25

    
26
  function setUp() {
27
    parent::setUp(array(
28
      'ldap_authentication',
29
      'ldap_authorization',
30
      'ldap_authorization_drupal_role',
31
      'ldap_test')); // don't need any real servers, configured, just ldap_servers code base
32
    variable_set('ldap_simpletest', 2);
33
  }
34

    
35
  function tearDown() {
36
    parent::tearDown();
37
    variable_del('ldap_help_watchdog_detail');
38
    variable_del('ldap_simpletest');
39
  }
40

    
41
  /**
42
   * test install, api functions, and simple authorizations granted on logon
43
   */
44
  function testSimpleStuff() {
45

    
46
    // just to give warning if setup doesn't succeed.  may want to take these out at some point.
47
    $setup_success = (
48
        module_exists('ldap_authentication') &&
49
        module_exists('ldap_servers') &&
50
        module_exists('ldap_authorization') &&
51
        module_exists('ldap_authorization_drupal_role') &&
52
        (variable_get('ldap_simpletest', 2) > 0)
53
      );
54
    $this->assertTrue($setup_success, ' ldap_authorizations setup successful', 'LDAP Authorization: Test Setup Success');
55

    
56

    
57
    $api_functions = array(
58
      'ldap_authorization_get_consumer_object' => array(1, 1),
59
      'ldap_authorization_get_consumers'  => array(3, 0),
60
      'ldap_authorizations_user_authorizations'  => array(4, 1),
61
    );
62

    
63
    foreach ($api_functions as $api_function_name => $param_count) {
64
      $reflector = new ReflectionFunction($api_function_name);
65
      $this->assertTrue(
66
        function_exists($api_function_name) &&
67
        $param_count[1] == $reflector->getNumberOfRequiredParameters() &&
68
        $param_count[0] == $reflector->getNumberOfParameters()
69
        , ' api function ' . $api_function_name . ' parameters and required parameters count unchanged.', 'LDAP Server: API Functions');
70
    }
71

    
72
    // make sure ldap authorization doesn't break cron.
73
    $this->assertTrue(
74
      drupal_cron_run(),
75
      t('Cron can run with ldap authorization enabled.'),
76
      'LDAP Authorization: Cron Test'
77
    );
78

    
79

    
80
    /**
81
    * this is geared toward testing logon functionality
82
    */
83

    
84
    $sid = 'activedirectory1';
85
    $testid = 'ExclusiveModeUserLogon3';
86
    $sids = array($sid);
87
    $this->prepTestData(LDAP_TEST_LDAP_NAME, $sids, 'provisionToDrupal', 'default', 'drupal_role_default');
88

    
89
    $hpotter_logon_edit = array(
90
      'name' => 'hpotter',
91
      'pass' => 'goodpwd',
92
    );
93
    $this->drupalPost('user', $hpotter_logon_edit, t('Log in'));
94
    $this->assertText(t('Member for'), 'New Ldap user with good password authenticated.', 'LDAP Authorization: Test Logon');
95
    $this->assertTrue(
96
      $this->testFunctions->ldapUserIsAuthmapped('hpotter'),
97
      'Ldap user properly authmapped.',
98
      'LDAP Authorization: Test Logon'
99
    );
100

    
101
    $hpotter = $this->testFunctions->userByNameFlushingCache('hpotter');
102
    $roles = array_values($hpotter->roles);
103
    $desired_roles = array('students', 'authenticated user', 'cn=gryffindor,ou=groups,dc=hogwarts,dc=edu', 'cn=honors students,ou=groups,dc=hogwarts,dc=edu');
104
    $diff1 = array_diff($roles, $desired_roles);
105
    $diff2 = array_diff($desired_roles, $roles);
106
    $correct_roles = (count($diff1) == 0 && count($diff2) == 0);
107
    $roles_display = join(', ', $roles);
108
    if (!$correct_roles) {
109
      debug('hpotter roles'); debug($roles); debug('desired roles'); debug($desired_roles);
110
    }
111
    $this->assertTrue(
112
      $correct_roles,
113
      t('hpotter granted correct roles on actual logon: %roles', array('%roles' => $roles_display)),
114
      'LDAP Authorization: Test Logon for roles'
115
    );
116

    
117
    $this->drupalGet('user/logout');
118

    
119
    /**
120
     * test revoking of no longer deserved roles when revokeLdapProvisioned=1
121
     */
122
    $this->consumerAdminConf['drupal_role']->revokeLdapProvisioned = 1;
123
    $this->consumerAdminConf['drupal_role']->save();
124

    
125
    // setup:  remove hpotter from honors members
126
    $test_data_pre_test = variable_get('ldap_test_server__' . $sid, NULL);
127
    $test_data = variable_get('ldap_test_server__' . $sid, NULL);
128

    
129
    $this->removeUserFromGroup($test_data, 'cn=hpotter,ou=people,dc=hogwarts,dc=edu', 'cn=honors students,ou=groups,dc=hogwarts,dc=edu', "dc=hogwarts,dc=edu");
130

    
131
    variable_set('ldap_test_server__' . $sid, $test_data);
132

    
133
    $hpotter_dn = 'cn=hpotter,ou=people,dc=hogwarts,dc=edu';
134
    $this->drupalPost('user', $hpotter_logon_edit, t('Log in'));
135
    $hpotter = $this->testFunctions->userByNameFlushingCache('hpotter');
136
    $roles = array_values($hpotter->roles);
137

    
138
    $this->assertFalse(
139
      in_array('cn=honors students,ou=groups,dc=hogwarts,dc=edu', $roles),
140
      'when revokeLdapProvisioned=1, removed role from user',
141
      'LDAP Authorization: Test Logon'
142
    );
143

    
144
    $this->assertTrue(
145
      empty($hpotter->data['ldap_authorizations']['drupal_role']['cn=honors students,ou=groups,dc=hogwarts,dc=edu']),
146
      'when revokeLdapProvisioned=1, removed user->data[ldap_authorizations][drupal_role][<role>]',
147
      'LDAP Authorization: Test Logon'
148
    );
149

    
150
    // return test data to original state
151
    variable_set('ldap_test_server__' . $sid, $test_data_pre_test);
152
    $this->drupalGet('user/logout');
153

    
154

    
155
    /**
156
     * test regranting of removed roles (regrantLdapProvisioned = 0)
157
     */
158
    $hpotter = $this->testFunctions->userByNameFlushingCache('hpotter');
159
    $roles = array_values($hpotter->roles);
160
    $this->consumerAdminConf['drupal_role']->regrantLdapProvisioned = 0;
161
    $this->consumerAdminConf['drupal_role']->save();
162
    $this->testFunctions->removeRoleFromUser($hpotter, "cn=gryffindor,ou=groups,dc=hogwarts,dc=edu");
163
    $this->drupalPost('user', $hpotter_logon_edit, t('Log in'));
164
    $hpotter = $this->testFunctions->userByNameFlushingCache('hpotter');
165
    $roles = array_values($hpotter->roles);
166

    
167
    $this->assertFalse(
168
      in_array("cn=gryffindor,ou=groups,dc=hogwarts,dc=edu", $roles),
169
      'when regrantLdapProvisioned=0, did not regrant role on logon',
170
      'LDAP Authorization: Test Logon'
171
    );
172
    $this->assertTrue(
173
      !empty($hpotter->data['ldap_authorizations']['drupal_role']['cn=gryffindor,ou=groups,dc=hogwarts,dc=edu']),
174
      'when regrantLdapProvisioned=0, role is not regranted, but initial grant still remains in user->data[ldap_authorizations][drupal_role][<role>]',
175
      'LDAP Authorization: Test Logon'
176
    );
177
    $this->drupalGet('user/logout');
178

    
179
    /**
180
     * test regranting of removed roles (regrantLdapProvisioned = 1)
181
     */
182
    $this->consumerAdminConf['drupal_role']->regrantLdapProvisioned = 1;
183
    $this->consumerAdminConf['drupal_role']->save();
184
    $this->drupalPost('user', $hpotter_logon_edit, t('Log in'));
185
    $hpotter = $this->testFunctions->userByNameFlushingCache('hpotter');
186
    $roles = array_values($hpotter->roles);
187
    $this->assertTrue(
188
      in_array("cn=gryffindor,ou=groups,dc=hogwarts,dc=edu", $roles),
189
      'when regrantLdapProvisioned=0, did not regrant role on logon',
190
      'LDAP Authorization: Test Logon'
191
    );
192
    $this->drupalGet('user/logout');
193

    
194
}
195

    
196

    
197
/**
198
 * authorization configuration flags tests clumped together
199
 */
200

    
201
function testFlags() {
202

    
203
  $sid = 'activedirectory1';
204
  $this->prepTestData(
205
    LDAP_TEST_LDAP_NAME,
206
    array($sid),
207
    'provisionToDrupal',
208
    'default',
209
    'drupal_role_default'
210
    );
211

    
212
  /**
213
   * LDAP_authorz.Flags.status=0: Disable ldap_authorization_drupal_role configuration and make sure no authorizations performed
214
   */
215

    
216
  $user = $this->drupalCreateUser(array());
217
  $hpotter = $this->testFunctions->drupalLdapUpdateUser(array('name' => 'hpotter', 'mail' =>  'hpotter@hogwarts.edu'), TRUE, $user);
218
  list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($hpotter, 'query');  // just see if the correct ones are derived.
219
  $roles1 = $new_authorizations['drupal_role'];
220

    
221
 // $consumer_conf_admin = ldap_authorization_get_consumer_admin_object('drupal_role', FALSE);
222
  $this->consumerAdminConf['drupal_role']->status = 0;
223
  $this->consumerAdminConf['drupal_role']->save();
224

    
225
  list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($hpotter, 'query', 'drupal_role');  // just see if the correct ones are derived.
226
  $roles2 = isset($new_authorizations['drupal_role']) ? $new_authorizations['drupal_role'] : array();
227
  $correct_roles = (count($roles1) > 0 && count($roles2) == 0); // not worried about which roles here, just that some are granted
228

    
229
  $this->assertTrue(
230
    $correct_roles,
231
    'disable consumer configuration disallows authorizations.',
232
    'LDAP_authorz.Flags.status.0'
233
  );
234
  if (!$correct_roles) {
235
    debug('LDAP_authorz.Flags.enable.0 roles with enabled'); debug($roles1);
236
    debug('LDAP_authorz.Flags.enable.0 roles with disabled'); debug($roles2);
237
  }
238

    
239

    
240
  /**
241
   * LDAP_authorz.onlyLdapAuthenticated=1: create normal user and
242
   * apply authorization query.  should return no roles
243
   */
244
  $this->consumerAdminConf['drupal_role']->onlyApplyToLdapAuthenticated = 1;
245
  $this->consumerAdminConf['drupal_role']->status = 1;
246
  $this->consumerAdminConf['drupal_role']->save();
247

    
248
  $user = $this->drupalCreateUser(array());
249
  $hgrainger = $this->testFunctions->drupalLdapUpdateUser(array('name' => 'hgrainger', 'mail' =>  'hgrainger@hogwarts.edu'), TRUE, $user);
250

    
251
  // remove authmap in case it exists so test will work
252
  db_delete('authmap')
253
    ->condition('uid', $user->uid)
254
    ->condition('module', 'ldap_user')
255
    ->execute();
256

    
257
  list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($hgrainger, 'query');  // just see if the correct ones are derived.
258
  $roles = isset($new_authorizations['drupal_role']) ? $new_authorizations['drupal_role'] : array();
259
  $success = (count($roles) == 0);
260
  $this->assertTrue(
261
    $success,
262
    ' only apply to ldap authenticated grants no roles for non ldap user.',
263
    'LDAP_authorz.onlyLdapAuthenticated.1'
264
  );
265
  if (!$success) {
266
    debug('LDAP_authorz.onlyLdapAuthenticated.1');
267
    debug($roles);
268
    debug($this->testFunctions->ldapUserIsAuthmapped('hgrainger'));
269
    debug($new_authorizations);
270
    debug($notifications);
271
  }
272

    
273

    
274
  /**
275
   * LDAP_authorz.Flags.synchOnLogon - execute logon and check that no roles are applied if disabled
276
   */
277

    
278
  $this->consumerAdminConf['drupal_role']->synchOnLogon = 0;
279
  $this->consumerAdminConf['drupal_role']->save();
280
  $edit = array(
281
    'name' => 'hgrainger',
282
    'pass' => 'goodpwd',
283
  );
284
  $this->drupalPost('user', $edit, t('Log in'));
285
  $this->assertText(
286
    t('Member for'),
287
    'New Ldap user with good password authenticated.',
288
    'LDAP_authorz.Flags.synchOnLogon.0'
289
  );
290
  $this->assertTrue(
291
    $this->testFunctions->ldapUserIsAuthmapped('hgrainger'),
292
    'Ldap user properly authmapped.',
293
    'LDAP_authorz.Flags.synchOnLogon.0'
294
  );
295

    
296
  $hgrainger = user_load_by_name('hgrainger');
297
  $this->drupalGet('user/logout');
298

    
299
  $this->consumerAdminConf['drupal_role']->synchOnLogon = 1;
300
  $this->consumerAdminConf['drupal_role']->save();
301
  $edit = array(
302
    'name' => 'hgrainger',
303
    'pass' => 'goodpwd',
304
  );
305
  $this->drupalPost('user', $edit, t('Log in'));
306
  $this->assertText(t('Member for'), 'New Ldap user with good password authenticated.',
307
    'LDAP_authorz.Flags.synchOnLogon=1');
308
  $hgrainger = user_load_by_name('hgrainger');
309
  $this->drupalGet('user/logout');
310

    
311
  // create a couple roles for next 2 tests
312
  $troublemaker = new stdClass();
313
  $troublemaker->name = 'troublemaker';
314
  user_role_save($troublemaker);
315
  $troublemaker = user_role_load_by_name('troublemaker');
316

    
317
  $superadmin = new stdClass();
318
  $superadmin->name = 'superadmin';
319
  user_role_save($superadmin);
320
  $superadmin = user_role_load_by_name('superadmin');
321

    
322
   /**
323
   * LDAP_authorz.Flags.revokeLdapProvisioned: test flag for
324
   *   removing manually granted roles
325
   *
326
   *   $this->revokeLdapProvisioned == 1 : Revoke !consumer_namePlural previously granted by LDAP Authorization but no longer valid.
327
   *
328
   *   grant roles via ldap and some not vai ldap manually,
329
   *   then alter ldap so they are no longer valid,
330
   *   then logon again and make sure the ldap provided roles are revoked and the drupal ones are not revoked
331
   *
332
   */
333

    
334
  $this->consumerAdminConf['drupal_role']->onlyApplyToLdapAuthenticated = 0;
335
  $this->consumerAdminConf['drupal_role']->revokeLdapProvisioned = 1;
336
  $this->consumerAdminConf['drupal_role']->createConsumers = 1;
337
  $this->consumerAdminConf['drupal_role']->save();
338
  // set correct roles manually
339
  $hpotter = user_load_by_name('hpotter');
340
  user_delete($hpotter->uid);
341
  $user = $this->drupalCreateUser(array());
342
  $hpotter = $this->testFunctions->drupalLdapUpdateUser(array('name' => 'hpotter', 'mail' =>  'hpotter@hogwarts.edu'), TRUE, $user);
343
  $edit = array(
344
    'name' => 'hpotter',
345
    'pass' => 'goodpwd',
346
  );
347
  $this->drupalPost('user', $edit, t('Log in'));
348
  $this->assertText(
349
    t('Member for'),
350
    'New Ldap user with good password authenticated.',
351
    'LDAP_authorz.Flags.revokeLdapProvisioned=1'
352
  );
353
  $hpotter = user_load_by_name('hpotter');
354

    
355
  // add an underserved, ldap granted drupal role superadmin
356
  // and an undeserved, non ldap granted role troublemaker
357
  $hpotter = user_load($hpotter->uid, TRUE);
358
  $roles = $hpotter->roles;
359
  $roles[$troublemaker->rid] = $troublemaker->name;
360
  $roles[$superadmin->rid] = $superadmin->name;
361

    
362
  $data = array(
363
    'roles' =>  $roles,
364
    'data' => array('ldap_authorizations' =>
365
      array(
366
        'drupal_role' =>
367
        array(
368
          $superadmin->name =>
369
          array('date_granted' => 1304216778),
370
        ),
371
      ),
372
    ),
373
  );
374
  $hpotter = user_save($hpotter, $data);
375

    
376
  // apply correct authorizations.  should remove the administrator role but not the manually created 'troublemaker' role
377
  list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($hpotter, 'set', 'drupal_role', 'logon');
378

    
379
  $hpotter = user_load($hpotter->uid, TRUE);
380
  $this->assertTrue(
381
    (!isset($new_authorizations['drupal_role'][$superadmin->rid])),
382
    ' revoke superadmin ldap granted roles when no longer deserved.',
383
    'LDAP_authorz.Flags.revokeLdapProvisioned=1'
384
  );
385

    
386

    
387
   /**
388
   * LDAP_authorz.Flags.regrantLdapProvisioned
389
   * $this->regrantLdapProvisioned == 1 :
390
   *   Re grant !consumer_namePlural previously granted
391
   *   by LDAP Authorization but removed manually.
392
   *
393
   * - manually remove ldap granted role
394
   * - logon
395
   * - check if regranted
396
   */
397
  $this->drupalGet('user/logout');
398
  $this->consumerAdminConf['drupal_role']->regrantLdapProvisioned = 1;
399
  $this->consumerAdminConf['drupal_role']->save();
400
  $hpotter = user_load($hpotter->uid, TRUE);
401
  $roles = $hpotter->roles;
402
  unset($roles[$superadmin->rid]);
403
  user_save($hpotter, array('roles' => $roles));
404
  $hpotter = user_load($hpotter->uid, TRUE);
405
  list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($hpotter, 'set', 'drupal_role', 'logon');
406
  $hpotter = user_load($hpotter->uid, TRUE);
407
  $success = !in_array('administrator', array_values($hpotter->roles));
408

    
409
  $this->assertTrue(
410
    $success,
411
    'regrant Ldap Provisioned roles that were manually revoked',
412
    'LDAP_authorz.Flags.regrantLdapProvisioned=1'
413
  );
414
  if (!$success) {
415
    debug('LDAP_authorz.Flags.regrantLdapProvisioned=1');
416
    debug('hpotter roles'); debug($hpotter->roles);
417
    debug('new_authorizations'); debug($new_authorizations);
418
  }
419

    
420
  /**
421
  * LDAP_authorz.Flags.createConsumers=1
422
  */
423

    
424
  //add new mapping to and enable create consumers
425
  $this->prepTestData(LDAP_TEST_LDAP_NAME, array($sid), 'provisionToDrupal', 'default', 'drupal_role_default');
426
  $this->drupalGet('user/logout');
427
  $new_role = 'oompa-loompas';
428
  $this->consumerAdminConf['drupal_role']->createConsumers = 1;
429
  $this->consumerAdminConf['drupal_role']->mappings[] = array(
430
      'from' => 'cn=students,ou=groups,dc=hogwarts,dc=edu',
431
      'user_entered' => $new_role,
432
      'normalized' => $new_role,
433
      'simplified' => $new_role,
434
      'valid' => TRUE,
435
      'error_message' => '',
436
      );
437
  $this->consumerAdminConf['drupal_role']->save();
438
//  debug('mappings'); debug($this->consumerAdminConf['drupal_role']->mappings);
439

    
440
  $edit = array(
441
    'name' => 'hpotter',
442
    'pass' => 'goodpwd',
443
  );
444
  $this->drupalPost('user', $edit, t('Log in'));
445

    
446
  $new_role_created = in_array($new_role, array_values(user_roles()));
447
 // debug("roles"); debug(user_roles());
448
  $roles_by_name = array_flip(user_roles());
449
  $hpotter = user_load_by_name('hpotter');
450
  $hpotter = user_load($hpotter->uid, TRUE);
451
  $role_granted = isset($hpotter->roles[$roles_by_name[$new_role]]);
452

    
453

    
454
  $this->assertTrue(
455
    ($new_role_created && $role_granted),
456
    'create consumers (e.g. roles)',
457
    'LDAP_authorz.Flags.createConsumers=1'
458
  );
459

    
460
  if (!($new_role_created && $role_granted)) {
461
    debug('roles'); debug(user_roles());
462
    debug('roles by name'); debug($roles_by_name);
463
    debug('hpotter->roles'); debug($hpotter->roles);
464
    debug("new role desired: $new_role");
465
    debug("$new_role_created AND $role_granted");
466
  }
467

    
468
}
469

    
470
  public function testUIForms() {
471

    
472
    $ldap_simpletest_initial = variable_get('ldap_simpletest', 2);
473
    variable_del('ldap_simpletest'); // need to be out of fake server mode to test ui.
474

    
475
    $sid = 'activedirectory1';
476
    $this->prepTestData(LDAP_TEST_LDAP_NAME, array($sid), 'provisionToDrupal', 'default');
477

    
478
    ldap_servers_module_load_include('php', 'ldap_servers', 'LdapServerAdmin.class');
479
    $ldap_server = new LdapServerAdmin($sid);
480

    
481
    $server_properties = $this->testFunctions->data['ldap_servers'][$sid]['properties'];
482
    foreach ($server_properties as $property => $value) {
483
      $ldap_server->{$property} = $value;
484
    }
485
    $ldap_server->save('add');
486

    
487

    
488
    $consumer_form_data = array(
489
      'sid'        => array('activedirectory1', 'activedirectory1'),
490
      'status'     => array(TRUE, TRUE),
491
      'only_ldap_authenticated'    => array(FALSE, TRUE),
492
      'use_first_attr_as_groupid'       => array(FALSE, TRUE),
493
      'mappings' => array("a|b", "a|b"),
494
      'use_filter' =>  array(FALSE, TRUE),
495
      'synchronization_modes[user_logon]' => array(TRUE, FALSE),
496
      'synchronization_actions[revoke_ldap_provisioned]' => array(TRUE, FALSE),
497
      'synchronization_actions[regrant_ldap_provisioned]' => array(FALSE, TRUE),
498
      'synchronization_actions[create_consumers]' => array(TRUE, FALSE),
499
    );
500

    
501

    
502
    $this->privileged_user = $this->drupalCreateUser(array('administer site configuration'));
503
    $this->drupalLogin($this->privileged_user);
504
    $ldap_server = ldap_servers_get_servers('activedirectory1', NULL, TRUE, TRUE);
505
    $this->drupalGet('admin/config/people/ldap/servers/edit/activedirectory1');  // this is just for debugging to show the server.
506
    $ldap_server_admin = new LdapServerAdmin($sid);
507

    
508
    if (!is_array($ldap_server_admin->basedn)) {
509
      $ldap_server_admin->basedn = @unserialize($ldap_server_admin->basedn);
510
      $ldap_server_admin->save('update');
511
      $ldap_server_admin = new LdapServerAdmin($sid);
512
    }
513
    $this->drupalGet('admin/config/people/ldap/servers/edit/activedirectory1');
514

    
515
    foreach (array(0) as $i) {
516
      foreach (array('drupal_role') as $consumer_type) {
517
        foreach (array(1) as $ctools_enabled) {  // may want to put this back in after ctools requirement is fixed
518
          $this->ldapTestId = "testUIForms.$i.$consumer_type.ctools.$ctools_enabled";
519
          if ($ctools_enabled) {
520
            module_enable(array('ctools'));
521
          }
522
          else {
523
            module_disable(array('ctools'));
524
          }
525

    
526
          $lcase_transformed = array();
527

    
528
          /** add server conf test **/
529
          $this->drupalGet('admin/config/people/ldap/authorization/add/' . $consumer_type);
530

    
531
          $edit = array();
532
          foreach ($consumer_form_data as $input_name => $input_values) {
533
            $edit[$input_name] = $input_values[$i];
534
          }
535

    
536
          $this->drupalPost('admin/config/people/ldap/authorization/add/' . $consumer_type, $edit, t('Add'));
537
          $field_to_prop_map = LdapAuthorizationConsumerConf::field_to_properties_map();
538
          $ldap_consumer = ldap_authorization_get_consumer_object($consumer_type);
539
          $this->assertTrue(is_object($ldap_consumer), 'ldap consumer conf loaded after add-save',  $this->ldapTestId . ' Add consumer configuration');
540
          // assert one ldap server exists in db table
541

    
542
          // assert load of server has correct properties for each input
543
          $mismatches = $this->compareFormToProperties($ldap_consumer, $consumer_form_data, $i, $field_to_prop_map, $lcase_transformed);
544
          if (count($mismatches)) {
545
            debug('mismatches between ldap server properties and form submitted values');
546
            debug($mismatches);
547
           // debug($ldap_consumer);  // throw recursion
548
            debug($consumer_form_data);
549
          }
550
          $this->assertTrue(count($mismatches) == 0, 'Add form for ldap consumer properties match values submitted.',  $this->ldapTestId . ' Add consumer conf');
551

    
552

    
553
          /** update server conf test **/
554

    
555
          $this->drupalGet('admin/config/people/ldap/authorization/edit/' . $consumer_type);
556

    
557
          $edit = array();
558
          foreach ($consumer_form_data as $input_name => $input_values) {
559
            if ($input_values[$i] !== NULL) {
560
              $edit[$input_name] = $input_values[$i];
561
            }
562
          }
563

    
564
          unset($edit['sid']);
565
          $this->drupalPost('admin/config/people/ldap/authorization/edit/' . $consumer_type, $edit, t('Save'));
566
          $ldap_consumer = ldap_authorization_get_consumer_object($consumer_type);
567
          $this->assertTrue(is_object($ldap_consumer), 'ldap consumer conf loaded after edit-save',  $this->ldapTestId . ' update consumer configuration');
568

    
569
          $mismatches = $this->compareFormToProperties($ldap_consumer, $consumer_form_data, $i, $field_to_prop_map, $lcase_transformed);
570
          if (count($mismatches)) {
571
            debug('mismatches between ldap server properties and form submitted values');
572
            debug($mismatches);
573
           // debug($ldap_consumer); // throw recursion
574
            debug($consumer_form_data);
575
          }
576
          $this->assertTrue(count($mismatches) == 0, 'Update form for ldap server properties match values submitted.',  $this->ldapTestId . '.Update consumer conf');
577

    
578
          /** delete server conf test **/
579
          $this->drupalGet('admin/config/people/ldap/authorization/delete/' . $consumer_type);
580
          $this->drupalPost('admin/config/people/ldap/authorization/delete/' . $consumer_type, array(), t('Delete'));
581
          ctools_include('export');
582
          ctools_export_load_object_reset('ldap_authorization');
583
          $consumer_conf = ldap_authorization_get_consumer_conf($consumer_type);//
584
          $pass = (is_object($consumer_conf) && $consumer_conf->inDatabase === FALSE);
585
          $this->assertTrue($pass, 'Delete form for consumer conf deleted conf.',  $this->ldapTestId . '.Delete  consumer conf');
586
          if (!$pass) {
587
            debug('ldap consumer after delete. is_object=' . is_object($consumer_conf));
588
            debug('inDatabase?' . is_object($ldap_consumer) ? $consumer_conf->inDatabase : '?');
589
            debug("numericConsumerConfId" . $consumer_conf->numericConsumerConfId);
590
            debug("status" . $consumer_conf->status);
591
            debug("sid" . $consumer_conf->sid);
592
          }
593
        }
594
      }
595
    }
596
    variable_set('ldap_simpletest', $ldap_simpletest_initial); // return to fake server mode
597
  }
598

    
599

    
600

    
601
}