You are here

public function WebformVariantPluginTest::testWebformVariantDependencies in Webform 6.x

Same name and namespace in other branches
  1. 8.5 tests/src/Functional/Variant/WebformVariantPluginTest.php \Drupal\Tests\webform\Functional\Variant\WebformVariantPluginTest::testWebformVariantDependencies()

Tests webform variant plugin dependencies.

See also

\Drupal\webform\Entity\Webform::onDependencyRemoval

File

tests/src/Functional/Variant/WebformVariantPluginTest.php, line 27

Class

WebformVariantPluginTest
Tests for the webform variant plugin.

Namespace

Drupal\Tests\webform\Functional\Variant

Code

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

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

  /** @var \Drupal\webform\Plugin\WebformVariantManagerInterface $variant_manager */
  $variant_manager = $this->container
    ->get('plugin.manager.webform.variant');

  // Add 'test' variant provided by the webform_test.module.
  $webform_variant_configuration = [
    'id' => 'test',
    'label' => 'test',
    'variant_id' => 'test',
    'status' => 1,
    'weight' => 2,
    'debug' => TRUE,
  ];
  $webform_variant = $variant_manager
    ->createInstance('test', $webform_variant_configuration);
  $webform
    ->addWebformVariant($webform_variant);
  $webform
    ->save();

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

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

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