View source
<?php
namespace Drupal\Tests\layout_builder_st\FunctionalJavascript;
use Drupal\Core\Url;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait;
use Drupal\Tests\layout_builder_st\Functional\TranslationTestTrait;
class ModeratedTranslationTest extends WebDriverTestBase {
use LayoutBuilderTestTrait;
use TranslationTestTrait;
use JavascriptTranslationTestTrait;
use ContextualLinkClickTrait;
use ContentModerationTestTrait;
const FIELD_UI_PREFIX = 'admin/structure/types/manage/bundle_with_section_field';
protected $defaultTheme = 'classy';
public static $modules = [
'content_translation',
'content_moderation',
'layout_builder',
'block',
'node',
'contextual',
'layout_builder_test',
'block_test',
'layout_builder_st',
];
protected function setUp() {
parent::setUp();
$page = $this
->getSession()
->getPage();
$this->container
->get('state')
->set('test_block_access', TRUE);
$this
->drupalPlaceBlock('local_tasks_block');
$this
->createContentType([
'type' => 'bundle_with_section_field',
'new_revision' => TRUE,
]);
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'bundle_with_section_field');
$workflow
->save();
ConfigurableLanguage::createFromLangcode('it')
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'bundle_with_section_field', TRUE);
$this
->drupalLogin($this
->drupalCreateUser([
'access contextual links',
'configure any layout',
'administer node display',
'administer node fields',
'translate bundle_with_section_field node',
'create content translations',
'edit any bundle_with_section_field content',
'view bundle_with_section_field revisions',
'revert bundle_with_section_field revisions',
'view own unpublished content',
'view latest version',
'use editorial transition create_new_draft',
'use editorial transition publish',
]));
$node = $this
->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The node title',
'body' => [
[
'value' => 'The node body',
],
],
]);
$this
->drupalGet('node/1');
$add_translation_url = Url::fromRoute("entity.node.content_translation_add", [
'node' => 1,
'source' => 'en',
'target' => 'it',
]);
$this
->drupalGet($add_translation_url);
$this
->drupalPostForm($add_translation_url, [
'title[0][value]' => 'The translated node title',
'body[0][value]' => 'The translated node body',
], 'Save');
$this
->drupalPostForm(static::FIELD_UI_PREFIX . '/display/default', [
'layout[enabled]' => TRUE,
], 'Save');
$this
->drupalPostForm(static::FIELD_UI_PREFIX . '/display/default', [
'layout[allow_custom]' => TRUE,
], 'Save');
$this
->drupalGet($node
->toUrl());
$page
->fillField('new_state', 'published');
$page
->pressButton('Apply');
$this
->drupalGet('it/node/1');
$page
->fillField('new_state', 'published');
$page
->pressButton('Apply');
}
public function testModerationTranslatedOverrides() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$node = Node::load(1);
$this
->drupalGet($node
->toUrl());
$page
->clickLink('Layout');
$assert_session
->checkboxChecked('revision');
$assert_session
->fieldDisabled('revision');
$this
->addBlock('Powered by Drupal', '.block-system-powered-by-block', TRUE, 'untranslated label');
$page
->fillField('moderation_state[0][state]', 'draft');
$page
->pressButton('Save layout');
$this
->drupalGet('it/node/1');
$assert_session
->elementNotExists('css', '[data-drupal-link-system-path="node/1/layout"]');
$this
->drupalGet($node
->toUrl());
$page
->clickLink('Layout');
$page
->fillField('moderation_state[0][state]', 'published');
$page
->pressButton('Save layout');
$assert_session
->addressEquals('node/1');
$assert_session
->pageTextContains('untranslated label');
$this
->drupalGet('it/node/1');
$assert_session
->elementExists('css', '[data-drupal-link-system-path="node/1/layout"]');
$page
->clickLink('Layout');
$assert_session
->checkboxChecked('revision');
$assert_session
->fieldDisabled('revision');
$assert_session
->pageTextContains('untranslated label');
$this
->assertNonTranslationActionsRemoved();
$this
->updateBlockTranslation('.block-system-powered-by-block', 'untranslated label', 'label in translation');
$page
->fillField('moderation_state[0][state]', 'draft');
$page
->pressButton('Save layout');
$this
->drupalGet($node
->toUrl());
$assert_session
->pageTextContains('untranslated label');
$assert_session
->pageTextNotContains('label in translation');
$page
->clickLink('Layout');
$assert_session
->pageTextContains('untranslated label');
$assert_session
->pageTextNotContains('label in translation');
$this
->drupalGet('it/node/1');
$assert_session
->pageTextContains('untranslated label');
$assert_session
->pageTextNotContains('label in translation');
$page
->clickLink('Latest version');
$assert_session
->pageTextContains('label in translation');
$this
->drupalGet($node
->toUrl());
$page
->clickLink('Layout');
$this
->addBlock('Test block access', '#layout-builder .block-test-access', TRUE, 'untranslated new label');
$page
->fillField('moderation_state[0][state]', 'draft');
$page
->pressButton('Save layout');
$this
->drupalGet('it/node/1');
$this
->clickLink('Layout');
$assert_session
->pageTextContains('label in translation');
$assert_session
->pageTextNotContains('untranslated new label');
$this
->drupalGet($node
->toUrl());
$page
->clickLink('Layout');
$page
->fillField('moderation_state[0][state]', 'published');
$page
->pressButton('Save layout');
$assert_session
->addressEquals('node/1');
$assert_session
->pageTextContains('untranslated new label');
$this
->drupalGet('it/node/1');
$assert_session
->pageTextContains('untranslated new label');
$page
->clickLink('Latest version');
$assert_session
->pageTextNotContains('untranslated new label');
$this
->clickLink('Layout');
$assert_session
->pageTextContains('label in translation');
$assert_session
->pageTextNotContains('untranslated new label');
$page
->fillField('moderation_state[0][state]', 'published');
$page
->pressButton('Save layout');
$assert_session
->addressEquals('it/node/1');
$assert_session
->pageTextContains('label in translation');
$assert_session
->pageTextNotContains('untranslated label');
$assert_session
->pageTextContains('untranslated new label');
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('untranslated label');
$assert_session
->pageTextNotContains('label in translation');
$page
->clickLink('Layout');
$assert_session
->pageTextContains('untranslated label');
$assert_session
->pageTextNotContains('label in translation');
}
}