Newer
Older
Dries Buytaert
committed
<?php
namespace Drupal\system\Tests\Bootstrap;
use Drupal\simpletest\KernelTestBase;
Dries Buytaert
committed
/**
* Tests that drupal_static() and drupal_static_reset() work.
*
* @group Bootstrap
Dries Buytaert
committed
*/
class ResettableStaticUnitTest extends KernelTestBase {
Dries Buytaert
committed
/**
Jennifer Hodgdon
committed
* Tests drupal_static() function.
*
* Tests that a variable reference returned by drupal_static() gets reset when
Dries Buytaert
committed
* drupal_static_reset() is called.
*/
function testDrupalStatic() {
$name = __CLASS__ . '_' . __METHOD__;
$var = &drupal_static($name, 'foo');
Jennifer Hodgdon
committed
$this->assertEqual($var, 'foo', 'Variable returned by drupal_static() was set to its default.');
Dries Buytaert
committed
// Call the specific reset and the global reset each twice to ensure that
// multiple resets can be issued without odd side effects.
$var = 'bar';
drupal_static_reset($name);
Jennifer Hodgdon
committed
$this->assertEqual($var, 'foo', 'Variable was reset after first invocation of name-specific reset.');
Dries Buytaert
committed
$var = 'bar';
drupal_static_reset($name);
Jennifer Hodgdon
committed
$this->assertEqual($var, 'foo', 'Variable was reset after second invocation of name-specific reset.');
Dries Buytaert
committed
$var = 'bar';
drupal_static_reset();
Jennifer Hodgdon
committed
$this->assertEqual($var, 'foo', 'Variable was reset after first invocation of global reset.');
Dries Buytaert
committed
$var = 'bar';
drupal_static_reset();
Jennifer Hodgdon
committed
$this->assertEqual($var, 'foo', 'Variable was reset after second invocation of global reset.');
Dries Buytaert
committed
}