1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-04 13:18:00 +02:00

[2.1.4] [MFH] Fixed bug with fallback languages in LanguageFactory

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/branches/php4@1724 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2008-05-15 23:20:21 +00:00
parent a2aca4819d
commit f26eb7551a
5 changed files with 77 additions and 35 deletions

View File

@@ -5,13 +5,20 @@ require_once 'HTMLPurifier/LanguageFactory.php';
class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness
{
/**
* Protected reference of global factory we're testing.
*/
var $factory;
function setUp() {
$this->factory = HTMLPurifier_LanguageFactory::instance();
parent::setUp();
}
function test() {
$factory = HTMLPurifier_LanguageFactory::instance();
$config = HTMLPurifier_Config::create(array('Core.Language' => 'en'));
$context = new HTMLPurifier_Context();
$language = $factory->create($config, $context);
$this->config->set('Core', 'Language', 'en');
$language = $this->factory->create($this->config, $this->context);
$this->assertIsA($language, 'HTMLPurifier_Language');
$this->assertIdentical($language->code, 'en');
@@ -21,18 +28,12 @@ class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness
$language->load();
$this->assertNotEqual(count($language->messages), 0);
// actual tests for content can be found in LanguageTest
}
function testFallback() {
$factory = HTMLPurifier_LanguageFactory::instance();
$config = HTMLPurifier_Config::create(array('Core.Language' => 'en-x-test'));
$context = new HTMLPurifier_Context();
$language = $factory->create($config, $context);
$this->config->set('Core', 'Language', 'en-x-test');
$language = $this->factory->create($this->config, $this->context);
$this->assertIsA($language, 'HTMLPurifier_Language_en_x_test');
$this->assertIdentical($language->code, 'en-x-test');
@@ -47,5 +48,24 @@ class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness
}
function testFallbackWithNoClass() {
$this->config->set('Core', 'Language', 'en-x-testmini');
$language = $this->factory->create($this->config, $this->context);
$this->assertIsA($language, 'HTMLPurifier_Language');
$this->assertIdentical($language->code, 'en-x-testmini');
$language->load();
$this->assertIdentical($language->getMessage('HTMLPurifier'), 'HTML Purifier XNone');
$this->assertIdentical($language->getMessage('LanguageFactoryTest: Pizza'), 'Pizza');
$this->assertIdentical($language->error, false);
}
function testNoSuchLanguage() {
$this->config->set('Core', 'Language', 'en-x-testnone');
$language = $this->factory->create($this->config, $this->context);
$this->assertIsA($language, 'HTMLPurifier_Language');
$this->assertIdentical($language->code, 'en-x-testnone');
$this->assertIdentical($language->error, true);
}
}