Files
admin
doz
html2pdf_v4.03
htmlpurifier-4.10.0
art
benchmarks
configdoc
docs
extras
library
maintenance
plugins
smoketests
tests
FSTools
HTMLPurifier
AttrDef
AttrTransform
ChildDef
ConfigSchema
DefinitionCache
Filter
HTMLModule
HTMLT
Injector
Lexer
PHPT
SimpleTest
Strategy
StringHashParser
URIFilter
VarParser
AttrCollectionsTest.php
AttrDefHarness.php
AttrDefTest.php
AttrTransformHarness.php
AttrTransformTest.php
AttrTypesTest.php
AttrValidator_ErrorsTest.php
ChildDefHarness.php
ComplexHarness.php
ConfigSchemaTest.php
ConfigTest-create.ini
ConfigTest-finalize.ini
ConfigTest-loadIni.ini
ConfigTest.php
ContextTest.php
DefinitionCacheFactoryTest.php
DefinitionCacheHarness.php
DefinitionCacheTest.php
DefinitionTest.php
DefinitionTestable.php
DoctypeRegistryTest.php
ElementDefTest.php
EncoderTest.php
EntityLookupTest.php
EntityParserTest.php
ErrorCollectorEMock.php
ErrorCollectorTest.php
ErrorsHarness.php
GeneratorTest.php
HTMLDefinitionTest.php
HTMLModuleHarness.php
HTMLModuleManagerTest.php
HTMLModuleTest.php
HTMLT.php
Harness.php
IDAccumulatorTest.php
InjectorHarness.php
LanguageFactoryTest.php
LanguageTest.php
LengthTest.php
LexerTest.php
PercentEncoderTest.php
PropertyListTest.php
StrategyHarness.php
StringHashParserTest.php
StringHashTest.php
TagTransformTest.php
TokenFactoryTest.php
TokenTest.php
URIDefinitionTest.php
URIFilterHarness.php
URIHarness.php
URIParserTest.php
URISchemeRegistryTest.php
URISchemeTest.php
URITest.php
UnitConverterTest.php
VarParserHarness.php
ZipperTest.php
PHPT
tmp
CliTestCase.php
Debugger.php
HTMLPurifierTest.php
common.php
default_load.php
generate_mock_once.func.php
index.php
multitest.php
path2class.func.php
test_files.php
.gitattributes
.gitignore
.travis.yml
CREDITS
Doxyfile
INSTALL
INSTALL.fr.utf8
LICENSE
NEWS
README.md
TODO
VERSION
WHATSNEW
WYSIWYG
composer.json
phpdoc.ini
images
prints
prints3
stud
Kennwortwechsel.php
hauptframe.php
htmlpurifier-4.10.0.zip
index.php
index_alt.php
index_db.php
index_frame.htm
index_ldap.php
login.php
logout.php
menuframe.htm
styles_pc.css
testpdf.php
topframe.php

86 lines
3.5 KiB
PHP
Executable File

<?php
/**
* @todo Fix usage of HTMLPurifier_Language->_loaded using something else
*/
class HTMLPurifier_LanguageTest extends HTMLPurifier_Harness
{
protected $lang;
protected function generateEnLanguage()
{
$factory = HTMLPurifier_LanguageFactory::instance();
$config = HTMLPurifier_Config::create(array('Core.Language' => 'en'));
$context = new HTMLPurifier_Context();
return $factory->create($config, $context);
}
public function test_getMessage()
{
$config = HTMLPurifier_Config::createDefault();
$context = new HTMLPurifier_Context();
$lang = new HTMLPurifier_Language($config, $context);
$lang->_loaded = true;
$lang->messages['HTMLPurifier'] = 'HTML Purifier';
$this->assertIdentical($lang->getMessage('HTMLPurifier'), 'HTML Purifier');
$this->assertIdentical($lang->getMessage('LanguageTest: Totally non-existent key'), '[LanguageTest: Totally non-existent key]');
}
public function test_formatMessage()
{
$config = HTMLPurifier_Config::createDefault();
$context = new HTMLPurifier_Context();
$lang = new HTMLPurifier_Language($config, $context);
$lang->_loaded = true;
$lang->messages['LanguageTest: Error'] = 'Error is $1 on line $2';
$this->assertIdentical($lang->formatMessage('LanguageTest: Error', array(1=>'fatal', 32)), 'Error is fatal on line 32');
}
public function test_formatMessage_tokenParameter()
{
$config = HTMLPurifier_Config::createDefault();
$context = new HTMLPurifier_Context();
$generator = new HTMLPurifier_Generator($config, $context); // replace with mock if this gets icky
$context->register('Generator', $generator);
$lang = new HTMLPurifier_Language($config, $context);
$lang->_loaded = true;
$lang->messages['LanguageTest: Element info'] = 'Element Token: $1.Name, $1.Serialized, $1.Compact, $1.Line';
$lang->messages['LanguageTest: Data info'] = 'Data Token: $1.Data, $1.Serialized, $1.Compact, $1.Line';
$this->assertIdentical($lang->formatMessage('LanguageTest: Element info',
array(1=>new HTMLPurifier_Token_Start('a', array('href'=>'http://example.com'), 18))),
'Element Token: a, <a href="http://example.com">, <a>, 18');
$this->assertIdentical($lang->formatMessage('LanguageTest: Data info',
array(1=>new HTMLPurifier_Token_Text('data>', 23))),
'Data Token: data>, data&gt;, data&gt;, 23');
}
public function test_listify()
{
$lang = $this->generateEnLanguage();
$this->assertEqual($lang->listify(array('Item')), 'Item');
$this->assertEqual($lang->listify(array('Item', 'Item2')), 'Item and Item2');
$this->assertEqual($lang->listify(array('Item', 'Item2', 'Item3')), 'Item, Item2 and Item3');
}
public function test_formatMessage_arrayParameter()
{
$lang = $this->generateEnLanguage();
$array = array('Item1', 'Item2', 'Item3');
$this->assertIdentical(
$lang->formatMessage('LanguageTest: List', array(1=>$array)),
'Item1, Item2 and Item3'
);
$array = array('Key1' => 'Value1', 'Key2' => 'Value2');
$this->assertIdentical(
$lang->formatMessage('LanguageTest: Hash', array(1=>$array)),
'Key1 and Key2; Value1 and Value2'
);
}
}
// vim: et sw=4 sts=4