View source
<?php
namespace Drupal\Tests\system\Functional\Form;
use Drupal\Core\Serialization\Yaml;
use Drupal\Tests\BrowserTestBase;
class ModulesListFormWebTest extends BrowserTestBase {
protected static $modules = [
'system_test',
'help',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
\Drupal::state()
->set('system_test.module_hidden', FALSE);
$this
->drupalLogin($this
->drupalCreateUser([
'administer modules',
'administer permissions',
]));
}
public function testModuleListForm() {
$this
->drupalGet('admin/modules');
$this
->assertSession()
->elementExists('xpath', "//a[contains(@href, '/system-test/configure/bar') and text()='Configure ']/span[contains(@class, 'visually-hidden') and text()='the System test module']");
$this
->assertSession()
->elementExists('xpath', "//a[contains(@href, '/admin/people/permissions#module-system_test') and @title='Configure permissions']");
$this
->assertSession()
->elementExists('xpath', "//a[contains(@href, '/admin/help/system_test') and @title='Help']");
$this
->assertSession()
->pageTextContains('dblog');
}
public function testModulesListFormWithInvalidInfoFile() {
$path = \Drupal::getContainer()
->getParameter('site.path') . "/modules/broken";
mkdir($path, 0777, TRUE);
$file_path = "{$path}/broken.info.yml";
$broken_infos = [
[
'yml' => <<<BROKEN
name: Module with no core_version_requirement or core
type: module
BROKEN
,
'expected_error' => "The 'core_version_requirement' key must be present in {$file_path}",
],
[
'yml' => <<<BROKEN
name: Module no core_version_requirement and invalid core
type: module
core: 9.x
BROKEN
,
'expected_error' => "'core: 9.x' is not supported. Use 'core_version_requirement' to specify core compatibility. Only 'core: 8.x' is supported to provide backwards compatibility for Drupal 8 when needed in {$file_path}",
],
[
'yml' => <<<BROKEN
name: Module with core_version_requirement and invalid core
type: module
core: 9.x
core_version_requirement: ^8 || ^9
BROKEN
,
'expected_error' => "'core: 9.x' is not supported. Use 'core_version_requirement' to specify core compatibility. Only 'core: 8.x' is supported to provide backwards compatibility for Drupal 8 when needed in {$file_path}",
],
];
foreach ($broken_infos as $broken_info) {
file_put_contents($file_path, $broken_info['yml']);
$this
->drupalGet('admin/modules');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Modules could not be listed due to an error: ' . $broken_info['expected_error']);
$this
->assertSession()
->elementExists('xpath', '//input[@name="text"]');
unlink($file_path);
$this
->drupalGet('admin/modules');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->elementExists('xpath', '//input[@name="text"]');
$this
->assertSession()
->pageTextNotContains('Modules could not be listed due to an error');
}
}
public function testRequiredByThemeMessage() {
$this
->drupalGet('admin/modules');
$module_theme_depends_on_description = $this
->getSession()
->getPage()
->findAll('css', '#edit-modules-test-module-required-by-theme-enable-description .admin-requirements li:contains("Test Theme Depending on Modules (theme) (disabled)")');
$this
->assertCount(1, $module_theme_depends_on_description);
$this
->assertSession()
->pageTextContains('Test Theme Depending on Modules (Theme) (Disabled)');
}
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);
}
$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);
}
}
}