language CRUD
This commit is contained in:
parent
354a8238a8
commit
5a8c7fd8f6
@ -45,19 +45,31 @@ class WDTSLanguageOptions {
|
||||
function delete_language($code_to_delete) {
|
||||
$options = get_option($this->key);
|
||||
|
||||
$new_languages = array();
|
||||
foreach ($options['languages'] as $code => $info) {
|
||||
if ($code != $code_to_delete) { $new_languages[$code] = $info; }
|
||||
$did_delete = false;
|
||||
if (isset($options['languages'][$code_to_delete])) {
|
||||
$did_delete = true;
|
||||
unset($options['languages'][$code_to_delete]);
|
||||
}
|
||||
$options['languages'] = $new_languages;
|
||||
|
||||
update_option($this->key, $options);
|
||||
return $did_delete;
|
||||
}
|
||||
|
||||
function add_language($code, $info) {
|
||||
$options = get_option($this->key);
|
||||
|
||||
$result = false;
|
||||
if (!empty($code) && is_array($info)) {
|
||||
if (!isset($options['languages'][$code])) {
|
||||
if (!empty($info['name'])) {
|
||||
$options['languages'][$code] = $info;
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_option($this->key, $options);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function rename_language($code_to_rename, $new_name) {
|
||||
|
@ -46,39 +46,75 @@ class WDTSLanguageOptionsTest extends PHPUnit_Framework_TestCase {
|
||||
);
|
||||
}
|
||||
|
||||
function testDeleteLanguage() {
|
||||
update_option($this->l->key, array(
|
||||
'languages' => array(
|
||||
function providerTestDeleteLanguage() {
|
||||
return array(
|
||||
array('de', true),
|
||||
array('fr', false)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestDeleteLanguage
|
||||
*/
|
||||
function testDeleteLanguage($code, $expected_result) {
|
||||
$check = array(
|
||||
'en' => array('name' => 'English'),
|
||||
'de' => array('name' => 'German')
|
||||
)
|
||||
);
|
||||
|
||||
update_option($this->l->key, array(
|
||||
'languages' => $check
|
||||
));
|
||||
|
||||
$this->l->delete_language('en');
|
||||
$this->assertEquals(
|
||||
$expected_result,
|
||||
$this->l->delete_language($code)
|
||||
);
|
||||
|
||||
if ($expected_result) {
|
||||
unset($check[$code]);
|
||||
}
|
||||
|
||||
$this->assertEquals(array(
|
||||
'languages' => array(
|
||||
'de' => array('name' => 'German')
|
||||
)
|
||||
),
|
||||
'languages' => $check ),
|
||||
get_option($this->l->key)
|
||||
);
|
||||
}
|
||||
|
||||
function testAddLanguage() {
|
||||
function providerTestAddLanguage() {
|
||||
return array(
|
||||
array('de', 'German', true),
|
||||
array('de', '', false),
|
||||
array('', 'German', false),
|
||||
array('en', 'English', false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestAddLanguage
|
||||
*/
|
||||
function testAddLanguage($code, $name, $expected_result) {
|
||||
update_option($this->l->key, array(
|
||||
'languages' => array(
|
||||
'en' => array('name' => 'English')
|
||||
)
|
||||
));
|
||||
|
||||
$this->l->add_language('de', array('name' => 'German'));
|
||||
$this->assertEquals(
|
||||
$expected_result,
|
||||
$this->l->add_language($code, array('name' => $name))
|
||||
);
|
||||
|
||||
$check = array(
|
||||
'en' => array('name' => 'English')
|
||||
);
|
||||
|
||||
if ($expected_result) {
|
||||
$check[$code] = array('name' => $name);
|
||||
}
|
||||
|
||||
$this->assertEquals(array(
|
||||
'languages' => array(
|
||||
'en' => array('name' => 'English'),
|
||||
'de' => array('name' => 'German')
|
||||
)
|
||||
'languages' => $check
|
||||
),
|
||||
get_option($this->l->key)
|
||||
);
|
||||
@ -105,7 +141,7 @@ class WDTSLanguageOptionsTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$this->assertEquals(
|
||||
$expected_result,
|
||||
$result = $this->l->rename_language($code_to_rename, $new_name)
|
||||
$this->l->rename_language($code_to_rename, $new_name)
|
||||
);
|
||||
|
||||
$check = array(
|
||||
|
Loading…
Reference in New Issue
Block a user