2009-09-06 22:15:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once('PHPUnit/Framework.php');
|
|
|
|
require_once(dirname(__FILE__) . '/../classes/WDTSLanguageOptions.php');
|
|
|
|
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
|
|
|
|
|
|
|
|
class WDTSLanguageOptionsTest extends PHPUnit_Framework_TestCase {
|
|
|
|
function setUp() {
|
|
|
|
$this->l = new WDTSLanguageOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetDefaultLanguage() {
|
|
|
|
update_option($this->l->key, array(
|
|
|
|
'languages' => array(
|
|
|
|
'en' => array('default' => false),
|
|
|
|
'de' => array('default' => true)
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertEquals('de', $this->l->get_default_language());
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetLanguageName() {
|
|
|
|
update_option($this->l->key, array(
|
|
|
|
'languages' => array(
|
|
|
|
'en' => array('name' => 'English')
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertEquals('English', $this->l->get_language_name('en'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetLanguages() {
|
|
|
|
update_option($this->l->key, array(
|
|
|
|
'languages' => array(
|
|
|
|
'en' => array('name' => 'English'),
|
|
|
|
'de' => array('name' => 'German')
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertEquals(array(
|
|
|
|
'en' => array('name' => 'English'),
|
|
|
|
'de' => array('name' => 'German')
|
|
|
|
),
|
|
|
|
$this->l->get_languages()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-09-06 22:28:43 +00:00
|
|
|
function providerTestDeleteLanguage() {
|
|
|
|
return array(
|
2009-09-09 12:20:07 +00:00
|
|
|
array('de', array('name' => 'German')),
|
2009-09-06 22:28:43 +00:00
|
|
|
array('fr', false)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestDeleteLanguage
|
|
|
|
*/
|
|
|
|
function testDeleteLanguage($code, $expected_result) {
|
|
|
|
$check = array(
|
|
|
|
'en' => array('name' => 'English'),
|
|
|
|
'de' => array('name' => 'German')
|
|
|
|
);
|
|
|
|
|
2009-09-06 22:15:37 +00:00
|
|
|
update_option($this->l->key, array(
|
2009-09-06 22:28:43 +00:00
|
|
|
'languages' => $check
|
2009-09-06 22:15:37 +00:00
|
|
|
));
|
|
|
|
|
2009-09-06 22:28:43 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
$expected_result,
|
|
|
|
$this->l->delete_language($code)
|
|
|
|
);
|
|
|
|
|
2009-09-09 12:20:07 +00:00
|
|
|
if ($expected_result) { unset($check[$code]); }
|
2009-09-06 22:15:37 +00:00
|
|
|
|
2009-09-09 12:20:07 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
array('languages' => $check),
|
2009-09-06 22:15:37 +00:00
|
|
|
get_option($this->l->key)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-09-06 22:28:43 +00:00
|
|
|
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) {
|
2009-09-06 22:15:37 +00:00
|
|
|
update_option($this->l->key, array(
|
|
|
|
'languages' => array(
|
|
|
|
'en' => array('name' => 'English')
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
2009-09-06 22:28:43 +00:00
|
|
|
$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);
|
|
|
|
}
|
2009-09-06 22:15:37 +00:00
|
|
|
|
|
|
|
$this->assertEquals(array(
|
2009-09-06 22:28:43 +00:00
|
|
|
'languages' => $check
|
2009-09-06 22:15:37 +00:00
|
|
|
),
|
|
|
|
get_option($this->l->key)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function providerTestRenameLanguage() {
|
|
|
|
return array(
|
|
|
|
array('en', 'Anglais', true),
|
|
|
|
array('de', 'Anglais', false),
|
|
|
|
array('en', '', false),
|
|
|
|
array('', 'Anglais', false),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestRenameLanguage
|
|
|
|
*/
|
|
|
|
function testRenameLanguage($code_to_rename, $new_name, $expected_result) {
|
|
|
|
update_option($this->l->key, array(
|
|
|
|
'languages' => array(
|
|
|
|
'en' => array('name' => 'English')
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$expected_result,
|
2009-09-06 22:28:43 +00:00
|
|
|
$this->l->rename_language($code_to_rename, $new_name)
|
2009-09-06 22:15:37 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$check = array(
|
|
|
|
'en' => array('name' => 'English')
|
|
|
|
);
|
|
|
|
if ($expected_result) {
|
|
|
|
$check['en']['name'] = $new_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals(array(
|
|
|
|
'languages' => $check
|
|
|
|
),
|
|
|
|
get_option($this->l->key)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|