ResettableStaticTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Drupal\KernelTests\Core\Bootstrap;
  3. use Drupal\KernelTests\KernelTestBase;
  4. /**
  5. * Tests that drupal_static() and drupal_static_reset() work.
  6. *
  7. * @group Bootstrap
  8. */
  9. class ResettableStaticTest extends KernelTestBase {
  10. /**
  11. * Tests drupal_static() function.
  12. *
  13. * Tests that a variable reference returned by drupal_static() gets reset when
  14. * drupal_static_reset() is called.
  15. */
  16. public function testDrupalStatic() {
  17. $name = __CLASS__ . '_' . __METHOD__;
  18. $var = &drupal_static($name, 'foo');
  19. $this->assertEqual($var, 'foo', 'Variable returned by drupal_static() was set to its default.');
  20. // Call the specific reset and the global reset each twice to ensure that
  21. // multiple resets can be issued without odd side effects.
  22. $var = 'bar';
  23. drupal_static_reset($name);
  24. $this->assertEqual($var, 'foo', 'Variable was reset after first invocation of name-specific reset.');
  25. $var = 'bar';
  26. drupal_static_reset($name);
  27. $this->assertEqual($var, 'foo', 'Variable was reset after second invocation of name-specific reset.');
  28. $var = 'bar';
  29. drupal_static_reset();
  30. $this->assertEqual($var, 'foo', 'Variable was reset after first invocation of global reset.');
  31. $var = 'bar';
  32. drupal_static_reset();
  33. $this->assertEqual($var, 'foo', 'Variable was reset after second invocation of global reset.');
  34. }
  35. }