Version 1
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Bootstrap / ResettableStaticTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Bootstrap;
4
5 use Drupal\KernelTests\KernelTestBase;
6
7 /**
8  * Tests that drupal_static() and drupal_static_reset() work.
9  *
10  * @group Bootstrap
11  */
12 class ResettableStaticTest extends KernelTestBase {
13
14   /**
15    * Tests drupal_static() function.
16    *
17    * Tests that a variable reference returned by drupal_static() gets reset when
18    * drupal_static_reset() is called.
19    */
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.');
24
25     // Call the specific reset and the global reset each twice to ensure that
26     // multiple resets can be issued without odd side effects.
27     $var = 'bar';
28     drupal_static_reset($name);
29     $this->assertEqual($var, 'foo', 'Variable was reset after first invocation of name-specific reset.');
30     $var = 'bar';
31     drupal_static_reset($name);
32     $this->assertEqual($var, 'foo', 'Variable was reset after second invocation of name-specific reset.');
33     $var = 'bar';
34     drupal_static_reset();
35     $this->assertEqual($var, 'foo', 'Variable was reset after first invocation of global reset.');
36     $var = 'bar';
37     drupal_static_reset();
38     $this->assertEqual($var, 'foo', 'Variable was reset after second invocation of global reset.');
39   }
40
41 }