ModulesListFormWebTest.php 2.5 KB
Newer Older
1 2
<?php

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 16

  /**
   * {@inheritdoc}
   */
17
  public static $modules = ['system_test', 'help'];
18

19 20 21 22 23
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

24 25 26
  /**
   * {@inheritdoc}
   */
27
  protected function setUp() {
28 29 30 31 32 33 34 35
    parent::setUp();
    \Drupal::state()->set('system_test.module_hidden', FALSE);
  }

  /**
   * Tests the module list form.
   */
  public function testModuleListForm() {
36 37
    $this->drupalLogin(
      $this->drupalCreateUser(
38
        ['administer modules', 'administer permissions']
39 40
      )
    );
41 42 43 44
    $this->drupalGet('admin/modules');
    $this->assertResponse('200');

    // Check that system_test's configure link was rendered correctly.
45
    $this->assertFieldByXPath("//a[contains(@href, '/system-test/configure/bar') and text()='Configure ']/span[contains(@class, 'visually-hidden') and text()='the System test module']");
46 47 48

    // Check that system_test's permissions link was rendered correctly.
    $this->assertFieldByXPath("//a[contains(@href, '/admin/people/permissions#module-system_test') and @title='Configure permissions']");
49 50 51

    // Check that system_test's help link was rendered correctly.
    $this->assertFieldByXPath("//a[contains(@href, '/admin/help/system_test') and @title='Help']");
52

53 54 55 56
    // Ensure that the Database Logging module's machine name is printed. This
    // module is used because its machine name is different than its human
    // readable name.
    $this->assertText('dblog');
57
  }
58

59 60 61 62 63
  public function testModulesListFormWithInvalidInfoFile() {
    $broken_info_yml = <<<BROKEN
name: Module With Broken Info file
type: module
BROKEN;
64
    $path = \Drupal::getContainer()->getParameter('site.path') . "/modules/broken";
65 66 67 68 69 70 71 72 73 74 75 76 77
    mkdir($path, 0777, TRUE);
    file_put_contents("$path/broken.info.yml", $broken_info_yml);

    $this->drupalLogin(
      $this->drupalCreateUser(
        ['administer modules', 'administer permissions']
      )
    );
    $this->drupalGet('admin/modules');
    $this->assertSession()->statusCodeEquals(200);

    // Confirm that the error message is shown.
    $this->assertSession()
78
      ->pageTextContains("The 'core' or the 'core_version_requirement' key must be present in " . $path . '/broken.info.yml');
79 80

    // Check that the module filter text box is available.
81
    $this->assertSession()->elementExists('xpath', '//input[@name="text"]');
82 83
  }

84
}