function FieldAccessTest::setUp

Same name in this branch

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

Generates a random database prefix and installs Drupal with the specified installation profile in Drupal\simpletest\WebTestBase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

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.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides WebTestBase::setUp

See also

Drupal\simpletest\WebTestBase::prepareDatabasePrefix()

Drupal\simpletest\WebTestBase::changeDatabasePrefix()

Drupal\simpletest\WebTestBase::prepareEnvironment()

File

drupal/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php, line 30
Definition of Drupal\field\Tests\FieldAccessTest.

Class

FieldAccessTest
Tests the functionality of field access.

Namespace

Drupal\field\Tests

Code

function setUp() {
  parent::setUp();
  $web_user = $this
    ->drupalCreateUser(array(
    'view test_view_field content',
  ));
  $this
    ->drupalLogin($web_user);

  // Create content type.
  $this->content_type_info = $this
    ->drupalCreateContentType();
  $this->content_type = $this->content_type_info->type;
  $this->field = array(
    'field_name' => 'test_view_field',
    'type' => 'text',
  );
  field_create_field($this->field);
  $this->instance = array(
    'field_name' => $this->field['field_name'],
    'entity_type' => 'node',
    'bundle' => $this->content_type,
  );
  field_create_instance($this->instance);

  // Assign display properties for the 'default' and 'teaser' view modes.
  foreach (array(
    'default',
    'teaser',
  ) as $view_mode) {
    entity_get_display('node', $this->content_type, $view_mode)
      ->setComponent($this->field['field_name'])
      ->save();
  }

  // Create test node.
  $this->test_view_field_value = 'This is some text';
  $settings = array();
  $settings['type'] = $this->content_type;
  $settings['title'] = 'Field view access test';
  $settings['test_view_field'] = array(
    array(
      'value' => $this->test_view_field_value,
    ),
  );
  $this->node = $this
    ->drupalCreateNode($settings);
}