/**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->keyValue = $this->getMock('Drupal\\Core\\KeyValueStore\\KeyValueStoreExpirableInterface');
     $this->lock = $this->getMock('Drupal\\Core\\Lock\\LockBackendInterface');
     $this->currentUser = $this->getMock('Drupal\\Core\\Session\\AccountProxyInterface');
     $this->currentUser->expects($this->any())->method('id')->willReturn(1);
     $this->requestStack = new RequestStack();
     $this->tempStore = new PrivateTempStore($this->keyValue, $this->lock, $this->currentUser, $this->requestStack, 604800);
     $this->ownObject = (object) array('data' => 'test_data', 'owner' => $this->currentUser->id(), 'updated' => REQUEST_TIME);
     // Clone the object but change the owner.
     $this->otherObject = clone $this->ownObject;
     $this->otherObject->owner = 2;
 }
 /**
  * Test the buildCommentedEntityLinks method.
  *
  * @param \Drupal\node\NodeInterface|\PHPUnit_Framework_MockObject_MockObject $node
  *   Mock node.
  * @param array $context
  *   Context for the links.
  * @param bool $has_access_comments
  *   TRUE if the user has 'access comments' permission.
  * @param bool $history_exists
  *   TRUE if the history module exists.
  * @param bool $has_post_comments
  *   TRUE if the use has 'post comments' permission.
  * @param bool $is_anonymous
  *   TRUE if the user is anonymous.
  * @param array $expected
  *   Array of expected links keyed by link ID. Can be either string (link
  *   title) or array of link properties.
  *
  * @dataProvider getLinkCombinations
  *
  * @covers ::buildCommentedEntityLinks
  */
 public function testCommentLinkBuilder(NodeInterface $node, $context, $has_access_comments, $history_exists, $has_post_comments, $is_anonymous, $expected)
 {
     $this->moduleHandler->expects($this->any())->method('moduleExists')->with('history')->willReturn($history_exists);
     $this->currentUser->expects($this->any())->method('hasPermission')->willReturnMap(array(array('access comments', $has_access_comments), array('post comments', $has_post_comments)));
     $this->currentUser->expects($this->any())->method('isAuthenticated')->willReturn(!$is_anonymous);
     $this->currentUser->expects($this->any())->method('isAnonymous')->willReturn($is_anonymous);
     $links = $this->commentLinkBuilder->buildCommentedEntityLinks($node, $context);
     if (!empty($expected)) {
         if (!empty($links)) {
             foreach ($expected as $link => $detail) {
                 if (is_array($detail)) {
                     // Array of link attributes.
                     foreach ($detail as $key => $value) {
                         $this->assertEquals($value, $links['comment__comment']['#links'][$link][$key]);
                     }
                 } else {
                     // Just the title.
                     $this->assertEquals($detail, $links['comment__comment']['#links'][$link]['title']);
                 }
             }
         } else {
             $this->fail('Expected links but found none.');
         }
     } else {
         $this->assertSame($links, $expected);
     }
 }