protected function CommentLinkBuilderTest::getMockNode in Drupal 10
Same name and namespace in other branches
- 8 core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php \Drupal\Tests\comment\Unit\CommentLinkBuilderTest::getMockNode()
- 9 core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php \Drupal\Tests\comment\Unit\CommentLinkBuilderTest::getMockNode()
Builds a mock node based on given scenario.
Parameters
bool $has_field: TRUE if the node has the 'comment' field.
int $comment_status: One of CommentItemInterface::OPEN|HIDDEN|CLOSED
int $form_location: One of CommentItemInterface::FORM_BELOW|FORM_SEPARATE_PAGE
int $comment_count: Number of comments against the field.
Return value
\Drupal\node\NodeInterface|\PHPUnit\Framework\MockObject\MockObject Mock node for testing.
File
- core/
modules/ comment/ tests/ src/ Unit/ CommentLinkBuilderTest.php, line 271
Class
- CommentLinkBuilderTest
- @coversDefaultClass \Drupal\comment\CommentLinkBuilder @group comment
Namespace
Drupal\Tests\comment\UnitCode
protected function getMockNode($has_field, $comment_status, $form_location, $comment_count) {
$node = $this
->createMock('\\Drupal\\node\\NodeInterface');
$node
->expects($this
->any())
->method('hasField')
->willReturn($has_field);
if (empty($this->timestamp)) {
$this->timestamp = time();
}
$field_item = (object) [
'status' => $comment_status,
'comment_count' => $comment_count,
'last_comment_timestamp' => $this->timestamp,
];
$node
->expects($this
->any())
->method('get')
->with('comment')
->willReturn($field_item);
$field_definition = $this
->createMock('\\Drupal\\Core\\Field\\FieldDefinitionInterface');
$field_definition
->expects($this
->any())
->method('getSetting')
->with('form_location')
->willReturn($form_location);
$node
->expects($this
->any())
->method('getFieldDefinition')
->with('comment')
->willReturn($field_definition);
$node
->expects($this
->any())
->method('language')
->willReturn('und');
$node
->expects($this
->any())
->method('getEntityTypeId')
->willReturn('node');
$node
->expects($this
->any())
->method('id')
->willReturn(1);
$url = Url::fromRoute('node.view');
$node
->expects($this
->any())
->method('toUrl')
->willReturn($url);
return $node;
}