Exemplo n.º 1
0
 public function test_get()
 {
     $types = new HTMLPurifier_AttrTypes();
     $this->assertIdentical($types->get('CDATA'), new HTMLPurifier_AttrDef_Text());
     $this->expectError('Cannot retrieve undefined attribute type foobar');
     $types->get('foobar');
     $this->assertIdentical($types->get('Enum#foo,bar'), new HTMLPurifier_AttrDef_Enum(array('foo', 'bar')));
 }
 /**
  * Expands all string identifiers in an attribute array by replacing
  * them with the appropriate values inside HTMLPurifier_AttrTypes
  * @param array &$attr Reference to attribute array
  * @param HTMLPurifier_AttrTypes $attr_types HTMLPurifier_AttrTypes instance
  */
 public function expandIdentifiers(&$attr, $attr_types)
 {
     // because foreach will process new elements we add, make sure we
     // skip duplicates
     $processed = array();
     foreach ($attr as $def_i => $def) {
         // skip inclusions
         if ($def_i === 0) {
             continue;
         }
         if (isset($processed[$def_i])) {
             continue;
         }
         // determine whether or not attribute is required
         if ($required = strpos($def_i, '*') !== false) {
             // rename the definition
             unset($attr[$def_i]);
             $def_i = trim($def_i, '*');
             $attr[$def_i] = $def;
         }
         $processed[$def_i] = true;
         // if we've already got a literal object, move on
         if (is_object($def)) {
             // preserve previous required
             $attr[$def_i]->required = $required || $attr[$def_i]->required;
             continue;
         }
         if ($def === false) {
             unset($attr[$def_i]);
             continue;
         }
         if ($t = $attr_types->get($def)) {
             $attr[$def_i] = $t;
             $attr[$def_i]->required = $required;
         } else {
             unset($attr[$def_i]);
         }
     }
 }