setCommentAnonymous example

'access comments',
      'post comments',
      'skip comment approval',
    ]);
  }

  /** * Tests anonymous comment functionality. */
  public function testAnonymous() {
    $this->drupalLogin($this->adminUser);
    $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAYNOT_CONTACT);
    $this->drupalLogout();

    // Preview comments (with `skip comment approval` permission).     $edit = [];
    $title = 'comment title with skip comment approval';
    $body = 'comment body with skip comment approval';
    $edit['subject[0][value]'] = $title;
    $edit['comment_body[0][value]'] = $body;
    $this->drupalGet($this->node->toUrl());
    $this->submitForm($edit, 'Preview');
    // Cannot use assertRaw here since both title and body are in the form.

  public function testApprovalAdminInterface() {
    // Set anonymous comments to require approval.     user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [
      'access comments' => TRUE,
      'post comments' => TRUE,
      'skip comment approval' => FALSE,
    ]);
    $this->drupalLogin($this->adminUser);
    // Ensure that doesn't require contact info.     $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAYNOT_CONTACT);

    // Test that the comments page loads correctly when there are no comments     $this->drupalGet('admin/content/comment');
    $this->assertSession()->pageTextContains('No comments available.');

    $this->drupalLogout();

    // Post anonymous comment without contact info.     $subject = $this->randomMachineName();
    $body = $this->randomMachineName();
    // Set $contact to true so that it won't check for id and message.
    $this->drupalLogin($this->rootUser);
    $this->drupalGet('admin/people/permissions');
    $edit = [
      'anonymous[access comments]' => 1,
      'anonymous[post comments]' => 1,
      'anonymous[skip comment approval]' => 0,
    ];
    $this->submitForm($edit, 'Save permissions');
    $this->drupalLogout();

    // Ensure that the poster can leave some contact info.     $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAY_CONTACT);

    // Post comment #2 as anonymous (comment approval enabled).     $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment');
    $anonymous_comment = $this->postComment($this->node, $this->randomMachineName(), '', TRUE);

    // Checks the new values of node comment statistics with comment #2 and     // ensure they haven't changed since the comment has not been moderated.     // The node needs to be reloaded with the cache reset.     $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.');
    

  public function testApprovalAdminInterface() {
    // Set anonymous comments to require approval.     user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [
      'access comments' => TRUE,
      'post comments' => TRUE,
      'skip comment approval' => FALSE,
    ]);
    $this->drupalPlaceBlock('page_title_block');
    $this->drupalLogin($this->adminUser);
    // Ensure that doesn't require contact info.     $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAYNOT_CONTACT);

    // Test that the comments page loads correctly when there are no comments.     $this->drupalGet('admin/content/comment');
    $this->assertSession()->pageTextContains('No comments available.');

    // Assert the expose filters on the admin page.     $this->assertSession()->fieldExists('subject');
    $this->assertSession()->fieldExists('author_name');
    $this->assertSession()->fieldExists('langcode');

    $this->drupalLogout();

    
Home | Imprint | This part of the site doesn't use cookies.