Mercurial > hg > isophonics-drupal-site
annotate core/lib/Drupal/Core/Test/RefreshVariablesTrait.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 129ea1e6d783 |
children |
rev | line source |
---|---|
Chris@17 | 1 <?php |
Chris@17 | 2 |
Chris@17 | 3 namespace Drupal\Core\Test; |
Chris@17 | 4 |
Chris@17 | 5 use Drupal\Core\Cache\Cache; |
Chris@17 | 6 |
Chris@17 | 7 /** |
Chris@17 | 8 * Provides a method to refresh in-memory configuration and state information. |
Chris@17 | 9 */ |
Chris@17 | 10 trait RefreshVariablesTrait { |
Chris@17 | 11 |
Chris@17 | 12 /** |
Chris@17 | 13 * Refreshes in-memory configuration and state information. |
Chris@17 | 14 * |
Chris@17 | 15 * Useful after a page request is made that changes configuration or state in |
Chris@17 | 16 * a different thread. |
Chris@17 | 17 * |
Chris@17 | 18 * In other words calling a settings page with $this->drupalPostForm() with a |
Chris@17 | 19 * changed value would update configuration to reflect that change, but in the |
Chris@17 | 20 * thread that made the call (thread running the test) the changed values |
Chris@17 | 21 * would not be picked up. |
Chris@17 | 22 * |
Chris@17 | 23 * This method clears the cache and loads a fresh copy. |
Chris@17 | 24 */ |
Chris@17 | 25 protected function refreshVariables() { |
Chris@17 | 26 // Clear the tag cache. |
Chris@17 | 27 \Drupal::service('cache_tags.invalidator')->resetChecksums(); |
Chris@17 | 28 foreach (Cache::getBins() as $backend) { |
Chris@17 | 29 if (is_callable([$backend, 'reset'])) { |
Chris@17 | 30 $backend->reset(); |
Chris@17 | 31 } |
Chris@17 | 32 } |
Chris@17 | 33 |
Chris@17 | 34 \Drupal::service('config.factory')->reset(); |
Chris@17 | 35 \Drupal::service('state')->resetCache(); |
Chris@17 | 36 } |
Chris@17 | 37 |
Chris@17 | 38 } |