You are here

protected function BmTestBasics::assertValidFieldValue in Backup and Migrate 7.3

Asserts that the content of a field passes its associated validation.

Parameters

string $validator: Drupal validator function callback.

array $element: Input for error setter.

string $value: Field value to be tested.

bool $value_is_valid: Expected outcome.

string $type: Description of value sub-type.

1 call to BmTestBasics::assertValidFieldValue()
BmTestBasics::testFieldValidators in tests/BmTestBasics.test
Test the custom validators.

File

tests/BmTestBasics.test, line 209
Tests for different parts of the Backup Migrate system.

Class

BmTestBasics
Test that the front page still loads.

Code

protected function assertValidFieldValue($validator, array $element, $value, $value_is_valid, $type) {
  $form = array();
  $form_state = array();
  $field = 'mock_field';
  $element['#value'] = $value;
  form_clear_error();
  call_user_func_array($validator, array(
    $element,
    &$form_state,
    $form,
  ));
  $errors = form_get_errors();
  if ($value_is_valid) {
    $args = array(
      '%value' => $value,
      '%type' => $type,
    );
    $msg = t('%value is a valid %type.', $args);
    $result = $this
      ->assertTrue(empty($errors[$field]), $msg);
  }
  else {
    $args = array(
      '%value' => $value,
      '%type' => $type,
      '%msg' => strip_tags($errors[$field]),
    );
    $msg = t('%value is not a valid %type. Error message: "%msg".', $args);
    $result = $this
      ->assertFalse(empty($errors[$field]), $msg);
  }
  return $result;
}