Skip to content
Snippets Groups Projects
Select Git revision
  • 6c91ce879fb613287d03d32299c9329f0c6796f3
  • 11.x default protected
  • 11.2.x protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

DependencyTest.php

Blame
  • Alex Pott's avatar
    Issue #2254203 by sun, neclimdul: Fix test performance of Drupal\system\Tests\Module\ModuleApiTest.
    Alex Pott authored
    6c91ce87
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    DependencyTest.php 7.84 KiB
    <?php
    
    /**
     * @file
     * Contains \Drupal\system\Tests\Module\DependencyTest.
     */
    
    namespace Drupal\system\Tests\Module;
    
    /**
     * Tests module dependency functionality.
     */
    class DependencyTest extends ModuleTestBase {
      public static function getInfo() {
        return array(
          'name' => 'Module dependencies',
          'description' => 'Enable module without dependency enabled.',
          'group' => 'Module',
        );
      }
    
      /**
       * Attempts to enable the Content Translation module without Language enabled.
       */
      function testEnableWithoutDependency() {
        // Attempt to enable Content Translation without Language enabled.
        $edit = array();
        $edit['modules[Multilingual][content_translation][enable]'] = 'content_translation';
        $this->drupalPostForm('admin/modules', $edit, t('Save configuration'));
        $this->assertText(t('Some required modules must be enabled'), 'Dependency required.');
    
        $this->assertModules(array('content_translation', 'language'), FALSE);
    
        // Assert that the language tables weren't enabled.
        $this->assertTableCount('language', FALSE);
    
        $this->drupalPostForm(NULL, NULL, t('Continue'));
        $this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.');
    
        $this->assertModules(array('content_translation', 'language'), TRUE);
    
        // Assert that the language YAML files were created.
        $storage = $this->container->get('config.storage');
        $this->assertTrue(count($storage->listAll('language.entity.')) > 0, 'Language config entity files exist.');
      }
    
      /**
       * Attempts to enable a module with a missing dependency.
       */
      function testMissingModules() {
        // Test that the system_dependencies_test module is marked
        // as missing a dependency.
        $this->drupalGet('admin/modules');
        $this->assertRaw(t('@module (<span class="admin-missing">missing</span>)', array('@module' => drupal_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.');
      }
    
      /**
       * Tests enabling a module that depends on an incompatible version of a module.
       */
      function testIncompatibleModuleVersionDependency() {
        // Test that the system_incompatible_module_version_dependencies_test is
        // marked as having an incompatible dependency.
        $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.');
      }
    
      /**
       * Tests enabling a module that depends on a module with an incompatible core version.
       */
      function testIncompatibleCoreVersionDependency() {
        // Test that the system_incompatible_core_version_dependencies_test is
        // marked as having an incompatible dependency.
        $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.');
      }
    
      /**
       * Tests enabling a module that depends on a module which fails hook_requirements().
       */
      function testEnableRequirementsFailureDependency() {
        \Drupal::moduleHandler()->install(array('comment'));
    
        $this->assertModules(array('requirements1_test'), FALSE);
        $this->assertModules(array('requirements2_test'), FALSE);
    
        // Attempt to install both modules at the same time.
        $edit = array();
        $edit['modules[Testing][requirements1_test][enable]'] = 'requirements1_test';
        $edit['modules[Testing][requirements2_test][enable]'] = 'requirements2_test';
        $this->drupalPostForm('admin/modules', $edit, t('Save configuration'));
    
        // Makes sure the modules were NOT installed.
        $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);
    
        // Makes sure that already enabled modules the failing modules depend on
        // were not disabled.
        $this->assertModules(array('comment'), TRUE);
      }
    
      /**
       * Tests that module dependencies are enabled in the correct order in the UI.
       *
       * Dependencies should be enabled before their dependents.
       */
      function testModuleEnableOrder() {
        \Drupal::moduleHandler()->install(array('module_test'), FALSE);
        $this->resetAll();
        $this->assertModules(array('module_test'), TRUE);
        \Drupal::state()->set('module_test.dependency', 'dependency');
        // module_test creates a dependency chain:
        // - color depends on config
        // - config depends on help
        $expected_order = array('help', 'config', 'color');
    
        // Enable the modules through the UI, verifying that the dependency chain
        // is correct.
        $edit = array();
        $edit['modules[Core][color][enable]'] = 'color';
        $this->drupalPostForm('admin/modules', $edit, t('Save configuration'));
        $this->assertModules(array('color'), FALSE);
        // Note that dependencies are sorted alphabetically in the confirmation
        // message.
        $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('Save configuration'));
        $this->assertModules(array('color', 'config', 'help'), TRUE);
    
        // Check the actual order which is saved by module_test_modules_enabled().
        $module_order = \Drupal::state()->get('module_test.install_order') ?: array();
        $this->assertIdentical($module_order, $expected_order);
      }
    
      /**
       * Tests attempting to uninstall a module that has installed dependents.
       */
      function testUninstallDependents() {
        // Enable the forum module.
        $edit = array('modules[Core][forum][enable]' => 'forum');
        $this->drupalPostForm('admin/modules', $edit, t('Save configuration'));
        $this->drupalPostForm(NULL, array(), t('Continue'));
        $this->assertModules(array('forum'), TRUE);
    
        // Check that the comment module cannot be uninstalled.
        $this->drupalGet('admin/modules/uninstall');
        $checkbox = $this->xpath('//input[@type="checkbox" and @name="uninstall[comment]"]');
        $this->assert(count($checkbox) == 0, 'Checkbox for uninstalling the comment module not found.');
    
        // Uninstall the forum module, and check that taxonomy now can also be
        // uninstalled.
        $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.');
    
        // Uninstall comment module.
        $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.');
      }
    
    }