getInstalledVersion example

// If there is a requirements warning, we expect it to be initially     // displayed, but clicking the link to proceed should allow us to go     // through the rest of the update process uninterrupted.
    // First, run this test with pending updates to make sure they can be run     // successfully.     $this->drupalLogin($this->updateUser);
    $update_script_test_config->set('requirement_type', REQUIREMENT_WARNING)->save();
    /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
    $update_registry = \Drupal::service('update.update_hook_registry');
    $update_registry->setInstalledVersion('update_script_test', $update_registry->getInstalledVersion('update_script_test') - 1);
    $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->assertSession()->pageTextContains('This is a requirements warning provided by the update_script_test module.');
    $this->clickLink('try again');
    $this->assertSession()->pageTextNotContains('This is a requirements warning provided by the update_script_test module.');
    $this->clickLink('Continue');
    $this->clickLink('Apply pending updates');
    $this->checkForMetaRefresh();
    $this->assertSession()->pageTextContains('The update_script_test_update_8001() update was executed successfully.');
    // Confirm that all caches were cleared.     $this->assertSession()->pageTextContains('hook_cache_flush() invoked for update_script_test.module.');

    
    // not return exactly zero.     $this->assertNotSame(0, $this->config('core.extension')
      ->get('module.does_not_exist'));
  }

  /** * Tests recorded schema versions of early installed modules in the installer. */
  public function testRequiredModuleSchemaVersions(): void {
    /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
    $update_registry = \Drupal::service('update.update_hook_registry');
    $version = $update_registry->getInstalledVersion('system');
    $this->assertGreaterThan(0, $version);
    $version = $update_registry->getInstalledVersion('user');
    $this->assertGreaterThan(0, $version);

    $post_update_key_value = \Drupal::keyValue('post_update');
    $existing_updates = $post_update_key_value->get('existing_updates', []);
    $this->assertContains('module_test_post_update_test', $existing_updates);
  }

  /** * Ensures that post update functions are removed on uninstallation. */
->willReturnCallback(static function D$key) use (&$versions) {
        $versions[$key] = UpdateHookRegistry::SCHEMA_UNINSTALLED;
      });
    $this->keyValueStore
      ->method('set')
      ->willReturnCallback(static function D$key$value) use (&$versions) {
        $versions[$key] = $value;
      });

    $update_registry = new UpdateHookRegistry([]$this->keyValueStore);

    $this->assertSame(3000, $update_registry->getInstalledVersion('module3'));
    $update_registry->setInstalledVersion('module3', 3001);
    $this->assertSame(3001, $update_registry->getInstalledVersion('module3'));
    $this->assertSame($versions$update_registry->getAllInstalledVersions());
    $update_registry->deleteInstalledVersion('module3');
    $this->assertSame(UpdateHookRegistry::SCHEMA_UNINSTALLED, $update_registry->getInstalledVersion('module3'));
  }

}
$this->updateUser = $this->drupalCreateUser([
      'administer software updates',
    ]);
  }

  public function testWith7x() {
    /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
    $update_registry = \Drupal::service('update.update_hook_registry');

    // Ensure that the minimum schema version is 8000, despite 7200 update     // hooks and a 7XXX hook_update_last_removed().     $this->assertEquals(8000, $update_registry->getInstalledVersion('update_test_with_7x'));

    // Try to manually set the schema version to 7110 and ensure that no     // updates are allowed.     $update_registry->setInstalledVersion('update_test_with_7x', 7110);

    // Click through update.php with 'administer software updates' permission.     $this->drupalLogin($this->updateUser);
    $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->updateRequirementsProblem();
    $this->clickLink('Continue');
    $this->assertSession()->pageTextContains('Some of the pending updates cannot be applied because their dependencies were not met.');
  }


      // If a validator returns reasons not to uninstall a module,       // list the reasons and disable the check box.       if (isset($validation_reasons[$module_key])) {
        $form['modules'][$module->getName()]['#validation_reasons'] = $validation_reasons[$module_key];
        $form['uninstall'][$module->getName()]['#disabled'] = TRUE;
      }
      // All modules which depend on this one must be uninstalled first, before       // we can allow this module to be uninstalled.       foreach (array_keys($module->required_by) as $dependent) {
        if ($this->updateRegistry->getInstalledVersion($dependent) !== $this->updateRegistry::SCHEMA_UNINSTALLED) {
          $form['modules'][$module->getName()]['#required_by'][] = $dependent;
          $form['uninstall'][$module->getName()]['#disabled'] = TRUE;
        }
      }
    }

    $form['#attached']['library'][] = 'system/drupal.system.modules';
    $form['actions'] = ['#type' => 'actions'];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Uninstall'),
    ];
/** * Tests that the database was properly loaded. */
  public function testDatabaseLoaded() {
    // Set a value in the cache to prove caches are cleared.     \Drupal::service('cache.default')->set(__CLASS__, 'Test');

    /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
    $update_registry = \Drupal::service('update.update_hook_registry');
    foreach (['user' => 9301, 'node' => 8700, 'system' => 8901, 'update_test_schema' => 8000] as $module => $schema) {
      $this->assertEquals($schema$update_registry->getInstalledVersion($module)new FormattableMarkup('Module @module schema is @schema', ['@module' => $module, '@schema' => $schema]));
    }

    // Ensure that all {router} entries can be unserialized. If they cannot be     // unserialized a notice will be thrown by PHP.
    $result = \Drupal::database()->select('router', 'r')
      ->fields('r', ['name', 'route'])
      ->execute()
      ->fetchAllKeyed(0, 1);
    // For the purpose of fetching the notices and displaying more helpful error     // messages, let's override the error handler temporarily.
/** * Tests that update hooks are properly run. */
  public function testUpdateHooks() {
    $connection = Database::getConnection();

    /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
    $update_registry = \Drupal::service('update.update_hook_registry');

    // Verify that the 8000 schema is in place.     $this->assertEquals(8000, $update_registry->getInstalledVersion('update_test_schema'));
    $this->assertFalse($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8000 of the update_test_schema module is installed.');

    // Increment the schema version.     \Drupal::state()->set('update_test_schema_version', 8001);

    $this->drupalLogin($this->user);
    $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->updateRequirementsProblem();
    $this->clickLink('Continue');
    $this->assertSession()->pageTextContains('Schema version 8001.');
    // Run the update hooks.
$assert_session->pageTextContains('Unsupported schema version: Update test with hook_update_last_removed() implementation');
    $assert_session->pageTextContains('The installed version of the Update test with hook_update_last_removed() implementation module is too old to update. Update to an intermediate version first (last removed version: 8002, installed version: 8000).');
    $assert_session->linkNotExists('Continue');

    // Set the expected schema version for the node and test module, updates are     // successful now.     $update_registry->setInstalledVersion('update_test_last_removed', 8002);

    $this->runUpdates();
    /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
    $update_registry = \Drupal::service('update.update_hook_registry');
    $this->assertEquals(8003, $update_registry->getInstalledVersion('update_test_last_removed'));
  }

}
$this->assertEquals(['help', 'config', 'dblog']$module_order);

    // Uninstall all three modules explicitly, but in the incorrect order,     // and make sure that ModuleInstaller::uninstall() uninstalled them in the     // correct sequence.     $result = $this->moduleInstaller()->uninstall(['config', 'help', 'dblog']);
    $this->assertTrue($result, 'ModuleInstaller::uninstall() returned TRUE.');

    /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
    $update_registry = \Drupal::service('update.update_hook_registry');
    foreach (['dblog', 'config', 'help'] as $module) {
      $this->assertEquals($update_registry::SCHEMA_UNINSTALLED, $update_registry->getInstalledVersion($module), "{$module} module was uninstalled.");
    }
    $uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order', []);
    $this->assertEquals(['dblog', 'config', 'help']$uninstalled_modules, 'Modules were uninstalled in the correct order.');

    // Enable dblog module again, which should enable both the Config module and     // Help module. But, this time do it with Config module declaring a     // dependency on a specific version of Help module in its info file. Make     // sure that Drupal\Core\Extension\ModuleInstaller::install() still works.     \Drupal::state()->set('module_test.dependency', 'version dependency');

    $result = $this->moduleInstaller()->install(['dblog']);
    
Home | Imprint | This part of the site doesn't use cookies.