1 system.test ModuleVersionTestCase::testModuleVersions()

Test version dependencies.

File

core/modules/system/tests/system.test, line 562
Tests for system.module.

Class

ModuleVersionTestCase
Test module dependency on specific versions.

Code

function testModuleVersions() {
  $dependencies = array(
    // All comparisons are done against 1.x-2.4.5-beta3.
    'common_test' => TRUE,
    // Branch incompatibility.
    'common_test (1.x)' => FALSE,
    // Branch compatibility.
    'common_test (2.x)' => TRUE,
    // Another branch incompatibility.
    'common_test (>2.x)' => FALSE,
    // Another branch compatibility.
    'common_test (<=2.x)' => TRUE,
    // Another branch incompatibility.
    'common_test (<2.x)' => FALSE,
    // Another branch compatibility.
    'common_test (>=2.x)' => TRUE,
    // Higher rc version. Incompatible.
    'common_test (>=1.x-2.4.5-rc1)' => FALSE,
    // Higher beta version. Incompatible.
    'common_test (>=1.x-2.4.5-beta4)' => FALSE,
    // Lower beta version. Compatible.
    'common_test (>=1.x-2.4.5-beta2)' => TRUE,
    // Lower alpha version. Compatible.
    'common_test (>=1.x-2.4.5-alpha8)' => TRUE,
    // Nonsense, misses a dash. Incompatible with everything.
    'common_test (=1.x2.x.5, >=2.4.5)' => FALSE,
    // Core version is optional. Compatible.
    'common_test (=1.x-2.x, >=2.4.5-alpha2)' => TRUE,
    // Test !=, explicitly incompatible.
    'common_test (=2.x, !=2.4.5-beta3)' => FALSE,
    // Three operations. Compatible.
    'common_test (=2.x, !=2.3.4, <2.5.0)' => TRUE,
    // Testing extra version. Incompatible.
    'common_test (<=2.4.5-beta2)' => FALSE,
    // Testing extra version. Compatible.
    'common_test (>2.4.5-beta2)' => TRUE,
    // Testing extra version. Incompatible.
    'common_test (>2.4.5-rc0)' => FALSE,
  );
  foreach ($dependencies as $version_string => $compatible) {
    // Each request, one dependency is shifted off the front and added to
    // module_test's dependencies. See system_test_system_info_alter().
    state_set('system_test_dependency', $version_string);
    $this->backdropGet('admin/modules');
    $checkbox = $this->xpath('//input[@id="edit-modules-testing-module-test-enable"]');
    $this->assertEqual(empty($checkbox[0]['disabled']), $compatible, $version_string);
  }

  $dev_dependencies = array(
    // Compare again against a dev version 1.x-2.x-dev.
    'common_test' => TRUE,
    // Branch incompatibility.
    'common_test (1.x)' => FALSE,
    // Branch compatibility.
    'common_test (2.x)' => TRUE,
    // Another branch incompatibility.
    'common_test (>2.x)' => FALSE,
    // Any alpha version
    'common_test (>=1.x-2.x-alpha4)' => TRUE,
    // Any beta version
    'common_test (>=1.x-2.x-beta4)' => TRUE,
    // Any rc version
    'common_test (>=1.x-2.x-rc4)' => TRUE,
    // Any preview version
    'common_test (>=1.x-2.x-preview)' => TRUE,
    // Complex version string.
    'common_test (>=1.x-2.4-beta2)' => TRUE,
    // Dev versions are later than any minor number.
    'common_test (>=2.4.0)' => TRUE,
    // Next version is not compatible.
    'common_test (>=3.0.0)' => FALSE,
  );

  // Same testing approach as above, only against a different version number.
  foreach ($dev_dependencies as $version_string => $compatible) {
    // Each request, one dependency is shifted off the front and added to
    // module_test's dependencies. See system_test_system_info_alter().
    state_set('system_test_dev_dependency', $version_string);
    $this->backdropGet('admin/modules');

    $checkbox = $this->xpath('//input[@id="edit-modules-testing-module-test-enable"]');
    $this->assertEqual(empty($checkbox[0]['disabled']), $compatible, 'Dev dependency: ' . $version_string);
  }
}