You are here

public function WebformNodeUninstallTest::testWebformNodeUninstall in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_node/tests/src/Kernel/WebformNodeUninstallTest.php \Drupal\Tests\webform_node\Kernel\WebformNodeUninstallTest::testWebformNodeUninstall()

Tests the webform_node_uninstall() method.

File

modules/webform_node/tests/src/Kernel/WebformNodeUninstallTest.php, line 45

Class

WebformNodeUninstallTest
Tests if webform nodes exist.

Namespace

Drupal\Tests\webform_node\Kernel

Code

public function testWebformNodeUninstall() {
  module_load_include('install', 'webform_node');

  // Check that webform node module can not be installed.
  $this
    ->assertNotEmpty(webform_node_requirements('install'), 'Webform node module can not be installed.');

  // No nodes exist.
  $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();

  // Check webform node module can't be uninstalled.
  $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();

  // Uninstall the Webform node module and check that all webform node have been deleted.
  \Drupal::service('module_installer')
    ->uninstall([
    'webform_node',
  ]);
  $this
    ->assertNull(NodeType::load('webform'), "The webform node type does not exist.");

  // Check that webform node module can be installed.
  $this
    ->assertEmpty(webform_node_requirements('install'), 'Webform node module can be installed.');
}