2007-05-20 19:29:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/AttrCollections.php';
|
|
|
|
|
|
|
|
Mock::generatePartial(
|
|
|
|
'HTMLPurifier_AttrCollections',
|
|
|
|
'HTMLPurifier_AttrCollections_TestForConstruct',
|
|
|
|
array('performInclusions', 'expandIdentifiers')
|
|
|
|
);
|
|
|
|
|
2007-08-01 14:06:59 +00:00
|
|
|
class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
|
2007-05-20 19:29:05 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
function testConstruction() {
|
|
|
|
|
|
|
|
generate_mock_once('HTMLPurifier_AttrTypes');
|
|
|
|
|
2007-06-26 15:40:04 +00:00
|
|
|
$collections = new HTMLPurifier_AttrCollections_TestForConstruct();
|
2007-05-20 19:29:05 +00:00
|
|
|
|
2007-06-26 15:40:04 +00:00
|
|
|
$types = new HTMLPurifier_AttrTypesMock();
|
2007-05-20 19:29:05 +00:00
|
|
|
|
|
|
|
$modules = array();
|
|
|
|
|
|
|
|
$modules['Module1'] = new HTMLPurifier_HTMLModule();
|
|
|
|
$modules['Module1']->attr_collections = array(
|
|
|
|
'Core' => array(
|
|
|
|
0 => array('Soup', 'Undefined'),
|
|
|
|
'attribute' => 'Type',
|
|
|
|
'attribute-2' => 'Type2',
|
|
|
|
),
|
|
|
|
'Soup' => array(
|
|
|
|
'attribute-3' => 'Type3-old' // overwritten
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$modules['Module2'] = new HTMLPurifier_HTMLModule();
|
|
|
|
$modules['Module2']->attr_collections = array(
|
|
|
|
'Core' => array(
|
|
|
|
0 => array('Brocolli')
|
|
|
|
),
|
|
|
|
'Soup' => array(
|
|
|
|
'attribute-3' => 'Type3'
|
|
|
|
),
|
|
|
|
'Brocolli' => array()
|
|
|
|
);
|
|
|
|
|
|
|
|
$collections->HTMLPurifier_AttrCollections($types, $modules);
|
|
|
|
// this is without identifier expansion or inclusions
|
|
|
|
$this->assertIdentical(
|
|
|
|
$collections->info,
|
|
|
|
array(
|
|
|
|
'Core' => array(
|
|
|
|
0 => array('Soup', 'Undefined', 'Brocolli'),
|
|
|
|
'attribute' => 'Type',
|
|
|
|
'attribute-2' => 'Type2'
|
|
|
|
),
|
|
|
|
'Soup' => array(
|
|
|
|
'attribute-3' => 'Type3'
|
|
|
|
),
|
|
|
|
'Brocolli' => array()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_performInclusions() {
|
|
|
|
|
|
|
|
generate_mock_once('HTMLPurifier_AttrTypes');
|
|
|
|
|
2007-06-26 15:40:04 +00:00
|
|
|
$types = new HTMLPurifier_AttrTypesMock();
|
2007-05-20 19:29:05 +00:00
|
|
|
$collections = new HTMLPurifier_AttrCollections($types, array());
|
|
|
|
$collections->info = array(
|
2007-05-20 22:29:31 +00:00
|
|
|
'Core' => array(0 => array('Inclusion', 'Undefined'), 'attr-original' => 'Type'),
|
2007-05-20 19:29:05 +00:00
|
|
|
'Inclusion' => array(0 => array('SubInclusion'), 'attr' => 'Type'),
|
|
|
|
'SubInclusion' => array('attr2' => 'Type')
|
|
|
|
);
|
|
|
|
|
|
|
|
$collections->performInclusions($collections->info['Core']);
|
|
|
|
$this->assertIdentical(
|
|
|
|
$collections->info['Core'],
|
|
|
|
array(
|
|
|
|
'attr-original' => 'Type',
|
|
|
|
'attr' => 'Type',
|
|
|
|
'attr2' => 'Type'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// test recursive
|
|
|
|
$collections->info = array(
|
|
|
|
'One' => array(0 => array('Two'), 'one' => 'Type'),
|
|
|
|
'Two' => array(0 => array('One'), 'two' => 'Type')
|
|
|
|
);
|
|
|
|
$collections->performInclusions($collections->info['One']);
|
|
|
|
$this->assertIdentical(
|
|
|
|
$collections->info['One'],
|
|
|
|
array(
|
|
|
|
'one' => 'Type',
|
|
|
|
'two' => 'Type'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_expandIdentifiers() {
|
|
|
|
|
|
|
|
generate_mock_once('HTMLPurifier_AttrTypes');
|
|
|
|
|
2007-06-26 15:40:04 +00:00
|
|
|
$types = new HTMLPurifier_AttrTypesMock();
|
2007-05-20 19:29:05 +00:00
|
|
|
$collections = new HTMLPurifier_AttrCollections($types, array());
|
|
|
|
|
|
|
|
$attr = array(
|
|
|
|
'attr1' => 'Color',
|
2007-06-20 21:39:28 +00:00
|
|
|
'attr2*' => 'URI'
|
2007-05-20 19:29:05 +00:00
|
|
|
);
|
2007-11-25 02:24:39 +00:00
|
|
|
$c_object = new HTMLPurifier_AttrDef_HTML_Color();
|
|
|
|
$u_object = new HTMLPurifier_AttrDef_URI();
|
2007-06-20 21:39:28 +00:00
|
|
|
|
|
|
|
$types->setReturnValue('get', $c_object, array('Color'));
|
|
|
|
$types->setReturnValue('get', $u_object, array('URI'));
|
|
|
|
|
2007-05-20 19:29:05 +00:00
|
|
|
$collections->expandIdentifiers($attr, $types);
|
|
|
|
|
2007-06-20 21:39:28 +00:00
|
|
|
$u_object->required = true;
|
2007-05-20 19:29:05 +00:00
|
|
|
$this->assertIdentical(
|
|
|
|
$attr,
|
|
|
|
array(
|
2007-06-20 21:39:28 +00:00
|
|
|
'attr1' => $c_object,
|
|
|
|
'attr2' => $u_object
|
2007-05-20 19:29:05 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|