0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 16:31:53 +00:00

[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
This commit is contained in:
Edward Z. Yang 2008-04-26 01:13:58 +00:00
parent 04b1ec33cb
commit 1f8619cda5
23 changed files with 114 additions and 70 deletions

2
NEWS
View File

@ -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

View File

@ -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");

View File

@ -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');

View File

@ -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.');
$style = 'plain';
$configdoc_xml = 'test-schema.xml';
// setup ConfigDoc environment
require_once '../configdoc/library/ConfigDoc.auto.php';
$xml_builder = new HTMLPurifier_ConfigSchema_Builder_Xml();
$xml_builder->openURI($configdoc_xml);
$xml_builder->build($interchange);
unset($xml_builder); // free handle
// perform the ConfigDoc generation
$configdoc = new ConfigDoc();
$html = $configdoc->generate($new_schema, 'plain', array(
$xslt = new ConfigDoc_HTMLXSLTProcessor();
$xslt->importStylesheet("../configdoc/styles/$style.xsl");
$xslt->setParameters(array(
'css' => '../configdoc/styles/plain.css',
'title' => 'Sample Configuration Documentation'
));
$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,14 +56,10 @@ of directive possible.</p>
style="float:right;">
<?php
require_once 'HTMLPurifier/Printer/ConfigForm.php';
$schema_builder = new HTMLPurifier_ConfigSchema_Builder_ConfigSchema();
$schema = $schema_builder->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');
$printer = new HTMLPurifier_Printer_ConfigForm('config', '?doc#%s');
echo $printer->render($config);
@ -66,7 +68,7 @@ echo $printer->render($config);
</form>
<pre>
<?php
echo htmlspecialchars(print_r($config->getAll(), true));
echo htmlspecialchars(var_export($config->getAll(), true));
?>
</pre>
</body>

View File

@ -0,0 +1,5 @@
Directive.Allowed
TYPE: string
DEFAULT: 'apple'
ALLOWED: 'apple', 'orange', 'pear', 'peach', 'mango'
DESCRIPTION: This directive has a constrained set of allowed values.

View File

@ -0,0 +1,6 @@
Directive.Deprecated
TYPE: int
DEFAULT: 0
DESCRIPTION: This is a deprecated directive that shouldn't show up on the form.
DEPRECATED-VERSION: 1.0.0
DEPRECATED-USE: Directive.Allowed

View File

@ -0,0 +1,2 @@
Directive
DESCRIPTION: Other custom options with directives.

View File

@ -0,0 +1,4 @@
Type.bool
TYPE: bool
DEFAULT: false
DESCRIPTION: The boolean type is true or false.

View File

@ -0,0 +1,4 @@
Type.float
TYPE: float
DEFAULT: 3.1415
DESCRIPTION: The float type is a floating point number.

View File

@ -0,0 +1,4 @@
Type.hash
TYPE: hash
DEFAULT: array('key1' => 'val1', 'key2' => 'val2')
DESCRIPTION: The hash type is an associative array of string keys and string values.

View File

@ -0,0 +1,4 @@
Type.int
TYPE: int
DEFAULT: 23
DESCRIPTION: The int type is an signed integer.

View File

@ -0,0 +1,4 @@
Type.istring
TYPE: istring
DEFAULT: 'case insensitive'
DESCRIPTION: The istring type is short (no newlines), must be ASCII and is case-insensitive.

View File

@ -0,0 +1,4 @@
Type.itext
TYPE: itext
DEFAULT: "case\ninsensitive\nand\npossibly\nquite\nlong"
DESCRIPTION: The text type has newlines, must be ASCII and is case-insensitive.

View File

@ -0,0 +1,4 @@
Type.list
TYPE: list
DEFAULT: array('item1', 'item2')
DESCRIPTION: The list type is a numerically indexed array of strings.

View File

@ -0,0 +1,4 @@
Type.lookup
TYPE: lookup
DEFAULT: array('key1' => true, 'key2' => true)
DESCRIPTION: The lookup type acts just like list, except its elements are unique and are checked with <code>isset($var[$key])</code>.

View File

@ -0,0 +1,4 @@
Type.mixed
TYPE: mixed
DEFAULT: new stdclass()
DESCRIPTION: The mixed type allows any type, and is not form-editable.

View File

@ -0,0 +1,6 @@
Type.nullbool
TYPE: bool/null
DEFAULT: null
--DESCRIPTION--
Null booleans need to be treated a little specially. See %Type.nullstring
for information on what the null flag does.

View File

@ -0,0 +1,8 @@
Type.nullstring
TYPE: string/null
DEFAULT: null
--DESCRIPTION--
The null type is not a type, but a flag that can be added to any type
making null a valid value for that entry. It's useful for saying, "Let
the software pick the value for me," or "Don't use this element" when
false has a special meaning.

View File

@ -0,0 +1,4 @@
Type.string
TYPE: string
DEFAULT: 'Case sensitive'
DESCRIPTION: The string type is short (no newlines) and case-sensitive.

View File

@ -0,0 +1,4 @@
Type.text
TYPE: text
DEFAULT: "Case sensitive\nand\npossibly\nquite long..."
DESCRIPTION: The text type has newlines and is case-sensitive.

View File

@ -0,0 +1,2 @@
Type
DESCRIPTION: Directives demonstration the variable types ConfigSchema supports.

View File

@ -0,0 +1 @@
name = "Test Schema"

View File

@ -1,41 +0,0 @@
<?php
// overload default configuration schema temporarily
$custom_schema = new HTMLPurifier_ConfigSchema();
$custom_schema->addNamespace('Element', 'Chemical substances that cannot be further decomposed');
$custom_schema->add('Element', 'Abbr', 'H', 'string', false, 'Abbreviation of element name.');
$custom_schema->add('Element', 'Name', 'hydrogen', 'istring', false, 'Full name of atoms.');
$custom_schema->add('Element', 'Number', 1, 'int', false, 'Atomic number, is identity.');
$custom_schema->add('Element', 'Mass', 1.00794, 'float', false, 'Atomic mass.');
$custom_schema->add('Element', 'Radioactive', false, 'bool', false, 'Does it have rapid decay?');
$custom_schema->add('Element', 'Isotopes', array('1' => true, '2' => true, '3' => true), 'lookup', false,
'What numbers of neutrons for this element have been observed?');
$custom_schema->add('Element', 'Traits', array('nonmetallic', 'odorless', 'flammable'), 'list', false,
'What are general properties of the element?');
$custom_schema->add('Element', 'IsotopeNames', array('1' => 'protium', '2' => 'deuterium', '3' => 'tritium'), 'hash', false,
'Lookup hash of neutron counts to formal names.');
$custom_schema->addNamespace('Instrument', 'Of the musical type.');
$custom_schema->add('Instrument', 'Manufacturer', 'Yamaha', 'string', false, 'Who made it?');
$custom_schema->addAllowedValues('Instrument', 'Manufacturer', array(
'Yamaha', 'Conn-Selmer', 'Vandoren', 'Laubin', 'Buffet', 'other'));
$custom_schema->addValueAliases('Instrument', 'Manufacturer', array(
'Selmer' => 'Conn-Selmer'));
$custom_schema->add('Instrument', 'Family', 'woodwind', 'istring', false, 'What family is it?');
$custom_schema->addAllowedValues('Instrument', 'Family', array(
'brass', 'woodwind', 'percussion', 'string', 'keyboard', 'electronic'));
$custom_schema->addValueAliases('Instrument', 'Family', array(
'synth' => 'electronic'));
$custom_schema->addNamespace('ReportCard', 'It is for grades.');
$custom_schema->add('ReportCard', 'English', null, 'string', true, 'Grade from English class.');
$custom_schema->add('ReportCard', 'Absences', 0, 'int', false, 'How many times missing from school?');
$custom_schema->addNamespace('Text', 'This stuff is long, boring, and English.');
$custom_schema->add('Text', 'AboutUs', 'Nothing much, but this should be decently long so that a textarea would be better', 'text', false, 'Who are we? What are we up to?');
$custom_schema->add('Text', 'Hash', "not-case-sensitive\nstill-not-case-sensitive\nsuper-not-case-sensitive", 'itext', false, 'This is of limited utility, but of course it ends up being used.');