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()='System test']");
$this
->assertSession()
->elementExists('xpath', "//a[contains(@href, '/admin/people/permissions/module/system_test') and text()='Permissions ']/span[contains(@class, 'visually-hidden') and text()='for System test']");
$this
->assertSession()
->elementExists('xpath', "//a[contains(@href, '/admin/help/system_test') and text()='Help ']/span[contains(@class, 'visually-hidden') and text()='for System test']");
$this
->assertSession()
->pageTextContains('dblog');
$this
->assertSession()
->elementExists('xpath', "//a[contains(@aria-label, 'View information on the Deprecated status of the module Deprecated module')]");
$this
->assertSession()
->elementExists('xpath', "//a[contains(@href, 'http://example.com/deprecated')]");
$this
->assertSession()
->pageTextNotContains('(Obsolete)');
}
public function testModulesListFormStatusMessage() {
$this
->drupalGet('admin/modules');
$edit = [
'modules[layout_discovery][enable]' => 'layout_discovery',
];
$this
->submitForm($edit, 'Install');
$this
->assertSession()
->elementTextContains('xpath', "//div[@role='contentinfo' and h2[text()='Status message']]", 'Module Layout Discovery has been enabled.');
$this
->assertSession()
->elementNotExists('xpath', "//div[@role='contentinfo' and h2[text()='Status message']]//a");
$edit = [
'modules[action][enable]' => 'action',
];
$this
->submitForm($edit, 'Install');
$this
->assertSession()
->elementTextContains('xpath', "//div[@role='contentinfo' and h2[text()='Status message']]", 'Module Actions has been enabled.');
$this
->assertSession()
->elementExists('xpath', "//div[@role='contentinfo' and h2[text()='Status message']]//a[contains(@href, '/admin/people/permissions/module/action')]");
$edit = [
'modules[content_moderation][enable]' => 'content_moderation',
];
$this
->submitForm($edit, 'Install');
$this
->submitForm([], 'Continue');
$this
->assertSession()
->elementTextContains('xpath', "//div[@role='contentinfo' and h2[text()='Status message']]", '2 modules have been enabled: Content Moderation, Workflows.');
$this
->assertSession()
->elementExists('xpath', "//div[@role='contentinfo' and h2[text()='Status message']]//a[contains(@href, '/admin/people/permissions/module/content_moderation%2Cworkflows')]");
}
public function testModulesListFormWithInvalidInfoFile() {
$path = \Drupal::getContainer()
->getParameter('site.path') . "/modules/broken";
mkdir($path, 0777, TRUE);
$file_path = "{$path}/broken.info.yml";
$yml = <<<BROKEN
name: Module with no core_version_requirement
type: module
BROKEN;
file_put_contents($file_path, $yml);
$this
->drupalGet('admin/modules');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains("Modules could not be listed due to an error: The 'core_version_requirement' key must be present in {$file_path}");
$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' => '*',
];
$incompatible_info = $info + [
'core_version_requirement' => '^1',
];
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.');
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.');
file_put_contents($file_path, Yaml::encode($incompatible_info));
$this
->drupalGet('admin/modules');
$this
->assertSession()
->pageTextNotContains($incompatible_modules_message);
}
}