From 646584b3f718897179589f4f014531e3d9365331 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Mon, 25 Jun 2018 13:51:30 +0100
Subject: [PATCH] Issue #2946419 by vaplas, Lendude, Mile23: Entity: Convert
 system functional tests to phpunit

---
 .../src/Functional/FeedCacheTagsTest.php      |   2 +-
 .../src/Functional/ItemCacheTagsTest.php      |   2 +-
 .../Functional/BlockContentCacheTagsTest.php  |   2 +-
 .../src/Functional}/CommentCacheTagsTest.php  |   5 +-
 .../Update/ContentTranslationUpdateTest.php   |   2 +-
 .../src/Functional/MediaCacheTagsTest.php     |   2 +-
 .../src/Functional/NodeCacheTagsTest.php      |   2 +-
 .../src/Functional/ShortcutCacheTagsTest.php  |   2 +-
 .../Entity/EntityDefinitionTestTrait.php      |   7 +
 .../Entity/EntityWithUriCacheTagsTestBase.php |   7 +
 .../src/Entity/EntityTestUpdate.php           |   3 +-
 .../Entity/EntityCacheTagsTestBase.php        |   2 +-
 .../src/Functional}/Entity/EntityFormTest.php |   6 +-
 .../Entity/EntityTranslationFormTest.php      |   6 +-
 .../Entity/EntityWithUriCacheTagsTestBase.php | 149 +++++++++
 .../Traits/EntityDefinitionTestTrait.php      | 299 ++++++++++++++++++
 ...ntEntityStorageSchemaConverterTestBase.php |   2 +-
 .../EntityUpdateAddRevisionDefaultTest.php    |   2 +-
 ...dateAddRevisionTranslationAffectedTest.php |   2 +-
 ...UpdateToRevisionableAndPublishableTest.php |   2 +-
 .../src/Functional/TermCacheTagsTest.php      |   2 +-
 .../src/Functional/UserCacheTagsTest.php      |   2 +-
 ...sEntitySchemaSubscriberIntegrationTest.php |   2 +-
 .../Entity/EntityDefinitionUpdateTest.php     |   2 +-
 24 files changed, 489 insertions(+), 25 deletions(-)
 rename core/modules/comment/{src/Tests => tests/src/Functional}/CommentCacheTagsTest.php (96%)
 rename core/modules/system/{src/Tests => tests/src/Functional}/Entity/EntityFormTest.php (98%)
 rename core/modules/system/{src/Tests => tests/src/Functional}/Entity/EntityTranslationFormTest.php (97%)
 create mode 100644 core/modules/system/tests/src/Functional/Entity/EntityWithUriCacheTagsTestBase.php
 create mode 100644 core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php

diff --git a/core/modules/aggregator/tests/src/Functional/FeedCacheTagsTest.php b/core/modules/aggregator/tests/src/Functional/FeedCacheTagsTest.php
index dc0aab9263e7..0cf6d1d03121 100644
--- a/core/modules/aggregator/tests/src/Functional/FeedCacheTagsTest.php
+++ b/core/modules/aggregator/tests/src/Functional/FeedCacheTagsTest.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\aggregator\Functional;
 
 use Drupal\aggregator\Entity\Feed;
-use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
+use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
 use Drupal\user\Entity\Role;
 use Drupal\user\RoleInterface;
 
diff --git a/core/modules/aggregator/tests/src/Functional/ItemCacheTagsTest.php b/core/modules/aggregator/tests/src/Functional/ItemCacheTagsTest.php
index 09da3436827b..edd2ac32a92c 100644
--- a/core/modules/aggregator/tests/src/Functional/ItemCacheTagsTest.php
+++ b/core/modules/aggregator/tests/src/Functional/ItemCacheTagsTest.php
@@ -5,7 +5,7 @@
 use Drupal\aggregator\Entity\Feed;
 use Drupal\aggregator\Entity\Item;
 use Drupal\Core\Cache\CacheBackendInterface;
-use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
+use Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase;
 use Drupal\user\Entity\Role;
 use Drupal\user\RoleInterface;
 
diff --git a/core/modules/block_content/tests/src/Functional/BlockContentCacheTagsTest.php b/core/modules/block_content/tests/src/Functional/BlockContentCacheTagsTest.php
index 683500928508..ea5dd2873deb 100644
--- a/core/modules/block_content/tests/src/Functional/BlockContentCacheTagsTest.php
+++ b/core/modules/block_content/tests/src/Functional/BlockContentCacheTagsTest.php
@@ -7,7 +7,7 @@
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Language\LanguageInterface;
-use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
+use Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase;
 use Symfony\Component\HttpFoundation\Request;
 
 /**
diff --git a/core/modules/comment/src/Tests/CommentCacheTagsTest.php b/core/modules/comment/tests/src/Functional/CommentCacheTagsTest.php
similarity index 96%
rename from core/modules/comment/src/Tests/CommentCacheTagsTest.php
rename to core/modules/comment/tests/src/Functional/CommentCacheTagsTest.php
index 12e0ef8451bc..0b0f4863afe7 100644
--- a/core/modules/comment/src/Tests/CommentCacheTagsTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentCacheTagsTest.php
@@ -1,14 +1,15 @@
 <?php
 
-namespace Drupal\comment\Tests;
+namespace Drupal\Tests\comment\Functional;
 
 use Drupal\comment\CommentInterface;
 use Drupal\comment\CommentManagerInterface;
 use Drupal\comment\Entity\Comment;
+use Drupal\comment\Tests\CommentTestTrait;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\entity_test\Entity\EntityTest;
 use Drupal\field\Entity\FieldConfig;
-use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
+use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
 use Drupal\user\Entity\Role;
 use Drupal\user\RoleInterface;
 
diff --git a/core/modules/content_translation/tests/src/Functional/Update/ContentTranslationUpdateTest.php b/core/modules/content_translation/tests/src/Functional/Update/ContentTranslationUpdateTest.php
index 25be0def2411..34fc579903f2 100644
--- a/core/modules/content_translation/tests/src/Functional/Update/ContentTranslationUpdateTest.php
+++ b/core/modules/content_translation/tests/src/Functional/Update/ContentTranslationUpdateTest.php
@@ -4,7 +4,7 @@
 
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
-use Drupal\system\Tests\Entity\EntityDefinitionTestTrait;
+use Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait;
 
 /**
  * Tests the upgrade path for the Content Translation module.
diff --git a/core/modules/media/tests/src/Functional/MediaCacheTagsTest.php b/core/modules/media/tests/src/Functional/MediaCacheTagsTest.php
index e1b6cf7ef1b5..ece89f43eae2 100644
--- a/core/modules/media/tests/src/Functional/MediaCacheTagsTest.php
+++ b/core/modules/media/tests/src/Functional/MediaCacheTagsTest.php
@@ -4,7 +4,7 @@
 
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\media\Entity\Media;
-use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
+use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
 
 /**
  * Tests the media items cache tags.
diff --git a/core/modules/node/tests/src/Functional/NodeCacheTagsTest.php b/core/modules/node/tests/src/Functional/NodeCacheTagsTest.php
index 5e8b29fe7eb5..6cda724cc446 100644
--- a/core/modules/node/tests/src/Functional/NodeCacheTagsTest.php
+++ b/core/modules/node/tests/src/Functional/NodeCacheTagsTest.php
@@ -5,7 +5,7 @@
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\node\Entity\Node;
 use Drupal\node\Entity\NodeType;
-use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
+use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
 
 /**
  * Tests the Node entity's cache tags.
diff --git a/core/modules/shortcut/tests/src/Functional/ShortcutCacheTagsTest.php b/core/modules/shortcut/tests/src/Functional/ShortcutCacheTagsTest.php
index e2d6a226f229..a2282b1ddfc8 100644
--- a/core/modules/shortcut/tests/src/Functional/ShortcutCacheTagsTest.php
+++ b/core/modules/shortcut/tests/src/Functional/ShortcutCacheTagsTest.php
@@ -4,7 +4,7 @@
 
 use Drupal\Core\Cache\CacheBackendInterface;
 use Drupal\shortcut\Entity\Shortcut;
-use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
+use Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase;
 use Drupal\user\Entity\Role;
 use Drupal\user\RoleInterface;
 
diff --git a/core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php b/core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php
index 380c1e66eda4..0817aa79811e 100644
--- a/core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php
+++ b/core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php
@@ -5,8 +5,15 @@
 use Drupal\Core\Field\BaseFieldDefinition;
 use Drupal\entity_test\FieldStorageDefinition;
 
+@trigger_error(__NAMESPACE__ . '\EntityDefinitionTestTrait is deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait. See https://www.drupal.org/node/2946549.', E_USER_DEPRECATED);
+
 /**
  * Provides some test methods used to update existing entity definitions.
+ *
+ * @deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.0.
+ * Use \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait.
+ *
+ * @see https://www.drupal.org/node/2946549
  */
 trait EntityDefinitionTestTrait {
 
diff --git a/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php
index 997a4d28f6f1..3fd9be010e2a 100644
--- a/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php
+++ b/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php
@@ -7,8 +7,15 @@
 use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\field\Entity\FieldConfig;
 
+@trigger_error(__NAMESPACE__ . '\EntityWithUriCacheTagsTestBase is deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase. See https://www.drupal.org/node/2946549.', E_USER_DEPRECATED);
+
 /**
  * Provides helper methods for Entity cache tags tests; for entities with URIs.
+ *
+ * @deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.0.
+ * Use \Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase.
+ *
+ * @see https://www.drupal.org/node/2946549
  */
 abstract class EntityWithUriCacheTagsTestBase extends EntityCacheTagsTestBase {
 
diff --git a/core/modules/system/tests/modules/entity_test_update/src/Entity/EntityTestUpdate.php b/core/modules/system/tests/modules/entity_test_update/src/Entity/EntityTestUpdate.php
index 286e8e62bdcd..631a89e54385 100644
--- a/core/modules/system/tests/modules/entity_test_update/src/Entity/EntityTestUpdate.php
+++ b/core/modules/system/tests/modules/entity_test_update/src/Entity/EntityTestUpdate.php
@@ -13,7 +13,8 @@
  *
  * This entity type starts out non-revisionable and non-translatable, but during
  * an update test it can be made revisionable and translatable using the helper
- * methods from \Drupal\system\Tests\Entity\EntityDefinitionTestTrait.
+ * methods from
+ * \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait.
  *
  * @ContentEntityType(
  *   id = "entity_test_update",
diff --git a/core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php b/core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php
index aa9452a4bacc..c043a2486e14 100644
--- a/core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php
+++ b/core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php
@@ -10,7 +10,7 @@
 use Drupal\Core\Url;
 use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\field\Entity\FieldConfig;
-use Drupal\system\Tests\Cache\PageCacheTagsTestBase;
+use Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase;
 use Drupal\user\Entity\Role;
 use Drupal\user\RoleInterface;
 
diff --git a/core/modules/system/src/Tests/Entity/EntityFormTest.php b/core/modules/system/tests/src/Functional/Entity/EntityFormTest.php
similarity index 98%
rename from core/modules/system/src/Tests/Entity/EntityFormTest.php
rename to core/modules/system/tests/src/Functional/Entity/EntityFormTest.php
index 2ebc35061782..4f0b7f0f71fc 100644
--- a/core/modules/system/src/Tests/Entity/EntityFormTest.php
+++ b/core/modules/system/tests/src/Functional/Entity/EntityFormTest.php
@@ -1,16 +1,16 @@
 <?php
 
-namespace Drupal\system\Tests\Entity;
+namespace Drupal\Tests\system\Functional\Entity;
 
 use Drupal\language\Entity\ConfigurableLanguage;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
 
 /**
  * Tests the entity form.
  *
  * @group Entity
  */
-class EntityFormTest extends WebTestBase {
+class EntityFormTest extends BrowserTestBase {
 
   /**
    * Modules to enable.
diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/tests/src/Functional/Entity/EntityTranslationFormTest.php
similarity index 97%
rename from core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php
rename to core/modules/system/tests/src/Functional/Entity/EntityTranslationFormTest.php
index f5134249a72a..e008e71e1f98 100644
--- a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php
+++ b/core/modules/system/tests/src/Functional/Entity/EntityTranslationFormTest.php
@@ -1,18 +1,18 @@
 <?php
 
-namespace Drupal\system\Tests\Entity;
+namespace Drupal\Tests\system\Functional\Entity;
 
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\language\Entity\ConfigurableLanguage;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
 
 /**
  * Tests entity translation form.
  *
  * @group Entity
  */
-class EntityTranslationFormTest extends WebTestBase {
+class EntityTranslationFormTest extends BrowserTestBase {
 
   /**
    * Modules to enable.
diff --git a/core/modules/system/tests/src/Functional/Entity/EntityWithUriCacheTagsTestBase.php b/core/modules/system/tests/src/Functional/Entity/EntityWithUriCacheTagsTestBase.php
new file mode 100644
index 000000000000..ed4914407ea1
--- /dev/null
+++ b/core/modules/system/tests/src/Functional/Entity/EntityWithUriCacheTagsTestBase.php
@@ -0,0 +1,149 @@
+<?php
+
+namespace Drupal\Tests\system\Functional\Entity;
+
+use Drupal\Core\Cache\Cache;
+use Drupal\Core\Language\LanguageInterface;
+use Drupal\field\Entity\FieldStorageConfig;
+use Drupal\field\Entity\FieldConfig;
+
+/**
+ * Provides helper methods for Entity cache tags tests; for entities with URIs.
+ */
+abstract class EntityWithUriCacheTagsTestBase extends EntityCacheTagsTestBase {
+
+  /**
+   * Tests cache tags presence and invalidation of the entity at its URI.
+   *
+   * Tests the following cache tags:
+   * - "<entity type>_view"
+   * - "<entity_type>:<entity ID>"
+   */
+  public function testEntityUri() {
+    $entity_url = $this->entity->urlInfo();
+    $entity_type = $this->entity->getEntityTypeId();
+
+    // Selects the view mode that will be used.
+    $view_mode = $this->selectViewMode($entity_type);
+
+    // The default cache contexts for rendered entities.
+    $entity_cache_contexts = $this->getDefaultCacheContexts();
+
+    // Generate the standardized entity cache tags.
+    $cache_tag = $this->entity->getCacheTags();
+    $view_cache_tag = \Drupal::entityManager()->getViewBuilder($entity_type)->getCacheTags();
+    $render_cache_tag = 'rendered';
+
+    $this->pass("Test entity.", 'Debug');
+    $this->verifyPageCache($entity_url, 'MISS');
+
+    // Verify a cache hit, but also the presence of the correct cache tags.
+    $this->verifyPageCache($entity_url, 'HIT');
+
+    // Also verify the existence of an entity render cache entry, if this entity
+    // type supports render caching.
+    if (\Drupal::entityManager()->getDefinition($entity_type)->isRenderCacheable()) {
+      $cache_keys = ['entity_view', $entity_type, $this->entity->id(), $view_mode];
+      $cid = $this->createCacheId($cache_keys, $entity_cache_contexts);
+      $redirected_cid = NULL;
+      $additional_cache_contexts = $this->getAdditionalCacheContextsForEntity($this->entity);
+      if (count($additional_cache_contexts)) {
+        $redirected_cid = $this->createCacheId($cache_keys, Cache::mergeContexts($entity_cache_contexts, $additional_cache_contexts));
+      }
+      $expected_cache_tags = Cache::mergeTags($cache_tag, $view_cache_tag);
+      $expected_cache_tags = Cache::mergeTags($expected_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity));
+      $expected_cache_tags = Cache::mergeTags($expected_cache_tags, [$render_cache_tag]);
+      $this->verifyRenderCache($cid, $expected_cache_tags, $redirected_cid);
+    }
+
+    // Verify that after modifying the entity, there is a cache miss.
+    $this->pass("Test modification of entity.", 'Debug');
+    $this->entity->save();
+    $this->verifyPageCache($entity_url, 'MISS');
+
+    // Verify a cache hit.
+    $this->verifyPageCache($entity_url, 'HIT');
+
+    // Verify that after modifying the entity's display, there is a cache miss.
+    $this->pass("Test modification of entity's '$view_mode' display.", 'Debug');
+    $entity_display = entity_get_display($entity_type, $this->entity->bundle(), $view_mode);
+    $entity_display->save();
+    $this->verifyPageCache($entity_url, 'MISS');
+
+    // Verify a cache hit.
+    $this->verifyPageCache($entity_url, 'HIT');
+
+    if ($bundle_entity_type_id = $this->entity->getEntityType()->getBundleEntityType()) {
+      // Verify that after modifying the corresponding bundle entity, there is a
+      // cache miss.
+      $this->pass("Test modification of entity's bundle entity.", 'Debug');
+      $bundle_entity = $this->container->get('entity_type.manager')
+        ->getStorage($bundle_entity_type_id)
+        ->load($this->entity->bundle());
+      $bundle_entity->save();
+      $this->verifyPageCache($entity_url, 'MISS');
+
+      // Verify a cache hit.
+      $this->verifyPageCache($entity_url, 'HIT');
+    }
+
+    if ($this->entity->getEntityType()->get('field_ui_base_route')) {
+      // Verify that after modifying a configurable field on the entity, there
+      // is a cache miss.
+      $this->pass("Test modification of entity's configurable field.", 'Debug');
+      $field_storage_name = $this->entity->getEntityTypeId() . '.configurable_field';
+      $field_storage = FieldStorageConfig::load($field_storage_name);
+      $field_storage->save();
+      $this->verifyPageCache($entity_url, 'MISS');
+
+      // Verify a cache hit.
+      $this->verifyPageCache($entity_url, 'HIT');
+
+      // Verify that after modifying a configurable field on the entity, there
+      // is a cache miss.
+      $this->pass("Test modification of entity's configurable field.", 'Debug');
+      $field_name = $this->entity->getEntityTypeId() . '.' . $this->entity->bundle() . '.configurable_field';
+      $field = FieldConfig::load($field_name);
+      $field->save();
+      $this->verifyPageCache($entity_url, 'MISS');
+
+      // Verify a cache hit.
+      $this->verifyPageCache($entity_url, 'HIT');
+    }
+
+    // Verify that after invalidating the entity's cache tag directly, there is
+    // a cache miss.
+    $this->pass("Test invalidation of entity's cache tag.", 'Debug');
+    Cache::invalidateTags($this->entity->getCacheTagsToInvalidate());
+    $this->verifyPageCache($entity_url, 'MISS');
+
+    // Verify a cache hit.
+    $this->verifyPageCache($entity_url, 'HIT');
+
+    // Verify that after invalidating the generic entity type's view cache tag
+    // directly, there is a cache miss.
+    $this->pass("Test invalidation of entity's 'view' cache tag.", 'Debug');
+    Cache::invalidateTags($view_cache_tag);
+    $this->verifyPageCache($entity_url, 'MISS');
+
+    // Verify a cache hit.
+    $this->verifyPageCache($entity_url, 'HIT');
+
+    // Verify that after deleting the entity, there is a cache miss.
+    $this->pass('Test deletion of entity.', 'Debug');
+    $this->entity->delete();
+    $this->verifyPageCache($entity_url, 'MISS');
+    $this->assertResponse(404);
+  }
+
+  /**
+   * Gets the default cache contexts for rendered entities.
+   *
+   * @return array
+   *   The default cache contexts for rendered entities.
+   */
+  protected function getDefaultCacheContexts() {
+    return ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions'];
+  }
+
+}
diff --git a/core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php b/core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php
new file mode 100644
index 000000000000..e873e096f0dc
--- /dev/null
+++ b/core/modules/system/tests/src/Functional/Entity/Traits/EntityDefinitionTestTrait.php
@@ -0,0 +1,299 @@
+<?php
+
+namespace Drupal\Tests\system\Functional\Entity\Traits;
+
+use Drupal\Core\Field\BaseFieldDefinition;
+use Drupal\entity_test\FieldStorageDefinition;
+
+/**
+ * Provides some test methods used to update existing entity definitions.
+ */
+trait EntityDefinitionTestTrait {
+
+  /**
+   * Enables a new entity type definition.
+   */
+  protected function enableNewEntityType() {
+    $this->state->set('entity_test_new', TRUE);
+    $this->entityManager->clearCachedDefinitions();
+    $this->entityDefinitionUpdateManager->applyUpdates();
+  }
+
+  /**
+   * Resets the entity type definition.
+   */
+  protected function resetEntityType() {
+    $this->state->set('entity_test_update.entity_type', NULL);
+    $this->entityManager->clearCachedDefinitions();
+    $this->entityDefinitionUpdateManager->applyUpdates();
+  }
+
+  /**
+   * Updates the 'entity_test_update' entity type to revisionable.
+   */
+  protected function updateEntityTypeToRevisionable() {
+    $entity_type = clone $this->entityManager->getDefinition('entity_test_update');
+
+    $keys = $entity_type->getKeys();
+    $keys['revision'] = 'revision_id';
+    $entity_type->set('entity_keys', $keys);
+    $entity_type->set('revision_table', 'entity_test_update_revision');
+
+    $this->state->set('entity_test_update.entity_type', $entity_type);
+  }
+
+  /**
+   * Updates the 'entity_test_update' entity type not revisionable.
+   */
+  protected function updateEntityTypeToNotRevisionable() {
+    $entity_type = clone $this->entityManager->getDefinition('entity_test_update');
+
+    $keys = $entity_type->getKeys();
+    unset($keys['revision']);
+    $entity_type->set('entity_keys', $keys);
+    $entity_type->set('revision_table', NULL);
+
+    $this->state->set('entity_test_update.entity_type', $entity_type);
+  }
+
+  /**
+   * Updates the 'entity_test_update' entity type to translatable.
+   */
+  protected function updateEntityTypeToTranslatable() {
+    $entity_type = clone $this->entityManager->getDefinition('entity_test_update');
+
+    $entity_type->set('translatable', TRUE);
+    $entity_type->set('data_table', 'entity_test_update_data');
+
+    if ($entity_type->isRevisionable()) {
+      $entity_type->set('revision_data_table', 'entity_test_update_revision_data');
+    }
+
+    $this->state->set('entity_test_update.entity_type', $entity_type);
+  }
+
+  /**
+   * Updates the 'entity_test_update' entity type to not translatable.
+   */
+  protected function updateEntityTypeToNotTranslatable() {
+    $entity_type = clone $this->entityManager->getDefinition('entity_test_update');
+
+    $entity_type->set('translatable', FALSE);
+    $entity_type->set('data_table', NULL);
+
+    if ($entity_type->isRevisionable()) {
+      $entity_type->set('revision_data_table', NULL);
+    }
+
+    $this->state->set('entity_test_update.entity_type', $entity_type);
+  }
+
+  /**
+   * Updates the 'entity_test_update' entity type to revisionable and
+   * translatable.
+   */
+  protected function updateEntityTypeToRevisionableAndTranslatable() {
+    $entity_type = clone $this->entityManager->getDefinition('entity_test_update');
+
+    $keys = $entity_type->getKeys();
+    $keys['revision'] = 'revision_id';
+    $entity_type->set('entity_keys', $keys);
+    $entity_type->set('translatable', TRUE);
+    $entity_type->set('data_table', 'entity_test_update_data');
+    $entity_type->set('revision_table', 'entity_test_update_revision');
+    $entity_type->set('revision_data_table', 'entity_test_update_revision_data');
+
+    $this->state->set('entity_test_update.entity_type', $entity_type);
+  }
+
+  /**
+   * Adds a new base field to the 'entity_test_update' entity type.
+   *
+   * @param string $type
+   *   (optional) The field type for the new field. Defaults to 'string'.
+   * @param string $entity_type_id
+   *   (optional) The entity type ID the base field should be attached to.
+   *   Defaults to 'entity_test_update'.
+   * @param bool $is_revisionable
+   *   (optional) If the base field should be revisionable or not. Defaults to
+   *   FALSE.
+   */
+  protected function addBaseField($type = 'string', $entity_type_id = 'entity_test_update', $is_revisionable = FALSE) {
+    $definitions['new_base_field'] = BaseFieldDefinition::create($type)
+      ->setName('new_base_field')
+      ->setRevisionable($is_revisionable)
+      ->setLabel(t('A new base field'));
+    $this->state->set($entity_type_id . '.additional_base_field_definitions', $definitions);
+  }
+
+  /**
+   * Adds a long-named base field to the 'entity_test_update' entity type.
+   */
+  protected function addLongNameBaseField() {
+    $key = 'entity_test_update.additional_base_field_definitions';
+    $definitions = $this->state->get($key, []);
+    $definitions['new_long_named_entity_reference_base_field'] = BaseFieldDefinition::create('entity_reference')
+      ->setName('new_long_named_entity_reference_base_field')
+      ->setLabel(t('A new long-named base field'))
+      ->setSetting('target_type', 'user')
+      ->setSetting('handler', 'default');
+    $this->state->set($key, $definitions);
+  }
+
+  /**
+   * Adds a new revisionable base field to the 'entity_test_update' entity type.
+   *
+   * @param string $type
+   *   (optional) The field type for the new field. Defaults to 'string'.
+   */
+  protected function addRevisionableBaseField($type = 'string') {
+    $definitions['new_base_field'] = BaseFieldDefinition::create($type)
+      ->setName('new_base_field')
+      ->setLabel(t('A new revisionable base field'))
+      ->setRevisionable(TRUE);
+    $this->state->set('entity_test_update.additional_base_field_definitions', $definitions);
+  }
+
+  /**
+   * Modifies the new base field from 'string' to 'text'.
+   */
+  protected function modifyBaseField() {
+    $this->addBaseField('text');
+  }
+
+  /**
+   * Promotes a field to an entity key.
+   */
+  protected function makeBaseFieldEntityKey() {
+    $entity_type = clone $this->entityManager->getDefinition('entity_test_update');
+    $entity_keys = $entity_type->getKeys();
+    $entity_keys['new_base_field'] = 'new_base_field';
+    $entity_type->set('entity_keys', $entity_keys);
+    $this->state->set('entity_test_update.entity_type', $entity_type);
+  }
+
+  /**
+   * Removes the new base field from the 'entity_test_update' entity type.
+   *
+   * @param string $entity_type_id
+   *   (optional) The entity type ID the base field should be attached to.
+   */
+  protected function removeBaseField($entity_type_id = 'entity_test_update') {
+    $this->state->delete($entity_type_id . '.additional_base_field_definitions');
+  }
+
+  /**
+   * Adds a single-field index to the base field.
+   */
+  protected function addBaseFieldIndex() {
+    $this->state->set('entity_test_update.additional_field_index.entity_test_update.new_base_field', TRUE);
+  }
+
+  /**
+   * Removes the index added in addBaseFieldIndex().
+   */
+  protected function removeBaseFieldIndex() {
+    $this->state->delete('entity_test_update.additional_field_index.entity_test_update.new_base_field');
+  }
+
+  /**
+   * Adds a new bundle field to the 'entity_test_update' entity type.
+   *
+   * @param string $type
+   *   (optional) The field type for the new field. Defaults to 'string'.
+   */
+  protected function addBundleField($type = 'string') {
+    $definitions['new_bundle_field'] = FieldStorageDefinition::create($type)
+      ->setName('new_bundle_field')
+      ->setLabel(t('A new bundle field'))
+      ->setTargetEntityTypeId('entity_test_update');
+    $this->state->set('entity_test_update.additional_field_storage_definitions', $definitions);
+    $this->state->set('entity_test_update.additional_bundle_field_definitions.test_bundle', $definitions);
+  }
+
+  /**
+   * Modifies the new bundle field from 'string' to 'text'.
+   */
+  protected function modifyBundleField() {
+    $this->addBundleField('text');
+  }
+
+  /**
+   * Removes the new bundle field from the 'entity_test_update' entity type.
+   */
+  protected function removeBundleField() {
+    $this->state->delete('entity_test_update.additional_field_storage_definitions');
+    $this->state->delete('entity_test_update.additional_bundle_field_definitions.test_bundle');
+  }
+
+  /**
+   * Adds an index to the 'entity_test_update' entity type's base table.
+   *
+   * @see \Drupal\entity_test\EntityTestStorageSchema::getEntitySchema()
+   */
+  protected function addEntityIndex() {
+    $indexes = [
+      'entity_test_update__new_index' => ['name', 'test_single_property'],
+    ];
+    $this->state->set('entity_test_update.additional_entity_indexes', $indexes);
+  }
+
+  /**
+   * Removes the index added in addEntityIndex().
+   */
+  protected function removeEntityIndex() {
+    $this->state->delete('entity_test_update.additional_entity_indexes');
+  }
+
+  /**
+   * Renames the base table to 'entity_test_update_new'.
+   */
+  protected function renameBaseTable() {
+    $entity_type = clone $this->entityManager->getDefinition('entity_test_update');
+
+    $entity_type->set('base_table', 'entity_test_update_new');
+
+    $this->state->set('entity_test_update.entity_type', $entity_type);
+  }
+
+  /**
+   * Renames the data table to 'entity_test_update_data_new'.
+   */
+  protected function renameDataTable() {
+    $entity_type = clone $this->entityManager->getDefinition('entity_test_update');
+
+    $entity_type->set('data_table', 'entity_test_update_data_new');
+
+    $this->state->set('entity_test_update.entity_type', $entity_type);
+  }
+
+  /**
+   * Renames the revision table to 'entity_test_update_revision_new'.
+   */
+  protected function renameRevisionBaseTable() {
+    $entity_type = clone $this->entityManager->getDefinition('entity_test_update');
+
+    $entity_type->set('revision_table', 'entity_test_update_revision_new');
+
+    $this->state->set('entity_test_update.entity_type', $entity_type);
+  }
+
+  /**
+   * Renames the revision data table to 'entity_test_update_revision_data_new'.
+   */
+  protected function renameRevisionDataTable() {
+    $entity_type = clone $this->entityManager->getDefinition('entity_test_update');
+
+    $entity_type->set('revision_data_table', 'entity_test_update_revision_data_new');
+
+    $this->state->set('entity_test_update.entity_type', $entity_type);
+  }
+
+  /**
+   * Removes the entity type.
+   */
+  protected function deleteEntityType() {
+    $this->state->set('entity_test_update.entity_type', 'null');
+  }
+
+}
diff --git a/core/modules/system/tests/src/Functional/Entity/Update/SqlContentEntityStorageSchemaConverterTestBase.php b/core/modules/system/tests/src/Functional/Entity/Update/SqlContentEntityStorageSchemaConverterTestBase.php
index a0acaef7571c..4a26f109140f 100644
--- a/core/modules/system/tests/src/Functional/Entity/Update/SqlContentEntityStorageSchemaConverterTestBase.php
+++ b/core/modules/system/tests/src/Functional/Entity/Update/SqlContentEntityStorageSchemaConverterTestBase.php
@@ -4,7 +4,7 @@
 
 use Drupal\Core\Entity\Sql\TemporaryTableMapping;
 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
-use Drupal\system\Tests\Entity\EntityDefinitionTestTrait;
+use Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait;
 
 /**
  * Defines a class for testing the conversion of entity types to revisionable.
diff --git a/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionDefaultTest.php b/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionDefaultTest.php
index e226540b6ae6..e696da67e81a 100644
--- a/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionDefaultTest.php
+++ b/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionDefaultTest.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\system\Functional\Update;
 
 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
-use Drupal\system\Tests\Entity\EntityDefinitionTestTrait;
+use Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait;
 
 /**
  * Tests the upgrade path for adding the 'revision_default' field.
diff --git a/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionTranslationAffectedTest.php b/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionTranslationAffectedTest.php
index f7dcd0c41bfe..018c10f0517b 100644
--- a/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionTranslationAffectedTest.php
+++ b/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionTranslationAffectedTest.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\system\Functional\Update;
 
 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
-use Drupal\system\Tests\Entity\EntityDefinitionTestTrait;
+use Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait;
 
 /**
  * Tests the upgrade path for adding the 'revision_translation_affected' field.
diff --git a/core/modules/system/tests/src/Functional/Update/EntityUpdateToRevisionableAndPublishableTest.php b/core/modules/system/tests/src/Functional/Update/EntityUpdateToRevisionableAndPublishableTest.php
index 2312dc6f0a67..e2206bed2688 100644
--- a/core/modules/system/tests/src/Functional/Update/EntityUpdateToRevisionableAndPublishableTest.php
+++ b/core/modules/system/tests/src/Functional/Update/EntityUpdateToRevisionableAndPublishableTest.php
@@ -4,7 +4,7 @@
 
 use Drupal\Core\Field\BaseFieldDefinition;
 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
-use Drupal\system\Tests\Entity\EntityDefinitionTestTrait;
+use Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait;
 
 /**
  * Tests the upgrade path for making an entity revisionable and publishable.
diff --git a/core/modules/taxonomy/tests/src/Functional/TermCacheTagsTest.php b/core/modules/taxonomy/tests/src/Functional/TermCacheTagsTest.php
index 35b7d6bd6e20..378d02c755f0 100644
--- a/core/modules/taxonomy/tests/src/Functional/TermCacheTagsTest.php
+++ b/core/modules/taxonomy/tests/src/Functional/TermCacheTagsTest.php
@@ -2,9 +2,9 @@
 
 namespace Drupal\Tests\taxonomy\Functional;
 
-use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
 use Drupal\taxonomy\Entity\Vocabulary;
 use Drupal\taxonomy\Entity\Term;
+use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
 
 /**
  * Tests the Taxonomy term entity's cache tags.
diff --git a/core/modules/user/tests/src/Functional/UserCacheTagsTest.php b/core/modules/user/tests/src/Functional/UserCacheTagsTest.php
index a9e98575b7b5..c9ab91fac71a 100644
--- a/core/modules/user/tests/src/Functional/UserCacheTagsTest.php
+++ b/core/modules/user/tests/src/Functional/UserCacheTagsTest.php
@@ -2,7 +2,7 @@
 
 namespace Drupal\Tests\user\Functional;
 
-use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
+use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
 use Drupal\user\Entity\Role;
 use Drupal\user\Entity\User;
 use Drupal\user\RoleInterface;
diff --git a/core/modules/views/tests/src/Kernel/EventSubscriber/ViewsEntitySchemaSubscriberIntegrationTest.php b/core/modules/views/tests/src/Kernel/EventSubscriber/ViewsEntitySchemaSubscriberIntegrationTest.php
index 2319a7064a9e..24e4e6af5105 100644
--- a/core/modules/views/tests/src/Kernel/EventSubscriber/ViewsEntitySchemaSubscriberIntegrationTest.php
+++ b/core/modules/views/tests/src/Kernel/EventSubscriber/ViewsEntitySchemaSubscriberIntegrationTest.php
@@ -4,7 +4,7 @@
 
 use Drupal\Core\Entity\EntityTypeEvent;
 use Drupal\Core\Entity\EntityTypeEvents;
-use Drupal\system\Tests\Entity\EntityDefinitionTestTrait;
+use Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait;
 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
 
 /**
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
index 4cbffedbf8c0..01044f724a1d 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
@@ -15,7 +15,7 @@
 use Drupal\Core\Field\FieldStorageDefinitionEvents;
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\entity_test_update\Entity\EntityTestUpdate;
-use Drupal\system\Tests\Entity\EntityDefinitionTestTrait;
+use Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait;
 
 /**
  * Tests EntityDefinitionUpdateManager functionality.
-- 
GitLab