function NonStableModulesTest::testDeprecatedConfirmForm

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Module/NonStableModulesTest.php \Drupal\Tests\system\Functional\Module\NonStableModulesTest::testDeprecatedConfirmForm()
  2. 11.x core/modules/system/tests/src/Functional/Module/NonStableModulesTest.php \Drupal\Tests\system\Functional\Module\NonStableModulesTest::testDeprecatedConfirmForm()

Tests installing deprecated modules and dependencies in the UI.

@group legacy

File

core/modules/system/tests/src/Functional/Module/NonStableModulesTest.php, line 179

Class

NonStableModulesTest
Tests the installation of deprecated and experimental modules.

Namespace

Drupal\Tests\system\Functional\Module

Code

public function testDeprecatedConfirmForm() : void {
    // Test installing a deprecated module with no dependencies. There should be
    // a confirmation form with a deprecated warning, but no list of
    // dependencies.
    $edit = [];
    $edit["modules[deprecated_module][enable]"] = TRUE;
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    // The module should not be enabled and there should be a warning and a
    // list of the deprecated modules with only this one.
    $assert = $this->assertSession();
    $assert->pageTextNotContains('Deprecated module has been installed.');
    $assert->pageTextContains('Deprecated modules are modules that may be removed from the next major release of Drupal core. Use at your own risk.');
    $assert->pageTextContains('The Deprecated module module is deprecated');
    $more_information_link = $assert->elementExists('named', [
        'link',
        'The Deprecated module module is deprecated. (more information)',
    ]);
    $this->assertEquals('http://example.com/deprecated', $more_information_link->getAttribute('href'));
    // There should be a warning about enabling deprecated modules, but no
    // warnings about experimental modules.
    $this->assertSession()
        ->pageTextContains('Are you sure you wish to install a deprecated module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install an experimental module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install experimental and deprecated modules?');
    // There should be no message about enabling dependencies.
    $assert->pageTextNotContains('You must install');
    // Enable the module and confirm that it worked.
    $this->submitForm([], 'Continue');
    $assert->pageTextContains('Deprecated module has been installed.');
    // Uninstall the module.
    \Drupal::service('module_installer')->uninstall([
        'deprecated_module',
    ]);
    // Test enabling a module that is not itself deprecated, but that depends on
    // a deprecated module.
    $edit = [];
    $edit["modules[deprecated_module_dependency][enable]"] = TRUE;
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    // The module should not be enabled and there should be a warning and a
    // list of the deprecated modules with only this one.
    $assert->pageTextNotContains('2 modules have been installed: Deprecated module dependency, Deprecated module');
    $assert->pageTextContains('Deprecated modules are modules that may be removed from the next major release of Drupal core. Use at your own risk.');
    $assert->pageTextContains('The Deprecated module module is deprecated');
    // There should be a warning about enabling deprecated modules, but no
    // warnings about experimental modules.
    $this->assertSession()
        ->pageTextContains('Are you sure you wish to install a deprecated module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install an experimental module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install experimental and deprecated modules?');
    // Ensure the non-deprecated module is not listed as deprecated.
    $assert->pageTextNotContains('The Deprecated module dependency module is deprecated');
    // There should be a message about enabling dependencies.
    $assert->pageTextContains('You must install the Deprecated module module to install Deprecated module dependency');
    // Enable the module and confirm that it worked.
    $this->submitForm([], 'Continue');
    $assert->pageTextContains('2 modules have been installed: Deprecated module dependency, Deprecated module');
    // Uninstall the modules.
    \Drupal::service('module_installer')->uninstall([
        'deprecated_module',
        'deprecated_module_dependency',
    ]);
    // Check a deprecated module with a non-deprecated dependency.
    $edit = [];
    $edit["modules[deprecated_module_with_non_deprecated_dependency][enable]"] = TRUE;
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    // The module should not be enabled and there should be a warning and a
    // list of the deprecated modules with only this one.
    $assert->pageTextNotContains('2 modules have been installed: Deprecated module with non deprecated dependency, Drupal system listing compatible test');
    $assert->pageTextContains('Deprecated modules are modules that may be removed from the next major release of Drupal core. Use at your own risk.');
    $assert->pageTextContains('The Deprecated module with non deprecated dependency module is deprecated');
    $more_information_link = $assert->elementExists('named', [
        'link',
        'The Deprecated module with non deprecated dependency module is deprecated. (more information)',
    ]);
    $this->assertEquals('http://example.com/deprecated', $more_information_link->getAttribute('href'));
    // There should be a warning about enabling deprecated modules, but no
    // warnings about experimental modules.
    $this->assertSession()
        ->pageTextContains('Are you sure you wish to install a deprecated module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install an experimental module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install experimental and deprecated modules?');
    // Ensure the non-deprecated dependency module is not listed as deprecated.
    $assert->pageTextNotContains('The Drupal system listing compatible test module is deprecated');
    // There should be a message about enabling dependencies.
    $assert->pageTextContains('You must install the Drupal system listing compatible test module to install Deprecated module with non deprecated dependency.');
    // Enable the module and confirm that it worked.
    $this->submitForm([], 'Continue');
    $assert->pageTextContains('2 modules have been installed: Deprecated module with non deprecated dependency, Drupal system listing compatible test.');
    // Uninstall the modules.
    \Drupal::service('module_installer')->uninstall([
        'deprecated_module_with_non_deprecated_dependency',
        'drupal_system_listing_compatible_test',
    ]);
    // Check both the module and its deprecated dependency. There is still a
    // warning about deprecated modules, but no message about dependencies,
    // since the user specifically enabled the dependency.
    $edit = [];
    $edit["modules[deprecated_module_dependency][enable]"] = TRUE;
    $edit["modules[deprecated_module][enable]"] = TRUE;
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    // The module should not be enabled and there should be a warning and a
    // list of the deprecated modules with only this one.
    $assert->pageTextNotContains('2 modules have been installed: Deprecated module dependency, Deprecated module');
    $assert->pageTextContains('Deprecated modules are modules that may be removed from the next major release of Drupal core. Use at your own risk.');
    $assert->pageTextContains('The Deprecated module module is deprecated');
    // There should be a warning about enabling deprecated modules, but no
    // warnings about experimental modules.
    $this->assertSession()
        ->pageTextContains('Are you sure you wish to install a deprecated module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install an experimental module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install experimental and deprecated modules?');
    // Ensure the non-deprecated module is not listed as deprecated.
    $assert->pageTextNotContains('The Deprecated module dependency module is deprecated');
    // There should be no message about enabling dependencies.
    $assert->pageTextNotContains('You must install');
    // Enable the modules and confirm that it worked.
    $this->submitForm([], 'Continue');
    $assert->pageTextContains('2 modules have been installed: Deprecated module, Deprecated module dependency');
    \Drupal::service('module_installer')->uninstall([
        'deprecated_module',
        'deprecated_module_dependency',
    ]);
    // Now, test when installing a non-core deprecated module alone and then
    // with a core deprecated module. First, install 'deprecated_module_test'
    // because it uses hook_system_info_alter() to set the origin of
    // 'deprecated_module_contrib' to something other than 'core'.
    $this->drupalGet('admin/modules');
    $this->submitForm([
        "modules[deprecated_module_test][enable]" => TRUE,
    ], 'Install');
    $assert->pageTextContains('Module Deprecated module test has been installed.');
    // Test installing a non-core deprecated module. There should be a
    // confirmation form with a deprecated warning for a 'project' and not for
    // Drupal core.
    $this->drupalGet('admin/modules');
    $this->submitForm([
        "modules[deprecated_module_contrib][enable]" => TRUE,
    ], 'Install');
    $assert->pageTextContains('Deprecated modules are modules that may be removed from the next major release of this project. Use at your own risk.');
    // Test installing a non-core deprecated module and a core deprecated
    // module. There should be a confirmation form with a deprecated warning for
    // both a 'project' and Drupal core.
    $this->drupalGet('admin/modules');
    $this->submitForm([
        "modules[deprecated_module_contrib][enable]" => TRUE,
        "modules[deprecated_module][enable]" => TRUE,
    ], 'Install');
    $assert->pageTextContains('Deprecated modules are modules that may be removed from the next major release of Drupal core and the relevant contributed module. Use at your own risk.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.