3 namespace Drupal\KernelTests\Core\Bootstrap;
5 use Drupal\KernelTests\KernelTestBase;
8 * Tests that drupal_static() and drupal_static_reset() work.
12 class ResettableStaticTest extends KernelTestBase {
15 * Tests drupal_static() function.
17 * Tests that a variable reference returned by drupal_static() gets reset when
18 * drupal_static_reset() is called.
20 public function testDrupalStatic() {
21 $name = __CLASS__ . '_' . __METHOD__;
22 $var = &drupal_static($name, 'foo');
23 $this->assertEqual($var, 'foo', 'Variable returned by drupal_static() was set to its default.');
25 // Call the specific reset and the global reset each twice to ensure that
26 // multiple resets can be issued without odd side effects.
28 drupal_static_reset($name);
29 $this->assertEqual($var, 'foo', 'Variable was reset after first invocation of name-specific reset.');
31 drupal_static_reset($name);
32 $this->assertEqual($var, 'foo', 'Variable was reset after second invocation of name-specific reset.');
34 drupal_static_reset();
35 $this->assertEqual($var, 'foo', 'Variable was reset after first invocation of global reset.');
37 drupal_static_reset();
38 $this->assertEqual($var, 'foo', 'Variable was reset after second invocation of global reset.');