Fix standards-compliance issue with YouTube filter with double hyphens.
[htmlpurifier/bfroehle.git] / tests / HTMLPurifier / HTMLModuleManagerTest.php
blob32ddab5e1738bd146f3df38807ade6d167b51490
1 <?php
3 class HTMLPurifier_HTMLModuleManagerTest extends HTMLPurifier_Harness
6 protected function createManager() {
7 $manager = new HTMLPurifier_HTMLModuleManager();
9 $this->config->set('HTML', 'CustomDoctype', 'Blank');
10 $manager->doctypes->register('Blank');
12 $attrdef_nmtokens = new HTMLPurifier_AttrDef_HTML_Nmtokens();
14 generate_mock_once('HTMLPurifier_AttrDef');
15 $attrdef = new HTMLPurifier_AttrDefMock();
16 $attrdef->setReturnValue('make', $attrdef_nmtokens);
17 $manager->attrTypes->set('NMTOKENS', $attrdef);
18 return $manager;
21 function test_addModule() {
23 $manager = $this->createManager();
25 // ...but we add user modules
27 $common_module = new HTMLPurifier_HTMLModule();
28 $common_module->name = 'Common';
29 $common_module->attr_collections['Common'] = array('class' => 'NMTOKENS');
30 $common_module->content_sets['Flow'] = 'Block | Inline';
31 $manager->addModule($common_module);
33 $structural_module = new HTMLPurifier_HTMLModule();
34 $structural_module->name = 'Structural';
35 $structural_module->addElement('p', 'Block', 'Inline', 'Common');
36 $manager->addModule($structural_module);
38 $formatting_module = new HTMLPurifier_HTMLModule();
39 $formatting_module->name = 'Formatting';
40 $formatting_module->addElement('em', 'Inline', 'Inline', 'Common');
41 $manager->addModule($formatting_module);
43 $unsafe_module = new HTMLPurifier_HTMLModule();
44 $unsafe_module->name = 'Unsafe';
45 $unsafe_module->safe = false;
46 $unsafe_module->addElement('div', 'Block', 'Flow');
47 $manager->addModule($unsafe_module);
49 $config = HTMLPurifier_Config::createDefault();
50 $config->set('HTML', 'Trusted', false);
51 $config->set('HTML', 'CustomDoctype', 'Blank');
53 $manager->setup($config);
55 $attrdef_nmtokens = new HTMLPurifier_AttrDef_HTML_Nmtokens();
57 $p = new HTMLPurifier_ElementDef();
58 $p->attr['class'] = $attrdef_nmtokens;
59 $p->child = new HTMLPurifier_ChildDef_Optional(array('em', '#PCDATA'));
60 $p->content_model = 'em | #PCDATA';
61 $p->content_model_type = 'optional';
62 $p->descendants_are_inline = true;
64 $em = new HTMLPurifier_ElementDef();
65 $em->attr['class'] = $attrdef_nmtokens;
66 $em->child = new HTMLPurifier_ChildDef_Optional(array('em', '#PCDATA'));
67 $em->content_model = 'em | #PCDATA';
68 $em->content_model_type = 'optional';
69 $em->descendants_are_inline = true;
71 $this->assertEqual(
72 array('p' => $p, 'em' => $em),
73 $manager->getElements()
76 // test trusted parameter override
78 $div = new HTMLPurifier_ElementDef();
79 $div->child = new HTMLPurifier_ChildDef_Optional(array('p', 'div', 'em', '#PCDATA'));
80 $div->content_model = 'p | div | em | #PCDATA';
81 $div->content_model_type = 'optional';
82 $div->descendants_are_inline = false;
84 $this->assertEqual($div, $manager->getElement('div', true));
88 function testAllowedModules() {
90 $manager = new HTMLPurifier_HTMLModuleManager();
91 $manager->doctypes->register(
92 'Fantasy Inventory 1.0', true,
93 array('Weapons', 'Magic')
96 // register these modules so it doesn't blow up
97 $weapons_module = new HTMLPurifier_HTMLModule();
98 $weapons_module->name = 'Weapons';
99 $manager->registerModule($weapons_module);
101 $magic_module = new HTMLPurifier_HTMLModule();
102 $magic_module->name = 'Magic';
103 $manager->registerModule($magic_module);
105 $config = HTMLPurifier_Config::create(array(
106 'HTML.CustomDoctype' => 'Fantasy Inventory 1.0',
107 'HTML.AllowedModules' => 'Weapons'
109 $manager->setup($config);
111 $this->assertTrue( isset($manager->modules['Weapons']));
112 $this->assertFalse(isset($manager->modules['Magic']));
120 // vim: et sw=4 sts=4