You are here

protected function EntityReferenceFormatterTest::setUp in Zircon Profile 8

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

Performs setup tasks before each individual test method is run.

Overrides EntityUnitTestBase::setUp

File

core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php, line 64
Contains \Drupal\field\Tests\EntityReference\EntityReferenceFormatterTest.

Class

EntityReferenceFormatterTest
Tests the formatters functionality.

Namespace

Drupal\field\Tests\EntityReference

Code

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

  // Use Classy theme for testing markup output.
  \Drupal::service('theme_handler')
    ->install([
    'classy',
  ]);
  $this
    ->config('system.theme')
    ->set('default', 'classy')
    ->save();

  // Grant the 'view test entity' permission.
  $this
    ->installConfig(array(
    'user',
  ));
  Role::load(RoleInterface::ANONYMOUS_ID)
    ->grantPermission('view test entity')
    ->save();

  // The label formatter rendering generates links, so build the router.
  $this
    ->installSchema('system', 'router');
  $this->container
    ->get('router.builder')
    ->rebuild();
  $this
    ->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType, 'default', array(), FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);

  // Set up a field, so that the entity that'll be referenced bubbles up a
  // cache tag when rendering it entirely.
  entity_create('field_storage_config', array(
    'field_name' => 'body',
    'entity_type' => $this->entityType,
    'type' => 'text',
    'settings' => array(),
  ))
    ->save();
  entity_create('field_config', array(
    'entity_type' => $this->entityType,
    'bundle' => $this->bundle,
    'field_name' => 'body',
    'label' => 'Body',
  ))
    ->save();
  entity_get_display($this->entityType, $this->bundle, 'default')
    ->setComponent('body', array(
    'type' => 'text_default',
    'settings' => array(),
  ))
    ->save();
  entity_create('filter_format', array(
    'format' => 'full_html',
    'name' => 'Full HTML',
  ))
    ->save();

  // Create the entity to be referenced.
  $this->referencedEntity = entity_create($this->entityType, array(
    'name' => $this
      ->randomMachineName(),
  ));
  $this->referencedEntity->body = array(
    'value' => '<p>Hello, world!</p>',
    'format' => 'full_html',
  );
  $this->referencedEntity
    ->save();

  // Create another entity to be referenced but do not save it.
  $this->unsavedReferencedEntity = entity_create($this->entityType, array(
    'name' => $this
      ->randomMachineName(),
  ));
  $this->unsavedReferencedEntity->body = array(
    'value' => '<p>Hello, unsaved world!</p>',
    'format' => 'full_html',
  );
}