class GenericModuleTestBase
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Module/GenericModuleTestBase.php \Drupal\Tests\system\Functional\Module\GenericModuleTestBase
- 10 core/modules/system/tests/src/Functional/Module/GenericModuleTestBase.php \Drupal\Tests\system\Functional\Module\GenericModuleTestBase
Runs a series of generic tests for one module.
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Module\GenericModuleTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of GenericModuleTestBase
74 files declare their use of GenericModuleTestBase
- GenericTest.php in core/
modules/ language/ tests/ src/ Functional/ GenericTest.php - GenericTest.php in core/
modules/ media/ tests/ src/ Functional/ GenericTest.php - GenericTest.php in core/
modules/ phpass/ tests/ src/ Functional/ GenericTest.php - GenericTest.php in core/
modules/ sqlite/ tests/ src/ Functional/ GenericTest.php - GenericTest.php in core/
modules/ layout_builder/ tests/ src/ Functional/ GenericTest.php
File
-
core/
modules/ system/ tests/ src/ Functional/ Module/ GenericModuleTestBase.php, line 15
Namespace
Drupal\Tests\system\Functional\ModuleView source
abstract class GenericModuleTestBase extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'help',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Get the module name.
*
* @return string
* The module to test.
*/
protected function getModule() : string {
return explode('\\', get_class($this))[2];
}
/**
* Checks some generic things about a module.
*/
public function testModuleGenericIssues() : void {
$module = $this->getModule();
\Drupal::service('module_installer')->install([
$module,
]);
$info = \Drupal::service('extension.list.module')->getExtensionInfo($module);
if (!empty($info['required']) && !empty($info['hidden'])) {
$this->markTestSkipped('Nothing to assert for hidden, required modules.');
}
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
'access help pages',
]);
$this->assertHookHelp($module);
if (empty($info['required'])) {
$connection = Database::getConnection();
// The module that provides the database driver, or is a dependency of
// the database driver, cannot be uninstalled.
$database_module_extension = \Drupal::service(ModuleExtensionList::class)->get($connection->getProvider());
$database_modules_required = $database_module_extension->requires ? array_keys($database_module_extension->requires) : [];
$database_modules_required[] = $connection->getProvider();
if (!in_array($module, $database_modules_required)) {
// Check that the module can be uninstalled and then re-installed again.
$this->preUnInstallSteps();
$this->assertTrue(\Drupal::service('module_installer')->uninstall([
$module,
]), "Failed to uninstall '{$module}' module");
$this->assertTrue(\Drupal::service('module_installer')->install([
$module,
]), "Failed to install '{$module}' module");
}
}
}
/**
* Verifies hook_help() syntax.
*
* @param string $module
* The module.
*/
protected function assertHookHelp(string $module) : void {
$info = \Drupal::service('extension.list.module')->getExtensionInfo($module);
if (empty($info['hidden'])) {
$this->drupalGet('admin/help/' . $module);
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains($info['name'] . ' module');
$this->assertSession()
->linkExists('online documentation for the ' . $info['name'] . ' module', 0, "Correct online documentation link is in the help page for {$module}");
}
}
/**
* Helper to perform any steps required prior to uninstalling a module.
*/
protected function preUnInstallSteps() : void {
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.