Issue #2946419 by vaplas, Lendude, Mile23: Entity: Convert system functional tests to phpunit
parent
9e9ee75ba4
commit
646584b3f7
|
@ -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 @@ namespace Drupal\Tests\aggregator\Functional;
|
|||
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\block_content\Entity\BlockContentType;
|
|||
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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
@ -4,7 +4,7 @@ namespace Drupal\Tests\content_translation\Functional\Update;
|
|||
|
||||
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 @@ namespace Drupal\Tests\media\Functional;
|
|||
|
||||
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 @@ namespace Drupal\Tests\node\Functional;
|
|||
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 @@ namespace Drupal\Tests\shortcut\Functional;
|
|||
|
||||
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 @@ namespace Drupal\system\Tests\Entity;
|
|||
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\Core\Language\LanguageInterface;
|
|||
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 @@ use Drupal\Core\StringTranslation\TranslatableMarkup;
|
|||
*
|
||||
* 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\Language\LanguageInterface;
|
|||
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;
|
||||
|
||||
|
|
|
@ -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.
|
|
@ -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.
|
|
@ -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'];
|
||||
}
|
||||
|
||||
}
|
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@ namespace Drupal\Tests\system\Functional\Entity\Update;
|
|||
|
||||
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 @@ namespace Drupal\Tests\system\Functional\Update;
|
|||
|
||||
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 @@ namespace Drupal\Tests\views\Kernel\EventSubscriber;
|
|||
|
||||
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\FieldException;
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue