Unit tests for Settings getValue/setValue
- fixed typo in Shortcodes - changed for -> foreach
This commit is contained in:
@@ -51,7 +51,7 @@ class Shortcodes {
|
||||
if(!empty($params['segments'])) {
|
||||
$segment_ids = array_map(function($segment_id) {
|
||||
return (int)trim($segment_id);
|
||||
},explode(',', $params['segments']));
|
||||
}, explode(',', $params['segments']));
|
||||
}
|
||||
|
||||
if(empty($segment_ids)) {
|
||||
@@ -68,7 +68,7 @@ class Shortcodes {
|
||||
if(!empty($params['segments'])) {
|
||||
$segment_ids = array_map(function($segment_id) {
|
||||
return (int)trim($segment_id);
|
||||
},explode(',', $params['segments']));
|
||||
}, explode(',', $params['segments']));
|
||||
}
|
||||
|
||||
$newsletters = array();
|
||||
|
@@ -51,7 +51,6 @@ class Setting extends Model {
|
||||
$keys = explode('.', $key);
|
||||
|
||||
if(count($keys) === 1) {
|
||||
|
||||
if(is_array($value)) {
|
||||
$value = serialize($value);
|
||||
}
|
||||
@@ -67,17 +66,15 @@ class Setting extends Model {
|
||||
$current_value = &$setting_value;
|
||||
$last_key = array_pop($keys);
|
||||
|
||||
for($i = 0, $count = count($keys); $i < $count; $i++) {
|
||||
if($i < $count) {
|
||||
foreach($keys as $key) {
|
||||
if(!is_array($current_value)) {
|
||||
$current_value = array();
|
||||
}
|
||||
|
||||
if(!array_key_exists($keys[$i], $current_value)) {
|
||||
$current_value = array($keys[$i] => array());
|
||||
}
|
||||
$current_value =& $current_value[$keys[$i]];
|
||||
if(!array_key_exists($key, $current_value)) {
|
||||
$current_value = array($key => array());
|
||||
}
|
||||
$current_value =& $current_value[$key];
|
||||
}
|
||||
if(is_scalar($current_value)) {
|
||||
$current_value = array();
|
||||
|
@@ -79,6 +79,31 @@ class SettingCest {
|
||||
expect($record->value)->equals('new data');
|
||||
}
|
||||
|
||||
function itCanGetAndSetValue() {
|
||||
expect(Setting::setValue('test', '123'))->true();
|
||||
expect(Setting::getValue('test'))->equals('123');
|
||||
}
|
||||
|
||||
function itCanGetAndSetNestedValue() {
|
||||
expect(Setting::setValue('test.key', '123'))->true();
|
||||
expect(Setting::getValue('test.key'))->equals('123');
|
||||
|
||||
expect(Setting::setValue('test.key.subkey', '123'))->true();
|
||||
expect(Setting::setValue('test.key.subkey2', '456'))->true();
|
||||
|
||||
expect(Setting::getValue('test.key'))->notEmpty();
|
||||
expect(Setting::getValue('test.key.subkey'))->equals('123');
|
||||
expect(Setting::getValue('test.key.subkey2'))->equals('456');
|
||||
}
|
||||
|
||||
function itCanSetValueToNull() {
|
||||
expect(Setting::setValue('test.key', true))->true();
|
||||
expect(Setting::getValue('test.key'))->equals(true);
|
||||
|
||||
expect(Setting::setValue('test.key', null))->true();
|
||||
expect(Setting::getValue('test.key'))->null();
|
||||
}
|
||||
|
||||
function _after() {
|
||||
ORM::forTable(Setting::$_table)
|
||||
->deleteMany();
|
||||
|
Reference in New Issue
Block a user