You are here

public function LdapAuthorizationBasicTests::testUIForms in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_authorization/tests/BasicTests.test \LdapAuthorizationBasicTests::testUIForms()

File

ldap_authorization/tests/BasicTests.test, line 484

Class

LdapAuthorizationBasicTests

Code

public function testUIForms() {

  // TODO: Fix failing tests, excluding to make branch pass.
  return;
  $ldap_simpletest_initial = variable_get('ldap_simpletest', 2);

  // Need to be out of fake server mode to test ui.
  variable_del('ldap_simpletest');
  $sid = 'activedirectory1';
  $this
    ->prepTestData(LDAP_TEST_LDAP_NAME, [
    $sid,
  ], 'provisionToDrupal', 'default');
  ldap_servers_module_load_include('php', 'ldap_servers', 'LdapServerAdmin.class');
  $ldap_server = new LdapServerAdmin($sid);
  $server_properties = $this->testFunctions->data['ldap_servers'][$sid]['properties'];
  foreach ($server_properties as $property => $value) {
    $ldap_server->{$property} = $value;
  }
  $ldap_server
    ->save('add');
  $consumer_form_data = [
    'sid' => [
      'activedirectory1',
      'activedirectory1',
    ],
    'status' => [
      TRUE,
      TRUE,
    ],
    'only_ldap_authenticated' => [
      FALSE,
      TRUE,
    ],
    'use_first_attr_as_groupid' => [
      FALSE,
      TRUE,
    ],
    'mappings' => [
      "a|b",
      "a|b",
    ],
    'use_filter' => [
      FALSE,
      TRUE,
    ],
    'synchronization_modes[user_logon]' => [
      TRUE,
      FALSE,
    ],
    'synchronization_actions[revoke_ldap_provisioned]' => [
      TRUE,
      FALSE,
    ],
    'synchronization_actions[regrant_ldap_provisioned]' => [
      FALSE,
      TRUE,
    ],
    'synchronization_actions[create_consumers]' => [
      TRUE,
      FALSE,
    ],
  ];
  $this->privileged_user = $this
    ->drupalCreateUser([
    'administer site configuration',
  ]);
  $this
    ->drupalLogin($this->privileged_user);
  $ldap_server = ldap_servers_get_servers('activedirectory1', NULL, TRUE, TRUE);

  // This is just for debugging to show the server.
  $this
    ->drupalGet('admin/config/people/ldap/servers/edit/activedirectory1');
  $ldap_server_admin = new LdapServerAdmin($sid);
  if (!is_array($ldap_server_admin->basedn)) {
    $ldap_server_admin->basedn = @unserialize($ldap_server_admin->basedn);
    $ldap_server_admin
      ->save('update');
    $ldap_server_admin = new LdapServerAdmin($sid);
  }
  $this
    ->drupalGet('admin/config/people/ldap/servers/edit/activedirectory1');
  foreach ([
    0,
  ] as $i) {
    foreach ([
      'drupal_role',
    ] as $consumer_type) {

      // May want to put this back in after ctools requirement is fixed.
      foreach ([
        1,
      ] as $ctools_enabled) {
        $this->ldapTestId = "testUIForms.{$i}.{$consumer_type}.ctools.{$ctools_enabled}";
        if ($ctools_enabled) {
          module_enable([
            'ctools',
          ]);
        }
        else {
          module_disable([
            'ctools',
          ]);
        }
        $lcase_transformed = [];

        /** add server conf test **/
        $this
          ->drupalGet('admin/config/people/ldap/authorization/add/' . $consumer_type);
        $edit = [];
        foreach ($consumer_form_data as $input_name => $input_values) {
          $edit[$input_name] = $input_values[$i];
        }
        $this
          ->drupalPost('admin/config/people/ldap/authorization/add/' . $consumer_type, $edit, t('Add'));
        $field_to_prop_map = LdapAuthorizationConsumerConf::field_to_properties_map();
        $ldap_consumer = ldap_authorization_get_consumer_object($consumer_type);
        $this
          ->assertTrue(is_object($ldap_consumer), 'ldap consumer conf loaded after add-save', $this->ldapTestId . ' Add consumer configuration');

        // Assert one ldap server exists in db table
        // Assert load of server has correct properties for each input.
        $mismatches = $this
          ->compareFormToProperties($ldap_consumer, $consumer_form_data, $i, $field_to_prop_map, $lcase_transformed);
        if (count($mismatches)) {
          debug('mismatches between ldap server properties and form submitted values');
          debug($mismatches);
          debug($consumer_form_data);
        }
        $this
          ->assertTrue(count($mismatches) == 0, 'Add form for ldap consumer properties match values submitted.', $this->ldapTestId . ' Add consumer conf');

        /** update server conf test **/
        $this
          ->drupalGet('admin/config/people/ldap/authorization/edit/' . $consumer_type);
        $edit = [];
        foreach ($consumer_form_data as $input_name => $input_values) {
          if ($input_values[$i] !== NULL) {
            $edit[$input_name] = $input_values[$i];
          }
        }
        unset($edit['sid']);
        $this
          ->drupalPost('admin/config/people/ldap/authorization/edit/' . $consumer_type, $edit, t('Save'));
        $ldap_consumer = ldap_authorization_get_consumer_object($consumer_type);
        $this
          ->assertTrue(is_object($ldap_consumer), 'ldap consumer conf loaded after edit-save', $this->ldapTestId . ' update consumer configuration');
        $mismatches = $this
          ->compareFormToProperties($ldap_consumer, $consumer_form_data, $i, $field_to_prop_map, $lcase_transformed);
        if (count($mismatches)) {
          debug('mismatches between ldap server properties and form submitted values');
          debug($mismatches);
          debug($consumer_form_data);
        }
        $this
          ->assertTrue(count($mismatches) == 0, 'Update form for ldap server properties match values submitted.', $this->ldapTestId . '.Update consumer conf');

        /** delete server conf test **/
        $this
          ->drupalGet('admin/config/people/ldap/authorization/delete/' . $consumer_type);
        $this
          ->drupalPost('admin/config/people/ldap/authorization/delete/' . $consumer_type, [], t('Delete'));
        ctools_include('export');
        ctools_export_load_object_reset('ldap_authorization');
        $consumer_conf = ldap_authorization_get_consumer_conf($consumer_type);
        $pass = is_object($consumer_conf) && $consumer_conf->inDatabase === FALSE;
        $this
          ->assertTrue($pass, 'Delete form for consumer conf deleted conf.', $this->ldapTestId . '.Delete  consumer conf');
        if (!$pass) {
          debug('ldap consumer after delete. is_object=' . is_object($consumer_conf));
          debug('inDatabase?' . is_object($ldap_consumer) ? $consumer_conf->inDatabase : '?');
          debug("numericConsumerConfId" . $consumer_conf->numericConsumerConfId);
          debug("status" . $consumer_conf->status);
          debug("sid" . $consumer_conf->sid);
        }
      }
    }
  }

  // Return to fake server mode.
  variable_set('ldap_simpletest', $ldap_simpletest_initial);
}