3 namespace Drupal\Tests\system\Functional\Form;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests \Drupal\system\Form\ModulesListForm.
12 class ModulesListFormWebTest extends BrowserTestBase {
17 public static $modules = ['system_test', 'help'];
22 protected function setUp() {
24 \Drupal::state()->set('system_test.module_hidden', FALSE);
28 * Tests the module list form.
30 public function testModuleListForm() {
32 $this->drupalCreateUser(
33 ['administer modules', 'administer permissions']
36 $this->drupalGet('admin/modules');
37 $this->assertResponse('200');
39 // Check that system_test's configure link was rendered correctly.
40 $this->assertFieldByXPath("//a[contains(@href, '/system-test/configure/bar') and text()='Configure ']/span[contains(@class, 'visually-hidden') and text()='the System test module']");
42 // Check that system_test's permissions link was rendered correctly.
43 $this->assertFieldByXPath("//a[contains(@href, '/admin/people/permissions#module-system_test') and @title='Configure permissions']");
45 // Check that system_test's help link was rendered correctly.
46 $this->assertFieldByXPath("//a[contains(@href, '/admin/help/system_test') and @title='Help']");
48 // Ensure that the Testing module's machine name is printed. Testing module
49 // is used because its machine name is different than its human readable
51 $this->assertText('simpletest');
54 public function testModulesListFormWithInvalidInfoFile() {
55 $broken_info_yml = <<<BROKEN
56 name: Module With Broken Info file
59 $path = \Drupal::service('site.path') . "/modules/broken";
60 mkdir($path, 0777, TRUE);
61 file_put_contents("$path/broken.info.yml", $broken_info_yml);
64 $this->drupalCreateUser(
65 ['administer modules', 'administer permissions']
68 $this->drupalGet('admin/modules');
69 $this->assertSession()->statusCodeEquals(200);
71 // Confirm that the error message is shown.
72 $this->assertSession()
73 ->pageTextContains('Modules could not be listed due to an error: Missing required keys (core) in ' . $path . '/broken.info.yml');
75 // Check that the module filter text box is available.
76 $this->assertTrue($this->xpath('//input[@name="text"]'));