Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / system / tests / src / Functional / Form / ModulesListFormWebTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Form;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests \Drupal\system\Form\ModulesListForm.
9  *
10  * @group Form
11  */
12 class ModulesListFormWebTest extends BrowserTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = ['system_test', 'help'];
18
19   /**
20    * {@inheritdoc}
21    */
22   protected function setUp() {
23     parent::setUp();
24     \Drupal::state()->set('system_test.module_hidden', FALSE);
25   }
26
27   /**
28    * Tests the module list form.
29    */
30   public function testModuleListForm() {
31     $this->drupalLogin(
32       $this->drupalCreateUser(
33         ['administer modules', 'administer permissions']
34       )
35     );
36     $this->drupalGet('admin/modules');
37     $this->assertResponse('200');
38
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']");
41
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']");
44
45     // Check that system_test's help link was rendered correctly.
46     $this->assertFieldByXPath("//a[contains(@href, '/admin/help/system_test') and @title='Help']");
47
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
50     // name.
51     $this->assertText('simpletest');
52   }
53
54   public function testModulesListFormWithInvalidInfoFile() {
55     $broken_info_yml = <<<BROKEN
56 name: Module With Broken Info file
57 type: module
58 BROKEN;
59     $path = \Drupal::service('site.path') . "/modules/broken";
60     mkdir($path, 0777, TRUE);
61     file_put_contents("$path/broken.info.yml", $broken_info_yml);
62
63     $this->drupalLogin(
64       $this->drupalCreateUser(
65         ['administer modules', 'administer permissions']
66       )
67     );
68     $this->drupalGet('admin/modules');
69     $this->assertSession()->statusCodeEquals(200);
70
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');
74
75     // Check that the module filter text box is available.
76     $this->assertTrue($this->xpath('//input[@name="text"]'));
77   }
78
79 }