function CommentLanguageTest::setUp
Same name in other branches
- 9 core/modules/comment/tests/src/Functional/CommentLanguageTest.php \Drupal\Tests\comment\Functional\CommentLanguageTest::setUp()
- 8.9.x core/modules/comment/tests/src/Functional/CommentLanguageTest.php \Drupal\Tests\comment\Functional\CommentLanguageTest::setUp()
- 11.x core/modules/comment/tests/src/Functional/CommentLanguageTest.php \Drupal\Tests\comment\Functional\CommentLanguageTest::setUp()
Overrides BrowserTestBase::setUp
File
-
core/
modules/ comment/ tests/ src/ Functional/ CommentLanguageTest.php, line 46
Class
- CommentLanguageTest
- Tests for comment language.
Namespace
Drupal\Tests\comment\FunctionalCode
protected function setUp() : void {
parent::setUp();
$this->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
// Create and log in user.
$admin_user = $this->drupalCreateUser([
'administer site configuration',
'administer languages',
'access administration pages',
'administer content types',
'administer comments',
'create article content',
'access comments',
'post comments',
'skip comment approval',
]);
$this->drupalLogin($admin_user);
// Add language.
$edit = [
'predefined_langcode' => 'fr',
];
$this->drupalGet('admin/config/regional/language/add');
$this->submitForm($edit, 'Add language');
// Set "Article" content type to use multilingual support.
$edit = [
'language_configuration[language_alterable]' => TRUE,
];
$this->drupalGet('admin/structure/types/manage/article');
$this->submitForm($edit, 'Save');
// Enable content language negotiation UI.
\Drupal::state()->set('language_test.content_language_type', TRUE);
// Set interface language detection to user and content language detection
// to URL. Disable inheritance from interface language to ensure content
// language will fall back to the default language if no URL language can be
// detected.
$edit = [
'language_interface[enabled][language-user]' => TRUE,
'language_content[enabled][language-url]' => TRUE,
'language_content[enabled][language-interface]' => FALSE,
];
$this->drupalGet('admin/config/regional/language/detection');
$this->submitForm($edit, 'Save settings');
// Change user language preference, this way interface language is always
// French no matter what path prefix the URLs have.
$edit = [
'preferred_langcode' => 'fr',
];
$this->drupalGet("user/" . $admin_user->id() . "/edit");
$this->submitForm($edit, 'Save');
// Create comment field on article.
$this->addDefaultCommentField('node', 'article');
// Make comment body translatable.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$field_storage->setTranslatable(TRUE);
$field_storage->save();
$this->assertTrue($field_storage->isTranslatable(), 'Comment body is translatable.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.