You are here

protected function HandlerFieldFieldTest::setUp in Views (for Drupal 7) 8.3

Sets up a Drupal site for running functional and integration tests.

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Overrides ViewTestBase::setUp

File

lib/Drupal/views/Tests/Field/HandlerFieldFieldTest.php, line 30
Definition of Drupal\views\Test\Field\HandlerFieldFieldTest.

Class

HandlerFieldFieldTest
Tests the field_field handler. @TODO Check a entity-type with bundles Check a entity-type without bundles Check locale:disabled, locale:enabled and locale:enabled with another language Check revisions

Namespace

Drupal\views\Tests\Field

Code

protected function setUp() {
  parent::setUp();

  // Setup basic fields.
  $this
    ->setUpFields(3);

  // Setup a field with cardinality > 1.
  $this->fields[3] = $field = field_create_field(array(
    'field_name' => 'field_name_3',
    'type' => 'text',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  ));

  // Setup a field that will have no value.
  $this->fields[4] = $field = field_create_field(array(
    'field_name' => 'field_name_4',
    'type' => 'text',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  ));
  $this
    ->setUpInstances();
  $this
    ->clearViewsCaches();

  // Create some nodes.
  $this->nodes = array();
  for ($i = 0; $i < 3; $i++) {
    $edit = array(
      'type' => 'page',
    );
    for ($key = 0; $key < 3; $key++) {
      $field = $this->fields[$key];
      $edit[$field['field_name']][LANGUAGE_NOT_SPECIFIED][0]['value'] = $this
        ->randomName(8);
    }
    for ($j = 0; $j < 5; $j++) {
      $edit[$this->fields[3]['field_name']][LANGUAGE_NOT_SPECIFIED][$j]['value'] = $this
        ->randomName(8);
    }

    // Set this field to be empty.
    $edit[$this->fields[4]['field_name']] = array(
      LANGUAGE_NOT_SPECIFIED => array(
        0 => array(
          'value' => NULL,
        ),
      ),
    );
    $this->nodes[$i] = $this
      ->drupalCreateNode($edit);
  }
  foreach ($this->fields as $key => $field) {
    $this->view->display_handler->display['display_options']['fields'][$field['field_name']]['id'] = $field['field_name'];
    $this->view->display_handler->display['display_options']['fields'][$field['field_name']]['table'] = 'field_data_' . $field['field_name'];
    $this->view->display_handler->display['display_options']['fields'][$field['field_name']]['field'] = $field['field_name'];
  }
}