You are here

public function ModulesListFormWebTest::testModulesListFormWithInvalidInfoFile in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php \Drupal\Tests\system\Functional\Form\ModulesListFormWebTest::testModulesListFormWithInvalidInfoFile()
  2. 10 core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php \Drupal\Tests\system\Functional\Form\ModulesListFormWebTest::testModulesListFormWithInvalidInfoFile()

Tests the module form with modules with invalid info.yml files.

File

core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php, line 61

Class

ModulesListFormWebTest
Tests \Drupal\system\Form\ModulesListForm.

Namespace

Drupal\Tests\system\Functional\Form

Code

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']);

    // Check that the module filter text box is available.
    $this
      ->assertSession()
      ->elementExists('xpath', '//input[@name="text"]');
    unlink($file_path);
    $this
      ->drupalGet('admin/modules');
    $this
      ->assertSession()
      ->statusCodeEquals(200);

    // Check that the module filter text box is available.
    $this
      ->assertSession()
      ->elementExists('xpath', '//input[@name="text"]');
    $this
      ->assertSession()
      ->pageTextNotContains('Modules could not be listed due to an error');
  }
}