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
->drupalGet('admin/modules');
$this
->submitForm($edit, 'Install');
$edit = [
'modules[system_project_namespace_test][enable]' => TRUE,
];
$this
->drupalGet('admin/modules');
$this
->submitForm($edit, 'Install');
$this
->assertModules([
'system_project_namespace_test',
], TRUE);
}
public function testEnableWithoutDependency() {
$edit = [];
$edit['modules[content_translation][enable]'] = 'content_translation';
$this
->drupalGet('admin/modules');
$this
->submitForm($edit, 'Install');
$this
->assertSession()
->pageTextContains('Some required modules must be enabled');
$this
->assertModules([
'content_translation',
'language',
], FALSE);
$this
->assertNoModuleConfig('language');
$this
->submitForm([], 'Continue');
$this
->assertSession()
->pageTextContains('2 modules have been enabled: Content Translation, Language.');
$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
->assertSession()
->pageTextContains(Unicode::ucfirst('_missing_dependency') . ' (missing)');
$this
->assertSession()
->elementTextEquals('xpath', '//tr[@data-drupal-selector="edit-modules-system-dependencies-test"]//span[@class="admin-missing"]', 'missing');
$this
->assertSession()
->checkboxNotChecked('modules[system_dependencies_test][enable]');
}
public function testIncompatibleModuleVersionDependency() {
$this
->drupalGet('admin/modules');
$this
->assertSession()
->pageTextContains('System incompatible module version test (>2.0) (incompatible with version 1.0)');
$this
->assertSession()
->elementTextEquals('xpath', '//tr[@data-drupal-selector="edit-modules-system-incompatible-module-version-dependencies-test"]//span[@class="admin-missing"]', 'incompatible with');
$this
->assertSession()
->fieldDisabled('modules[system_incompatible_module_version_dependencies_test][enable]');
}
public function testIncompatibleCoreVersionDependency() {
$this
->drupalGet('admin/modules');
$this
->assertSession()
->pageTextContains('System core incompatible semver test (incompatible with this version of Drupal core)');
$this
->assertSession()
->elementTextEquals('xpath', '//tr[@data-drupal-selector="edit-modules-system-incompatible-core-version-dependencies-test"]//span[@class="admin-missing"]', 'incompatible with');
$this
->assertSession()
->fieldDisabled('modules[system_incompatible_core_version_dependencies_test][enable]');
}
public function testIncompatiblePhpVersionDependency() {
$this
->drupalGet('admin/modules');
$this
->assertSession()
->pageTextContains('This module requires PHP version 6502.* and is incompatible with PHP version ' . phpversion() . '.');
$this
->assertSession()
->fieldDisabled('modules[system_incompatible_php_version_test][enable]');
}
public function testCoreCompatibility() {
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/modules');
$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
->drupalGet('admin/modules');
$this
->submitForm($edit, '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
->drupalGet('admin/modules');
$this
->submitForm($edit, 'Install');
$this
->assertSession()
->pageTextContains('Requirements 1 Test failed requirements');
$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
->drupalGet('admin/modules');
$this
->submitForm($edit, 'Install');
$this
->assertModules([
'color',
], FALSE);
$this
->assertSession()
->pageTextContains('You must enable the Configuration Manager, Help modules to install Color.');
$edit['modules[config][enable]'] = 'config';
$edit['modules[help][enable]'] = 'help';
$this
->drupalGet('admin/modules');
$this
->submitForm($edit, 'Install');
$this
->assertModules([
'color',
'config',
'help',
], TRUE);
$module_order = \Drupal::state()
->get('module_test.install_order', []);
$this
->assertSame($expected_order, $module_order);
}
public function testUninstallDependents() {
$edit = [
'modules[forum][enable]' => 'forum',
];
$this
->drupalGet('admin/modules');
$this
->submitForm($edit, 'Install');
$this
->submitForm([], 'Continue');
$this
->assertModules([
'forum',
], TRUE);
$this
->drupalGet('admin/modules/uninstall');
$this
->assertSession()
->fieldDisabled('uninstall[comment]');
$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
->drupalGet('admin/modules/uninstall');
$this
->submitForm($edit, 'Uninstall');
$this
->submitForm([], 'Uninstall');
$this
->assertSession()
->pageTextContains('The selected modules have been uninstalled.');
$edit = [
'uninstall[comment]' => 'comment',
];
$this
->drupalGet('admin/modules/uninstall');
$this
->submitForm($edit, 'Uninstall');
$this
->submitForm([], 'Uninstall');
$this
->assertSession()
->pageTextContains('The selected modules have been uninstalled.');
}
}