From 1f8619cda5cf2f07d9401a1a85d198a4ddf06781 Mon Sep 17 00:00:00 2001
From: "Edward Z. Yang"
Date: Sat, 26 Apr 2008 01:13:58 +0000
Subject: [PATCH] [3.1.0] Fix and revamp configForm.php smoketest - Fix
bool/null ConfigForm field
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1694 48356398-32a2-884e-a903-53898d9a118a
---
NEWS | 2 +
configdoc/generate.php | 1 +
library/HTMLPurifier/Printer/ConfigForm.php | 10 +++-
smoketests/configForm.php | 56 ++++++++++---------
smoketests/test-schema/Directive.Allowed.txt | 5 ++
.../test-schema/Directive.Deprecated.txt | 6 ++
smoketests/test-schema/Directive.txt | 2 +
smoketests/test-schema/Type.bool.txt | 4 ++
smoketests/test-schema/Type.float.txt | 4 ++
smoketests/test-schema/Type.hash.txt | 4 ++
smoketests/test-schema/Type.int.txt | 4 ++
smoketests/test-schema/Type.istring.txt | 4 ++
smoketests/test-schema/Type.itext.txt | 4 ++
smoketests/test-schema/Type.list.txt | 4 ++
smoketests/test-schema/Type.lookup.txt | 4 ++
smoketests/test-schema/Type.mixed.txt | 4 ++
smoketests/test-schema/Type.nullbool.txt | 6 ++
smoketests/test-schema/Type.nullstring.txt | 8 +++
smoketests/test-schema/Type.string.txt | 4 ++
smoketests/test-schema/Type.text.txt | 4 ++
smoketests/test-schema/Type.txt | 2 +
smoketests/test-schema/info.ini | 1 +
smoketests/testSchema.php | 41 --------------
23 files changed, 114 insertions(+), 70 deletions(-)
create mode 100644 smoketests/test-schema/Directive.Allowed.txt
create mode 100644 smoketests/test-schema/Directive.Deprecated.txt
create mode 100644 smoketests/test-schema/Directive.txt
create mode 100644 smoketests/test-schema/Type.bool.txt
create mode 100644 smoketests/test-schema/Type.float.txt
create mode 100644 smoketests/test-schema/Type.hash.txt
create mode 100644 smoketests/test-schema/Type.int.txt
create mode 100644 smoketests/test-schema/Type.istring.txt
create mode 100644 smoketests/test-schema/Type.itext.txt
create mode 100644 smoketests/test-schema/Type.list.txt
create mode 100644 smoketests/test-schema/Type.lookup.txt
create mode 100644 smoketests/test-schema/Type.mixed.txt
create mode 100644 smoketests/test-schema/Type.nullbool.txt
create mode 100644 smoketests/test-schema/Type.nullstring.txt
create mode 100644 smoketests/test-schema/Type.string.txt
create mode 100644 smoketests/test-schema/Type.text.txt
create mode 100644 smoketests/test-schema/Type.txt
create mode 100644 smoketests/test-schema/info.ini
delete mode 100644 smoketests/testSchema.php
diff --git a/NEWS b/NEWS
index a3adf89a..d20c92b0 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
do not honor error_reporting
- Add protection against imagecrash attack with CSS height/width
- HTMLPurifier::instance() created for consistency, is equivalent to getInstance()
+- Fixed and revamped broken ConfigForm smoketest
+- Bug with bool/null fields in Printer_ConfigForm fixed
. Out-of-date documentation revised
. UTF-8 encoding check optimization as suggested by Diego
. HTMLPurifier_Error removed in favor of exceptions
diff --git a/configdoc/generate.php b/configdoc/generate.php
index b0faf72f..3e4a695c 100644
--- a/configdoc/generate.php
+++ b/configdoc/generate.php
@@ -38,6 +38,7 @@ $configdoc_xml = 'configdoc.xml';
$xml_builder = new HTMLPurifier_ConfigSchema_Builder_Xml();
$xml_builder->openURI($configdoc_xml);
$xml_builder->build($interchange);
+unset($xml_builder); // free handle
$xslt = new ConfigDoc_HTMLXSLTProcessor();
$xslt->importStylesheet(dirname(__FILE__) . "/styles/$style.xsl");
diff --git a/library/HTMLPurifier/Printer/ConfigForm.php b/library/HTMLPurifier/Printer/ConfigForm.php
index addda702..172d7bb4 100644
--- a/library/HTMLPurifier/Printer/ConfigForm.php
+++ b/library/HTMLPurifier/Printer/ConfigForm.php
@@ -194,6 +194,10 @@ class HTMLPurifier_Printer_ConfigForm_NullDecorator extends HTMLPurifier_Printer
'id' => "$name:Null_$ns.$directive",
'onclick' => "toggleWriteability('$name:$ns.$directive',checked)" // INLINE JAVASCRIPT!!!!
);
+ if ($this->obj instanceof HTMLPurifier_Printer_ConfigForm_bool) {
+ // modify inline javascript slightly
+ $attr['onclick'] = "toggleWriteability('$name:Yes_$ns.$directive',checked);toggleWriteability('$name:No_$ns.$directive',checked)";
+ }
if ($value === null) $attr['checked'] = 'checked';
$ret .= $this->elementEmpty('input', $attr);
$ret .= $this->text(' or ');
@@ -291,7 +295,8 @@ class HTMLPurifier_Printer_ConfigForm_bool extends HTMLPurifier_Printer {
'id' => "$name:Yes_$ns.$directive",
'value' => '1'
);
- if ($value) $attr['checked'] = 'checked';
+ if ($value === true) $attr['checked'] = 'checked';
+ if ($value === null) $attr['disabled'] = 'disabled';
$ret .= $this->elementEmpty('input', $attr);
$ret .= $this->start('label', array('for' => "$name:No_$ns.$directive"));
@@ -305,7 +310,8 @@ class HTMLPurifier_Printer_ConfigForm_bool extends HTMLPurifier_Printer {
'id' => "$name:No_$ns.$directive",
'value' => '0'
);
- if (!$value) $attr['checked'] = 'checked';
+ if ($value === false) $attr['checked'] = 'checked';
+ if ($value === null) $attr['disabled'] = 'disabled';
$ret .= $this->elementEmpty('input', $attr);
$ret .= $this->end('div');
diff --git a/smoketests/configForm.php b/smoketests/configForm.php
index 3bb52060..051472d9 100644
--- a/smoketests/configForm.php
+++ b/smoketests/configForm.php
@@ -2,31 +2,37 @@
require_once 'common.php';
+// Setup environment
+require_once '../extras/HTMLPurifierExtras.auto.php';
+$interchange = HTMLPurifier_ConfigSchema_InterchangeBuilder::buildFromDirectory('test-schema/');
+$interchange->validate();
+
if (isset($_GET['doc'])) {
- if (
- file_exists('testSchema.html') &&
- filemtime('testSchema.php') < filemtime('testSchema.html') &&
- !isset($_GET['purge'])
- ) {
- echo file_get_contents('testSchema.html');
+ // Hijack page generation to supply documentation
+
+ if (file_exists('test-schema.html') && !isset($_GET['purge'])) {
+ echo file_get_contents('test-schema.html');
exit;
}
- if (version_compare('5', PHP_VERSION, '>')) exit('Requires PHP 5 or higher.');
-
- // setup ConfigDoc environment
- require_once '../configdoc/library/ConfigDoc.auto.php';
-
- // perform the ConfigDoc generation
- $configdoc = new ConfigDoc();
- $html = $configdoc->generate($new_schema, 'plain', array(
- 'css' => '../configdoc/styles/plain.css',
- 'title' => 'Sample Configuration Documentation'
+ $style = 'plain';
+ $configdoc_xml = 'test-schema.xml';
+
+ $xml_builder = new HTMLPurifier_ConfigSchema_Builder_Xml();
+ $xml_builder->openURI($configdoc_xml);
+ $xml_builder->build($interchange);
+ unset($xml_builder); // free handle
+
+ $xslt = new ConfigDoc_HTMLXSLTProcessor();
+ $xslt->importStylesheet("../configdoc/styles/$style.xsl");
+ $xslt->setParameters(array(
+ 'css' => '../configdoc/styles/plain.css',
));
- $configdoc->cleanup();
+ $html = $xslt->transformToHTML($configdoc_xml);
- file_put_contents('testSchema.html', $html);
+ unlink('test-schema.xml');
+ file_put_contents('test-schema.html', $html);
echo $html;
exit;
@@ -50,15 +56,11 @@ of directive possible.
style="float:right;">
build($interchange);
+HTMLPurifier_ConfigSchema::instance($schema);
-// fictional set, attempts to cover every possible data-type
-// see source at ConfigTest.php
-require_once 'testSchema.php';
-HTMLPurifier_ConfigSchema::instance($custom_schema);
-
-// cleanup ( this should be rolled into Config )
-$config = HTMLPurifier_Config::loadArrayFromForm($_GET, 'config');
+$config = HTMLPurifier_Config::loadArrayFromForm($_GET, 'config');
$printer = new HTMLPurifier_Printer_ConfigForm('config', '?doc#%s');
echo $printer->render($config);
@@ -66,7 +68,7 @@ echo $printer->render($config);
getAll(), true));
+echo htmlspecialchars(var_export($config->getAll(), true));
?>