public function LocaleContentTest::testContentTypeDirLang in Drupal 9
Same name and namespace in other branches
- 8 core/modules/locale/tests/src/Functional/LocaleContentTest.php \Drupal\Tests\locale\Functional\LocaleContentTest::testContentTypeDirLang()
- 10 core/modules/locale/tests/src/Functional/LocaleContentTest.php \Drupal\Tests\locale\Functional\LocaleContentTest::testContentTypeDirLang()
Tests if a dir and lang tags exist in node's attributes.
File
- core/
modules/ locale/ tests/ src/ Functional/ LocaleContentTest.php, line 161
Class
- LocaleContentTest
- Tests you can enable multilingual support on content types and configure a language for a node.
Namespace
Drupal\Tests\locale\FunctionalCode
public function testContentTypeDirLang() {
$type = $this
->drupalCreateContentType();
// User to add and remove language.
$admin_user = $this
->drupalCreateUser([
'administer languages',
'administer content types',
'access administration pages',
]);
// User to create a node.
$web_user = $this
->drupalCreateUser([
"create {$type->id()} content",
"edit own {$type->id()} content",
]);
// Log in as admin.
$this
->drupalLogin($admin_user);
// Install Arabic language.
$edit = [];
$edit['predefined_langcode'] = 'ar';
$this
->drupalGet('admin/config/regional/language/add');
$this
->submitForm($edit, 'Add language');
// Install Spanish language.
$edit = [];
$edit['predefined_langcode'] = 'es';
$this
->drupalGet('admin/config/regional/language/add');
$this
->submitForm($edit, 'Add language');
\Drupal::languageManager()
->reset();
// Set the content type to use multilingual support.
$this
->drupalGet("admin/structure/types/manage/{$type->id()}");
$edit = [
'language_configuration[language_alterable]' => TRUE,
];
$this
->drupalGet("admin/structure/types/manage/{$type->id()}");
$this
->submitForm($edit, 'Save content type');
$this
->assertSession()
->pageTextContains("The content type {$type->label()} has been updated.");
$this
->drupalLogout();
// Log in as web user to add new node.
$this
->drupalLogin($web_user);
// Create three nodes: English, Arabic and Spanish.
$nodes = [];
foreach ([
'en',
'es',
'ar',
] as $langcode) {
$nodes[$langcode] = $this
->drupalCreateNode([
'langcode' => $langcode,
'type' => $type
->id(),
'promote' => NodeInterface::PROMOTED,
]);
}
// Check if English node does not have lang tag.
$this
->drupalGet('node/' . $nodes['en']
->id());
$element = $this
->cssSelect('article.node[lang="en"]');
$this
->assertTrue(empty($element), 'The lang tag has not been assigned to the English node.');
// Check if English node does not have dir tag.
$element = $this
->cssSelect('article.node[dir="ltr"]');
$this
->assertTrue(empty($element), 'The dir tag has not been assigned to the English node.');
// Check if Arabic node has lang="ar" & dir="rtl" tags.
$this
->drupalGet('node/' . $nodes['ar']
->id());
$element = $this
->cssSelect('article.node[lang="ar"][dir="rtl"]');
$this
->assertTrue(!empty($element), 'The lang and dir tags have been assigned correctly to the Arabic node.');
// Check if Spanish node has lang="es" tag.
$this
->drupalGet('node/' . $nodes['es']
->id());
$element = $this
->cssSelect('article.node[lang="es"]');
$this
->assertTrue(!empty($element), 'The lang tag has been assigned correctly to the Spanish node.');
// Check if Spanish node does not have dir="ltr" tag.
$element = $this
->cssSelect('article.node[lang="es"][dir="ltr"]');
$this
->assertTrue(empty($element), 'The dir tag has not been assigned to the Spanish node.');
}