class CommentUninstallTest
Same name and namespace in other branches
- 11.x core/modules/comment/tests/src/Kernel/CommentUninstallTest.php \Drupal\Tests\comment\Kernel\CommentUninstallTest
Tests comment module uninstall.
@group comment
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\comment\Kernel\CommentUninstallTest uses \Drupal\comment\Tests\CommentTestTrait implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of CommentUninstallTest
File
-
core/
modules/ comment/ tests/ src/ Kernel/ CommentUninstallTest.php, line 16
Namespace
Drupal\Tests\comment\KernelView source
class CommentUninstallTest extends KernelTestBase {
use CommentTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'comment',
'field',
'node',
'system',
'text',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installEntitySchema('comment');
$this->installConfig([
'comment',
]);
$this->installSchema('user', [
'users_data',
]);
NodeType::create([
'type' => 'article',
])->save();
// Create comment field on article so that it adds 'comment_body' field.
FieldStorageConfig::create([
'type' => 'text_long',
'entity_type' => 'comment',
'field_name' => 'comment',
])->save();
$this->addDefaultCommentField('node', 'article');
}
/**
* Tests if comment module uninstall fails if the field exists.
*/
public function testCommentUninstallWithField() {
// 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',
]);
}
/**
* Tests if uninstallation succeeds if the field has been deleted beforehand.
*/
public function testCommentUninstallWithoutField() {
// Tests if uninstall succeeds if the field has been deleted beforehand.
// Manually delete the comment_body field before module uninstall.
FieldStorageConfig::loadByName('comment', 'comment_body')->delete();
// Check that the field is now deleted.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$this->assertNull($field_storage);
// Manually delete the comment field on the node before module uninstall.
$field_storage = FieldStorageConfig::loadByName('node', 'comment');
$this->assertNotNull($field_storage);
$field_storage->delete();
// Check that the field is now deleted.
$field_storage = FieldStorageConfig::loadByName('node', 'comment');
$this->assertNull($field_storage);
field_purge_batch(10);
// Ensure that uninstall succeeds even if the field has already been deleted
// manually beforehand.
$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.