3 namespace Drupal\system\Tests\Update;
5 use Drupal\Core\StringTranslation\StringTranslationTrait;
9 * Provides methods to conditionally enable db update functions and apply
10 * pending db updates through the Update UI.
12 * This should be used only by classes extending \Drupal\simpletest\WebTestBase.
14 trait DbUpdatesTrait {
16 use StringTranslationTrait;
19 * Enables db updates until the specified index.
21 * @param string $module
22 * The name of the module defining the update functions.
23 * @param string $group
24 * A name identifying the group of update functions to enable.
26 * The index of the last update function to run.
28 protected function enableUpdates($module, $group, $index) {
29 $this->container->get('state')->set($module . '.db_updates.' . $group, $index);
33 * Applies any pending DB updates through the Update UI.
35 protected function applyUpdates() {
36 $this->drupalGet(Url::fromRoute('system.db_update'));
37 $this->clickLink($this->t('Continue'));
38 $this->clickLink($this->t('Apply pending updates'));
42 * Conditionally load Update API functions for the specified group.
44 * @param string $module
45 * The name of the module defining the update functions.
46 * @param string $group
47 * A name identifying the group of update functions to enable.
49 public static function includeUpdates($module, $group) {
50 if ($index = \Drupal::state()->get($module . '.db_updates.' . $group)) {
51 module_load_include('inc', $module, 'update/' . $group . '_' . $index);