Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / src / Functional / Update / DbUpdatesTrait.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Update;
4
5 use Drupal\Core\StringTranslation\StringTranslationTrait;
6 use Drupal\Core\Url;
7
8 /**
9  * Provides methods to conditionally enable db update functions and apply
10  * pending db updates through the Update UI.
11  *
12  * This should be used only by classes extending \Drupal\Tests\BrowserTestBase.
13  */
14 trait DbUpdatesTrait {
15
16   use StringTranslationTrait;
17
18   /**
19    * Enables db updates until the specified index.
20    *
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.
25    * @param $index
26    *   The index of the last update function to run.
27    */
28   protected function enableUpdates($module, $group, $index) {
29     $this->container->get('state')->set($module . '.db_updates.' . $group, $index);
30   }
31
32   /**
33    * Applies any pending DB updates through the Update UI.
34    */
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();
40   }
41
42   /**
43    * Conditionally load Update API functions for the specified group.
44    *
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.
49    */
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);
53     }
54   }
55
56 }