Skip to content
Snippets Groups Projects
Select Git revision
  • a79891dadf3eb1a43f25d7bae5fe5ddc2910934f
  • 11.x default protected
  • 11.2.x protected
  • 10.6.x protected
  • 10.5.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

CommentBookTest.php

Blame
  • Nathaniel Catchpole's avatar
    Issue #2503411 by DuaelFr, Mac_Weber: Replace deprecated usage of...
    catch authored
    Issue #2503411 by DuaelFr, Mac_Weber: Replace deprecated usage of entity_create('comment*') with a direct call to Comment/CommentType::create()
    a79891da
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    CommentBookTest.php 2.16 KiB
    <?php
    
    /**
     * @file
     * Contains \Drupal\comment\Tests\CommentBookTest.
     */
    
    namespace Drupal\comment\Tests;
    
    use Drupal\comment\CommentInterface;
    use Drupal\simpletest\WebTestBase;
    use Drupal\comment\Entity\Comment;
    
    /**
     * Tests visibility of comments on book pages.
     *
     * @group comment
     */
    class CommentBookTest extends WebTestBase {
    
      use CommentTestTrait;
    
      /**
       * Modules to install.
       *
       * @var array
       */
      public static $modules = array('book', 'comment');
    
      protected function setUp() {
        parent::setUp();
    
        // Create comment field on book.
        $this->addDefaultCommentField('node', 'book');
      }
    
      /**
       * Tests comments in book export.
       */
      public function testBookCommentPrint() {
        $book_node = entity_create('node', array(
          'type' => 'book',
          'title' => 'Book title',
          'body' => 'Book body',
        ));
        $book_node->book['bid'] = 'new';
        $book_node->save();
    
        $comment_subject = $this->randomMachineName(8);
        $comment_body = $this->randomMachineName(8);
        $comment = Comment::create(array(
          'subject' => $comment_subject,
          'comment_body' => $comment_body,
          'entity_id' => $book_node->id(),
          'entity_type' => 'node',
          'field_name' => 'comment',
          'status' => CommentInterface::PUBLISHED,
        ));
        $comment->save();
    
        $commenting_user = $this->drupalCreateUser(array('access printer-friendly version', 'access comments', 'post comments'));
        $this->drupalLogin($commenting_user);
    
        $this->drupalGet('node/' . $book_node->id());
    
        $this->assertText($comment_subject, 'Comment subject found');
        $this->assertText($comment_body, 'Comment body found');
        $this->assertText(t('Add new comment'), 'Comment form found');
        $this->assertField('subject[0][value]', 'Comment form subject found');
    
        $this->drupalGet('book/export/html/' . $book_node->id());
    
        $this->assertText(t('Comments'), 'Comment thread found');
        $this->assertText($comment_subject, 'Comment subject found');
        $this->assertText($comment_body, 'Comment body found');
    
        $this->assertNoText(t('Add new comment'), 'Comment form not found');
        $this->assertNoField('subject[0][value]', 'Comment form subject not found');
      }
    
    }