ExperimentalModuleTest.php 5.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
<?php

namespace Drupal\system\Tests\Module;

use Drupal\simpletest\WebTestBase;

/**
 * Tests the installation of modules.
 *
 * @group Module
 */
class ExperimentalModuleTest extends WebTestBase {


  /**
   * The admin user.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $adminUser;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->adminUser = $this->drupalCreateUser(['access administration pages', 'administer modules']);
    $this->drupalLogin($this->adminUser);
  }

  /**
   * Tests installing experimental modules and dependencies in the UI.
   */
  public function testExperimentalConfirmForm() {

    // First, test installing a non-experimental module with no dependencies.
    // There should be no confirmation form and no experimental module warning.
    $edit = [];
39
    $edit["modules[test_page_test][enable]"] = TRUE;
40 41 42 43 44 45 46 47 48 49 50
    $this->drupalPostForm('admin/modules', $edit, t('Install'));
    $this->assertText('Module Test page has been enabled.');
    $this->assertNoText('Experimental modules are provided for testing purposes only.');

    // Uninstall the module.
    \Drupal::service('module_installer')->uninstall(['test_page_test']);

    // Next, test installing an experimental module with no dependencies.
    // There should be a confirmation form with an experimental warning, but no
    // list of dependencies.
    $edit = [];
51
    $edit["modules[experimental_module_test][enable]"] = TRUE;
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    $this->drupalPostForm('admin/modules', $edit, 'Install');

    // The module should not be enabled and there should be a warning and a
    // list of the experimental modules with only this one.
    $this->assertNoText('Experimental Test has been enabled.');
    $this->assertText('Experimental modules are provided for testing purposes only.');
    $this->assertText('The following modules are experimental: Experimental Test');

    // There should be no message about enabling dependencies.
    $this->assertNoText('You must enable');

    // Enable the module and confirm that it worked.
    $this->drupalPostForm(NULL, [], 'Continue');
    $this->assertText('Experimental Test has been enabled.');

    // Uninstall the module.
    \Drupal::service('module_installer')->uninstall(['experimental_module_test']);

    // Test enabling a module that is not itself experimental, but that depends
    // on an experimental module.
    $edit = [];
73
    $edit["modules[experimental_module_dependency_test][enable]"] = TRUE;
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    $this->drupalPostForm('admin/modules', $edit, 'Install');

    // The module should not be enabled and there should be a warning and a
    // list of the experimental modules with only this one.
    $this->assertNoText('2 modules have been enabled: Experimental Dependency Test, Experimental Test');
    $this->assertText('Experimental modules are provided for testing purposes only.');

    $this->assertText('The following modules are experimental: Experimental Test');

    // Ensure the non-experimental module is not listed as experimental.
    $this->assertNoText('The following modules are experimental: Experimental Test, Experimental Dependency Test');
    $this->assertNoText('The following modules are experimental: Experimental Dependency Test');

    // There should be a message about enabling dependencies.
    $this->assertText('You must enable the Experimental Test module to install Experimental Dependency Test');

    // Enable the module and confirm that it worked.
    $this->drupalPostForm(NULL, [], 'Continue');
    $this->assertText('2 modules have been enabled: Experimental Dependency Test, Experimental Test');

    // Uninstall the modules.
    \Drupal::service('module_installer')->uninstall(['experimental_module_test', 'experimental_module_dependency_test']);

    // Finally, check both the module and its experimental dependency. There is
    // still a warning about experimental modules, but no message about
    // dependencies, since the user specifically enabled the dependency.
    $edit = [];
101 102
    $edit["modules[experimental_module_test][enable]"] = TRUE;
    $edit["modules[experimental_module_dependency_test][enable]"] = TRUE;
103 104 105 106 107 108 109 110 111 112
    $this->drupalPostForm('admin/modules', $edit, 'Install');

    // The module should not be enabled and there should be a warning and a
    // list of the experimental modules with only this one.
    $this->assertNoText('2 modules have been enabled: Experimental Dependency Test, Experimental Test');
    $this->assertText('Experimental modules are provided for testing purposes only.');

    $this->assertText('The following modules are experimental: Experimental Test');

    // Ensure the non-experimental module is not listed as experimental.
113
    $this->assertNoText('The following modules are experimental: Experimental Dependency Test, Experimental Test');
114 115 116 117 118 119 120
    $this->assertNoText('The following modules are experimental: Experimental Dependency Test');

    // There should be no message about enabling dependencies.
    $this->assertNoText('You must enable');

    // Enable the module and confirm that it worked.
    $this->drupalPostForm(NULL, [], 'Continue');
121
    $this->assertText('2 modules have been enabled: Experimental Dependency Test, Experimental Test');
122

123 124 125 126
    // Try to enable an experimental module that can not be due to
    // hook_requirements().
    \Drupal::state()->set('experimental_module_requirements_test_requirements', TRUE);
    $edit = [];
127
    $edit["modules[experimental_module_requirements_test][enable]"] = TRUE;
128 129 130
    $this->drupalPostForm('admin/modules', $edit, 'Install');
    $this->assertUrl('admin/modules', [], 'If the module can not be installed we are not taken to the confirm form.');
    $this->assertText('The Experimental Test Requirements module can not be installed.');
131 132 133
  }

}