class TranslatedViewTest
Same name and namespace in other branches
- 11.x core/modules/views_ui/tests/src/Functional/TranslatedViewTest.php \Drupal\Tests\views_ui\Functional\TranslatedViewTest
Tests that translated strings in views UI don't override original strings.
@group views_ui
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\views_ui\Functional\UITestBase implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views_ui\Functional\TranslatedViewTest implements \Drupal\Tests\views_ui\Functional\UITestBase
- class \Drupal\Tests\views_ui\Functional\UITestBase implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of TranslatedViewTest
File
-
core/
modules/ views_ui/ tests/ src/ Functional/ TranslatedViewTest.php, line 12
Namespace
Drupal\Tests\views_ui\FunctionalView source
class TranslatedViewTest extends UITestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'config_translation',
'views_ui',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Languages to enable.
*
* @var array
*/
protected $langcodes = [
'fr',
];
/**
* Administrator user for tests.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE, $modules = []) : void {
parent::setUp($import_test_views, $modules);
$permissions = [
'administer site configuration',
'administer views',
'translate configuration',
'translate interface',
];
// Create and log in user.
$this->adminUser = $this->drupalCreateUser($permissions);
$this->drupalLogin($this->adminUser);
// Add languages.
foreach ($this->langcodes as $langcode) {
ConfigurableLanguage::createFromLangcode($langcode)->save();
}
$this->resetAll();
$this->rebuildContainer();
}
public function testTranslatedStrings() {
$translation_url = 'admin/structure/views/view/files/translate/fr/add';
$edit_url = 'admin/structure/views/view/files';
// Check the original string.
$this->drupalGet($edit_url);
$this->assertSession()
->titleEquals('Files (File) | Drupal');
// Translate the label of the view.
$this->drupalGet($translation_url);
$edit = [
'translation[config_names][views.view.files][label]' => 'Fichiers',
];
$this->submitForm($edit, 'Save translation');
// Check if the label is translated.
$this->drupalGet($edit_url, [
'language' => \Drupal::languageManager()->getLanguage('fr'),
]);
$this->assertSession()
->titleEquals('Files (File) | Drupal');
$this->assertSession()
->pageTextNotContains('Fichiers');
// Ensure that "Link URL" and "Link Path" fields are translatable.
// First, Add the block display and change pager's 'link display' to
// custom URL.
// Second, change filename to use plain text and rewrite output with link.
$this->drupalGet($edit_url);
$this->submitForm([], 'Add Block');
$this->drupalGet('admin/structure/views/nojs/display/files/block_1/link_display');
$edit = [
'link_display' => 'custom_url',
'link_url' => '/node',
];
$this->submitForm($edit, 'Apply');
$this->submitForm([], 'Save');
$this->drupalGet('admin/structure/views/nojs/handler/files/block_1/field/filename');
$edit = [
'override[dropdown]' => 'block_1',
'options[type]' => 'string',
'options[alter][path]' => '/node',
'options[alter][make_link]' => 1,
];
$this->submitForm($edit, 'Apply');
$this->submitForm([], 'Save');
// Visit the translation page and ensure that field exists.
$this->drupalGet($translation_url);
$this->assertSession()
->fieldExists('translation[config_names][views.view.files][display][block_1][display_options][fields][filename][alter][path]');
$this->assertSession()
->fieldExists('translation[config_names][views.view.files][display][default][display_options][link_url]');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.