View source
<?php
namespace Drupal\Tests\layout_builder_st\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Core\Url;
use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait;
use Drupal\Tests\layout_builder_st\Functional\TranslationTestTrait;
class TranslationTest extends WebDriverTestBase {
use LayoutBuilderTestTrait;
use TranslationTestTrait;
use JavascriptTranslationTestTrait;
use ContextualLinkClickTrait;
const FIELD_UI_PREFIX = 'admin/structure/types/manage/bundle_with_section_field';
protected $defaultTheme = 'classy';
public static $modules = [
'content_translation',
'layout_builder',
'block',
'node',
'contextual',
];
public function providerLabelTranslation() {
return [
'install before' => [
TRUE,
],
'install after' => [
FALSE,
],
];
}
public function testLabelTranslation($install_before) {
if ($install_before) {
$this->container
->get('module_installer')
->install([
'layout_builder_st',
]);
$this
->layoutBuilderSetup();
}
else {
$this
->layoutBuilderSetup();
$this->container
->get('module_installer')
->install([
'layout_builder_st',
]);
}
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$this
->drupalLogin($this
->drupalCreateUser([
'access contextual links',
'configure any layout',
]));
$this
->drupalGet('node/1/layout');
$this
->clickContextualLink('.block-field-blocknodebundle-with-section-fieldbody', 'Configure');
$this
->assertNotEmpty($assert_session
->waitForElementVisible('css', '#drupal-off-canvas'));
$page
->fillField('settings[label]', 'field label untranslated');
$page
->checkField('settings[label_display]');
$page
->pressButton('Update');
$assert_session
->assertWaitOnAjaxRequest();
$this
->assertNoElementAfterWait('#drupal-off-canvas');
$this
->addBlock('Powered by Drupal', '.block-system-powered-by-block', TRUE, 'untranslated label');
$assert_session
->pageTextContains('untranslated label');
$assert_session
->buttonExists('Save layout');
$page
->pressButton('Save layout');
$assert_session
->addressEquals('node/1');
$this
->drupalGet('it/node/1/layout');
$this
->assertNonTranslationActionsRemoved();
$this
->updateBlockTranslation('.block-system-powered-by-block', 'untranslated label', 'label in translation');
$assert_session
->buttonExists('Save layout');
$page
->pressButton('Save layout');
$assert_session
->addressEquals('it/node/1');
$assert_session
->pageTextContains('label in translation');
$assert_session
->pageTextNotContains('untranslated label');
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('untranslated label');
$assert_session
->pageTextNotContains('label in translation');
$this
->drupalGet('it/node/1/layout');
$this
->assertNonTranslationActionsRemoved();
$this
->updateBlockTranslation('.block-system-powered-by-block', 'untranslated label', 'label updated in translation', 'label in translation');
$assert_session
->buttonExists('Save layout');
$page
->pressButton('Save layout');
$assert_session
->addressEquals('it/node/1');
$assert_session
->pageTextContains('label updated in translation');
$assert_session
->pageTextNotContains('label in translation');
}
protected function layoutBuilderSetup() {
$this
->drupalPlaceBlock('local_tasks_block');
$this
->createContentType([
'type' => 'bundle_with_section_field',
'new_revision' => TRUE,
]);
$this
->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The node title',
'body' => [
[
'value' => 'The node body',
],
],
]);
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',
]));
$add_translation_url = Url::fromRoute("entity.node.content_translation_add", [
'node' => 1,
'source' => 'en',
'target' => 'it',
]);
$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');
}
}