HookRequirementsTest.php

Same filename in other branches
  1. 9 core/modules/system/tests/src/Functional/Module/HookRequirementsTest.php
  2. 8.9.x core/modules/system/tests/src/Functional/Module/HookRequirementsTest.php
  3. 10 core/modules/system/tests/src/Functional/Module/HookRequirementsTest.php

Namespace

Drupal\Tests\system\Functional\Module

File

core/modules/system/tests/src/Functional/Module/HookRequirementsTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\system\Functional\Module;


/**
 * Attempts enabling a module that fails hook_requirements('install').
 *
 * @group Module
 */
class HookRequirementsTest extends ModuleTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * Assert that a module cannot be installed if it fails hook_requirements().
     */
    public function testHookRequirementsFailure() : void {
        $this->assertModules([
            'requirements1_test',
        ], FALSE);
        // Attempt to install the requirements1_test module.
        $edit = [];
        $edit['modules[requirements1_test][enable]'] = 'requirements1_test';
        $this->drupalGet('admin/modules');
        $this->submitForm($edit, 'Install');
        // Makes sure the module was NOT installed.
        $this->assertSession()
            ->pageTextContains('Requirements 1 Test failed requirements');
        $this->assertModules([
            'requirements1_test',
        ], FALSE);
    }

}

Classes

Title Deprecated Summary
HookRequirementsTest Attempts enabling a module that fails hook_requirements('install').

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