CommentTestBase.php in Drupal 10
File
core/modules/comment/tests/src/Functional/Views/CommentTestBase.php
View source
<?php
namespace Drupal\Tests\comment\Functional\Views;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\comment\Entity\Comment;
abstract class CommentTestBase extends ViewTestBase {
use CommentTestTrait;
protected static $modules = [
'node',
'comment',
'comment_test_views',
];
protected $account;
protected $account2;
protected $nodeUserPosted;
protected $nodeUserCommented;
protected $comment;
protected function setUp($import_test_views = TRUE, $modules = [
'comment_test_views',
]) : void {
parent::setUp($import_test_views, $modules);
$this->account = $this
->drupalCreateUser([
'skip comment approval',
]);
$this->account2 = $this
->drupalCreateUser();
$this
->drupalLogin($this->account);
$this
->drupalCreateContentType([
'type' => 'page',
'name' => t('Basic page'),
]);
$this
->addDefaultCommentField('node', 'page');
$this->nodeUserPosted = $this
->drupalCreateNode();
$this->nodeUserCommented = $this
->drupalCreateNode([
'uid' => $this->account2
->id(),
]);
$comment = [
'uid' => $this->loggedInUser
->id(),
'entity_id' => $this->nodeUserCommented
->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'subject' => 'How much wood would a woodchuck chuck',
'cid' => '',
'pid' => '',
'mail' => 'someone@example.com',
];
$this->comment = Comment::create($comment);
$this->comment
->save();
}
}