function NonStableModulesTest::testExperimentalConfirmForm

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

Tests installing experimental modules and dependencies in the UI.

File

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

Class

NonStableModulesTest
Tests the installation of deprecated and experimental modules.

Namespace

Drupal\Tests\system\Functional\Module

Code

public function testExperimentalConfirmForm() : void {
    // First, test installing a non-experimental module with no dependencies.
    // There should be no confirmation form and no experimental module warning.
    $edit = [];
    $edit["modules[test_page_test][enable]"] = TRUE;
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    $this->assertSession()
        ->pageTextContains('Module Test page has been installed.');
    $this->assertSession()
        ->pageTextNotContains('Experimental modules are provided for testing purposes only.');
    // There should be no warning about enabling experimental or deprecated
    // modules, since there's no confirmation form.
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install ');
    // Uninstall the module.
    \Drupal::service('module_installer')->uninstall([
        'test_page_test',
    ]);
    // Next, test installing an experimental module with no dependencies.
    // There should be a confirmation form with an experimental warning, but no
    // list of dependencies.
    $edit = [];
    $edit["modules[experimental_module_test][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 experimental modules with only this one.
    $this->assertSession()
        ->pageTextNotContains('Experimental Test has been installed.');
    $this->assertSession()
        ->pageTextContains('Experimental modules are provided for testing purposes only.');
    $this->assertSession()
        ->pageTextContains('The following module is experimental: Experimental Test');
    // There should be a warning about enabling experimental modules, but no
    // warnings about deprecated modules.
    $this->assertSession()
        ->pageTextContains('Are you sure you wish to install an experimental module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install a deprecated module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install experimental and deprecated modules?');
    // There should be no message about enabling dependencies.
    $this->assertSession()
        ->pageTextNotContains('You must install');
    // Enable the module and confirm that it worked.
    $this->submitForm([], 'Continue');
    $this->assertSession()
        ->pageTextContains('Experimental Test has been installed.');
    // Uninstall the module.
    \Drupal::service('module_installer')->uninstall([
        'experimental_module_test',
    ]);
    // Test enabling a module that is not itself experimental, but that depends
    // on an experimental module.
    $edit = [];
    $edit["modules[experimental_module_dependency_test][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 experimental modules with only this one.
    $this->assertSession()
        ->pageTextNotContains('2 modules have been installed: Experimental Dependency Test, Experimental Test');
    $this->assertSession()
        ->pageTextContains('Experimental modules are provided for testing purposes only.');
    $this->assertSession()
        ->pageTextContains('The following module is experimental: Experimental Test');
    // There should be a warning about enabling experimental modules, but no
    // warnings about deprecated modules.
    $this->assertSession()
        ->pageTextContains('Are you sure you wish to install an experimental module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install a deprecated module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install experimental and deprecated modules?');
    // Ensure the non-experimental module is not listed as experimental.
    $this->assertSession()
        ->pageTextNotContains('The following modules are experimental: Experimental Test, Experimental Dependency Test');
    $this->assertSession()
        ->pageTextNotContains('The following module is experimental: Experimental Dependency Test');
    // There should be a message about enabling dependencies.
    $this->assertSession()
        ->pageTextContains('You must install the Experimental Test module to install Experimental Dependency Test');
    // Enable the module and confirm that it worked.
    $this->submitForm([], 'Continue');
    $this->assertSession()
        ->pageTextContains('2 modules have been installed: Experimental Dependency Test, Experimental Test');
    // Uninstall the modules.
    \Drupal::service('module_installer')->uninstall([
        'experimental_module_test',
        'experimental_module_dependency_test',
    ]);
    // Finally, check both the module and its experimental dependency. There is
    // still a warning about experimental modules, but no message about
    // dependencies, since the user specifically enabled the dependency.
    $edit = [];
    $edit["modules[experimental_module_test][enable]"] = TRUE;
    $edit["modules[experimental_module_dependency_test][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 experimental modules with only this one.
    $this->assertSession()
        ->pageTextNotContains('2 modules have been installed: Experimental Dependency Test, Experimental Test');
    $this->assertSession()
        ->pageTextContains('Experimental modules are provided for testing purposes only.');
    $this->assertSession()
        ->pageTextContains('The following module is experimental: Experimental Test');
    // There should be a warning about enabling experimental modules, but no
    // warnings about deprecated modules.
    $this->assertSession()
        ->pageTextContains('Are you sure you wish to install an experimental module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install a deprecated module?');
    $this->assertSession()
        ->pageTextNotContains('Are you sure you wish to install experimental and deprecated modules?');
    // Ensure the non-experimental module is not listed as experimental.
    $this->assertSession()
        ->pageTextNotContains('The following modules are experimental: Experimental Dependency Test, Experimental Test');
    $this->assertSession()
        ->pageTextNotContains('The following module is experimental: Experimental Dependency Test');
    // There should be no message about enabling dependencies.
    $this->assertSession()
        ->pageTextNotContains('You must install');
    // Enable the module and confirm that it worked.
    $this->submitForm([], 'Continue');
    $this->assertSession()
        ->pageTextContains('2 modules have been installed: Experimental Dependency Test, Experimental Test');
    // Try to enable an experimental module that can not be due to
    // hook_requirements().
    \Drupal::state()->set('experimental_module_requirements_test_requirements', TRUE);
    $edit = [];
    $edit["modules[experimental_module_requirements_test][enable]"] = TRUE;
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    // Verify that if the module can not be installed, we are not taken to the
    // confirm form.
    $this->assertSession()
        ->addressEquals('admin/modules');
    $this->assertSession()
        ->pageTextContains('The Experimental Test Requirements module can not be installed.');
}

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