You are here

protected function FieldAccessTest::setUp in Zircon Profile 8.0

Same name in this branch
  1. 8.0 core/modules/field/src/Tests/FieldAccessTest.php \Drupal\field\Tests\FieldAccessTest::setUp()
  2. 8.0 core/modules/system/src/Tests/Entity/FieldAccessTest.php \Drupal\system\Tests\Entity\FieldAccessTest::setUp()
Same name and namespace in other branches
  1. 8 core/modules/field/src/Tests/FieldAccessTest.php \Drupal\field\Tests\FieldAccessTest::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 WebTestBase::setUp

File

core/modules/field/src/Tests/FieldAccessTest.php, line 38
Contains \Drupal\field\Tests\FieldAccessTest.

Class

FieldAccessTest
Tests Field access.

Namespace

Drupal\field\Tests

Code

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

  // Create content type.
  $content_type_info = $this
    ->drupalCreateContentType();
  $content_type = $content_type_info
    ->id();
  $field_storage = array(
    'field_name' => 'test_view_field',
    'entity_type' => 'node',
    'type' => 'text',
  );
  entity_create('field_storage_config', $field_storage)
    ->save();
  $field = array(
    'field_name' => $field_storage['field_name'],
    'entity_type' => 'node',
    'bundle' => $content_type,
  );
  entity_create('field_config', $field)
    ->save();

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

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