addDefaultCommentField example


  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    node_access_rebuild();
    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
    $this->addDefaultCommentField('node', 'page');
    $this->webUser = $this->drupalCreateUser([
      'access content',
      'access comments',
      'node test view',
    ]);
  }

  /** * Tests the comment pager for nodes with multiple grants per realm. */
  public function testCommentPager() {
    
$returned_page = \Drupal::entityTypeManager()->getStorage('comment')
        ->getNewCommentPageNumber($node->get('comment')->comment_count, $new_replies$node, 'comment');
      $this->assertEquals($expected_page$returned_pagenew FormattableMarkup('Threaded mode, @new replies: expected page @expected, returned page @returned.', ['@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page]));
    }
  }

  /** * Confirms comment paging works correctly with two pagers. */
  public function testTwoPagers() {
    // Add another field to article content-type.     $this->addDefaultCommentField('node', 'article', 'comment_2');
    // Set default to display comment list with unique pager id.     \Drupal::service('entity_display.repository')
      ->getViewDisplay('node', 'article')
      ->setComponent('comment_2', [
        'label' => 'hidden',
        'type' => 'comment_default',
        'weight' => 30,
        'settings' => [
          'pager_id' => 1,
          'view_mode' => 'default',
        ],
      ])
'access content',
      'access comments',
      'post comments',
      'skip comment approval',
      $filtered_html_format->getPermissionName(),
    ]);
    $this->drupalLogin($webUser);

    // Setup a node to comment and test on.     $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
    // Add a comment field.     $this->addDefaultCommentField('node', 'page');
  }

  /** * Tests removal of images having a non-local source. */
  public function testImageSource() {
    global $base_url;

    $node = $this->drupalCreateNode();

    $public_files_path = PublicStream::basePath();

    


  /** * Tests hook invocations for CRUD operations on comments. */
  public function testCommentHooks() {
    $account = $this->createUser();
    NodeType::create([
      'type' => 'article',
      'name' => 'Article',
    ])->save();
    $this->addDefaultCommentField('node', 'article', 'comment', CommentItemInterface::OPEN);

    $node = Node::create([
      'uid' => $account->id(),
      'type' => 'article',
      'title' => 'Test node',
      'status' => 1,
      'promote' => 0,
      'sticky' => 0,
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
      'created' => REQUEST_TIME,
      'changed' => REQUEST_TIME,
    ]);

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE, $modules = []): void {
    parent::setUp($import_test_views$modules);
    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
    // Add comment field to page node type.     $this->addDefaultCommentField('node', 'page');
  }

  /** * Tests adding a view of comments. */
  public function testCommentWizard() {
    $view = [];
    $view['label'] = $this->randomMachineName(16);
    $view['id'] = strtolower($this->randomMachineName(16));
    $view['show[wizard_key]'] = 'comment';
    $view['page[create]'] = TRUE;
    
parent::setUp();
    $this->drupalPlaceBlock('system_breadcrumb_block');
    $this->drupalPlaceBlock('page_title_block');

    $this->adminUser = $this->drupalCreateUser([
      'administer nodes',
      'create article content',
      'create page content',
      'post comments',
    ]);
    $this->drupalLogin($this->adminUser);
    $this->addDefaultCommentField('node', 'page');
  }

  /** * Creates one node and tests if the node title has the correct value. */
  public function testNodeTitle() {
    // Create "Basic page" content with title.     // Add the node to the frontpage so we can test if teaser links are     // clickable.     $settings = [
      'title' => $this->randomMachineName(8),
      
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE, $modules = ['views_test_config']): void {
    parent::setUp($import_test_views$modules);
    $this->drupalCreateContentType(['type' => 'page']);
    $this->addDefaultCommentField('node', 'page');
    $this->enableViewsTestModule();
  }

  /** * {@inheritdoc} */
  protected function viewsData() {
    $data = parent::viewsData();
    // Override the name handler to be able to call placeholder() from outside.     $data['views_test_data']['name']['field']['id'] = 'test_field';

    
'administer filters',
      $full_html_format->getPermissionName(),
      'administer permissions',
      'create page content',
      'post comments',
      'skip comment approval',
      'access comments',
    ];
    $this->adminUser = $this->drupalCreateUser($permissions);
    $this->drupalLogin($this->adminUser);
    // Add a comment field.     $this->addDefaultCommentField('node', 'article');
  }

  /** * Verify that comments are rendered using proper format in search results. */
  public function testSearchResultsComment() {
    $node_storage = $this->container->get('entity_type.manager')->getStorage('node');
    // Create basic_html format that escapes all HTML.     $basic_html_format = FilterFormat::create([
      'format' => 'basic_html',
      'name' => 'Basic HTML',
      
->save();

    // Create a comment type.     CommentType::create([
      'id' => 'comment',
      'label' => 'Default comments',
      'description' => 'Default comment field',
      'target_entity_type_id' => 'node',
    ])->save();

    // Add comment and entity reference comment fields.     $this->addDefaultCommentField('node', 'page', 'comment');
    $this->createEntityReferenceField(
      'node',
      'page',
      'entity_reference_comment',
      'Entity Reference Comment',
      'comment',
      'default',
      ['target_bundles' => ['comment']]
    );

    $comment_admin_user = $this->drupalCreateUser([
      
    $this->drupalGet('admin/structure/comment/manage/comment/fields');
    $this->assertCount(0, $this->cssSelect('tr#comment-body'), 'Body field does not exist.');
  }

  /** * Tests deleting a comment type that still has content. */
  public function testCommentTypeDeletion() {
    // Create a comment type programmatically.     $type = $this->createCommentType('foo');
    $this->drupalCreateContentType(['type' => 'page']);
    $this->addDefaultCommentField('node', 'page', 'foo', CommentItemInterface::OPEN, 'foo');
    $field_storage = FieldStorageConfig::loadByName('node', 'foo');

    $this->drupalLogin($this->adminUser);

    // Create a node.     $node = Node::create([
      'type' => 'page',
      'title' => 'foo',
    ]);
    $node->save();

    

  protected function setUp($import_test_views = TRUE, $modules = ['comment_test_views']): void {
    parent::setUp($import_test_views$modules);

    // Add two users, create a node with the user1 as author and another node     // with user2 as author. For the second node add a comment from user1.     $this->account = $this->drupalCreateUser(['skip comment approval']);
    $this->account2 = $this->drupalCreateUser();
    $this->drupalLogin($this->account);

    $this->drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]);
    $this->addDefaultCommentField('node', 'page');

    $this->nodeUserPosted = $this->drupalCreateNode();
    $this->nodeUserCommented = $this->drupalCreateNode(['uid' => $this->account2->id()]);

    $comment = [
      'uid' => $this->loggedInUser->id(),
      'entity_id' => $this->nodeUserCommented->id(),
      'entity_type' => 'node',
      'field_name' => 'comment',
      'subject' => 'How much wood would a woodchuck chuck',
      'cid' => '',
      

    $this->webUser = $this->drupalCreateUser([
      'access comments',
      'post comments',
      'create article content',
      'edit own comments',
      'skip comment approval',
      'access content',
    ]);

    // Create comment field on article.     $this->addDefaultCommentField('node', 'article');

    // Create a test node authored by the web user.     $this->node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1, 'uid' => $this->webUser->id()]);
    $this->drupalPlaceBlock('local_tasks_block');
  }

  /** * Posts a comment. * * @param \Drupal\Core\Entity\EntityInterface|null $entity * Node to post comment on or NULL to post to the previously loaded page. * @param string $comment * Comment body. * @param string $subject * Comment subject. * @param string $contact * Set to NULL for no contact info, TRUE to ignore success checking, and * array of values to set contact info. * @param string $field_name * (optional) Field name through which the comment should be posted. * Defaults to 'comment'. * * @return \Drupal\comment\CommentInterface|null * The posted comment or NULL when posted comment was not found. */
// An unprivileged user.     $comment_disabled_user = $this->createUser(['access content'], 'disabled');

    $role = Role::load(RoleInterface::ANONYMOUS_ID);
    $role->grantPermission('post comments')
      ->save();

    $anonymous_user = new AnonymousUserSession();

    // Add two fields.     $this->addDefaultCommentField('entity_test', 'entity_test', 'comment');
    $this->addDefaultCommentField('entity_test', 'entity_test', 'comment_other');

    // Create a comment against a test entity.     $host = EntityTest::create();
    $host->save();

    $host2 = EntityTest::create();
    $host2->comment->status = CommentItemInterface::CLOSED;
    $host2->comment_other->status = CommentItemInterface::CLOSED;
    $host2->save();

    
protected function setUp(): void {
    parent::setUp();

    $this->vocab = $this->createVocabulary();
    $this->commentType = CommentType::create([
      'id' => 'taxonomy_comment',
      'label' => 'Taxonomy comment',
      'description' => '',
      'target_entity_type_id' => 'taxonomy_term',
    ]);
    $this->commentType->save();
    $this->addDefaultCommentField(
      'taxonomy_term',
      $this->vocab->id(),
      'field_comment',
      CommentItemInterface::OPEN,
      $this->commentType->id()
    );
  }

  /** * Tests CSS classes on comments. */
  
'uid' => 1,
      ],
    ];
    $nodes = [];
    foreach ($node_values as $key => $values) {
      $node = Node::create($values);
      $node->save();
      $nodes[$key] = $node;
    }

    // Create comment field on article.     $this->addDefaultCommentField('node', 'article');

    $comment_values = [
      'published_published' => [
        'entity_id' => $nodes['published']->id(),
        'entity_type' => 'node',
        'field_name' => 'comment',
        'uid' => 1,
        'cid' => NULL,
        'pid' => 0,
        'status' => CommentInterface::PUBLISHED,
        'subject' => 'Comment Published <&>',
        
Home | Imprint | This part of the site doesn't use cookies.