class FieldAttachOtherTest

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

Hierarchy

Expanded class hierarchy of FieldAttachOtherTest

File

drupal/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php, line 16
Definition of Drupal\field\Tests\FieldAttachOtherTest.

Namespace

Drupal\field\Tests
View source
class FieldAttachOtherTest extends FieldUnitTestBase {
  public static function getInfo() {
    return array(
      'name' => 'Field attach tests (other)',
      'description' => 'Test other Field Attach API functions.',
      'group' => 'Field API',
    );
  }
  public function setUp() {
    parent::setUp();
    $this
      ->createFieldWithInstance();
  }

  /**
   * Test field_attach_view() and field_attach_prepare_view().
   */
  function testFieldAttachView() {
    $this
      ->createFieldWithInstance('_2');
    $entity_type = 'test_entity';
    $entity_init = field_test_create_entity();
    $langcode = Language::LANGCODE_NOT_SPECIFIED;
    $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;
    $display = entity_get_display($entity_type, $entity
      ->bundle(), 'full');
    $displays = array(
      $entity
        ->bundle() => $display,
    );
    $formatter_setting = $this
      ->randomName();
    $display_options = array(
      'label' => 'above',
      'type' => 'field_test_default',
      'settings' => array(
        'test_formatter_setting' => $formatter_setting,
      ),
    );
    $display
      ->setComponent($this->field['field_name'], $display_options);
    $formatter_setting_2 = $this
      ->randomName();
    $display_options_2 = array(
      'label' => 'above',
      'type' => 'field_test_default',
      'settings' => array(
        'test_formatter_setting' => $formatter_setting_2,
      ),
    );
    $display
      ->setComponent($this->field_2['field_name'], $display_options_2);

    // View all fields.
    field_attach_prepare_view($entity_type, array(
      $entity->ftid => $entity,
    ), $displays);
    $entity->content = field_attach_view($entity, $display);
    $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,
    ), $displays, $langcode, $options);
    $entity->content = field_attach_view($entity, $display, $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;
    $display_options['label'] = 'hidden';
    $display
      ->setComponent($this->field['field_name'], $display_options);
    field_attach_prepare_view($entity_type, array(
      $entity->ftid => $entity,
    ), $displays);
    $entity->content = field_attach_view($entity, $display);
    $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;
    $display
      ->removeComponent($this->field['field_name']);
    field_attach_prepare_view($entity_type, array(
      $entity->ftid => $entity,
    ), $displays);
    $entity->content = field_attach_view($entity, $display);
    $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();
    $display
      ->setComponent($this->field['field_name'], array(
      'label' => 'above',
      'type' => 'field_test_multiple',
      'settings' => array(
        'test_formatter_setting_multiple' => $formatter_setting,
      ),
    ));
    field_attach_prepare_view($entity_type, array(
      $entity->ftid => $entity,
    ), $displays);
    $entity->content = field_attach_view($entity, $display);
    $output = drupal_render($entity->content);
    $expected_output = $formatter_setting;
    foreach ($values as $delta => $value) {
      $expected_output .= "|{$delta}:{$value['value']}";
    }
    $this->content = $output;
    $this
      ->assertRaw($expected_output, "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();
    $display
      ->setComponent($this->field['field_name'], array(
      'label' => 'above',
      'type' => 'field_test_with_prepare_view',
      'settings' => array(
        'test_formatter_setting_additional' => $formatter_setting,
      ),
    ));
    field_attach_prepare_view($entity_type, array(
      $entity->ftid => $entity,
    ), $displays);
    $entity->content = field_attach_view($entity, $display);
    $output = drupal_render($entity->content);
    $this->content = $output;
    foreach ($values as $delta => $value) {
      $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, $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::LANGCODE_NOT_SPECIFIED;

    // Set the instance to be hidden.
    $display = entity_get_display('test_entity', 'test_bundle', 'full')
      ->removeComponent($this->field['field_name']);

    // 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';
    field_create_instance($this->instance2);
    $display_2 = entity_get_display('test_entity', 'test_bundle_2', 'full')
      ->setComponent($this->field['field_name'], array(
      'type' => 'field_test_with_prepare_view',
      'settings' => array(
        'test_formatter_setting_additional' => $formatter_setting,
      ),
    ));
    $displays = array(
      'test_bundle' => $display,
      'test_bundle_2' => $display_2,
    );

    // Create one entity in each bundle.
    $entity1_init = field_test_create_entity(1, 1, 'test_bundle');
    $values1 = $this
      ->_generateTestFieldValues($this->field['cardinality']);
    $entity1_init->{$this->field_name}[$langcode] = $values1;
    $entity2_init = field_test_create_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;
    $entities = array(
      $entity1->ftid => $entity1,
      $entity2->ftid => $entity2,
    );
    field_attach_prepare_view($entity_type, $entities, $displays);
    $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;
    $entities = array(
      $entity1->ftid => $entity1,
      $entity2->ftid => $entity2,
    );
    field_attach_prepare_view($entity_type, $entities, $displays);
    $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_entity(1, 1, $this->instance['bundle']);
    $langcode = Language::LANGCODE_NOT_SPECIFIED;
    $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('field')
      ->get($cid), '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);
    $this
      ->assertFalse(cache('field')
      ->get($cid), '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('field')
      ->get($cid), 'Non-cached: no cache entry on load');

    // Cacheable entity type.
    $entity_type = 'test_cacheable_entity';
    $entity_init = entity_create($entity_type, array(
      'ftid' => 1,
      'ftvid' => 1,
      'fttype' => $this->instance['bundle'],
    ));
    $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('field')
      ->get($cid), '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);
    $this
      ->assertFalse(cache('field')
      ->get($cid), '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('field')
      ->get($cid);
    $this
      ->assertFalse(cache('field')
      ->get($cid), '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('field')
      ->get($cid);
    $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);
    $this
      ->assertFalse(cache('field')
      ->get($cid), '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('field')
      ->get($cid);
    $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 = entity_create($entity_type, array(
      'ftid' => 1,
      'ftvid' => 2,
      'fttype' => $this->instance['bundle'],
    ));
    $values = $this
      ->_generateTestFieldValues($this->field['cardinality']);
    $entity = clone $entity_init;
    $entity->{$this->field_name}[$langcode] = $values;
    field_attach_update($entity);
    $cache = cache('field')
      ->get($cid);
    $this
      ->assertFalse(cache('field')
      ->get($cid), '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('field')
      ->get($cid);
    $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);
    $this
      ->assertFalse(cache('field')
      ->get($cid), '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_entity(0, 0, $this->instance['bundle']);
    $langcode = Language::LANGCODE_NOT_SPECIFIED;

    // 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);
    } 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, $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);
    } 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, $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_entity(0, 0, $this->instance['bundle']);
    $langcode = Language::LANGCODE_NOT_SPECIFIED;

    // When generating form for all fields.
    $form = array();
    $form_state = form_state_defaults();
    $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle'], 'default');
    field_attach_form($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();
    $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle'], 'default');
    field_attach_form($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_extract_form_values().
   */
  function testFieldAttachExtractFormValues() {
    $this
      ->createFieldWithInstance('_2');
    $entity_type = 'test_entity';
    $entity_init = field_test_create_entity(0, 0, $this->instance['bundle']);
    $langcode = Language::LANGCODE_NOT_SPECIFIED;

    // Build the form for all fields.
    $form = array();
    $form_state = form_state_defaults();
    $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle'], 'default');
    field_attach_form($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_extract_form_values() for all fields.
    $entity = clone $entity_init;
    field_attach_extract_form_values($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_extract_form_values() for a single field (the second field).
    $options = array(
      'field_name' => $this->field_name_2,
    );
    $entity = clone $entity_init;
    field_attach_extract_form_values($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

Namesort descending Modifiers Type Description Overrides
DrupalUnitTestBase::$keyValueFactory protected property A KeyValueMemoryFactory instance to use when building the container.
DrupalUnitTestBase::$moduleFiles private property
DrupalUnitTestBase::$themeData private property
DrupalUnitTestBase::$themeFiles private property
DrupalUnitTestBase::containerBuild public function Sets up the base service container for this test. 1
DrupalUnitTestBase::disableModules protected function Disables modules for this test.
DrupalUnitTestBase::enableModules protected function Enables modules for this test.
DrupalUnitTestBase::installConfig protected function Installs default configuration for a given list of modules.
DrupalUnitTestBase::installSchema protected function Installs a specific table from a module schema definition.
DrupalUnitTestBase::tearDown protected function Deletes created files, database tables, and reverts all environment changes. Overrides TestBase::tearDown 2
DrupalUnitTestBase::__construct function Overrides \Drupal\simpletest\UnitTestBase::__construct(). Overrides UnitTestBase::__construct
FieldAttachOtherTest::getInfo public static function
FieldAttachOtherTest::setUp public function Set the default field storage backend for fields created during tests. Overrides FieldUnitTestBase::setUp
FieldAttachOtherTest::testFieldAttachCache function Test field cache.
FieldAttachOtherTest::testFieldAttachExtractFormValues function Test field_attach_extract_form_values().
FieldAttachOtherTest::testFieldAttachForm function Test field_attach_form().
FieldAttachOtherTest::testFieldAttachPrepareViewMultiple function Tests the 'multiple entity' behavior of field_attach_prepare_view().
FieldAttachOtherTest::testFieldAttachValidate function Test field_attach_validate().
FieldAttachOtherTest::testFieldAttachView function Test field_attach_view() and field_attach_prepare_view().
FieldUnitTestBase::$content protected property A string for assert raw and text helper methods.
FieldUnitTestBase::$modules public static property Modules to enable. Overrides DrupalUnitTestBase::$modules 15
FieldUnitTestBase::assertFieldValues function Assert that a field has the expected values in an entity.
FieldUnitTestBase::assertNoRaw protected function Pass if the raw text IS NOT found in set string.
FieldUnitTestBase::assertNoText protected function Pass if the text IS NOT found in set string.
FieldUnitTestBase::assertRaw protected function Pass if the raw text IS found in set string.
FieldUnitTestBase::assertText protected function Pass if the text IS found in set string.
FieldUnitTestBase::createFieldWithInstance function Create a field and an instance of it.
FieldUnitTestBase::_generateTestFieldValues function Generate random values for a field_test field.
TestBase::$assertions protected property Assertions thrown in that test case.
TestBase::$configImporter protected property The config importer that can used in a test. 1
TestBase::$container protected property The dependency injection container used in the test. 1
TestBase::$databasePrefix protected property The database prefix of this test run.
TestBase::$dieOnFail public property Whether to die in case any test assertion fails.
TestBase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
TestBase::$originalPrefix protected property The original database prefix when running inside Simpletest.
TestBase::$originalSettings protected property The settings array.
TestBase::$public_files_directory protected property The public file directory for the test environment.
TestBase::$results public property Current results of this test case.
TestBase::$setup protected property Flag to indicate whether the test has been set up.
TestBase::$setupDatabasePrefix protected property
TestBase::$setupEnvironment protected property
TestBase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
TestBase::$testId protected property The test run ID.
TestBase::$timeLimit protected property Time limit for the test.
TestBase::$verbose protected property TRUE if verbose debugging is enabled.
TestBase::$verboseClassName protected property Safe class name for use in verbose output filenames.
TestBase::$verboseDirectory protected property Directory where verbose output files are put.
TestBase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
TestBase::$verboseId protected property Incrementing identifier for verbose output filenames.
TestBase::assert protected function Internal helper: stores the assert.
TestBase::assertEqual protected function Check to see if two values are equal.
TestBase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
TestBase::assertIdentical protected function Check to see if two values are identical.
TestBase::assertIdenticalObject protected function Checks to see if two objects are identical.
TestBase::assertNotEqual protected function Check to see if two values are not equal.
TestBase::assertNotIdentical protected function Check to see if two values are not identical.
TestBase::assertNotNull protected function Check to see if a value is not NULL.
TestBase::assertNull protected function Check to see if a value is NULL.
TestBase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
TestBase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
TestBase::checkRequirements protected function Checks the matching requirements for Test. 4
TestBase::configImporter public function Returns a ConfigImporter object to import test importing of configuration. 1
TestBase::copyConfig public function Copies configuration objects from source storage to target storage.
TestBase::deleteAssert public static function Delete an assertion record by message ID.
TestBase::error protected function Fire an error assertion. 1
TestBase::errorHandler public function Handle errors during test runs.
TestBase::exceptionHandler protected function Handle exceptions.
TestBase::fail protected function Fire an assertion that is always negative.
TestBase::filePreDeleteCallback public static function Ensures test files are deletable within file_unmanaged_delete_recursive().
TestBase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
TestBase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
TestBase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
TestBase::insertAssert public static function Store an assertion from outside the testing context.
TestBase::pass protected function Fire an assertion that is always positive.
TestBase::prepareConfigDirectories protected function Create and set new configuration directories. 1
TestBase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
TestBase::prepareEnvironment protected function Prepares the current environment for running the test.
TestBase::randomName public static function Generates a random string containing letters and numbers.
TestBase::randomObject public static function Generates a random PHP object.
TestBase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
TestBase::rebuildContainer protected function Rebuild drupal_container(). 1
TestBase::run public function Run all tests in this class.
TestBase::settingsSet protected function Changes in memory settings.
TestBase::verbose protected function Logs verbose message in a text file.
UnitTestBase::$configDirectories protected property