Merge pull request #16491 from mfb/undefined-index
[civicrm-core.git] / tests / phpunit / CRM / Utils / GlobalStackTest.php
1 <?php
2
3 /**
4 * Class CRM_Utils_GlobalStackTest
5 * @group headless
6 */
7 class CRM_Utils_GlobalStackTest extends CiviUnitTestCase {
8
9 /**
10 * Temporarily override global variables and ensure that the variable data.
11 * is set as expected (before/during/after the override).
12 */
13 public function testPushPop() {
14 global $_FOO, $_EXTRA;
15
16 $_FOO['bar'] = 1;
17 $_FOO['whiz'] = 1;
18 $_EXTRA = 1;
19
20 $this->assertEquals(1, $_FOO['bar']);
21 $this->assertEquals(1, $_FOO['whiz']);
22 $this->assertFalse(isset($_FOO['bang']));
23 $this->assertEquals(1, $_EXTRA);
24
25 CRM_Utils_GlobalStack::singleton()->push([
26 '_FOO' => [
27 'bar' => 2,
28 'bang' => 2,
29 ],
30 '_EXTRA' => 2,
31 ]);
32
33 $this->assertEquals(2, $_FOO['bar']);
34 $this->assertEquals(1, $_FOO['whiz']);
35 $this->assertEquals(2, $_FOO['bang']);
36 $this->assertEquals(2, $_EXTRA);
37
38 CRM_Utils_GlobalStack::singleton()->pop();
39
40 $this->assertEquals(1, $_FOO['bar']);
41 $this->assertEquals(1, $_FOO['whiz']);
42 $this->assertEquals(NULL, $_FOO['bang']);
43 $this->assertEquals(1, $_EXTRA);
44 }
45
46 }