3 namespace Drupal\Tests\system\Functional\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\Tests\BrowserTestBase.
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'));
39 $this->checkForMetaRefresh();
43 * Conditionally load Update API functions for the specified group.
45 * @param string $module
46 * The name of the module defining the update functions.
47 * @param string $group
48 * A name identifying the group of update functions to enable.
50 public static function includeUpdates($module, $group) {
51 if ($index = \Drupal::state()->get($module . '.db_updates.' . $group)) {
52 module_load_include('inc', $module, 'update/' . $group . '_' . $index);