Issue #2254189 by smustgrave, quietone, anya_m, andregp, sun, joachim: Fix test performance of Drupal\node\Tests\NodeTranslationUITest

merge-requests/6102/head
catch 2024-01-10 21:12:27 +00:00
parent ef985e937c
commit f0d3a7bf58
19 changed files with 64 additions and 25 deletions

View File

@ -51,6 +51,7 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
$this->bundle = 'basic';
$this->testLanguageSelector = FALSE;
parent::setUp();
$this->doSetup();
$this->drupalPlaceBlock('page_title_block');
}

View File

@ -71,6 +71,7 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
$this->testLanguageSelector = FALSE;
$this->subject = $this->randomMachineName();
parent::setUp();
$this->doSetup();
}
/**

View File

@ -48,6 +48,7 @@ class ContentTestTranslationUITest extends ContentTranslationUITestBase {
// Use the entity_test_mul as this has multilingual property support.
$this->entityTypeId = 'entity_test_mul_changed';
parent::setUp();
$this->doSetup();
}
/**

View File

@ -43,6 +43,14 @@ class ContentTranslationMetadataFieldsTest extends ContentTranslationTestBase {
$this->createContentType(['type' => $this->bundle]);
}
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->doSetup();
}
/**
* Tests skipping setting non translatable metadata fields.
*/

View File

@ -33,6 +33,7 @@ class ContentTranslationNewTranslationWithExistingRevisionsTest extends ContentT
*/
protected function setUp(): void {
parent::setUp();
$this->doSetup();
$this->enableContentModeration();
}

View File

@ -22,6 +22,7 @@ class ContentTranslationOutdatedRevisionTranslationTest extends ContentTranslati
*/
protected function setUp(): void {
parent::setUp();
$this->doSetup();
$this->enableContentModeration();
}

View File

@ -22,6 +22,7 @@ class ContentTranslationRevisionTranslationDeletionTest extends ContentTranslati
*/
protected function setUp(): void {
parent::setUp();
$this->doSetup();
$this->enableContentModeration();
}

View File

@ -57,6 +57,7 @@ class ContentTranslationSyncImageTest extends ContentTranslationTestBase {
*/
protected function setUp(): void {
parent::setUp();
$this->doSetup();
$this->files = $this->drupalGetTestFiles('image');
}

View File

@ -83,11 +83,9 @@ abstract class ContentTranslationTestBase extends BrowserTestBase {
protected $manager;
/**
* {@inheritdoc}
* Completes preparation for content translation tests.
*/
protected function setUp(): void {
parent::setUp();
protected function doSetup(): void {
$this->setupLanguages();
$this->setupBundle();
$this->enableTranslation();

View File

@ -32,6 +32,7 @@ class ContentTranslationUntranslatableFieldsTest extends ContentTranslationPendi
*/
protected function setUp(): void {
parent::setUp();
$this->doSetup();
// Configure one field as untranslatable.
$this->drupalLogin($this->administrator);

View File

@ -74,6 +74,7 @@ class ContentTranslationWorkflowsTest extends ContentTranslationTestBase {
*/
protected function setUp(): void {
parent::setUp();
$this->doSetup();
$field_storage = FieldStorageConfig::create([
'field_name' => 'field_reference',

View File

@ -42,6 +42,7 @@ class TranslationLinkTest extends ContentTranslationTestBase {
$this->entityTypeId = 'user';
parent::setUp();
$this->doSetup();
// Assign user 1 a language code so that the entity can be translated.
$user = User::load(1);

View File

@ -41,6 +41,7 @@ class LayoutBuilderTranslationTest extends ContentTranslationTestBase {
*/
protected function setUp(): void {
parent::setUp();
$this->doSetup();
$this->setUpViewDisplay();
$this->setUpEntities();
}

View File

@ -49,6 +49,7 @@ class MediaTranslationUITest extends ContentTranslationUITestBase {
$this->entityTypeId = 'media';
$this->bundle = 'test';
parent::setUp();
$this->doSetup();
}
/**

View File

@ -41,6 +41,7 @@ class MenuLinkContentTranslationUITest extends ContentTranslationUITestBase {
$this->entityTypeId = 'menu_link_content';
$this->bundle = 'menu_link_content';
parent::setUp();
$this->doSetup();
}
/**

View File

@ -3,12 +3,18 @@
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
use Drupal\Tests\language\Traits\LanguageTestTrait;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Tests the Node Translation UI.
@ -19,6 +25,7 @@ use Drupal\node\Entity\Node;
class NodeTranslationUITest extends ContentTranslationUITestBase {
use LanguageTestTrait;
use CommentTestTrait;
/**
* {@inheritdoc}
@ -29,18 +36,11 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
* {@inheritdoc}
*/
protected $defaultCacheContexts = [
'languages:language_interface',
'theme',
'route',
'timezone',
'url.path.parent',
'url.query_args:_wrapper_format',
'url.site',
'user.roles',
'url.path.is_front',
// These two cache contexts are added by BigPipe.
'cookies:big_pipe_nojs',
'session.exists',
'user.permissions',
];
/**
@ -53,18 +53,9 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
'language',
'content_translation',
'node',
'datetime',
'field_ui',
'help',
];
/**
* The profile to install as a basis for testing.
*
* @var string
*/
protected $profile = 'standard';
/**
* {@inheritdoc}
*/
@ -73,6 +64,10 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
$this->bundle = 'article';
parent::setUp();
// Create the bundle.
$this->drupalCreateContentType(['type' => 'article', 'title' => 'Article']);
$this->doSetup();
// Ensure the help message is shown even with prefixed paths.
$this->drupalPlaceBlock('help_block', ['region' => 'content']);
@ -99,10 +94,6 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
$this->drupalGet('admin/structure/types/manage/article/fields');
$this->drupalGet('admin/structure/types/manage/article/fields/node.article.' . $this->fieldName . '/delete');
$this->submitForm([], 'Delete');
$this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_tags/delete');
$this->submitForm([], 'Delete');
$this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_image/delete');
$this->submitForm([], 'Delete');
// Add a node.
$default_langcode = $this->langcodes[0];
@ -312,6 +303,14 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
* Tests that translations are rendered properly.
*/
public function testTranslationRendering() {
// Add a comment field to the article content type.
\Drupal::service('module_installer')->install(['comment']);
$this->addDefaultCommentField('node', 'article');
// Add 'post comments' permission to the authenticated role.
$role = Role::load(RoleInterface::AUTHENTICATED_ID);
$role->grantPermission('post comments')->save();
$default_langcode = $this->langcodes[0];
$values[$default_langcode] = $this->getNewEntityValues($default_langcode);
$this->entityId = $this->createEntity($values[$default_langcode], $default_langcode);
@ -556,6 +555,20 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
* Tests title is not escaped (but XSS-filtered) for details form element.
*/
public function testDetailsTitleIsNotEscaped() {
// Create an image field.
\Drupal::service('module_installer')->install(['image']);
FieldStorageConfig::create([
'entity_type' => 'node',
'field_name' => 'field_image',
'type' => 'image',
])->save();
FieldConfig::create([
'entity_type' => 'node',
'field_name' => 'field_image',
'bundle' => 'article',
'translatable' => TRUE,
])->save();
$this->drupalLogin($this->administrator);
// Make the image field a multi-value field in order to display a
// details form element.
@ -563,6 +576,10 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
$this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_image');
$this->submitForm($edit, 'Save');
// Enable the display of the image field.
EntityFormDisplay::load('node.article.default')
->setComponent('field_image', ['region' => 'content'])->save();
// Make the image field non-translatable.
static::setFieldTranslatable('node', 'article', 'field_image', FALSE);

View File

@ -43,6 +43,7 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase {
$this->entityTypeId = 'shortcut';
$this->bundle = 'default';
parent::setUp();
$this->doSetup();
}
/**

View File

@ -50,6 +50,7 @@ class TermTranslationUITest extends ContentTranslationUITestBase {
$this->entityTypeId = 'taxonomy_term';
$this->bundle = 'tags';
parent::setUp();
$this->doSetup();
}
/**

View File

@ -54,6 +54,7 @@ class UserTranslationUITest extends ContentTranslationUITestBase {
$this->testLanguageSelector = FALSE;
$this->name = $this->randomMachineName();
parent::setUp();
$this->doSetup();
\Drupal::entityTypeManager()->getStorage('user')->resetCache();
}