what-did-they-say/test/WDTSLanguageOptionsTest.php

185 lines
4.3 KiB
PHP
Raw Permalink Normal View History

2009-09-06 22:15:37 +00:00
<?php
require_once('PHPUnit/Framework.php');
2009-09-25 03:26:04 +00:00
require_once(dirname(__FILE__) . '/../classes/WDTSLanguageOptions.inc');
require_once('MockPress/mockpress.php');
2009-09-06 22:15:37 +00:00
class WDTSLanguageOptionsTest extends PHPUnit_Framework_TestCase {
function setUp() {
2009-09-11 01:00:10 +00:00
_reset_wp();
2009-09-06 22:15:37 +00:00
$this->l = new WDTSLanguageOptions();
}
function testGetDefaultLanguage() {
update_option($this->l->key, array(
'languages' => array(
2009-09-11 01:00:10 +00:00
'en' => array(),
2009-09-06 22:15:37 +00:00
'de' => array('default' => true)
)
));
$this->assertEquals('de', $this->l->get_default_language());
}
2009-09-11 01:00:10 +00:00
function providerTestSetDefaultLanguage() {
return array(
array('en', true, array('en' => array('default' => true), 'de' => array())),
array('de', false, array('en' => array(), 'de' => array('default' => true))),
array('fr', false, array('en' => array(), 'de' => array('default' => true))),
);
}
/**
* @dataProvider providerTestSetDefaultLanguage
*/
function testSetDefaultLanguage($set_default, $expected_result, $expected_language_info) {
update_option($this->l->key, array(
'languages' => array(
'en' => array(),
'de' => array('default' => true)
)
));
$this->assertEquals($expected_result, $this->l->set_default_language($set_default));
$this->assertEquals($expected_language_info, $this->l->get_languages());
}
2009-09-06 22:15:37 +00:00
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)
);
}
}
?>