Unverified Commit 646584b3 authored by alexpott's avatar alexpott

Issue #2946419 by vaplas, Lendude, Mile23: Entity: Convert system functional tests to phpunit

parent 9e9ee75b
......@@ -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;
......
......@@ -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;
......
......@@ -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;
/**
......
<?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;
......
......@@ -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.
......
......@@ -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.
......
......@@ -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.
......
......@@ -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;
......
......@@ -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 {
......
......@@ -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 {
......
......@@ -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",
......
......@@ -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;
......
<?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.
......
<?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.
......
<?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'];
}
}
......@@ -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.
......
......@@ -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.
......
......@@ -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.
......
......@@ -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.
......
......@@ -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.
......
......@@ -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;
......
......@@ -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;
/**
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment