You are here

protected function CommentLinkBuilderTest::getMockNode in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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.

1 call to CommentLinkBuilderTest::getMockNode()
CommentLinkBuilderTest::getLinkCombinations in core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php
Data provider for ::testCommentLinkBuilder.

File

core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php, line 273
Contains \Drupal\Tests\comment\Unit\CommentLinkBuilderTest.

Class

CommentLinkBuilderTest
@coversDefaultClass \Drupal\comment\CommentLinkBuilder @group comment

Namespace

Drupal\Tests\comment\Unit

Code

protected function getMockNode($has_field, $comment_status, $form_location, $comment_count) {
  $node = $this
    ->getMock('\\Drupal\\node\\NodeInterface');
  $node
    ->expects($this
    ->once())
    ->method('hasField')
    ->willReturn($has_field);
  if (empty($this->timestamp)) {
    $this->timestamp = time();
  }
  $field_item = (object) array(
    '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
    ->getMock('\\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('urlInfo')
    ->willReturn($url);
  $node
    ->expects($this
    ->any())
    ->method('url')
    ->willReturn(array(
    'route_name' => 'node.view',
  ));
  return $node;
}