class FieldAttachOtherTestCase

Unit test class for non-storage related field_attach_* functions.

Hierarchy

Expanded class hierarchy of FieldAttachOtherTestCase

File

drupal/modules/field/tests/field.test, line 707
Tests for field.module.

View source
class FieldAttachOtherTestCase extends FieldAttachTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Field attach tests (other)',
      'description' => 'Test other Field Attach API functions.',
      'group' => 'Field API',
    );
  }

  /**
   * Test field_attach_view() and field_attach_prepare_view().
   */
  function testFieldAttachView() {
    $this
      ->createFieldWithInstance('_2');
    $entity_type = 'test_entity';
    $entity_init = field_test_create_stub_entity();
    $langcode = LANGUAGE_NONE;
    $options = array(
      'field_name' => $this->field_name_2,
    );

    // Populate values to be displayed.
    $values = $this
      ->_generateTestFieldValues($this->field['cardinality']);
    $entity_init->{$this->field_name}[$langcode] = $values;
    $values_2 = $this
      ->_generateTestFieldValues($this->field_2['cardinality']);
    $entity_init->{$this->field_name_2}[$langcode] = $values_2;

    // Simple formatter, label displayed.
    $entity = clone $entity_init;
    $formatter_setting = $this
      ->randomName();
    $this->instance['display'] = array(
      'full' => array(
        'label' => 'above',
        'type' => 'field_test_default',
        'settings' => array(
          'test_formatter_setting' => $formatter_setting,
        ),
      ),
    );
    field_update_instance($this->instance);
    $formatter_setting_2 = $this
      ->randomName();
    $this->instance_2['display'] = array(
      'full' => array(
        'label' => 'above',
        'type' => 'field_test_default',
        'settings' => array(
          'test_formatter_setting' => $formatter_setting_2,
        ),
      ),
    );
    field_update_instance($this->instance_2);

    // View all fields.
    field_attach_prepare_view($entity_type, array(
      $entity->ftid => $entity,
    ), 'full');
    $entity->content = field_attach_view($entity_type, $entity, 'full');
    $output = drupal_render($entity->content);
    $this->content = $output;
    $this
      ->assertRaw($this->instance['label'], "First field's label is displayed.");
    foreach ($values as $delta => $value) {
      $this->content = $output;
      $this
        ->assertRaw("{$formatter_setting}|{$value['value']}", "Value {$delta} is displayed, formatter settings are applied.");
    }
    $this
      ->assertRaw($this->instance_2['label'], "Second field's label is displayed.");
    foreach ($values_2 as $delta => $value) {
      $this->content = $output;
      $this
        ->assertRaw("{$formatter_setting_2}|{$value['value']}", "Value {$delta} is displayed, formatter settings are applied.");
    }

    // View single field (the second field).
    field_attach_prepare_view($entity_type, array(
      $entity->ftid => $entity,
    ), 'full', $langcode, $options);
    $entity->content = field_attach_view($entity_type, $entity, 'full', $langcode, $options);
    $output = drupal_render($entity->content);
    $this->content = $output;
    $this
      ->assertNoRaw($this->instance['label'], "First field's label is not displayed.");
    foreach ($values as $delta => $value) {
      $this->content = $output;
      $this
        ->assertNoRaw("{$formatter_setting}|{$value['value']}", "Value {$delta} is displayed, formatter settings are applied.");
    }
    $this
      ->assertRaw($this->instance_2['label'], "Second field's label is displayed.");
    foreach ($values_2 as $delta => $value) {
      $this->content = $output;
      $this
        ->assertRaw("{$formatter_setting_2}|{$value['value']}", "Value {$delta} is displayed, formatter settings are applied.");
    }

    // Label hidden.
    $entity = clone $entity_init;
    $this->instance['display']['full']['label'] = 'hidden';
    field_update_instance($this->instance);
    field_attach_prepare_view($entity_type, array(
      $entity->ftid => $entity,
    ), 'full');
    $entity->content = field_attach_view($entity_type, $entity, 'full');
    $output = drupal_render($entity->content);
    $this->content = $output;
    $this
      ->assertNoRaw($this->instance['label'], "Hidden label: label is not displayed.");

    // Field hidden.
    $entity = clone $entity_init;
    $this->instance['display'] = array(
      'full' => array(
        'label' => 'above',
        'type' => 'hidden',
      ),
    );
    field_update_instance($this->instance);
    field_attach_prepare_view($entity_type, array(
      $entity->ftid => $entity,
    ), 'full');
    $entity->content = field_attach_view($entity_type, $entity, 'full');
    $output = drupal_render($entity->content);
    $this->content = $output;
    $this
      ->assertNoRaw($this->instance['label'], "Hidden field: label is not displayed.");
    foreach ($values as $delta => $value) {
      $this
        ->assertNoRaw("{$formatter_setting}|{$value['value']}", "Hidden field: value {$delta} is not displayed.");
    }

    // Multiple formatter.
    $entity = clone $entity_init;
    $formatter_setting = $this
      ->randomName();
    $this->instance['display'] = array(
      'full' => array(
        'label' => 'above',
        'type' => 'field_test_multiple',
        'settings' => array(
          'test_formatter_setting_multiple' => $formatter_setting,
        ),
      ),
    );
    field_update_instance($this->instance);
    field_attach_prepare_view($entity_type, array(
      $entity->ftid => $entity,
    ), 'full');
    $entity->content = field_attach_view($entity_type, $entity, 'full');
    $output = drupal_render($entity->content);
    $display = $formatter_setting;
    foreach ($values as $delta => $value) {
      $display .= "|{$delta}:{$value['value']}";
    }
    $this->content = $output;
    $this
      ->assertRaw($display, "Multiple formatter: all values are displayed, formatter settings are applied.");

    // Test a formatter that uses hook_field_formatter_prepare_view().
    $entity = clone $entity_init;
    $formatter_setting = $this
      ->randomName();
    $this->instance['display'] = array(
      'full' => array(
        'label' => 'above',
        'type' => 'field_test_with_prepare_view',
        'settings' => array(
          'test_formatter_setting_additional' => $formatter_setting,
        ),
      ),
    );
    field_update_instance($this->instance);
    field_attach_prepare_view($entity_type, array(
      $entity->ftid => $entity,
    ), 'full');
    $entity->content = field_attach_view($entity_type, $entity, 'full');
    $output = drupal_render($entity->content);
    $this->content = $output;
    foreach ($values as $delta => $value) {
      $this->content = $output;
      $expected = $formatter_setting . '|' . $value['value'] . '|' . ($value['value'] + 1);
      $this
        ->assertRaw($expected, "Value {$delta} is displayed, formatter settings are applied.");
    }

    // TODO:
    // - check display order with several fields
    // Preprocess template.
    $variables = array();
    field_attach_preprocess($entity_type, $entity, $entity->content, $variables);
    $result = TRUE;
    foreach ($values as $delta => $item) {
      if ($variables[$this->field_name][$delta]['value'] !== $item['value']) {
        $result = FALSE;
        break;
      }
    }
    $this
      ->assertTrue($result, format_string('Variable $@field_name correctly populated.', array(
      '@field_name' => $this->field_name,
    )));
  }

  /**
   * Tests the 'multiple entity' behavior of field_attach_prepare_view().
   */
  function testFieldAttachPrepareViewMultiple() {
    $entity_type = 'test_entity';
    $langcode = LANGUAGE_NONE;

    // Set the instance to be hidden.
    $this->instance['display']['full']['type'] = 'hidden';
    field_update_instance($this->instance);

    // Set up a second instance on another bundle, with a formatter that uses
    // hook_field_formatter_prepare_view().
    field_test_create_bundle('test_bundle_2');
    $formatter_setting = $this
      ->randomName();
    $this->instance2 = $this->instance;
    $this->instance2['bundle'] = 'test_bundle_2';
    $this->instance2['display']['full'] = array(
      'type' => 'field_test_with_prepare_view',
      'settings' => array(
        'test_formatter_setting_additional' => $formatter_setting,
      ),
    );
    field_create_instance($this->instance2);

    // Create one entity in each bundle.
    $entity1_init = field_test_create_stub_entity(1, 1, 'test_bundle');
    $values1 = $this
      ->_generateTestFieldValues($this->field['cardinality']);
    $entity1_init->{$this->field_name}[$langcode] = $values1;
    $entity2_init = field_test_create_stub_entity(2, 2, 'test_bundle_2');
    $values2 = $this
      ->_generateTestFieldValues($this->field['cardinality']);
    $entity2_init->{$this->field_name}[$langcode] = $values2;

    // Run prepare_view, and check that the entities come out as expected.
    $entity1 = clone $entity1_init;
    $entity2 = clone $entity2_init;
    field_attach_prepare_view($entity_type, array(
      $entity1->ftid => $entity1,
      $entity2->ftid => $entity2,
    ), 'full');
    $this
      ->assertFalse(isset($entity1->{$this->field_name}[$langcode][0]['additional_formatter_value']), 'Entity 1 did not run through the prepare_view hook.');
    $this
      ->assertTrue(isset($entity2->{$this->field_name}[$langcode][0]['additional_formatter_value']), 'Entity 2 ran through the prepare_view hook.');

    // Same thing, reversed order.
    $entity1 = clone $entity1_init;
    $entity2 = clone $entity2_init;
    field_attach_prepare_view($entity_type, array(
      $entity2->ftid => $entity2,
      $entity1->ftid => $entity1,
    ), 'full');
    $this
      ->assertFalse(isset($entity1->{$this->field_name}[$langcode][0]['additional_formatter_value']), 'Entity 1 did not run through the prepare_view hook.');
    $this
      ->assertTrue(isset($entity2->{$this->field_name}[$langcode][0]['additional_formatter_value']), 'Entity 2 ran through the prepare_view hook.');
  }

  /**
   * Test field cache.
   */
  function testFieldAttachCache() {

    // Initialize random values and a test entity.
    $entity_init = field_test_create_stub_entity(1, 1, $this->instance['bundle']);
    $langcode = LANGUAGE_NONE;
    $values = $this
      ->_generateTestFieldValues($this->field['cardinality']);

    // Non-cacheable entity type.
    $entity_type = 'test_entity';
    $cid = "field:{$entity_type}:{$entity_init->ftid}";

    // Check that no initial cache entry is present.
    $this
      ->assertFalse(cache_get($cid, 'cache_field'), 'Non-cached: no initial cache entry');

    // Save, and check that no cache entry is present.
    $entity = clone $entity_init;
    $entity->{$this->field_name}[$langcode] = $values;
    field_attach_insert($entity_type, $entity);
    $this
      ->assertFalse(cache_get($cid, 'cache_field'), 'Non-cached: no cache entry on insert');

    // Load, and check that no cache entry is present.
    $entity = clone $entity_init;
    field_attach_load($entity_type, array(
      $entity->ftid => $entity,
    ));
    $this
      ->assertFalse(cache_get($cid, 'cache_field'), 'Non-cached: no cache entry on load');

    // Cacheable entity type.
    $entity_type = 'test_cacheable_entity';
    $cid = "field:{$entity_type}:{$entity_init->ftid}";
    $instance = $this->instance;
    $instance['entity_type'] = $entity_type;
    field_create_instance($instance);

    // Check that no initial cache entry is present.
    $this
      ->assertFalse(cache_get($cid, 'cache_field'), 'Cached: no initial cache entry');

    // Save, and check that no cache entry is present.
    $entity = clone $entity_init;
    $entity->{$this->field_name}[$langcode] = $values;
    field_attach_insert($entity_type, $entity);
    $this
      ->assertFalse(cache_get($cid, 'cache_field'), 'Cached: no cache entry on insert');

    // Load a single field, and check that no cache entry is present.
    $entity = clone $entity_init;
    field_attach_load($entity_type, array(
      $entity->ftid => $entity,
    ), FIELD_LOAD_CURRENT, array(
      'field_id' => $this->field_id,
    ));
    $cache = cache_get($cid, 'cache_field');
    $this
      ->assertFalse(cache_get($cid, 'cache_field'), 'Cached: no cache entry on loading a single field');

    // Load, and check that a cache entry is present with the expected values.
    $entity = clone $entity_init;
    field_attach_load($entity_type, array(
      $entity->ftid => $entity,
    ));
    $cache = cache_get($cid, 'cache_field');
    $this
      ->assertEqual($cache->data[$this->field_name][$langcode], $values, 'Cached: correct cache entry on load');

    // Update with different values, and check that the cache entry is wiped.
    $values = $this
      ->_generateTestFieldValues($this->field['cardinality']);
    $entity = clone $entity_init;
    $entity->{$this->field_name}[$langcode] = $values;
    field_attach_update($entity_type, $entity);
    $this
      ->assertFalse(cache_get($cid, 'cache_field'), 'Cached: no cache entry on update');

    // Load, and check that a cache entry is present with the expected values.
    $entity = clone $entity_init;
    field_attach_load($entity_type, array(
      $entity->ftid => $entity,
    ));
    $cache = cache_get($cid, 'cache_field');
    $this
      ->assertEqual($cache->data[$this->field_name][$langcode], $values, 'Cached: correct cache entry on load');

    // Create a new revision, and check that the cache entry is wiped.
    $entity_init = field_test_create_stub_entity(1, 2, $this->instance['bundle']);
    $values = $this
      ->_generateTestFieldValues($this->field['cardinality']);
    $entity = clone $entity_init;
    $entity->{$this->field_name}[$langcode] = $values;
    field_attach_update($entity_type, $entity);
    $cache = cache_get($cid, 'cache_field');
    $this
      ->assertFalse(cache_get($cid, 'cache_field'), 'Cached: no cache entry on new revision creation');

    // Load, and check that a cache entry is present with the expected values.
    $entity = clone $entity_init;
    field_attach_load($entity_type, array(
      $entity->ftid => $entity,
    ));
    $cache = cache_get($cid, 'cache_field');
    $this
      ->assertEqual($cache->data[$this->field_name][$langcode], $values, 'Cached: correct cache entry on load');

    // Delete, and check that the cache entry is wiped.
    field_attach_delete($entity_type, $entity);
    $this
      ->assertFalse(cache_get($cid, 'cache_field'), 'Cached: no cache entry after delete');
  }

  /**
   * Test field_attach_validate().
   *
   * Verify that field_attach_validate() invokes the correct
   * hook_field_validate.
   */
  function testFieldAttachValidate() {
    $this
      ->createFieldWithInstance('_2');
    $entity_type = 'test_entity';
    $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
    $langcode = LANGUAGE_NONE;

    // Set up all but one values of the first field to generate errors.
    $values = array();
    for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
      $values[$delta]['value'] = -1;
    }

    // Arrange for item 1 not to generate an error
    $values[1]['value'] = 1;
    $entity->{$this->field_name}[$langcode] = $values;

    // Set up all values of the second field to generate errors.
    $values_2 = array();
    for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) {
      $values_2[$delta]['value'] = -1;
    }
    $entity->{$this->field_name_2}[$langcode] = $values_2;

    // Validate all fields.
    try {
      field_attach_validate($entity_type, $entity);
    } catch (FieldValidationException $e) {
      $errors = $e->errors;
    }
    foreach ($values as $delta => $value) {
      if ($value['value'] != 1) {
        $this
          ->assertIdentical($errors[$this->field_name][$langcode][$delta][0]['error'], 'field_test_invalid', "Error set on first field's value {$delta}");
        $this
          ->assertEqual(count($errors[$this->field_name][$langcode][$delta]), 1, "Only one error set on first field's value {$delta}");
        unset($errors[$this->field_name][$langcode][$delta]);
      }
      else {
        $this
          ->assertFalse(isset($errors[$this->field_name][$langcode][$delta]), "No error set on first field's value {$delta}");
      }
    }
    foreach ($values_2 as $delta => $value) {
      $this
        ->assertIdentical($errors[$this->field_name_2][$langcode][$delta][0]['error'], 'field_test_invalid', "Error set on second field's value {$delta}");
      $this
        ->assertEqual(count($errors[$this->field_name_2][$langcode][$delta]), 1, "Only one error set on second field's value {$delta}");
      unset($errors[$this->field_name_2][$langcode][$delta]);
    }
    $this
      ->assertEqual(count($errors[$this->field_name][$langcode]), 0, 'No extraneous errors set for first field');
    $this
      ->assertEqual(count($errors[$this->field_name_2][$langcode]), 0, 'No extraneous errors set for second field');

    // Validate a single field.
    $options = array(
      'field_name' => $this->field_name_2,
    );
    try {
      field_attach_validate($entity_type, $entity, $options);
    } catch (FieldValidationException $e) {
      $errors = $e->errors;
    }
    foreach ($values_2 as $delta => $value) {
      $this
        ->assertIdentical($errors[$this->field_name_2][$langcode][$delta][0]['error'], 'field_test_invalid', "Error set on second field's value {$delta}");
      $this
        ->assertEqual(count($errors[$this->field_name_2][$langcode][$delta]), 1, "Only one error set on second field's value {$delta}");
      unset($errors[$this->field_name_2][$langcode][$delta]);
    }
    $this
      ->assertFalse(isset($errors[$this->field_name]), 'No validation errors are set for the first field, despite it having errors');
    $this
      ->assertEqual(count($errors[$this->field_name_2][$langcode]), 0, 'No extraneous errors set for second field');

    // Check that cardinality is validated.
    $entity->{$this->field_name_2}[$langcode] = $this
      ->_generateTestFieldValues($this->field_2['cardinality'] + 1);

    // When validating all fields.
    try {
      field_attach_validate($entity_type, $entity);
    } catch (FieldValidationException $e) {
      $errors = $e->errors;
    }
    $this
      ->assertEqual($errors[$this->field_name_2][$langcode][0][0]['error'], 'field_cardinality', 'Cardinality validation failed.');

    // When validating a single field (the second field).
    try {
      field_attach_validate($entity_type, $entity, $options);
    } catch (FieldValidationException $e) {
      $errors = $e->errors;
    }
    $this
      ->assertEqual($errors[$this->field_name_2][$langcode][0][0]['error'], 'field_cardinality', 'Cardinality validation failed.');
  }

  /**
   * Test field_attach_form().
   *
   * This could be much more thorough, but it does verify that the correct
   * widgets show up.
   */
  function testFieldAttachForm() {
    $this
      ->createFieldWithInstance('_2');
    $entity_type = 'test_entity';
    $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
    $langcode = LANGUAGE_NONE;

    // When generating form for all fields.
    $form = array();
    $form_state = form_state_defaults();
    field_attach_form($entity_type, $entity, $form, $form_state);
    $this
      ->assertEqual($form[$this->field_name][$langcode]['#title'], $this->instance['label'], "First field's form title is {$this->instance['label']}");
    $this
      ->assertEqual($form[$this->field_name_2][$langcode]['#title'], $this->instance_2['label'], "Second field's form title is {$this->instance_2['label']}");
    for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {

      // field_test_widget uses 'textfield'
      $this
        ->assertEqual($form[$this->field_name][$langcode][$delta]['value']['#type'], 'textfield', "First field's form delta {$delta} widget is textfield");
    }
    for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) {

      // field_test_widget uses 'textfield'
      $this
        ->assertEqual($form[$this->field_name_2][$langcode][$delta]['value']['#type'], 'textfield', "Second field's form delta {$delta} widget is textfield");
    }

    // When generating form for a single field (the second field).
    $options = array(
      'field_name' => $this->field_name_2,
    );
    $form = array();
    $form_state = form_state_defaults();
    field_attach_form($entity_type, $entity, $form, $form_state, NULL, $options);
    $this
      ->assertFalse(isset($form[$this->field_name]), 'The first field does not exist in the form');
    $this
      ->assertEqual($form[$this->field_name_2][$langcode]['#title'], $this->instance_2['label'], "Second field's form title is {$this->instance_2['label']}");
    for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) {

      // field_test_widget uses 'textfield'
      $this
        ->assertEqual($form[$this->field_name_2][$langcode][$delta]['value']['#type'], 'textfield', "Second field's form delta {$delta} widget is textfield");
    }
  }

  /**
   * Test field_attach_submit().
   */
  function testFieldAttachSubmit() {
    $this
      ->createFieldWithInstance('_2');
    $entity_type = 'test_entity';
    $entity_init = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
    $langcode = LANGUAGE_NONE;

    // Build the form for all fields.
    $form = array();
    $form_state = form_state_defaults();
    field_attach_form($entity_type, $entity_init, $form, $form_state);

    // Simulate incoming values.
    // First field.
    $values = array();
    $weights = array();
    for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
      $values[$delta]['value'] = mt_rand(1, 127);

      // Assign random weight.
      do {
        $weight = mt_rand(0, $this->field['cardinality']);
      } while (in_array($weight, $weights));
      $weights[$delta] = $weight;
      $values[$delta]['_weight'] = $weight;
    }

    // Leave an empty value. 'field_test' fields are empty if empty().
    $values[1]['value'] = 0;

    // Second field.
    $values_2 = array();
    $weights_2 = array();
    for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) {
      $values_2[$delta]['value'] = mt_rand(1, 127);

      // Assign random weight.
      do {
        $weight = mt_rand(0, $this->field_2['cardinality']);
      } while (in_array($weight, $weights_2));
      $weights_2[$delta] = $weight;
      $values_2[$delta]['_weight'] = $weight;
    }

    // Leave an empty value. 'field_test' fields are empty if empty().
    $values_2[1]['value'] = 0;

    // Pretend the form has been built.
    drupal_prepare_form('field_test_entity_form', $form, $form_state);
    drupal_process_form('field_test_entity_form', $form, $form_state);
    $form_state['values'][$this->field_name][$langcode] = $values;
    $form_state['values'][$this->field_name_2][$langcode] = $values_2;

    // Call field_attach_submit() for all fields.
    $entity = clone $entity_init;
    field_attach_submit($entity_type, $entity, $form, $form_state);
    asort($weights);
    asort($weights_2);
    $expected_values = array();
    $expected_values_2 = array();
    foreach ($weights as $key => $value) {
      if ($key != 1) {
        $expected_values[] = array(
          'value' => $values[$key]['value'],
        );
      }
    }
    $this
      ->assertIdentical($entity->{$this->field_name}[$langcode], $expected_values, 'Submit filters empty values');
    foreach ($weights_2 as $key => $value) {
      if ($key != 1) {
        $expected_values_2[] = array(
          'value' => $values_2[$key]['value'],
        );
      }
    }
    $this
      ->assertIdentical($entity->{$this->field_name_2}[$langcode], $expected_values_2, 'Submit filters empty values');

    // Call field_attach_submit() for a single field (the second field).
    $options = array(
      'field_name' => $this->field_name_2,
    );
    $entity = clone $entity_init;
    field_attach_submit($entity_type, $entity, $form, $form_state, $options);
    $expected_values_2 = array();
    foreach ($weights_2 as $key => $value) {
      if ($key != 1) {
        $expected_values_2[] = array(
          'value' => $values_2[$key]['value'],
        );
      }
    }
    $this
      ->assertFalse(isset($entity->{$this->field_name}), 'The first field does not exist in the entity object');
    $this
      ->assertIdentical($entity->{$this->field_name_2}[$langcode], $expected_values_2, 'Submit filters empty values');
  }

}

Members

Name Modifiers Type Description Overridessort ascending
DrupalWebTestCase::$profile protected property The profile to install as a basis for testing. 20
DrupalWebTestCase::tearDown protected function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. 6
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
FieldAttachOtherTestCase::getInfo public static function
FieldAttachOtherTestCase::testFieldAttachView function Test field_attach_view() and field_attach_prepare_view().
FieldAttachOtherTestCase::testFieldAttachPrepareViewMultiple function Tests the 'multiple entity' behavior of field_attach_prepare_view().
FieldAttachOtherTestCase::testFieldAttachCache function Test field cache.
FieldAttachOtherTestCase::testFieldAttachValidate function Test field_attach_validate().
FieldAttachOtherTestCase::testFieldAttachForm function Test field_attach_form().
FieldAttachOtherTestCase::testFieldAttachSubmit function Test field_attach_submit().
FieldAttachTestCase::setUp function Set the default field storage backend for fields created during tests. Overrides FieldTestCase::setUp
FieldAttachTestCase::createFieldWithInstance function Create a field and an instance of it.
FieldTestCase::_generateTestFieldValues function Generate random values for a field_test field.
FieldTestCase::assertFieldValues function Assert that a field has the expected values in an entity.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
FieldTestCase::$default_storage property
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.