2006-08-05 02:56:57 +00:00
|
|
|
<?php
|
|
|
|
|
2007-05-05 15:48:41 +00:00
|
|
|
require_once 'HTMLPurifier/AttrTransform/EnumToCSS.php';
|
2007-01-19 23:02:28 +00:00
|
|
|
require_once 'HTMLPurifier/AttrTransformHarness.php';
|
2006-08-05 02:56:57 +00:00
|
|
|
|
2007-05-05 15:48:41 +00:00
|
|
|
class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransformHarness
|
2006-08-05 02:56:57 +00:00
|
|
|
{
|
|
|
|
|
2007-05-05 15:48:41 +00:00
|
|
|
function testRegular() {
|
|
|
|
|
|
|
|
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
|
|
|
'left' => 'text-align:left;',
|
|
|
|
'right' => 'text-align:right;'
|
|
|
|
));
|
2006-08-05 02:56:57 +00:00
|
|
|
|
|
|
|
// leave empty arrays alone
|
2006-10-22 03:38:32 +00:00
|
|
|
$this->assertResult( array() );
|
2006-08-05 02:56:57 +00:00
|
|
|
|
|
|
|
// leave arrays without interesting stuff alone
|
2006-10-22 03:38:32 +00:00
|
|
|
$this->assertResult( array('style' => 'font-weight:bold;') );
|
2006-08-05 02:56:57 +00:00
|
|
|
|
|
|
|
// test each of the conversions
|
|
|
|
|
2006-10-22 03:38:32 +00:00
|
|
|
$this->assertResult(
|
|
|
|
array('align' => 'left'),
|
|
|
|
array('style' => 'text-align:left;')
|
|
|
|
);
|
2006-08-05 02:56:57 +00:00
|
|
|
|
2006-10-22 03:38:32 +00:00
|
|
|
$this->assertResult(
|
|
|
|
array('align' => 'right'),
|
|
|
|
array('style' => 'text-align:right;')
|
|
|
|
);
|
2006-08-05 02:56:57 +00:00
|
|
|
|
|
|
|
// drop garbage value
|
2006-10-22 03:38:32 +00:00
|
|
|
$this->assertResult(
|
|
|
|
array('align' => 'invalid'),
|
|
|
|
array()
|
|
|
|
);
|
2006-08-05 02:56:57 +00:00
|
|
|
|
|
|
|
// test CSS munging
|
2006-10-22 03:38:32 +00:00
|
|
|
$this->assertResult(
|
|
|
|
array('align' => 'left', 'style' => 'font-weight:bold;'),
|
|
|
|
array('style' => 'text-align:left;font-weight:bold;')
|
|
|
|
);
|
2006-08-05 02:56:57 +00:00
|
|
|
|
2007-05-05 15:48:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testCaseInsensitive() {
|
|
|
|
|
|
|
|
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
|
|
|
'right' => 'text-align:right;'
|
|
|
|
));
|
|
|
|
|
2006-08-05 02:56:57 +00:00
|
|
|
// test case insensitivity
|
2006-10-22 03:38:32 +00:00
|
|
|
$this->assertResult(
|
2007-05-05 15:48:41 +00:00
|
|
|
array('align' => 'RIGHT'),
|
|
|
|
array('style' => 'text-align:right;')
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCaseSensitive() {
|
|
|
|
|
|
|
|
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
|
|
|
'right' => 'text-align:right;'
|
|
|
|
), true);
|
|
|
|
|
|
|
|
// test case insensitivity
|
|
|
|
$this->assertResult(
|
|
|
|
array('align' => 'RIGHT'),
|
|
|
|
array()
|
2006-10-22 03:38:32 +00:00
|
|
|
);
|
2006-08-05 02:56:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|