0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-23 00:41:52 +00:00
htmlpurifier/tests/HTMLPurifier/LanguageTest.php
Edward Z. Yang 6a95d91a1a [2.0.1] Revamp error collector scheme: we now have custom mocks and an exchange of responsibilities
- Fix oversight in AutoParagraph dealing with armor.
- Order errors with no line number last
- Language object now needs $config and $context objects to do parameterized objects
- Auto-close notice added
- Token constructors accept line numbers

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1245 48356398-32a2-884e-a903-53898d9a118a
2007-06-26 19:33:37 +00:00

48 lines
2.1 KiB
PHP

<?php
require_once 'HTMLPurifier/Language.php';
class HTMLPurifier_LanguageTest extends UnitTestCase
{
var $lang;
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]');
}
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');
}
function test_formatMessage_complexParameter() {
$config = HTMLPurifier_Config::createDefault();
$context = new HTMLPurifier_Context();
$generator = new HTMLPurifier_Generator(); // 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');
}
}
?>