Example #1
0
 public function test_makeLookup()
 {
     $module = new HTMLPurifier_HTMLModule();
     $this->assertIdentical($module->makeLookup('foo'), array('foo' => true));
     $this->assertIdentical($module->makeLookup(array('foo')), array('foo' => true));
     $this->assertIdentical($module->makeLookup('foo', 'two'), array('foo' => true, 'two' => true));
     $this->assertIdentical($module->makeLookup(array('foo', 'two')), array('foo' => true, 'two' => true));
 }
 public function test_addModule()
 {
     $manager = $this->createManager();
     // ...but we add user modules
     $common_module = new HTMLPurifier_HTMLModule();
     $common_module->name = 'Common';
     $common_module->attr_collections['Common'] = array('class' => 'NMTOKENS');
     $common_module->content_sets['Flow'] = 'Block | Inline';
     $manager->addModule($common_module);
     $structural_module = new HTMLPurifier_HTMLModule();
     $structural_module->name = 'Structural';
     $structural_module->addElement('p', 'Block', 'Inline', 'Common');
     $manager->addModule($structural_module);
     $formatting_module = new HTMLPurifier_HTMLModule();
     $formatting_module->name = 'Formatting';
     $formatting_module->addElement('em', 'Inline', 'Inline', 'Common');
     $manager->addModule($formatting_module);
     $unsafe_module = new HTMLPurifier_HTMLModule();
     $unsafe_module->name = 'Unsafe';
     $unsafe_module->safe = false;
     $unsafe_module->addElement('div', 'Block', 'Flow');
     $manager->addModule($unsafe_module);
     $config = HTMLPurifier_Config::createDefault();
     $config->set('HTML.Trusted', false);
     $config->set('HTML.CustomDoctype', 'Blank');
     $manager->setup($config);
     $attrdef_nmtokens = new HTMLPurifier_AttrDef_HTML_Nmtokens();
     $p = new HTMLPurifier_ElementDef();
     $p->attr['class'] = $attrdef_nmtokens;
     $p->child = new HTMLPurifier_ChildDef_Optional(array('em', '#PCDATA'));
     $p->content_model = 'em | #PCDATA';
     $p->content_model_type = 'optional';
     $p->descendants_are_inline = true;
     $em = new HTMLPurifier_ElementDef();
     $em->attr['class'] = $attrdef_nmtokens;
     $em->child = new HTMLPurifier_ChildDef_Optional(array('em', '#PCDATA'));
     $em->content_model = 'em | #PCDATA';
     $em->content_model_type = 'optional';
     $em->descendants_are_inline = true;
     $this->assertEqual(array('p' => $p, 'em' => $em), $manager->getElements());
     // test trusted parameter override
     $div = new HTMLPurifier_ElementDef();
     $div->child = new HTMLPurifier_ChildDef_Optional(array('p', 'div', 'em', '#PCDATA'));
     $div->content_model = 'p | div | em | #PCDATA';
     $div->content_model_type = 'optional';
     $div->descendants_are_inline = false;
     $this->assertEqual($div, $manager->getElement('div', true));
 }
 /**
  * Instantiates a ChildDef based on content_model and content_model_type
  * member variables in HTMLPurifier_ElementDef
  * @note This will also defer to modules for custom HTMLPurifier_ChildDef
  *       subclasses that need content set expansion
  * @param HTMLPurifier_ElementDef $def HTMLPurifier_ElementDef to have ChildDef extracted
  * @param HTMLPurifier_HTMLModule $module Module that defined the ElementDef
  * @return HTMLPurifier_ChildDef corresponding to ElementDef
  */
 public function getChildDef($def, $module)
 {
     $value = $def->content_model;
     if (is_object($value)) {
         trigger_error('Literal object child definitions should be stored in ' . 'ElementDef->child not ElementDef->content_model', E_USER_NOTICE);
         return $value;
     }
     switch ($def->content_model_type) {
         case 'required':
             return new HTMLPurifier_ChildDef_Required($value);
         case 'optional':
             return new HTMLPurifier_ChildDef_Optional($value);
         case 'empty':
             return new HTMLPurifier_ChildDef_Empty();
         case 'custom':
             return new HTMLPurifier_ChildDef_Custom($value);
     }
     // defer to its module
     $return = false;
     if ($module->defines_child_def) {
         // save a func call
         $return = $module->getChildDef($def);
     }
     if ($return !== false) {
         return $return;
     }
     // error-out
     trigger_error('Could not determine which ChildDef class to instantiate', E_USER_ERROR);
     return false;
 }