public function testDefaults() { // from js $options = array('zero' => 0, 'one' => 1, 'empty' => '', 'nan' => acos(8), 'string' => 'string'); $options = __u::defaults($options, array('zero' => 1, 'one' => 10, 'twenty' => 20)); $this->assertEquals(0, $options['zero'], 'value exists'); $this->assertEquals(1, $options['one'], 'value exists'); $this->assertEquals(20, $options['twenty'], 'default applied'); $options_obj = (object) array('zero' => 0, 'one' => 1, 'empty' => '', 'nan' => acos(8), 'string' => 'string'); $options_obj = __u::defaults($options_obj, (object) array('zero' => 1, 'one' => 10, 'twenty' => 20)); $this->assertEquals(0, $options_obj->zero, 'value exists'); $this->assertEquals(1, $options_obj->one, 'value exists'); $this->assertEquals(20, $options_obj->twenty, 'default applied'); $options = __u::defaults($options, array('empty' => 'full'), array('nan' => 'nan'), array('word' => 'word'), array('word' => 'dog')); $this->assertEquals('', $options['empty'], 'value exists'); $this->assertTrue(__u::isNaN($options['nan']), 'NaN is not overridden'); $this->assertEquals('word', $options['word'], 'new value is added, first one wins'); $options_obj = __u::defaults($options_obj, (object) array('empty' => 'full'), (object) array('nan' => 'nan'), (object) array('word' => 'word'), (object) array('word' => 'dog')); $this->assertEquals('', $options_obj->empty, 'value exists'); $this->assertTrue(__u::isNaN($options_obj->nan), 'NaN is not overridden'); $this->assertEquals('word', $options_obj->word, 'new value is added, first one wins'); // extra $options = array('zero' => 0, 'one' => 1, 'empty' => '', 'nan' => acos(8), 'string' => 'string'); $options = __u($options)->defaults(array('zero' => 1, 'one' => 10, 'twenty' => 20)); $this->assertEquals(0, $options['zero'], 'value exists'); $this->assertEquals(1, $options['one'], 'value exists'); $this->assertEquals(20, $options['twenty'], 'default applied'); // docs $food = (object) array('dairy' => 'cheese'); $defaults = (object) array('meat' => 'bacon'); $expected = (object) array('dairy' => 'cheese', 'meat' => 'bacon'); $this->assertEquals($expected, __u::defaults($food, $defaults)); }