View source
<?php
namespace Drupal\Tests\webform_node\Kernel;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\KernelTests\KernelTestBase;
class WebformNodeUninstallTest extends KernelTestBase {
public static $modules = [
'system',
'field',
'filter',
'text',
'user',
'node',
'webform',
'webform_node',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installEntitySchema('node');
$this
->installEntitySchema('webform');
$this
->installEntitySchema('webform_submission');
$this
->installSchema('webform', [
'webform',
]);
$this
->installSchema('node', [
'node_access',
]);
$this
->installConfig([
'system',
'node',
'webform',
'webform_node',
]);
$this
->installSchema('user', [
'users_data',
]);
}
public function testWebformNodeUninstall() {
module_load_include('install', 'webform_node');
$this
->assertNotEmpty(webform_node_requirements('install'), 'Webform node module can not be installed.');
$validation_reasons = \Drupal::service('module_installer')
->validateUninstall([
'webform_node',
]);
$this
->assertEquals($validation_reasons, [], 'The webform_node module is not required.');
$node = Node::create([
'title' => $this
->randomString(),
'type' => 'webform',
]);
$node
->save();
$validation_reasons = \Drupal::service('module_installer')
->validateUninstall([
'webform_node',
]);
$this
->assertEquals($validation_reasons['webform_node'], [
'To uninstall Webform node, delete all content that has the Webform content type.',
]);
$node
->delete();
\Drupal::service('module_installer')
->uninstall([
'webform_node',
]);
$this
->assertNull(NodeType::load('webform'), "The webform node type does not exist.");
$this
->assertEmpty(webform_node_requirements('install'), 'Webform node module can be installed.');
}
}