function CommentFieldFilterTest::setUp
Same name in other branches
- 9 core/modules/comment/tests/src/Functional/Views/CommentFieldFilterTest.php \Drupal\Tests\comment\Functional\Views\CommentFieldFilterTest::setUp()
- 8.9.x core/modules/comment/tests/src/Functional/Views/CommentFieldFilterTest.php \Drupal\Tests\comment\Functional\Views\CommentFieldFilterTest::setUp()
- 10 core/modules/comment/tests/src/Functional/Views/CommentFieldFilterTest.php \Drupal\Tests\comment\Functional\Views\CommentFieldFilterTest::setUp()
Overrides CommentTestBase::setUp
File
-
core/
modules/ comment/ tests/ src/ Functional/ Views/ CommentFieldFilterTest.php, line 44
Class
- CommentFieldFilterTest
- Tests comment field filters with translations.
Namespace
Drupal\Tests\comment\Functional\ViewsCode
protected function setUp($import_test_views = TRUE, $modules = [
'comment_test_views',
]) : void {
parent::setUp($import_test_views, $modules);
$this->drupalLogin($this->drupalCreateUser([
'access comments',
]));
// Add two new languages.
ConfigurableLanguage::createFromLangcode('fr')->save();
ConfigurableLanguage::createFromLangcode('es')->save();
// Set up comment titles.
$this->commentTitles = [
'en' => 'Food in Paris',
'es' => 'Comida en Paris',
'fr' => 'Nourriture en Paris',
];
// Create a new comment. Using the one created earlier will not work,
// as it predates the language set-up.
$comment = [
'uid' => $this->loggedInUser
->id(),
'entity_id' => $this->nodeUserCommented
->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'cid' => '',
'pid' => '',
'node_type' => '',
];
$this->comment = Comment::create($comment);
// Add field values and translate the comment.
$this->comment->subject->value = $this->commentTitles['en'];
$this->comment->comment_body->value = $this->commentTitles['en'];
$this->comment->langcode = 'en';
$this->comment
->save();
foreach ([
'es',
'fr',
] as $langcode) {
$translation = $this->comment
->addTranslation($langcode, []);
$translation->comment_body->value = $this->commentTitles[$langcode];
$translation->subject->value = $this->commentTitles[$langcode];
}
$this->comment
->save();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.