diff --git a/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/TestType.php b/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/TestType.php index ddd074a..26dc42f 100644 --- a/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/TestType.php +++ b/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/TestType.php @@ -3,6 +3,7 @@ namespace Drupal\workflow_type_test\Plugin\WorkflowType; use Drupal\workflows\Plugin\WorkflowTypeBase; +use Drupal\workflows\WorkflowInterface; /** * Test workflow type. @@ -17,6 +18,13 @@ class TestType extends WorkflowTypeBase { /** * {@inheritdoc} */ + public function workflowHasData(WorkflowInterface $workflow) { + return \Drupal::state()->get('workflow_type_test.has_data', FALSE); + } + + /** + * {@inheritdoc} + */ public function getRequiredStates() { // Normally this is obtained from the annotation but we get from state to // allow dynamic testing. diff --git a/core/modules/workflows/tests/src/Kernel/WorkflowDependenciesTest.php b/core/modules/workflows/tests/src/Kernel/WorkflowDependenciesTest.php index c1070dc..75efcc7 100644 --- a/core/modules/workflows/tests/src/Kernel/WorkflowDependenciesTest.php +++ b/core/modules/workflows/tests/src/Kernel/WorkflowDependenciesTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\workflows\Kernel; +use Drupal\Core\Extension\ModuleUninstallValidatorException; use Drupal\KernelTests\KernelTestBase; use Drupal\workflows\Entity\Workflow; @@ -38,4 +39,43 @@ public function testOnDependencyRemoval() { $this->assertSame(['workflow_type_test'], $workflow->getDependencies()['module']); } + /** + * Test uninstalling a module that provides a workflow type. + * + * @covers \Drupal\workflows\WorkflowsUninstallValidator::validate + */ + public function testUninstallModuleWithWorkflowTypeInUse() { + $module_installer = \Drupal::service('module_installer'); + + // Create a workflow of a type for which we can control whether it is in use + // or not. + $workflow = Workflow::create([ + 'type' => 'workflow_type_test', + 'id' => 'test_workflow', + ]); + $workflow->save(); + + // Simulate a workflow type that is in use. + \Drupal::state()->set('workflow_type_test.has_data', TRUE); + + try { + $module_installer->uninstall(['workflow_type_test']); + $this->fail('A module that provides a workflow type that is in use can not be uninstalled.'); + } + catch (ModuleUninstallValidatorException $e) { + $this->assertTrue(TRUE,'A module that provides a workflow type that is in use can not be uninstalled.'); + } + + // Simulate a workflow type that is no longer being used. + \Drupal::state()->set('workflow_type_test.has_data', FALSE); + try { + $module_installer->uninstall(['workflow_type_test']); + $this->assertTrue(TRUE,'A module that provides a workflow type that is not in use can be uninstalled.'); + + } + catch (ModuleUninstallValidatorException $e) { + $this->fail('A module that provides a workflow type that is not in use can be uninstalled.'); + } + } + }