function ModulesListFormWebTest::testModulesListFormWithInvalidInfoFile

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

Tests the module form with a module with an invalid info.yml file.

File

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

Class

ModulesListFormWebTest
Tests <a href="/api/drupal/core%21modules%21system%21src%21Form%21ModulesListForm.php/class/ModulesListForm/11.x" title="Provides module installation interface." class="local">\Drupal\system\Form\ModulesListForm</a>.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testModulesListFormWithInvalidInfoFile() : void {
    $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}");
    // 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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.