NonStableModulesTest.php

Same filename and directory in other branches
  1. 11.x core/modules/system/tests/src/Functional/Module/NonStableModulesTest.php
  2. 10 core/modules/system/tests/src/Functional/Module/NonStableModulesTest.php
  3. 9 core/modules/system/tests/src/Functional/Module/NonStableModulesTest.php

Namespace

Drupal\Tests\system\Functional\Module

File

core/modules/system/tests/src/Functional/Module/NonStableModulesTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\system\Functional\Module;

use Drupal\Tests\BrowserTestBase;
use Drupal\user\UserInterface;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;

/**
 * Tests the installation of deprecated and experimental modules.
 */
class NonStableModulesTest extends BrowserTestBase {
  
  /**
   * The admin user.
   */
  protected UserInterface $adminUser;
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->adminUser = $this->drupalCreateUser([
      'access administration pages',
      'administer modules',
    ]);
    $this->drupalLogin($this->adminUser);
  }
  
  /**
   * Tests installing experimental modules and dependencies in the UI.
   */
  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 following module to install Experimental Dependency Test:Experimental 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.');
  }
  
  /**
   * Tests installing deprecated and experimental modules at the same time.
   */
  public function testDeprecatedAndExperimentalConfirmForm() : void {
    $edit = [];
    $edit["modules[deprecated_module][enable]"] = TRUE;
    $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 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'));
    // The module should not be enabled and there should be a warning and a
    // list of the experimental modules with only this one.
    $assert->pageTextNotContains('Experimental Test has been installed.');
    $assert->pageTextContains('Experimental modules are provided for testing purposes only.');
    $assert->pageTextContains('The following module is experimental: Experimental Test');
    // There should be a warning about enabling experimental and deprecated
    // modules, but no warnings about solitary experimental or deprecated
    // modules.
    $this->assertSession()
      ->pageTextContains('Are you sure you wish to install experimental and deprecated modules?');
    $this->assertSession()
      ->pageTextNotContains('Are you sure you wish to install experimental modules?');
    $this->assertSession()
      ->pageTextNotContains('Are you sure you wish to install 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('2 modules have been installed: Deprecated module, Experimental Test.');
  }

}

Classes

Title Deprecated Summary
NonStableModulesTest Tests the installation of deprecated and experimental modules.

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