You are here

public function WebformHandlerPluginTest::testWebformHandlerDependencies in Webform 6.x

Same name and namespace in other branches
  1. 8.5 tests/src/Functional/Handler/WebformHandlerPluginTest.php \Drupal\Tests\webform\Functional\Handler\WebformHandlerPluginTest::testWebformHandlerDependencies()

Tests webform handler plugin dependencies.

See also

\Drupal\webform\Entity\Webform::onDependencyRemoval

File

tests/src/Functional/Handler/WebformHandlerPluginTest.php, line 27

Class

WebformHandlerPluginTest
Tests for the webform handler plugin.

Namespace

Drupal\Tests\webform\Functional\Handler

Code

public function testWebformHandlerDependencies() {
  $webform = Webform::load('contact');

  // Check initial dependencies.
  $this
    ->assertEqual($webform
    ->getDependencies(), [
    'module' => [
      'webform',
    ],
  ]);

  /** @var \Drupal\webform\Plugin\WebformHandlerManagerInterface $handler_manager */
  $handler_manager = $this->container
    ->get('plugin.manager.webform.handler');

  // Add 'test' handler provided by the webform_test.module.
  $webform_handler_configuration = [
    'id' => 'test',
    'label' => 'test',
    'handler_id' => 'test',
    'status' => 1,
    'weight' => 2,
    'settings' => [],
  ];
  $webform_handler = $handler_manager
    ->createInstance('test', $webform_handler_configuration);
  $webform
    ->addWebformHandler($webform_handler);
  $webform
    ->save();

  // Check that handler has been added to the dependencies.
  $this
    ->assertEqual($webform
    ->getDependencies(), [
    'module' => [
      'webform_test_handler',
      'webform',
    ],
  ]);

  // Uninstall the webform_test_handler.module which will also remove the
  // test handler.
  $this->container
    ->get('module_installer')
    ->uninstall([
    'webform_test_handler',
  ]);
  $webform = Webform::load('contact');

  // Check that handler was removed from the dependencies.
  $this
    ->assertNotEqual($webform
    ->getDependencies(), [
    'module' => [
      'webform_test_handler',
      'webform',
    ],
  ]);
  $this
    ->assertEqual($webform
    ->getDependencies(), [
    'module' => [
      'webform',
    ],
  ]);
}