2 require_once 'include/SugarObjects/SugarRegistry.php';
4 class SugarRegistryTest extends Sugar_PHPUnit_Framework_TestCase
6 private $_old_reporting = null;
7 private $_old_globals = null;
9 public function setUp()
11 $this->_old_reporting = error_reporting(E_ALL);
12 $this->_old_globals = $GLOBALS;
16 public function tearDown()
18 error_reporting($this->_old_reporting);
19 $GLOBALS = $this->_old_globals;
20 unset($this->_old_globals);
23 public function testGetInstanceReturnsAnInstanceOfSugarRegistry()
25 $this->assertTrue(SugarRegistry::getInstance() instanceOf SugarRegistry,'Returned object is not a SugarRegistry instance');
28 public function testGetInstanceReturnsSameObject()
30 $one = SugarRegistry::getInstance();
31 $two = SugarRegistry::getInstance();
32 $this->assertSame($one, $two);
35 public function testParameterPassedToGetInstanceSpecifiesInstanceName()
37 $foo1 = SugarRegistry::getInstance('foo');
38 $foo2 = SugarRegistry::getInstance('foo');
39 $this->assertSame($foo1, $foo2);
41 $bar = SugarRegistry::getInstance('bar');
42 $this->assertNotSame($foo1, $bar);
45 public function testCanSetAndGetValues()
47 $random = rand(100, 200);
48 $r = SugarRegistry::getInstance();
49 $r->integer = $random;
50 $this->assertEquals($random, $r->integer);
51 $this->assertEquals($random, SugarRegistry::getInstance()->integer);
54 public function testIssetReturnsTrueFalse()
56 $r = SugarRegistry::getInstance();
57 $this->assertFalse(isset($r->foo));
58 $this->assertFalse(isset(SugarRegistry::getInstance()->foo));
61 $this->assertTrue(isset($r->foo));
62 $this->assertTrue(isset(SugarRegistry::getInstance()->foo));
65 public function testUnsetRemovesValueFromRegistry()
67 $r = SugarRegistry::getInstance();
70 $this->assertFalse(isset($r->foo));
71 $this->assertFalse(isset(SugarRegistry::getInstance()->foo));
74 public function testReturnsNullOnAnyUnknownValue()
76 $r = SugarRegistry::getInstance();
77 $this->assertNull($r->unknown);
78 $this->assertNull(SugarRegistry::getInstance()->unknown);
81 public function testAddToGlobalsPutsRefsToAllRegistryObjectsInGlobalSpace()
83 $r = SugarRegistry::getInstance();
86 $this->assertFalse(isset($GLOBALS['foo']), 'sanity check');
88 $this->assertTrue(isset($GLOBALS['foo']));