You are here

public function LdapServersTestCase::compareFormToProperties in Lightweight Directory Access Protocol (LDAP) 7

Same name and namespace in other branches
  1. 8.2 ldap_servers/tests/ldap_servers.test \LdapServersTestCase::compareFormToProperties()
  2. 7.2 ldap_servers/tests/ldap_servers.test \LdapServersTestCase::compareFormToProperties()
1 call to LdapServersTestCase::compareFormToProperties()
LdapServersTestCase::testUIForms in ldap_servers/tests/ldap_servers.test

File

ldap_servers/tests/ldap_servers.test, line 219
simpletest for ldap aservers

Class

LdapServersTestCase

Code

public function compareFormToProperties($object, $data, $item_id, $map, $testid = '') {
  $mismatches = array();
  foreach ($data as $field_id => $values) {
    if (!isset($map[$field_id])) {
      debug("no mapping for field: {$field_id} in test {$testid}");
      continue;
    }
    $property = $map[$field_id];
    if (!property_exists($object, $property)) {
      debug("property {$property} does not exist in object in test {$testid}");
      continue;
    }
    $property_value = $object->{$property};
    $property_value_show = is_scalar($property_value) ? $property_value : serialize($property_value);
    $field_value = isset($values[$item_id + 2]) ? $values[$item_id + 2] : $values[$item_id];

    // for cases where string input is not same as array.
    $field_value_show = is_scalar($field_value) ? $field_value : serialize($field_value);

    //debug("property name $property "); debug($property_value); debug("field id: $field_id"); debug($field_value);
    if (is_array($property_value) && is_array($field_value)) {
      $pass = count(array_diff($property_value, $field_value)) == 0;
    }
    elseif (is_scalar($property_value) && is_scalar($field_value)) {
      $pass = $property_value == $field_value;
    }
    else {
      $pass = FALSE;
    }
    if (!$pass) {

      // debug($property_value); debug($field_value);
      $mismatches[] = "property {$property} ({$property_value_show}) does not match field {$field_id} value ({$field_value_show})";
    }
  }
  return $mismatches;
}