Chris@0: install(['stark']); Chris@0: $this->config('system.theme') Chris@0: ->set('default', 'stark') Chris@0: ->save(); Chris@0: Chris@0: // Remove additional user permissions from $this->webUser added by setUp(), Chris@0: // since this test is limited to anonymous and authenticated roles only. Chris@0: $roles = $this->webUser->getRoles(); Chris@0: entity_delete_multiple('user_role', [reset($roles)]); Chris@0: Chris@0: // Create a comment via CRUD API functionality, since Chris@0: // $this->postComment() relies on actual user permissions. Chris@0: $comment = Comment::create([ Chris@0: 'cid' => NULL, Chris@0: 'entity_id' => $this->node->id(), Chris@0: 'entity_type' => 'node', Chris@0: 'field_name' => 'comment', Chris@0: 'pid' => 0, Chris@0: 'uid' => 0, Chris@0: 'status' => CommentInterface::PUBLISHED, Chris@0: 'subject' => $this->randomMachineName(), Chris@0: 'hostname' => '127.0.0.1', Chris@0: 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, Chris@0: 'comment_body' => [['value' => $this->randomMachineName()]], Chris@0: ]); Chris@0: $comment->save(); Chris@0: $this->comment = $comment; Chris@0: Chris@0: // Change comment settings. Chris@0: $this->setCommentSettings('form_location', CommentItemInterface::FORM_BELOW, 'Set comment form location'); Chris@0: $this->setCommentAnonymous(TRUE); Chris@0: $this->node->comment = CommentItemInterface::OPEN; Chris@0: $this->node->save(); Chris@0: Chris@0: // Change user permissions. Chris@0: $perms = [ Chris@0: 'access comments' => 1, Chris@0: 'post comments' => 1, Chris@0: 'skip comment approval' => 1, Chris@0: 'edit own comments' => 1, Chris@0: ]; Chris@0: user_role_change_permissions(RoleInterface::ANONYMOUS_ID, $perms); Chris@0: Chris@0: $nid = $this->node->id(); Chris@0: Chris@0: // Assert basic link is output, actual functionality is unit-tested in Chris@0: // \Drupal\comment\Tests\CommentLinkBuilderTest. Chris@0: foreach (['node', "node/$nid"] as $path) { Chris@0: $this->drupalGet($path); Chris@0: Chris@0: // In teaser view, a link containing the comment count is always Chris@0: // expected. Chris@0: if ($path == 'node') { Chris@0: $this->assertLink(t('1 comment')); Chris@0: } Chris@0: $this->assertLink('Add new comment'); Chris@0: } Chris@0: Chris@0: // Change weight to make links go before comment body. Chris@0: entity_get_display('comment', 'comment', 'default') Chris@0: ->setComponent('links', ['weight' => -100]) Chris@0: ->save(); Chris@18: $this->drupalGet($this->node->toUrl()); Chris@0: $element = $this->cssSelect('article.js-comment > div'); Chris@0: // Get last child element. Chris@0: $element = end($element); Chris@0: $this->assertIdentical($element->getTagName(), 'div', 'Last element is comment body.'); Chris@0: Chris@0: // Change weight to make links go after comment body. Chris@0: entity_get_display('comment', 'comment', 'default') Chris@0: ->setComponent('links', ['weight' => 100]) Chris@0: ->save(); Chris@18: $this->drupalGet($this->node->toUrl()); Chris@0: $element = $this->cssSelect('article.js-comment > div'); Chris@0: // Get last child element. Chris@0: $element = end($element); Chris@0: $this->assertNotEmpty($element->find('css', 'ul.links'), 'Last element is comment links.'); Chris@0: Chris@0: // Make sure we can hide node links. Chris@0: entity_get_display('node', $this->node->bundle(), 'default') Chris@0: ->removeComponent('links') Chris@0: ->save(); Chris@18: $this->drupalGet($this->node->toUrl()); Chris@0: $this->assertNoLink('1 comment'); Chris@0: $this->assertNoLink('Add new comment'); Chris@0: Chris@0: // Visit the full node, make sure there are links for the comment. Chris@0: $this->drupalGet('node/' . $this->node->id()); Chris@0: $this->assertText($comment->getSubject()); Chris@0: $this->assertLink('Reply'); Chris@0: Chris@0: // Make sure we can hide comment links. Chris@0: entity_get_display('comment', 'comment', 'default') Chris@0: ->removeComponent('links') Chris@0: ->save(); Chris@0: $this->drupalGet('node/' . $this->node->id()); Chris@0: $this->assertText($comment->getSubject()); Chris@0: $this->assertNoLink('Reply'); Chris@0: } Chris@0: Chris@0: }