protected function ModulesFormTest::installModules in farmOS 2.x
Helper function to test installing a list of modules.
Parameters
array $modules: The array of modules to install. Expects arrays of module names keyed by the module type.
1 call to ModulesFormTest::installModules()
- ModulesFormTest::testInstallFunctionality in modules/
core/ settings/ tests/ src/ Functional/ ModulesFormTest.php - Tests the install functionality of the module settings form.
File
- modules/
core/ settings/ tests/ src/ Functional/ ModulesFormTest.php, line 123
Class
- ModulesFormTest
- Tests installing modules via the module settings form.
Namespace
Drupal\Tests\farm_settings\FunctionalCode
protected function installModules(array $modules) {
// Build a list of module names.
$module_names = [];
// Loop through module types, core or contrib.
$this
->assertNotEmpty($modules, 'Modules array is not empty.');
foreach ($modules as $type => $module_list) {
// Check each module in the list.
$this
->assertNotEmpty($module_list, 'Modules of the specified type are provided.');
foreach ($module_list as $module_name) {
$module_names[] = $module_name;
$page = $this
->getSession()
->getPage();
$page
->checkField($type . "[modules][{$module_name}]");
$this
->assertModuleCheckboxState($type, $module_name, TRUE, FALSE);
}
}
// Assert the install button becomes enabled.
$this
->assertInstallButtonState(FALSE);
// Submit the form.
$page
->pressButton('install-modules');
// Wait for the batch process to complete.
$this
->assertSession()
->waitForText('Install modules', 30000);
// Rebuild the list of installed modules.
$this
->rebuildContainer();
/** @var \Drupal\Core\Extension\ModuleExtensionList $module_list */
$module_extension_list = \Drupal::service('extension.list.module');
$module_extension_list
->reset();
// Assert that each module was installed and the form was updated.
foreach ($modules as $type => $module_list) {
foreach ($module_list as $module_name) {
// This method raises an error if the module is not installed.
$module_info = $module_extension_list
->getExtensionInfo($module_name);
$this
->assertNotEmpty($module_info);
// Assert that the checkbox is checked and disabled.
$this
->assertModuleCheckboxState($type, $module_name, TRUE, TRUE);
}
}
}