2007-01-29 20:11:00 +00:00
|
|
|
<?php
|
|
|
|
|
2007-08-01 14:06:59 +00:00
|
|
|
class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness
|
2007-01-29 20:11:00 +00:00
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-05-15 23:04:46 +00:00
|
|
|
/**
|
|
|
|
* Protected reference of global factory we're testing.
|
|
|
|
*/
|
|
|
|
protected $factory;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-05-15 23:04:46 +00:00
|
|
|
public function setUp() {
|
|
|
|
$this->factory = HTMLPurifier_LanguageFactory::instance();
|
|
|
|
parent::setUp();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
function test() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Core.Language', 'en');
|
2008-05-15 23:04:46 +00:00
|
|
|
$language = $this->factory->create($this->config, $this->context);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
$this->assertIsA($language, 'HTMLPurifier_Language');
|
2007-05-05 20:17:04 +00:00
|
|
|
$this->assertIdentical($language->code, 'en');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
// lazy loading test
|
2007-05-05 20:17:04 +00:00
|
|
|
$this->assertIdentical(count($language->messages), 0);
|
2007-01-29 20:11:00 +00:00
|
|
|
$language->load();
|
|
|
|
$this->assertNotEqual(count($language->messages), 0);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
function testFallback() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Core.Language', 'en-x-test');
|
2008-05-15 23:04:46 +00:00
|
|
|
$language = $this->factory->create($this->config, $this->context);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
$this->assertIsA($language, 'HTMLPurifier_Language_en_x_test');
|
2007-05-05 20:17:04 +00:00
|
|
|
$this->assertIdentical($language->code, 'en-x-test');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
$language->load();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
// test overloaded message
|
2007-06-25 01:11:56 +00:00
|
|
|
$this->assertIdentical($language->getMessage('HTMLPurifier'), 'HTML Purifier X');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
// test inherited message
|
2007-06-25 01:11:56 +00:00
|
|
|
$this->assertIdentical($language->getMessage('LanguageFactoryTest: Pizza'), 'Pizza');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-05-15 23:04:46 +00:00
|
|
|
function testFallbackWithNoClass() {
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Core.Language', 'en-x-testmini');
|
2008-05-15 23:04:46 +00:00
|
|
|
$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);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-05-15 23:04:46 +00:00
|
|
|
function testNoSuchLanguage() {
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Core.Language', 'en-x-testnone');
|
2008-05-15 23:04:46 +00:00
|
|
|
$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);
|
2008-05-15 17:47:47 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|