setCommentSettings example



  /** * Tests that threaded comments can be viewed. */
  public function testThreadedCommentView() {
    // Set comments to have subject required and preview disabled.     $this->drupalLogin($this->adminUser);
    $this->setCommentPreview(DRUPAL_DISABLED);
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(TRUE);
    $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
    $this->drupalLogout();

    // Post comment.     $this->drupalLogin($this->webUser);
    $comment_text = $this->randomMachineName();
    $comment_subject = $this->randomMachineName();
    $comment = $this->postComment($this->node, $comment_text$comment_subject);
    $this->assertTrue($this->commentExists($comment), 'Comment found.');

    // Check comment display.     $this->drupalGet('node/' . $this->node->id());
    
protected $defaultTheme = 'olivero';

  /** * Tests comment preview. */
  public function testCommentPreview() {
    // As admin user, configure comment settings.     $this->drupalLogin($this->adminUser);
    $this->setCommentPreview(DRUPAL_OPTIONAL);
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(TRUE);
    $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
    $this->drupalLogout();

    // Log in as web user.     $this->drupalLogin($this->webUser);

    // Test escaping of the username on the preview form.     \Drupal::service('module_installer')->install(['user_hooks_test']);
    \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
    $edit = [];
    $edit['subject[0][value]'] = $this->randomMachineName(8);
    $edit['comment_body[0][value]'] = $this->randomMachineName(16);
    
'status' => CommentInterface::PUBLISHED,
      'subject' => $this->randomMachineName(),
      'hostname' => '127.0.0.1',
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
      'comment_body' => [['value' => $this->randomMachineName()]],
    ]);
    $comment->save();
    $this->comment = $comment;

    // Tests that reply link is not visible when threading is disabled.     $this->drupalLogin($this->webUser);
    $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_FLAT, 'Comment paging changed.');
    $this->drupalGet('node/' . $this->node->id());
    $this->assertSession()->linkNotExists('Reply');
    // Tests that reply link is visible when threading is enabled.     $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
    $this->drupalGet('node/' . $this->node->id());
    $this->assertSession()->linkExists('Reply');

    // Change comment settings.     $this->setCommentSettings('form_location', CommentItemInterface::FORM_BELOW, 'Set comment form location');
    $this->node->comment = CommentItemInterface::OPEN;
    $this->node->save();

    
$mode_text = 'disabled';
        break;

      case DRUPAL_OPTIONAL:
        $mode_text = 'optional';
        break;

      case DRUPAL_REQUIRED:
        $mode_text = 'required';
        break;
    }
    $this->setCommentSettings('preview', $modenew FormattableMarkup('Comment preview @mode_text.', ['@mode_text' => $mode_text])$field_name);
  }

  /** * Sets the value governing whether the comment form is on its own page. * * @param bool $enabled * TRUE if the comment form should be displayed on the same page as the * comments; FALSE if it should be displayed on its own page. * @param string $field_name * (optional) Field name through which the comment should be posted. * Defaults to 'comment'. */
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(TRUE);
    $this->setCommentPreview(DRUPAL_DISABLED);

    // Create a node and three comments.     $node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1]);
    $comments = [];
    $comments[] = $this->postComment($node$this->randomMachineName()$this->randomMachineName(), TRUE);
    $comments[] = $this->postComment($node$this->randomMachineName()$this->randomMachineName(), TRUE);
    $comments[] = $this->postComment($node$this->randomMachineName()$this->randomMachineName(), TRUE);

    $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_FLAT, 'Comment paging changed.');

    // Set "Comments per page" as zero and verify that all comments are appearing     // on the page.     $this->setCommentsPerPage(0);
    $this->drupalGet('node/' . $node->id());
    $this->assertTrue($this->commentExists($comments[0]), 'Comment 1 appears on page.');
    $this->assertTrue($this->commentExists($comments[1]), 'Comment 2 appears on page.');
    $this->assertTrue($this->commentExists($comments[2]), 'Comment 3 appears on page.');

    // Set comments to one per page so that we are able to test paging without     // needing to insert large numbers of comments.
protected $defaultTheme = 'stark';

  /** * Tests the comment threading. */
  public function testCommentThreading() {
    // Set comments to have a subject with preview disabled.     $this->drupalLogin($this->adminUser);
    $this->setCommentPreview(DRUPAL_DISABLED);
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(TRUE);
    $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
    $this->drupalLogout();

    // Create a node.     $this->drupalLogin($this->webUser);
    $this->node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1, 'uid' => $this->webUser->id()]);

    // Post comment #1.     $this->drupalLogin($this->webUser);
    $subject_text = $this->randomMachineName();
    $comment_text = $this->randomMachineName();

    
/** * Tests the node comment statistics. */
  public function testCommentNodeCommentStatistics() {
    $node_storage = $this->container->get('entity_type.manager')->getStorage('node');
    // Set comments to have subject and preview disabled.     $this->drupalLogin($this->adminUser);
    $this->setCommentPreview(DRUPAL_DISABLED);
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(FALSE);
    $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
    $this->drupalLogout();

    // Checks the initial values of node comment statistics with no comment.     $node = $node_storage->load($this->node->id());
    $this->assertEquals($this->node->getCreatedTime()$node->get('comment')->last_comment_timestamp, 'The initial value of node last_comment_timestamp is the node created date.');
    $this->assertNull($node->get('comment')->last_comment_name, 'The initial value of node last_comment_name is NULL.');
    $this->assertEquals($this->webUser->id()$node->get('comment')->last_comment_uid, 'The initial value of node last_comment_uid is the node uid.');
    $this->assertEquals(0, $node->get('comment')->comment_count, 'The initial value of node comment_count is zero.');

    // Post comment #1 as web_user2.     $this->drupalLogin($this->webUser2);
    
parent::setUp();
    $this->drupalLogin($this->adminUser);
    // Make sure that comment field title is not displayed when there's no     // comments posted.     $this->drupalGet($this->node->toUrl());
    $this->assertSession()->responseNotMatches('@<h2[^>]*>Comments</h2>@');

    // Set comments to have subject and preview disabled.     $this->setCommentPreview(DRUPAL_DISABLED);
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(FALSE);
    $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
    $this->drupalLogout();
  }

  /** * Tests the comment interface. */
  public function testCommentInterface() {

    // Post comment #1 without subject or preview.     $this->drupalLogin($this->webUser);
    $comment_text = $this->randomMachineName();
    
Home | Imprint | This part of the site doesn't use cookies.