View source
<?php
namespace Drupal\Tests\system\Functional\Module;
use Drupal\Component\Utility\Unicode;
class DependencyTest extends ModuleTestBase {
protected $defaultTheme = 'stark';
public function testProjectNamespaceForDependencies() {
$edit = [
'modules[filter][enable]' => TRUE,
];
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$edit = [
'modules[system_project_namespace_test][enable]' => TRUE,
];
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$this
->assertModules([
'system_project_namespace_test',
], TRUE);
}
public function testEnableWithoutDependency() {
$edit = [];
$edit['modules[content_translation][enable]'] = 'content_translation';
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$this
->assertText(t('Some required modules must be enabled'), 'Dependency required.');
$this
->assertModules([
'content_translation',
'language',
], FALSE);
$this
->assertTableCount('language', FALSE);
$this
->drupalPostForm(NULL, NULL, t('Continue'));
$this
->assertText(t('2 modules have been enabled: Content Translation, Language.'), 'Modules status has been updated.');
$this
->assertModules([
'content_translation',
'language',
], TRUE);
$storage = $this->container
->get('config.storage');
$this
->assertNotEmpty($storage
->listAll('language.entity.'), 'Language config entity files exist.');
}
public function testMissingModules() {
$this
->drupalGet('admin/modules');
$this
->assertRaw(t('@module (<span class="admin-missing">missing</span>)', [
'@module' => Unicode::ucfirst('_missing_dependency'),
]), 'A module with missing dependencies is marked as such.');
$checkbox = $this
->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_dependencies_test][enable]"]');
$this
->assertCount(1, $checkbox, 'Checkbox for the module is disabled.');
}
public function testIncompatibleModuleVersionDependency() {
$this
->drupalGet('admin/modules');
$this
->assertRaw(t('@module (<span class="admin-missing">incompatible with</span> version @version)', [
'@module' => 'System incompatible module version test (>2.0)',
'@version' => '1.0',
]), 'A module that depends on an incompatible version of a module is marked as such.');
$checkbox = $this
->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_incompatible_module_version_dependencies_test][enable]"]');
$this
->assertCount(1, $checkbox, 'Checkbox for the module is disabled.');
}
public function testIncompatibleCoreVersionDependency() {
$this
->drupalGet('admin/modules');
$this
->assertRaw(t('@module (<span class="admin-missing">incompatible with</span> this version of Drupal core)', [
'@module' => 'System incompatible core version test',
]), 'A module that depends on a module with an incompatible core version is marked as such.');
$checkbox = $this
->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_incompatible_core_version_dependencies_test][enable]"]');
$this
->assertCount(1, $checkbox, 'Checkbox for the module is disabled.');
}
public function testIncompatiblePhpVersionDependency() {
$this
->drupalGet('admin/modules');
$this
->assertRaw('This module requires PHP version 6502.* and is incompatible with PHP version ' . phpversion() . '.', 'User is informed when the PHP dependency requirement of a module is not met.');
$checkbox = $this
->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_incompatible_php_version_test][enable]"]');
$this
->assertCount(1, $checkbox, 'Checkbox for the module is disabled.');
}
public function testCoreCompatibility() {
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/modules');
$assert_session
->fieldDisabled('modules[system_incompatible_core_version_test_1x][enable]');
$assert_session
->fieldDisabled('modules[system_core_incompatible_semver_test][enable]');
$this
->drupalGet('admin/modules');
$assert_session
->fieldEnabled('modules[common_test][enable]');
$assert_session
->fieldEnabled('modules[system_core_semver_test][enable]');
$edit['modules[common_test][enable]'] = 'common_test';
$edit['modules[system_core_semver_test][enable]'] = 'system_core_semver_test';
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$this
->assertModules([
'common_test',
'system_core_semver_test',
], TRUE);
}
public function testEnableRequirementsFailureDependency() {
\Drupal::service('module_installer')
->install([
'comment',
]);
$this
->assertModules([
'requirements1_test',
], FALSE);
$this
->assertModules([
'requirements2_test',
], FALSE);
$edit = [];
$edit['modules[requirements1_test][enable]'] = 'requirements1_test';
$edit['modules[requirements2_test][enable]'] = 'requirements2_test';
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$this
->assertText(t('Requirements 1 Test failed requirements'), 'Modules status has been updated.');
$this
->assertModules([
'requirements1_test',
], FALSE);
$this
->assertModules([
'requirements2_test',
], FALSE);
$this
->assertModules([
'comment',
], TRUE);
}
public function testModuleEnableOrder() {
\Drupal::service('module_installer')
->install([
'module_test',
], FALSE);
$this
->resetAll();
$this
->assertModules([
'module_test',
], TRUE);
\Drupal::state()
->set('module_test.dependency', 'dependency');
$expected_order = [
'help',
'config',
'color',
];
$edit = [];
$edit['modules[color][enable]'] = 'color';
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$this
->assertModules([
'color',
], FALSE);
$this
->assertText(t('You must enable the Configuration Manager, Help modules to install Color.'));
$edit['modules[config][enable]'] = 'config';
$edit['modules[help][enable]'] = 'help';
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$this
->assertModules([
'color',
'config',
'help',
], TRUE);
$module_order = \Drupal::state()
->get('module_test.install_order') ?: [];
$this
->assertIdentical($module_order, $expected_order);
}
public function testUninstallDependents() {
$edit = [
'modules[forum][enable]' => 'forum',
];
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$this
->drupalPostForm(NULL, [], t('Continue'));
$this
->assertModules([
'forum',
], TRUE);
$this
->drupalGet('admin/modules/uninstall');
$checkbox = $this
->xpath('//input[@type="checkbox" and @name="uninstall[comment]" and @disabled="disabled"]');
$this
->assertCount(1, $checkbox, 'Checkbox for uninstalling the comment module is disabled.');
$vid = $this
->config('forum.settings')
->get('vocabulary');
\Drupal::moduleHandler()
->load('taxonomy');
$storage = \Drupal::entityTypeManager()
->getStorage('taxonomy_term');
$terms = $storage
->loadByProperties([
'vid' => $vid,
]);
$storage
->delete($terms);
$edit = [
'uninstall[forum]' => 'forum',
];
$this
->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
$this
->drupalPostForm(NULL, NULL, t('Uninstall'));
$this
->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
$edit = [
'uninstall[comment]' => 'comment',
];
$this
->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
$this
->drupalPostForm(NULL, NULL, t('Uninstall'));
$this
->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
}
}