You are here

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

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

File

ldap_authorization/tests/BasicTests.test, line 470

Class

LdapAuthorizationBasicTests

Code

public function testUIForms() {
  $ldap_simpletest_initial = config('ldap_test.settings')
    ->get('simpletest');
  variable_del('ldap_simpletest');

  // need to be out of fake server mode to test ui.
  $sid = 'activedirectory1';
  $this
    ->prepTestData(LDAP_TEST_LDAP_NAME, array(
    $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 = array(
    'sid' => array(
      'activedirectory1',
      'activedirectory1',
    ),
    'status' => array(
      TRUE,
      TRUE,
    ),
    'only_ldap_authenticated' => array(
      FALSE,
      TRUE,
    ),
    'use_first_attr_as_groupid' => array(
      FALSE,
      TRUE,
    ),
    'mappings' => array(
      "a|b",
      "a|b",
    ),
    'use_filter' => array(
      FALSE,
      TRUE,
    ),
    'synchronization_modes[user_logon]' => array(
      TRUE,
      FALSE,
    ),
    'synchronization_actions[revoke_ldap_provisioned]' => array(
      TRUE,
      FALSE,
    ),
    'synchronization_actions[regrant_ldap_provisioned]' => array(
      FALSE,
      TRUE,
    ),
    'synchronization_actions[create_consumers]' => array(
      TRUE,
      FALSE,
    ),
  );
  $this->privileged_user = $this
    ->drupalCreateUser(array(
    'administer site configuration',
  ));
  $this
    ->drupalLogin($this->privileged_user);
  $ldap_server = ldap_servers_get_servers('activedirectory1', NULL, TRUE, TRUE);
  $this
    ->drupalGet('admin/config/people/ldap/servers/edit/activedirectory1');

  // this is just for debugging to show the server.
  $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 (array(
    0,
  ) as $i) {
    foreach (array(
      'drupal_role',
    ) as $consumer_type) {
      foreach (array(
        1,
      ) as $ctools_enabled) {

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

        /** add server conf test **/
        $this
          ->drupalGet('admin/config/people/ldap/authorization/add/' . $consumer_type);
        $edit = array();
        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($ldap_consumer);  // throw recursion
          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 = array();
        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($ldap_consumer); // throw recursion
          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, array(), 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);
        }
      }
    }
  }
  variable_set('ldap_simpletest', $ldap_simpletest_initial);

  // return to fake server mode
}