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