Skip to content
Snippets Groups Projects

Resolve #2254189 "Fix performance nodetranslation attempt2"

1 unresolved thread
1 file
+ 61
23
Compare changes
  • Side-by-side
  • Inline
@@ -2,13 +2,20 @@
namespace Drupal\Tests\node\Functional;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
use Drupal\Tests\language\Traits\LanguageTestTrait;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Tests the Node Translation UI.
@@ -18,6 +25,7 @@
*/
class NodeTranslationUITest extends ContentTranslationUITestBase {
use CommentTestTrait;
use LanguageTestTrait;
/**
@@ -29,18 +37,12 @@ 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',
'user.roles:authenticated',
];
/**
@@ -53,27 +55,40 @@ 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}
* @phpstan-ignore-next-line
*/
protected function setUp(): void {
// Skip the parent setup method because it requires the bundle to exist.
BrowserTestBase::setup();
// Create the bundle.
$this->drupalCreateContentType(['type' => 'article', 'title' => 'Article']);
// Set the entity type and bundle.
$this->entityTypeId = 'node';
$this->bundle = 'article';
parent::setUp();
// Ensure the help message is shown even with prefixed paths.
// Execute the same tasks as in parent::setup().
$this->setupLanguages();
$this->setupBundle();
$this->enableTranslation();
$this->setupUsers();
$this->setupTestFields();
$this->manager = $this->container->get('content_translation.manager');
$this->controller = $this->manager->getTranslationHandler($this->entityTypeId);
// Rebuild the container so that the new languages are picked up by services
// that hold a list of languages.
$this->rebuildContainer();
// This is now the remainder of setup for this class. Ensure the help
// message is shown even with prefixed paths.
$this->drupalPlaceBlock('help_block', ['region' => 'content']);
// Display the language selector.
@@ -99,10 +114,6 @@ public function testPublishedStatusNoFields() {
$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 could be done in an API call.

      Though I have no idea why we need to delete a field here. That smells wrong too.

      • When using the standard profile these fields are created. Now that the testing profile is used these fields do not exist and attempting to delete them fails with this error.

        1) Drupal\Tests\node\Functional\NodeTranslationUITest::testPublishedStatusNoFields
        Behat\Mink\Exception\ElementNotFoundException: Button with id|name|label|value "Delete" not found.
      • Please register or sign in to reply
Please register or sign in to reply
$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 +323,15 @@ public function testDisabledBundle() {
* 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 +576,20 @@ public function testRevisionTranslationRendering() {
* 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 +597,10 @@ public function testDetailsTitleIsNotEscaped() {
$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);
Loading