function CommentUninstallTest::testCommentUninstallWithField

Same name in other branches
  1. 9 core/modules/comment/tests/src/Kernel/CommentUninstallTest.php \Drupal\Tests\comment\Kernel\CommentUninstallTest::testCommentUninstallWithField()
  2. 8.9.x core/modules/comment/tests/src/Kernel/CommentUninstallTest.php \Drupal\Tests\comment\Kernel\CommentUninstallTest::testCommentUninstallWithField()
  3. 10 core/modules/comment/tests/src/Kernel/CommentUninstallTest.php \Drupal\Tests\comment\Kernel\CommentUninstallTest::testCommentUninstallWithField()

Tests if comment module uninstall fails if the field exists.

File

core/modules/comment/tests/src/Kernel/CommentUninstallTest.php, line 61

Class

CommentUninstallTest
Tests comment module uninstall.

Namespace

Drupal\Tests\comment\Kernel

Code

public function testCommentUninstallWithField() : void {
    // Ensure that the field exists before uninstalling.
    $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
    $this->assertNotNull($field_storage);
    // Uninstall the comment module which should trigger an exception.
    $this->expectException(ModuleUninstallValidatorException::class);
    $this->expectExceptionMessage('The following reasons prevent the modules from being uninstalled: The <em class="placeholder">Comments</em> field type is used in the following field: node.comment');
    $this->container
        ->get('module_installer')
        ->uninstall([
        'comment',
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.