mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-10 08:04:37 +02:00
[1.6.1] Implement generic EnumToCSS attribute transformation, migrate text alignment to it
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1017 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrTransform/TextAlign.php';
|
||||
require_once 'HTMLPurifier/AttrTransform/EnumToCSS.php';
|
||||
require_once 'HTMLPurifier/AttrTransformHarness.php';
|
||||
|
||||
class HTMLPurifier_AttrTransform_TextAlignTest extends HTMLPurifier_AttrTransformHarness
|
||||
class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_TextAlign();
|
||||
}
|
||||
|
||||
function test() {
|
||||
function testRegular() {
|
||||
|
||||
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'left' => 'text-align:left;',
|
||||
'right' => 'text-align:right;'
|
||||
));
|
||||
|
||||
// leave empty arrays alone
|
||||
$this->assertResult( array() );
|
||||
@@ -31,16 +31,6 @@ class HTMLPurifier_AttrTransform_TextAlignTest extends HTMLPurifier_AttrTransfor
|
||||
array('style' => 'text-align:right;')
|
||||
);
|
||||
|
||||
$this->assertResult(
|
||||
array('align' => 'center'),
|
||||
array('style' => 'text-align:center;')
|
||||
);
|
||||
|
||||
$this->assertResult(
|
||||
array('align' => 'justify'),
|
||||
array('style' => 'text-align:justify;')
|
||||
);
|
||||
|
||||
// drop garbage value
|
||||
$this->assertResult(
|
||||
array('align' => 'invalid'),
|
||||
@@ -53,10 +43,32 @@ class HTMLPurifier_AttrTransform_TextAlignTest extends HTMLPurifier_AttrTransfor
|
||||
array('style' => 'text-align:left;font-weight:bold;')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testCaseInsensitive() {
|
||||
|
||||
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'right' => 'text-align:right;'
|
||||
));
|
||||
|
||||
// test case insensitivity
|
||||
$this->assertResult(
|
||||
array('align' => 'CENTER'),
|
||||
array('style' => 'text-align:center;')
|
||||
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()
|
||||
);
|
||||
|
||||
}
|
@@ -95,6 +95,22 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
'<h1 align="center">Centered Headline</h1>',
|
||||
'<h1 style="text-align:center;">Centered Headline</h1>'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<h1 align="right">Right-aligned Headline</h1>',
|
||||
'<h1 style="text-align:right;">Right-aligned Headline</h1>'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<h1 align="left">Left-aligned Headline</h1>',
|
||||
'<h1 style="text-align:left;">Left-aligned Headline</h1>'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<p align="justify">Justified Paragraph</p>',
|
||||
'<p style="text-align:justify;">Justified Paragraph</p>'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<h1 align="invalid">Invalid Headline</h1>',
|
||||
'<h1>Invalid Headline</h1>'
|
||||
);
|
||||
|
||||
// test table
|
||||
$this->assertResult(
|
||||
@@ -237,6 +253,8 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
'<b xml:lang="en">asdf</b>', array('HTML.Doctype' => 'XHTML 1.1')
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user