core/modules/config_translation/tests/src/Functional/ConfigTranslationListUiTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\config_translation\Functional;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
use Drupal\shortcut\Entity\ShortcutSet;
use Drupal\contact\Entity\ContactForm;
use Drupal\filter\Entity\FilterFormat;
use Drupal\taxonomy\Entity\Vocabulary;
class ConfigTranslationListUiTest extends BrowserTestBase {
protected static $modules = [
'block',
'config_translation',
'contact',
'block_content',
'field',
'field_ui',
'menu_ui',
'node',
'shortcut',
'taxonomy',
'image',
'responsive_image',
'toolbar',
];
protected $defaultTheme = 'stark';
protected $adminUser;
protected function setUp() : void {
parent::setUp();
$permissions = [
'access site-wide contact form',
'administer blocks',
'administer block content',
'administer block types',
'access block library',
'administer contact forms',
'administer content types',
'administer block_content fields',
'administer filters',
'administer menu',
'administer node fields',
'administer permissions',
'administer shortcuts',
'administer site configuration',
'administer taxonomy',
'administer account settings',
'administer languages',
'administer image styles',
'administer responsive images',
'translate configuration',
];
$this->adminUser = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->adminUser);
$this
->config('locale.settings')
->set('translation.import_enabled', TRUE)
->set('translation.use_source', LOCALE_TRANSLATION_USE_SOURCE_LOCAL)
->save();
$this
->drupalPlaceBlock('local_tasks_block');
}
protected function doBlockListTest() {
$id = $this
->randomMachineName(16);
$this
->drupalPlaceBlock('system_powered_by_block', [
'id' => $id,
]);
$this
->drupalGet('admin/structure/block');
$translate_link = 'admin/structure/block/manage/' . $id . '/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
protected function doMenuListTest() {
$this
->drupalGet('admin/structure/menu/add');
$menu_name = $this
->randomMachineName(16);
$label = $this
->randomMachineName(16);
$edit = [
'id' => $menu_name,
'description' => '',
'label' => $label,
];
$this
->drupalGet('admin/structure/menu/add');
$this
->submitForm($edit, 'Save');
$this
->drupalGet('admin/structure/menu');
$translate_link = 'admin/structure/menu/manage/' . $menu_name . '/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$permissions = [
'administer menu',
];
$this
->drupalLogin($this
->drupalCreateUser($permissions));
$this
->drupalGet('admin/structure/menu');
$translate_link = 'admin/structure/menu/manage/' . $menu_name . '/translate';
$this
->assertSession()
->linkByHrefNotExists($translate_link);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
protected function doVocabularyListTest() {
$vocabulary = Vocabulary::create([
'name' => $this
->randomMachineName(),
'description' => $this
->randomMachineName(),
'vid' => $this
->randomMachineName(),
]);
$vocabulary
->save();
$this
->drupalGet('admin/structure/taxonomy');
$translate_link = 'admin/structure/taxonomy/manage/' . $vocabulary
->id() . '/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
$this
->assertSession()
->linkExists('Translate taxonomy vocabulary');
$local_task_url = parse_url($this
->getSession()
->getPage()
->findLink('Translate taxonomy vocabulary')
->getAttribute('href'));
$this
->assertSame(base_path() . $translate_link, $local_task_url['path']);
}
public function doCustomContentTypeListTest() {
$block_content_type = BlockContentType::create([
'id' => $this
->randomMachineName(16),
'label' => $this
->randomMachineName(),
'revision' => FALSE,
]);
$block_content_type
->save();
$this
->drupalGet('admin/structure/block-content');
$translate_link = 'admin/structure/block-content/manage/' . $block_content_type
->id() . '/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
public function doContactFormsListTest() {
$contact_form = ContactForm::create([
'id' => $this
->randomMachineName(16),
'label' => $this
->randomMachineName(),
]);
$contact_form
->save();
$this
->drupalGet('admin/structure/contact');
$translate_link = 'admin/structure/contact/manage/' . $contact_form
->id() . '/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
public function doContentTypeListTest() {
$content_type = $this
->drupalCreateContentType([
'type' => $this
->randomMachineName(16),
'name' => $this
->randomMachineName(),
]);
$this
->drupalGet('admin/structure/types');
$translate_link = 'admin/structure/types/manage/' . $content_type
->id() . '/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
public function doFormatsListTest() {
$filter_format = FilterFormat::create([
'format' => $this
->randomMachineName(16),
'name' => $this
->randomMachineName(),
]);
$filter_format
->save();
$this
->drupalGet('admin/config/content/formats');
$translate_link = 'admin/config/content/formats/manage/' . $filter_format
->id() . '/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
public function doShortcutListTest() {
$shortcut = ShortcutSet::create([
'id' => $this
->randomMachineName(16),
'label' => $this
->randomString(),
]);
$shortcut
->save();
$this
->drupalGet('admin/config/user-interface/shortcut');
$translate_link = 'admin/config/user-interface/shortcut/manage/' . $shortcut
->id() . '/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
public function doUserRoleListTest() {
$role_id = $this
->randomMachineName(16);
$this
->drupalCreateRole([], $role_id);
$this
->drupalGet('admin/people/roles');
$translate_link = 'admin/people/roles/manage/' . $role_id . '/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
public function doLanguageListTest() {
ConfigurableLanguage::createFromLangcode('ga')
->save();
$this
->drupalGet('admin/config/regional/language');
$translate_link = 'admin/config/regional/language/edit/ga/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
public function doImageStyleListTest() {
$this
->drupalGet('admin/config/media/image-styles');
$translate_link = 'admin/config/media/image-styles/manage/medium/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
public function doResponsiveImageListTest() {
$edit = [];
$edit['label'] = $this
->randomMachineName();
$edit['id'] = strtolower($edit['label']);
$edit['fallback_image_style'] = 'thumbnail';
$this
->drupalGet('admin/config/media/responsive-image-style/add');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains("Responsive image style {$edit['label']} saved.");
$this
->drupalGet('admin/config/media/responsive-image-style');
$translate_link = 'admin/config/media/responsive-image-style/' . $edit['id'] . '/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
public function doFieldListTest() {
$content_type = $this
->drupalCreateContentType([
'type' => $this
->randomMachineName(16),
'name' => $this
->randomMachineName(),
]);
$block_content_type = BlockContentType::create([
'id' => 'basic',
'label' => 'Basic',
'revision' => FALSE,
]);
$block_content_type
->save();
$field = FieldConfig::create([
'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
'bundle' => $block_content_type
->id(),
'label' => 'Body',
'settings' => [
'display_summary' => FALSE,
'allowed_formats' => [],
],
]);
$field
->save();
$pages = [
[
'list' => 'admin/structure/types/manage/' . $content_type
->id() . '/fields',
'field' => 'node.' . $content_type
->id() . '.body',
],
[
'list' => 'admin/structure/block-content/manage/basic/fields',
'field' => 'block_content.basic.body',
],
];
foreach ($pages as $values) {
$this
->drupalGet($values['list']);
$translate_link = $values['list'] . '/' . $values['field'] . '/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
}
public function doDateFormatListTest() {
$this
->drupalGet('admin/config/regional/date-time');
$translate_link = 'admin/config/regional/date-time/formats/manage/long/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
public function doSettingsPageTest($link) {
$this
->drupalGet($link);
$translate_link = $link . '/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
}
public function testTranslateOperationInListUi() {
$this
->doBlockListTest();
$this
->doMenuListTest();
$this
->doVocabularyListTest();
$this
->doCustomContentTypeListTest();
$this
->doContactFormsListTest();
$this
->doContentTypeListTest();
$this
->doFormatsListTest();
$this
->doShortcutListTest();
$this
->doUserRoleListTest();
$this
->doLanguageListTest();
$this
->doImageStyleListTest();
$this
->doResponsiveImageListTest();
$this
->doDateFormatListTest();
$this
->doFieldListTest();
$this
->doSettingsPageTest('admin/config/development/maintenance');
$this
->doSettingsPageTest('admin/config/system/site-information');
$this
->doSettingsPageTest('admin/config/people/accounts');
}
}