You are here

protected function PagePreviewTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/PagePreviewTest.php \Drupal\node\Tests\PagePreviewTest::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 NodeTestBase::setUp

File

core/modules/node/src/Tests/PagePreviewTest.php, line 43
Contains \Drupal\node\Tests\PagePreviewTest.

Class

PagePreviewTest
Tests the node entity preview functionality.

Namespace

Drupal\node\Tests

Code

protected function setUp() {
  parent::setUp();
  $this
    ->addDefaultCommentField('node', 'page');
  $web_user = $this
    ->drupalCreateUser(array(
    'edit own page content',
    'create page content',
  ));
  $this
    ->drupalLogin($web_user);

  // Add a vocabulary so we can test different view modes.
  $vocabulary = entity_create('taxonomy_vocabulary', array(
    'name' => $this
      ->randomMachineName(),
    'description' => $this
      ->randomMachineName(),
    'vid' => $this
      ->randomMachineName(),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    'help' => '',
  ));
  $vocabulary
    ->save();
  $this->vocabulary = $vocabulary;

  // Add a term to the vocabulary.
  $term = entity_create('taxonomy_term', array(
    'name' => $this
      ->randomMachineName(),
    'description' => $this
      ->randomMachineName(),
    'vid' => $this->vocabulary
      ->id(),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ));
  $term
    ->save();
  $this->term = $term;

  // Create an image field.
  FieldStorageConfig::create([
    'field_name' => 'field_image',
    'entity_type' => 'node',
    'type' => 'image',
    'settings' => [],
    'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED,
  ])
    ->save();
  $field_config = FieldConfig::create([
    'field_name' => 'field_image',
    'label' => 'Images',
    'entity_type' => 'node',
    'bundle' => 'page',
    'required' => FALSE,
    'settings' => [],
  ]);
  $field_config
    ->save();

  // Create a field.
  $this->fieldName = Unicode::strtolower($this
    ->randomMachineName());
  $handler_settings = array(
    'target_bundles' => array(
      $this->vocabulary
        ->id() => $this->vocabulary
        ->id(),
    ),
    'auto_create' => TRUE,
  );
  $this
    ->createEntityReferenceField('node', 'page', $this->fieldName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  entity_get_form_display('node', 'page', 'default')
    ->setComponent($this->fieldName, array(
    'type' => 'entity_reference_autocomplete_tags',
  ))
    ->save();

  // Show on default display and teaser.
  entity_get_display('node', 'page', 'default')
    ->setComponent($this->fieldName, array(
    'type' => 'entity_reference_label',
  ))
    ->save();
  entity_get_display('node', 'page', 'teaser')
    ->setComponent($this->fieldName, array(
    'type' => 'entity_reference_label',
  ))
    ->save();
  entity_get_form_display('node', 'page', 'default')
    ->setComponent('field_image', array(
    'type' => 'image_image',
    'settings' => [],
  ))
    ->save();
  entity_get_display('node', 'page', 'default')
    ->setComponent('field_image')
    ->save();
}