Fix standards-compliance issue with YouTube filter with double hyphens.
[htmlpurifier/bfroehle.git] / tests / HTMLPurifier / LanguageTest.php
blob033b6aa712755c084711e088124b4ec2c2f72c8a
1 <?php
3 /**
4 * @todo Fix usage of HTMLPurifier_Language->_loaded using something else
5 */
6 class HTMLPurifier_LanguageTest extends HTMLPurifier_Harness
9 protected $lang;
11 protected function generateEnLanguage() {
12 $factory = HTMLPurifier_LanguageFactory::instance();
13 $config = HTMLPurifier_Config::create(array('Core.Language' => 'en'));
14 $context = new HTMLPurifier_Context();
15 return $factory->create($config, $context);
18 function test_getMessage() {
19 $config = HTMLPurifier_Config::createDefault();
20 $context = new HTMLPurifier_Context();
21 $lang = new HTMLPurifier_Language($config, $context);
22 $lang->_loaded = true;
23 $lang->messages['HTMLPurifier'] = 'HTML Purifier';
24 $this->assertIdentical($lang->getMessage('HTMLPurifier'), 'HTML Purifier');
25 $this->assertIdentical($lang->getMessage('LanguageTest: Totally non-existent key'), '[LanguageTest: Totally non-existent key]');
28 function test_formatMessage() {
29 $config = HTMLPurifier_Config::createDefault();
30 $context = new HTMLPurifier_Context();
31 $lang = new HTMLPurifier_Language($config, $context);
32 $lang->_loaded = true;
33 $lang->messages['LanguageTest: Error'] = 'Error is $1 on line $2';
34 $this->assertIdentical($lang->formatMessage('LanguageTest: Error', array(1=>'fatal', 32)), 'Error is fatal on line 32');
37 function test_formatMessage_tokenParameter() {
38 $config = HTMLPurifier_Config::createDefault();
39 $context = new HTMLPurifier_Context();
40 $generator = new HTMLPurifier_Generator($config, $context); // replace with mock if this gets icky
41 $context->register('Generator', $generator);
42 $lang = new HTMLPurifier_Language($config, $context);
43 $lang->_loaded = true;
44 $lang->messages['LanguageTest: Element info'] = 'Element Token: $1.Name, $1.Serialized, $1.Compact, $1.Line';
45 $lang->messages['LanguageTest: Data info'] = 'Data Token: $1.Data, $1.Serialized, $1.Compact, $1.Line';
46 $this->assertIdentical($lang->formatMessage('LanguageTest: Element info',
47 array(1=>new HTMLPurifier_Token_Start('a', array('href'=>'http://example.com'), 18))),
48 'Element Token: a, <a href="http://example.com">, <a>, 18');
49 $this->assertIdentical($lang->formatMessage('LanguageTest: Data info',
50 array(1=>new HTMLPurifier_Token_Text('data>', 23))),
51 'Data Token: data>, data&gt;, data&gt;, 23');
54 function test_listify() {
55 $lang = $this->generateEnLanguage();
56 $this->assertEqual($lang->listify(array('Item')), 'Item');
57 $this->assertEqual($lang->listify(array('Item', 'Item2')), 'Item and Item2');
58 $this->assertEqual($lang->listify(array('Item', 'Item2', 'Item3')), 'Item, Item2 and Item3');
61 function test_formatMessage_arrayParameter() {
62 $lang = $this->generateEnLanguage();
64 $array = array('Item1', 'Item2', 'Item3');
65 $this->assertIdentical(
66 $lang->formatMessage('LanguageTest: List', array(1=>$array)),
67 'Item1, Item2 and Item3'
70 $array = array('Key1' => 'Value1', 'Key2' => 'Value2');
71 $this->assertIdentical(
72 $lang->formatMessage('LanguageTest: Hash', array(1=>$array)),
73 'Key1 and Key2; Value1 and Value2'
79 // vim: et sw=4 sts=4