Prepended constants with C_ to avoid reserved words as per https://www.php.net/manual...
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / HTMLModuleManagerTest.php
blob9175c05975c9a7b60f848734d1c4d5fe63c73113
1 <?php
3 class HTMLPurifier_HTMLModuleManagerTest extends HTMLPurifier_Harness
6 protected function createManager()
8 $manager = new HTMLPurifier_HTMLModuleManager();
10 $this->config->set('HTML.CustomDoctype', 'Blank');
11 $manager->doctypes->register('Blank');
13 $attrdef_nmtokens = new HTMLPurifier_AttrDef_HTML_Nmtokens();
15 generate_mock_once('HTMLPurifier_AttrDef');
16 $attrdef = new HTMLPurifier_AttrDefMock();
17 $attrdef->returns('make', $attrdef_nmtokens);
18 $manager->attrTypes->set('NMTOKENS', $attrdef);
19 return $manager;
22 public function test_addModule()
24 $manager = $this->createManager();
26 // ...but we add user modules
28 $common_module = new HTMLPurifier_HTMLModule();
29 $common_module->name = 'Common';
30 $common_module->attr_collections['Common'] = array('class' => 'NMTOKENS');
31 $common_module->content_sets['Flow'] = 'Block | Inline';
32 $manager->addModule($common_module);
34 $structural_module = new HTMLPurifier_HTMLModule();
35 $structural_module->name = 'Structural';
36 $structural_module->addElement('p', 'Block', 'Inline', 'Common');
37 $manager->addModule($structural_module);
39 $formatting_module = new HTMLPurifier_HTMLModule();
40 $formatting_module->name = 'Formatting';
41 $formatting_module->addElement('em', 'Inline', 'Inline', 'Common');
42 $manager->addModule($formatting_module);
44 $unsafe_module = new HTMLPurifier_HTMLModule();
45 $unsafe_module->name = 'Unsafe';
46 $unsafe_module->safe = false;
47 $unsafe_module->addElement('div', 'Block', 'Flow');
48 $manager->addModule($unsafe_module);
50 $config = HTMLPurifier_Config::createDefault();
51 $config->set('HTML.Trusted', false);
52 $config->set('HTML.CustomDoctype', 'Blank');
54 $manager->setup($config);
56 $attrdef_nmtokens = new HTMLPurifier_AttrDef_HTML_Nmtokens();
58 $p = new HTMLPurifier_ElementDef();
59 $p->attr['class'] = $attrdef_nmtokens;
60 $p->child = new HTMLPurifier_ChildDef_Optional(array('em', '#PCDATA'));
61 $p->content_model = 'em | #PCDATA';
62 $p->content_model_type = 'optional';
63 $p->descendants_are_inline = true;
65 $em = new HTMLPurifier_ElementDef();
66 $em->attr['class'] = $attrdef_nmtokens;
67 $em->child = new HTMLPurifier_ChildDef_Optional(array('em', '#PCDATA'));
68 $em->content_model = 'em | #PCDATA';
69 $em->content_model_type = 'optional';
70 $em->descendants_are_inline = true;
72 $this->assertEqual(
73 array('p' => $p, 'em' => $em),
74 $manager->getElements()
77 // test trusted parameter override
79 $div = new HTMLPurifier_ElementDef();
80 $div->child = new HTMLPurifier_ChildDef_Optional(array('p', 'div', 'em', '#PCDATA'));
81 $div->content_model = 'p | div | em | #PCDATA';
82 $div->content_model_type = 'optional';
83 $div->descendants_are_inline = false;
85 $this->assertEqual($div, $manager->getElement('div', true));
89 public function testAllowedModules()
91 $manager = new HTMLPurifier_HTMLModuleManager();
92 $manager->doctypes->register(
93 'Fantasy Inventory 1.0', true,
94 array('Weapons', 'Magic')
97 // register these modules so it doesn't blow up
98 $weapons_module = new HTMLPurifier_HTMLModule();
99 $weapons_module->name = 'Weapons';
100 $manager->registerModule($weapons_module);
102 $magic_module = new HTMLPurifier_HTMLModule();
103 $magic_module->name = 'Magic';
104 $manager->registerModule($magic_module);
106 $config = HTMLPurifier_Config::create(array(
107 'HTML.CustomDoctype' => 'Fantasy Inventory 1.0',
108 'HTML.AllowedModules' => 'Weapons'
110 $manager->setup($config);
112 $this->assertTrue( isset($manager->modules['Weapons']));
113 $this->assertFalse(isset($manager->modules['Magic']));
121 // vim: et sw=4 sts=4