function ModulesListFormWebTest::testInstalledIncompatibleModule

Same name in other branches
  1. 10 core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php \Drupal\Tests\system\Functional\Form\ModulesListFormWebTest::testInstalledIncompatibleModule()
  2. 11.x core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php \Drupal\Tests\system\Functional\Form\ModulesListFormWebTest::testInstalledIncompatibleModule()

Tests that incompatible modules message is shown.

File

core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php, line 164

Class

ModulesListFormWebTest
Tests \Drupal\system\Form\ModulesListForm.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testInstalledIncompatibleModule() {
    $incompatible_modules_message = 'There are errors with some installed modules. Visit the status report page for more information.';
    $path = \Drupal::getContainer()->getParameter('site.path') . "/modules/changing_module";
    mkdir($path, 0777, TRUE);
    $file_path = "{$path}/changing_module.info.yml";
    $info = [
        'name' => 'Module that changes',
        'type' => 'module',
    ];
    $compatible_info = $info + [
        'core_version_requirement' => '*',
    ];
    file_put_contents($file_path, Yaml::encode($compatible_info));
    $edit = [
        'modules[changing_module][enable]' => 'changing_module',
    ];
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    $this->assertSession()
        ->pageTextContains('Module Module that changes has been enabled.');
    $incompatible_updates = [
        [
            'core_version_requirement' => '^1',
        ],
        [
            'core' => '8.x',
        ],
    ];
    foreach ($incompatible_updates as $incompatible_update) {
        $incompatible_info = $info + $incompatible_update;
        file_put_contents($file_path, Yaml::encode($incompatible_info));
        $this->drupalGet('admin/modules');
        $this->assertSession()
            ->pageTextContains($incompatible_modules_message);
        file_put_contents($file_path, Yaml::encode($compatible_info));
        $this->drupalGet('admin/modules');
        $this->assertSession()
            ->pageTextNotContains($incompatible_modules_message);
    }
    // Uninstall the module and ensure that incompatible modules message is not
    // displayed for modules that are not installed.
    $edit = [
        'uninstall[changing_module]' => 'changing_module',
    ];
    $this->drupalGet('admin/modules/uninstall');
    $this->submitForm($edit, 'Uninstall');
    $this->submitForm([], 'Uninstall');
    $this->assertSession()
        ->pageTextContains('The selected modules have been uninstalled.');
    foreach ($incompatible_updates as $incompatible_update) {
        $incompatible_info = $info + $incompatible_update;
        file_put_contents($file_path, Yaml::encode($incompatible_info));
        $this->drupalGet('admin/modules');
        $this->assertSession()
            ->pageTextNotContains($incompatible_modules_message);
    }
}

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