2 require_once 'include/utils/array_utils.php';
4 class SugarArrayTest extends Sugar_PHPUnit_Framework_TestCase
6 public function testCanFindValueUsingDotNotation()
8 $random = rand(100, 200);
17 $array = new SugarArray($array);
18 $this->assertEquals($array->get("foo.{$random}.bar"), $random);
21 public function testReturnsDefaultValueWhenDoesNotContainRequestedValue()
23 $random = rand(100, 200);
24 $array = new SugarArray(array());
25 $this->assertEquals($array->get('unknown', $random), $random);
28 public function testImplementsArrayAccess()
30 $reflection = new ReflectionClass('SugarArray');
31 $this->assertTrue($reflection->implementsInterface('ArrayAccess'));
34 public function testImplementsCountable()
36 $reflection = new ReflectionClass('SugarArray');
37 $this->assertTrue($reflection->implementsInterface('Countable'));
40 public function testStaticMethodCanTraverseProvidedArray()
42 $random = rand(100, 200);
51 $this->assertEquals(SugarArray::staticGet($array, "foo.{$random}.bar"), $random);
54 public function testStaticMethodCanReturnDefaultOnUnknownValue()
56 $random = rand(100, 200);
57 $this->assertEquals(SugarArray::staticGet(array(123, 321), 'unknown', $random), $random);
60 public function testAdd_blank_option()
62 $options = 'noneArray';
63 $expectedArray = array(''=>'');
64 $result = add_blank_option($options);
65 $this->assertEquals($result[''], $expectedArray['']);
66 $options2 = array('mason'=>'unittest');
67 $expectedArray2 = array(''=>'','mason'=>'unittest');
68 $result2 = add_blank_option($options2);
69 $this->assertEquals($result2, $expectedArray2);