CommentUninstallTest.php in Zircon Profile 8
File
core/modules/comment/src/Tests/CommentUninstallTest.php
View source
<?php
namespace Drupal\comment\Tests;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Extension\ModuleUninstallValidatorException;
use Drupal\simpletest\WebTestBase;
class CommentUninstallTest extends WebTestBase {
use CommentTestTrait;
public static $modules = array(
'comment',
'node',
);
protected function setUp() {
parent::setup();
$this
->drupalCreateContentType(array(
'type' => 'article',
'name' => t('Article'),
));
$this
->addDefaultCommentField('node', 'article');
}
function testCommentUninstallWithField() {
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$this
->assertNotNull($field_storage, 'The comment_body field exists.');
try {
$this->container
->get('module_installer')
->uninstall(array(
'comment',
));
$this
->fail("Expected an exception when uninstall was attempted.");
} catch (ModuleUninstallValidatorException $e) {
$this
->pass("Caught an exception when uninstall was attempted.");
}
}
function testCommentUninstallWithoutField() {
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$this
->assertNotNull($field_storage, 'The comment_body field exists.');
$field_storage
->delete();
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$this
->assertNull($field_storage, 'The comment_body field has been deleted.');
$field_storage = FieldStorageConfig::loadByName('node', 'comment');
$this
->assertNotNull($field_storage, 'The comment field exists.');
$field_storage
->delete();
$field_storage = FieldStorageConfig::loadByName('node', 'comment');
$this
->assertNull($field_storage, 'The comment field has been deleted.');
field_purge_batch(10);
$this->container
->get('module_installer')
->uninstall(array(
'comment',
));
}
}