You are here

function ABTPermissionFieldTestCase::runFieldSettingCombos in Access By Term 7

1 call to ABTPermissionFieldTestCase::runFieldSettingCombos()
ABTPermissionFieldTestCase::testEditFieldSettings in ./abt.test

File

./abt.test, line 287

Class

ABTPermissionFieldTestCase

Code

function runFieldSettingCombos() {
  $combos = array(
    array(
      'v' => ABT_CONTROL_DEFAULT_RESTRICT,
      'u' => ABT_NO_CONTROL,
      'd' => ABT_NO_CONTROL,
    ),
    array(
      'v' => ABT_NO_CONTROL,
      'u' => ABT_CONTROL_DEFAULT_RESTRICT,
      'd' => ABT_NO_CONTROL,
    ),
    array(
      'v' => ABT_NO_CONTROL,
      'u' => ABT_NO_CONTROL,
      'd' => ABT_CONTROL_DEFAULT_RESTRICT,
    ),
    array(
      'v' => ABT_CONTROL_DEFAULT_RESTRICT,
      'u' => ABT_CONTROL_DEFAULT_RESTRICT,
      'd' => ABT_NO_CONTROL,
    ),
    array(
      'v' => ABT_CONTROL_DEFAULT_RESTRICT,
      'u' => ABT_NO_CONTROL,
      'd' => ABT_CONTROL_DEFAULT_RESTRICT,
    ),
    array(
      'v' => ABT_NO_CONTROL,
      'u' => ABT_CONTROL_DEFAULT_RESTRICT,
      'd' => ABT_CONTROL_DEFAULT_RESTRICT,
    ),
    array(
      'v' => ABT_NO_CONTROL,
      'u' => ABT_NO_CONTROL,
      'd' => ABT_NO_CONTROL,
    ),
    /* this row should not be saved */
    array(
      'v' => ABT_CONTROL_DEFAULT_RESTRICT,
      'u' => ABT_CONTROL_DEFAULT_RESTRICT,
      'd' => ABT_CONTROL_DEFAULT_RESTRICT,
    ),
  );
  for ($j = 0, $i = 0; $i < count($combos); $i++, $j++) {
    $j = $j >= count($this->field_instances['node']) ? 0 : $j;

    // field counter
    $v = $combos[$i]['v'];
    $u = $combos[$i]['u'];
    $d = $combos[$i]['d'];
    $this
      ->postFieldSettings($this->content_type->type, $this->field_instances['node'][$j], $v, $u, $d);
    $expect = 1;
    $field = field_info_field($this->field_instances['node'][$j]['field_name']);
    $rowCount = 1;
    if (isset($field['settings']['abt_map'])) {
      if ($field['settings']['abt_map']['ctrl_view_access'] != $v) {
        $rowCount = 0;
      }
      if ($field['settings']['abt_map']['ctrl_update_access'] != $u) {
        $rowCount = 0;
      }
      if ($field['settings']['abt_map']['ctrl_delete_access'] != $d) {
        $rowCount = 0;
      }
    }
    $this
      ->assertTrue($rowCount == $expect, t('Field values changed as planned. (' . $v . $u . $d . ') = (' . $rowCount . ') Row was @not found.', array(
      '@not' => $expect ? '' : 'not',
    )));
  }
}