You are here

function CommentFieldsTest::testCommentInstallAfterContentModule in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Tests/CommentFieldsTest.php \Drupal\comment\Tests\CommentFieldsTest::testCommentInstallAfterContentModule()

Tests that comment module works when installed after a content module.

File

core/modules/comment/src/Tests/CommentFieldsTest.php, line 191
Contains \Drupal\comment\Tests\CommentFieldsTest.

Class

CommentFieldsTest
Tests fields on comments.

Namespace

Drupal\comment\Tests

Code

function testCommentInstallAfterContentModule() {

  // Create a user to do module administration.
  $this->adminUser = $this
    ->drupalCreateUser(array(
    'access administration pages',
    'administer modules',
  ));
  $this
    ->drupalLogin($this->adminUser);

  // Drop default comment field added in CommentTestBase::setup().
  FieldStorageConfig::loadByName('node', 'comment')
    ->delete();
  if ($field_storage = FieldStorageConfig::loadByName('node', 'comment_forum')) {
    $field_storage
      ->delete();
  }

  // Purge field data now to allow comment module to be uninstalled once the
  // field has been deleted.
  field_purge_batch(10);

  // Uninstall the comment module.
  $edit = array();
  $edit['uninstall[comment]'] = TRUE;
  $this
    ->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
  $this
    ->drupalPostForm(NULL, array(), t('Uninstall'));
  $this
    ->rebuildContainer();
  $this
    ->assertFalse($this->container
    ->get('module_handler')
    ->moduleExists('comment'), 'Comment module uninstalled.');

  // Install core content type module (book).
  $edit = array();
  $edit['modules[Core][book][enable]'] = 'book';
  $this
    ->drupalPostForm('admin/modules', $edit, t('Install'));

  // Now install the comment module.
  $edit = array();
  $edit['modules[Core][comment][enable]'] = 'comment';
  $this
    ->drupalPostForm('admin/modules', $edit, t('Install'));
  $this
    ->rebuildContainer();
  $this
    ->assertTrue($this->container
    ->get('module_handler')
    ->moduleExists('comment'), 'Comment module enabled.');

  // Create nodes of each type.
  $this
    ->addDefaultCommentField('node', 'book');
  $book_node = $this
    ->drupalCreateNode(array(
    'type' => 'book',
  ));
  $this
    ->drupalLogout();

  // Try to post a comment on each node. A failure will be triggered if the
  // comment body is missing on one of these forms, due to postComment()
  // asserting that the body is actually posted correctly.
  $this->webUser = $this
    ->drupalCreateUser(array(
    'access content',
    'access comments',
    'post comments',
    'skip comment approval',
  ));
  $this
    ->drupalLogin($this->webUser);
  $this
    ->postComment($book_node, $this
    ->randomMachineName(), $this
    ->randomMachineName());
}