You are here

protected function HandlerFieldFieldTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php \Drupal\field\Tests\Views\HandlerFieldFieldTest::setUp()

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 FieldTestBase::setUp

File

core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php, line 48
Contains \Drupal\field\Tests\Views\HandlerFieldFieldTest.

Class

HandlerFieldFieldTest
Tests the field itself of the Field integration.

Namespace

Drupal\field\Tests\Views

Code

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

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

  // Setup a field with cardinality > 1.
  $this->fieldStorages[3] = entity_create('field_storage_config', array(
    'field_name' => 'field_name_3',
    'entity_type' => 'node',
    'type' => 'string',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
  ));
  $this->fieldStorages[3]
    ->save();

  // Setup a field that will have no value.
  $this->fieldStorages[4] = entity_create('field_storage_config', array(
    'field_name' => 'field_name_4',
    'entity_type' => 'node',
    'type' => 'string',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
  ));
  $this->fieldStorages[4]
    ->save();

  // Setup a text field.
  $this->fieldStorages[5] = entity_create('field_storage_config', array(
    'field_name' => 'field_name_5',
    'entity_type' => 'node',
    'type' => 'text',
  ));
  $this->fieldStorages[5]
    ->save();

  // Setup a text field with access control.
  // @see field_test_entity_field_access()
  $this->fieldStorages[6] = entity_create('field_storage_config', array(
    'field_name' => 'field_no_view_access',
    'entity_type' => 'node',
    'type' => 'text',
  ));
  $this->fieldStorages[6]
    ->save();
  $this
    ->setUpFields();

  // Create some nodes.
  $this->nodes = array();
  for ($i = 0; $i < 3; $i++) {
    $edit = array(
      'type' => 'page',
    );
    foreach (array(
      0,
      1,
      2,
      5,
    ) as $key) {
      $field_storage = $this->fieldStorages[$key];
      $edit[$field_storage
        ->getName()][0]['value'] = $this
        ->randomMachineName(8);
    }

    // Add a hidden value for the no-view field.
    $edit[$this->fieldStorages[6]
      ->getName()][0]['value'] = 'ssh secret squirrel';
    for ($j = 0; $j < 5; $j++) {
      $edit[$this->fieldStorages[3]
        ->getName()][$j]['value'] = $this
        ->randomMachineName(8);
    }

    // Set this field to be empty.
    $edit[$this->fieldStorages[4]
      ->getName()] = array(
      array(
        'value' => NULL,
      ),
    );
    $this->nodes[$i] = $this
      ->drupalCreateNode($edit);
  }
  $this->container
    ->get('views.views_data')
    ->clear();
}