// Checks the initial values of node comment statistics with no comment.
$node =
$node_storage->
load($this->node->
id());
$this->
assertEquals($this->node->
getCreatedTime(),
$node->
get('comment'
)->last_comment_timestamp, 'The initial value of node last_comment_timestamp is the node created date.'
);
$this->
assertNull($node->
get('comment'
)->last_comment_name, 'The initial value of node last_comment_name is NULL.'
);
$this->
assertEquals($this->webUser->
id(),
$node->
get('comment'
)->last_comment_uid, 'The initial value of node last_comment_uid is the node uid.'
);
$this->
assertEquals(0,
$node->
get('comment'
)->comment_count, 'The initial value of node comment_count is zero.'
);
// Post comment #1 as web_user2.
$this->
drupalLogin($this->webUser2
);
$comment_text =
$this->
randomMachineName();
$this->
postComment($this->node,
$comment_text);
// Checks the new values of node comment statistics with comment #1.
// The node cache needs to be reset before reload.
$node_storage->
resetCache([$this->node->
id()]);
$node =
$node_storage->
load($this->node->
id());
$this->
assertSame('',
$node->
get('comment'
)->last_comment_name, 'The value of node last_comment_name should be an empty string.'
);
$this->
assertEquals($this->webUser2->
id(),
$node->
get('comment'
)->last_comment_uid, 'The value of node last_comment_uid is the comment #1 uid.'
);
$this->
assertEquals(1,
$node->
get('comment'
)->comment_count, 'The value of node comment_count is 1.'
);
// Prepare for anonymous comment submission (comment approval enabled).
// Note we don't use user_role_change_permissions(), because that caused