View source
<?php
namespace Drupal\system\Tests\Module;
use Drupal\Component\Utility\Unicode;
class DependencyTest extends ModuleTestBase {
function testProjectNamespaceForDependencies() {
$edit = array(
'modules[Core][filter][enable]' => TRUE,
);
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$edit = array(
'modules[Testing][system_project_namespace_test][enable]' => TRUE,
);
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$this
->assertModules(array(
'system_project_namespace_test',
), TRUE);
}
function testEnableWithoutDependency() {
$edit = array();
$edit['modules[Multilingual][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(array(
'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(array(
'content_translation',
'language',
), TRUE);
$storage = $this->container
->get('config.storage');
$this
->assertTrue(count($storage
->listAll('language.entity.')) > 0, 'Language config entity files exist.');
}
function testMissingModules() {
$this
->drupalGet('admin/modules');
$this
->assertRaw(t('@module (<span class="admin-missing">missing</span>)', array(
'@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[Testing][system_dependencies_test][enable]"]');
$this
->assert(count($checkbox) == 1, 'Checkbox for the module is disabled.');
}
function testIncompatibleModuleVersionDependency() {
$this
->drupalGet('admin/modules');
$this
->assertRaw(t('@module (<span class="admin-missing">incompatible with</span> version @version)', array(
'@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[Testing][system_incompatible_module_version_dependencies_test][enable]"]');
$this
->assert(count($checkbox) == 1, 'Checkbox for the module is disabled.');
}
function testIncompatibleCoreVersionDependency() {
$this
->drupalGet('admin/modules');
$this
->assertRaw(t('@module (<span class="admin-missing">incompatible with</span> this version of Drupal core)', array(
'@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[Testing][system_incompatible_core_version_dependencies_test][enable]"]');
$this
->assert(count($checkbox) == 1, 'Checkbox for the module is disabled.');
}
function testEnableRequirementsFailureDependency() {
\Drupal::service('module_installer')
->install(array(
'comment',
));
$this
->assertModules(array(
'requirements1_test',
), FALSE);
$this
->assertModules(array(
'requirements2_test',
), FALSE);
$edit = array();
$edit['modules[Testing][requirements1_test][enable]'] = 'requirements1_test';
$edit['modules[Testing][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(array(
'requirements1_test',
), FALSE);
$this
->assertModules(array(
'requirements2_test',
), FALSE);
$this
->assertModules(array(
'comment',
), TRUE);
}
function testModuleEnableOrder() {
\Drupal::service('module_installer')
->install(array(
'module_test',
), FALSE);
$this
->resetAll();
$this
->assertModules(array(
'module_test',
), TRUE);
\Drupal::state()
->set('module_test.dependency', 'dependency');
$expected_order = array(
'help',
'config',
'color',
);
$edit = array();
$edit['modules[Core][color][enable]'] = 'color';
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$this
->assertModules(array(
'color',
), FALSE);
$this
->assertText(t('You must enable the Configuration Manager, Help modules to install Color.'));
$edit['modules[Core][config][enable]'] = 'config';
$edit['modules[Core][help][enable]'] = 'help';
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$this
->assertModules(array(
'color',
'config',
'help',
), TRUE);
$module_order = \Drupal::state()
->get('module_test.install_order') ?: array();
$this
->assertIdentical($module_order, $expected_order);
}
function testUninstallDependents() {
$edit = array(
'modules[Core][forum][enable]' => 'forum',
);
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
$this
->drupalPostForm(NULL, array(), t('Continue'));
$this
->assertModules(array(
'forum',
), TRUE);
$this
->drupalGet('admin/modules/uninstall');
$checkbox = $this
->xpath('//input[@type="checkbox" and @name="uninstall[comment]" and @disabled="disabled"]');
$this
->assert(count($checkbox) == 1, 'Checkbox for uninstalling the comment module is disabled.');
$vid = $this
->config('forum.settings')
->get('vocabulary');
\Drupal::moduleHandler()
->load('taxonomy');
$terms = entity_load_multiple_by_properties('taxonomy_term', [
'vid' => $vid,
]);
foreach ($terms as $term) {
$term
->delete();
}
$edit = array(
'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 = array(
'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.');
}
}