setCommentSubject example


  protected $defaultTheme = 'stark';

  /** * Confirms comment paging works correctly with flat and threaded comments. */
  public function testCommentPaging() {
    $this->drupalLogin($this->adminUser);

    // Set comment variables.     $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.');

    


  /** * 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.
protected function setUp(): void {
    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);
    

  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);
    
    $this->node->setOwnerId($this->webUser->id())->save();
  }

  /** * 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.
    Vocabulary::create([
      'vid' => 'tags',
      'name' => 'Tags',
    ])->save();

    // Change the title of the admin user.     $this->adminUser->name->value = 'This is a title with some special & > " stuff.';
    $this->adminUser->save();
    $this->drupalLogin($this->adminUser);

    // Set comment variables.     $this->setCommentSubject(TRUE);

    // To test hostname token field should be populated.     \Drupal::configFactory()
      ->getEditable('comment.settings')
      ->set('log_ip_addresses', TRUE)
      ->save(TRUE);

    // Create a node and a comment.     $node = $this->drupalCreateNode(['type' => 'article', 'title' => '<script>alert("123")</script>']);
    $parent_comment = $this->postComment($node$this->randomMachineName()$this->randomMachineName(), TRUE);

    

  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();

    
$this->postComment($this->node, $comment_text$subject_text, TRUE);
    // Tests that markup is generated for the comment title.     $regex_h3 = '|<h3[^>]*>.*?</h3>|';
    $this->assertSession()->responseMatches($regex_h3);

    // Installs module that sets comment title to an empty string.     \Drupal::service('module_installer')->install(['comment_empty_title_test']);

    // Set comments to have a subject with preview disabled.     $this->setCommentPreview(DRUPAL_DISABLED);
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(TRUE);

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

    // Post another comment and verify that h3 is not rendered.     $subject_text = $this->randomMachineName();
    $comment_text = $this->randomMachineName();
    $comment = $this->postComment($this->node, $comment_text$subject_text, TRUE);

    // The entity fields for name and mail have no meaning if the user is not     // Anonymous.
Home | Imprint | This part of the site doesn't use cookies.