You are here

protected function EntityCacheTagsTestBase::setUp in Zircon Profile 8

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

5 calls to EntityCacheTagsTestBase::setUp()
CommentCacheTagsTest::setUp in core/modules/comment/src/Tests/CommentCacheTagsTest.php
Sets up a Drupal site for running functional and integration tests.
FeedCacheTagsTest::setUp in core/modules/aggregator/src/Tests/FeedCacheTagsTest.php
Sets up a Drupal site for running functional and integration tests.
ItemCacheTagsTest::setUp in core/modules/aggregator/src/Tests/ItemCacheTagsTest.php
Sets up a Drupal site for running functional and integration tests.
ShortcutCacheTagsTest::setUp in core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php
Sets up a Drupal site for running functional and integration tests.
UserCacheTagsTest::setUp in core/modules/user/src/Tests/UserCacheTagsTest.php
Sets up a Drupal site for running functional and integration tests.
5 methods override EntityCacheTagsTestBase::setUp()
CommentCacheTagsTest::setUp in core/modules/comment/src/Tests/CommentCacheTagsTest.php
Sets up a Drupal site for running functional and integration tests.
FeedCacheTagsTest::setUp in core/modules/aggregator/src/Tests/FeedCacheTagsTest.php
Sets up a Drupal site for running functional and integration tests.
ItemCacheTagsTest::setUp in core/modules/aggregator/src/Tests/ItemCacheTagsTest.php
Sets up a Drupal site for running functional and integration tests.
ShortcutCacheTagsTest::setUp in core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php
Sets up a Drupal site for running functional and integration tests.
UserCacheTagsTest::setUp in core/modules/user/src/Tests/UserCacheTagsTest.php
Sets up a Drupal site for running functional and integration tests.

File

core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php, line 58
Contains \Drupal\system\Tests\Entity\EntityCacheTagsTestBase.

Class

EntityCacheTagsTestBase
Provides helper methods for Entity cache tags tests.

Namespace

Drupal\system\Tests\Entity

Code

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

  // Give anonymous users permission to view test entities, so that we can
  // verify the cache tags of cached versions of test entity pages.
  $user_role = Role::load(RoleInterface::ANONYMOUS_ID);
  $user_role
    ->grantPermission('view test entity');
  $user_role
    ->save();

  // Create an entity.
  $this->entity = $this
    ->createEntity();

  // If this is an entity with field UI enabled, then add a configurable
  // field. We will use this configurable field in later tests to ensure that
  // field configuration invalidate render cache entries.
  if ($this->entity
    ->getEntityType()
    ->get('field_ui_base_route')) {

    // Add field, so we can modify the field storage and field entities to
    // verify that changes to those indeed clear cache tags.
    entity_create('field_storage_config', array(
      'field_name' => 'configurable_field',
      'entity_type' => $this->entity
        ->getEntityTypeId(),
      'type' => 'test_field',
      'settings' => array(),
    ))
      ->save();
    entity_create('field_config', array(
      'entity_type' => $this->entity
        ->getEntityTypeId(),
      'bundle' => $this->entity
        ->bundle(),
      'field_name' => 'configurable_field',
      'label' => 'Configurable field',
      'settings' => array(),
    ))
      ->save();

    // Reload the entity now that a new field has been added to it.
    $storage = $this->container
      ->get('entity.manager')
      ->getStorage($this->entity
      ->getEntityTypeId());
    $storage
      ->resetCache();
    $this->entity = $storage
      ->load($this->entity
      ->id());
  }

  // Create a referencing and a non-referencing entity.
  list($this->referencingEntity, $this->nonReferencingEntity, ) = $this
    ->createReferenceTestEntities($this->entity);
}