first commit
This commit is contained in:
88
htmlpurifier-4.10.0/tests/CliTestCase.php
Executable file
88
htmlpurifier-4.10.0/tests/CliTestCase.php
Executable file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements an external test-case like RemoteTestCase that parses its
|
||||
* output from XML returned by a command line call
|
||||
*/
|
||||
class CliTestCase
|
||||
{
|
||||
public $_command;
|
||||
public $_out = false;
|
||||
public $_quiet = false;
|
||||
public $_errors = array();
|
||||
public $_size = false;
|
||||
/**
|
||||
* @param $command Command to execute to retrieve XML
|
||||
* @param $xml Whether or not to suppress error messages
|
||||
*/
|
||||
public function __construct($command, $quiet = false, $size = false)
|
||||
{
|
||||
$this->_command = $command;
|
||||
$this->_quiet = $quiet;
|
||||
$this->_size = $size;
|
||||
}
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->_command;
|
||||
}
|
||||
public function run($reporter)
|
||||
{
|
||||
if (!$this->_quiet) $reporter->paintFormattedMessage('Running ['.$this->_command.']');
|
||||
return $this->_invokeCommand($this->_command, $reporter);
|
||||
}
|
||||
public function _invokeCommand($command, $reporter)
|
||||
{
|
||||
$xml = shell_exec($command);
|
||||
if (! $xml) {
|
||||
if (!$this->_quiet) {
|
||||
$reporter->paintFail('Command did not have any output [' . $command . ']');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
$parser = $this->_createParser($reporter);
|
||||
|
||||
set_error_handler(array($this, '_errorHandler'));
|
||||
$status = $parser->parse($xml);
|
||||
restore_error_handler();
|
||||
|
||||
if (! $status) {
|
||||
if (!$this->_quiet) {
|
||||
foreach ($this->_errors as $error) {
|
||||
list($no, $str, $file, $line) = $error;
|
||||
$reporter->paintFail("Error $no: $str on line $line of $file");
|
||||
}
|
||||
if (strlen($xml) > 120) {
|
||||
$msg = substr($xml, 0, 50) . "...\n\n[snip]\n\n..." . substr($xml, -50);
|
||||
} else {
|
||||
$msg = $xml;
|
||||
}
|
||||
$reporter->paintFail("Command produced malformed XML");
|
||||
$reporter->paintFormattedMessage($msg);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function _createParser($reporter)
|
||||
{
|
||||
$parser = new SimpleTestXmlParser($reporter);
|
||||
return $parser;
|
||||
}
|
||||
public function getSize()
|
||||
{
|
||||
// This code properly does the dry run and allows for proper test
|
||||
// case reporting but it's REALLY slow, so I don't recommend it.
|
||||
if ($this->_size === false) {
|
||||
$reporter = new SimpleReporter();
|
||||
$this->_invokeCommand($this->_command . ' --dry', $reporter);
|
||||
$this->_size = $reporter->getTestCaseCount();
|
||||
}
|
||||
return $this->_size;
|
||||
}
|
||||
public function _errorHandler($a, $b, $c, $d)
|
||||
{
|
||||
$this->_errors[] = array($a, $b, $c, $d); // see set_error_handler()
|
||||
}
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
164
htmlpurifier-4.10.0/tests/Debugger.php
Executable file
164
htmlpurifier-4.10.0/tests/Debugger.php
Executable file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Debugging tools.
|
||||
*
|
||||
* This file gives a developer a set of tools useful for performing code
|
||||
* consistency checks. This includes scoping code blocks to ensure that
|
||||
* only the interesting iteration of a loop gets outputted, a paint()
|
||||
* function that acts like var_dump() with pre tags, and conditional
|
||||
* printing.
|
||||
*/
|
||||
|
||||
/*
|
||||
TODO
|
||||
* Integrate into SimpleTest so it tells us whether or not there were any
|
||||
not cleaned up debug calls.
|
||||
* Custom var_dump() that ignores blacklisted properties
|
||||
* DEPRECATE AND REMOVE ALL CALLS!
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
* Convenience global functions. Corresponds to method on Debugger.
|
||||
*/
|
||||
function paint($mixed)
|
||||
{
|
||||
$Debugger =& Debugger::instance();
|
||||
return $Debugger->paint($mixed);
|
||||
}
|
||||
function paintIf($mixed, $conditional)
|
||||
{
|
||||
$Debugger =& Debugger::instance();
|
||||
return $Debugger->paintIf($mixed, $conditional);
|
||||
}
|
||||
function paintWhen($mixed, $scopes = array())
|
||||
{
|
||||
$Debugger =& Debugger::instance();
|
||||
return $Debugger->paintWhen($mixed, $scopes);
|
||||
}
|
||||
function paintIfWhen($mixed, $conditional, $scopes = array())
|
||||
{
|
||||
$Debugger =& Debugger::instance();
|
||||
return $Debugger->paintIfWhen($mixed, $conditional, $scopes);
|
||||
}
|
||||
function addScope($id = false)
|
||||
{
|
||||
$Debugger =& Debugger::instance();
|
||||
return $Debugger->addScope($id);
|
||||
}
|
||||
function removeScope($id)
|
||||
{
|
||||
$Debugger =& Debugger::instance();
|
||||
return $Debugger->removeScope($id);
|
||||
}
|
||||
function resetScopes()
|
||||
{
|
||||
$Debugger =& Debugger::instance();
|
||||
return $Debugger->resetScopes();
|
||||
}
|
||||
function isInScopes($array = array())
|
||||
{
|
||||
$Debugger =& Debugger::instance();
|
||||
return $Debugger->isInScopes($array);
|
||||
}
|
||||
/**#@-*/
|
||||
|
||||
|
||||
/**
|
||||
* The debugging singleton. Most interesting stuff happens here.
|
||||
*/
|
||||
class Debugger
|
||||
{
|
||||
|
||||
public $shouldPaint = false;
|
||||
public $paints = 0;
|
||||
public $current_scopes = array();
|
||||
public $scope_nextID = 1;
|
||||
public $add_pre = true;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->add_pre = !extension_loaded('xdebug');
|
||||
}
|
||||
|
||||
public static function &instance() {
|
||||
static $soleInstance = false;
|
||||
if (!$soleInstance) $soleInstance = new Debugger();
|
||||
return $soleInstance;
|
||||
}
|
||||
|
||||
public function paintIf($mixed, $conditional)
|
||||
{
|
||||
if (!$conditional) return;
|
||||
$this->paint($mixed);
|
||||
}
|
||||
|
||||
public function paintWhen($mixed, $scopes = array())
|
||||
{
|
||||
if (!$this->isInScopes($scopes)) return;
|
||||
$this->paint($mixed);
|
||||
}
|
||||
|
||||
public function paintIfWhen($mixed, $conditional, $scopes = array())
|
||||
{
|
||||
if (!$conditional) return;
|
||||
if (!$this->isInScopes($scopes)) return;
|
||||
$this->paint($mixed);
|
||||
}
|
||||
|
||||
public function paint($mixed)
|
||||
{
|
||||
$this->paints++;
|
||||
if($this->add_pre) echo '<pre>';
|
||||
var_dump($mixed);
|
||||
if($this->add_pre) echo '</pre>';
|
||||
}
|
||||
|
||||
public function addScope($id = false)
|
||||
{
|
||||
if ($id == false) {
|
||||
$id = $this->scope_nextID++;
|
||||
}
|
||||
$this->current_scopes[$id] = true;
|
||||
}
|
||||
|
||||
public function removeScope($id)
|
||||
{
|
||||
if (isset($this->current_scopes[$id])) unset($this->current_scopes[$id]);
|
||||
}
|
||||
|
||||
public function resetScopes()
|
||||
{
|
||||
$this->current_scopes = array();
|
||||
$this->scope_nextID = 1;
|
||||
}
|
||||
|
||||
public function isInScopes($scopes = array())
|
||||
{
|
||||
if (empty($this->current_scopes)) {
|
||||
return false;
|
||||
}
|
||||
if (!is_array($scopes)) {
|
||||
$scopes = array($scopes);
|
||||
}
|
||||
foreach ($scopes as $scope_id) {
|
||||
if (empty($this->current_scopes[$scope_id])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (empty($scopes)) {
|
||||
if ($this->scope_nextID == 1) {
|
||||
return false;
|
||||
}
|
||||
for($i = 1; $i < $this->scope_nextID; $i++) {
|
||||
if (empty($this->current_scopes[$i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
40
htmlpurifier-4.10.0/tests/FSTools/FileSystemHarness.php
Executable file
40
htmlpurifier-4.10.0/tests/FSTools/FileSystemHarness.php
Executable file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test harness that sets up a filesystem sandbox for file-emulation
|
||||
* functions to safely unit test in.
|
||||
*
|
||||
* @todo Make an automatic FSTools mock or something
|
||||
*/
|
||||
class FSTools_FileSystemHarness extends UnitTestCase
|
||||
{
|
||||
|
||||
protected $dir, $oldDir;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dir = 'tmp/' . md5(uniqid(rand(), true)) . '/';
|
||||
mkdir($this->dir);
|
||||
$this->oldDir = getcwd();
|
||||
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
FSTools::singleton()->rmdirr($this->dir);
|
||||
}
|
||||
|
||||
public function setup()
|
||||
{
|
||||
chdir($this->dir);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
chdir($this->oldDir);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
49
htmlpurifier-4.10.0/tests/FSTools/FileTest.php
Executable file
49
htmlpurifier-4.10.0/tests/FSTools/FileTest.php
Executable file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
require_once 'FSTools/FileSystemHarness.php';
|
||||
|
||||
/**
|
||||
* These are not really unit tests, just sanity checks of basic functionality.
|
||||
*/
|
||||
class FSTools_FileTest extends FSTools_FileSystemHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$name = 'test.txt';
|
||||
$file = new FSTools_File($name);
|
||||
$this->assertFalse($file->exists());
|
||||
$file->write('foobar');
|
||||
$this->assertTrue($file->exists());
|
||||
$this->assertEqual($file->get(), 'foobar');
|
||||
$file->delete();
|
||||
$this->assertFalse($file->exists());
|
||||
}
|
||||
|
||||
public function testGetNonExistent()
|
||||
{
|
||||
$name = 'notfound.txt';
|
||||
$file = new FSTools_File($name);
|
||||
$this->expectError();
|
||||
$this->assertFalse($file->get());
|
||||
}
|
||||
|
||||
public function testHandle()
|
||||
{
|
||||
$file = new FSTools_File('foo.txt');
|
||||
$this->assertFalse($file->exists());
|
||||
$file->open('w');
|
||||
$this->assertTrue($file->exists());
|
||||
$file->put('Foobar');
|
||||
$file->close();
|
||||
$file->open('r');
|
||||
$this->assertIdentical('F', $file->getChar());
|
||||
$this->assertFalse($file->eof());
|
||||
$this->assertIdentical('oo', $file->read(2));
|
||||
$this->assertIdentical('bar', $file->getLine());
|
||||
$this->assertTrue($file->eof());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
134
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrCollectionsTest.php
Executable file
134
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrCollectionsTest.php
Executable file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
Mock::generatePartial(
|
||||
'HTMLPurifier_AttrCollections',
|
||||
'HTMLPurifier_AttrCollections_TestForConstruct',
|
||||
array('performInclusions', 'expandIdentifiers')
|
||||
);
|
||||
|
||||
class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
public function testConstruction()
|
||||
{
|
||||
generate_mock_once('HTMLPurifier_AttrTypes');
|
||||
|
||||
$collections = new HTMLPurifier_AttrCollections_TestForConstruct();
|
||||
|
||||
$types = new HTMLPurifier_AttrTypesMock();
|
||||
|
||||
$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->doConstruct($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()
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function test_performInclusions()
|
||||
{
|
||||
generate_mock_once('HTMLPurifier_AttrTypes');
|
||||
|
||||
$types = new HTMLPurifier_AttrTypesMock();
|
||||
$collections = new HTMLPurifier_AttrCollections($types, array());
|
||||
$collections->info = array(
|
||||
'Core' => array(0 => array('Inclusion', 'Undefined'), 'attr-original' => 'Type'),
|
||||
'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'
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function test_expandIdentifiers()
|
||||
{
|
||||
generate_mock_once('HTMLPurifier_AttrTypes');
|
||||
|
||||
$types = new HTMLPurifier_AttrTypesMock();
|
||||
$collections = new HTMLPurifier_AttrCollections($types, array());
|
||||
|
||||
$attr = array(
|
||||
'attr1' => 'Color',
|
||||
'attr2*' => 'URI'
|
||||
);
|
||||
$c_object = new HTMLPurifier_AttrDef_HTML_Color();
|
||||
$u_object = new HTMLPurifier_AttrDef_URI();
|
||||
|
||||
$types->returns('get', $c_object, array('Color'));
|
||||
$types->returns('get', $u_object, array('URI'));
|
||||
|
||||
$collections->expandIdentifiers($attr, $types);
|
||||
|
||||
$u_object->required = true;
|
||||
$this->assertIdentical(
|
||||
$attr,
|
||||
array(
|
||||
'attr1' => $c_object,
|
||||
'attr2' => $u_object
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
28
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/AlphaValueTest.php
Executable file
28
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/AlphaValueTest.php
Executable file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_AlphaValueTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_AlphaValue();
|
||||
|
||||
$this->assertDef('0');
|
||||
$this->assertDef('1');
|
||||
$this->assertDef('.2');
|
||||
|
||||
// clamping to [0.0, 1,0]
|
||||
$this->assertDef('1.2', '1');
|
||||
$this->assertDef('-3', '0');
|
||||
|
||||
$this->assertDef('0.0', '0');
|
||||
$this->assertDef('1.0', '1');
|
||||
$this->assertDef('000', '0');
|
||||
|
||||
$this->assertDef('asdf', false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_BackgroundPositionTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_BackgroundPosition();
|
||||
|
||||
// explicitly cited in spec
|
||||
$this->assertDef('0% 0%');
|
||||
$this->assertDef('100% 100%');
|
||||
$this->assertDef('14% 84%');
|
||||
$this->assertDef('2cm 1cm');
|
||||
$this->assertDef('top');
|
||||
$this->assertDef('left');
|
||||
$this->assertDef('center');
|
||||
$this->assertDef('right');
|
||||
$this->assertDef('bottom');
|
||||
$this->assertDef('left top');
|
||||
$this->assertDef('center top');
|
||||
$this->assertDef('right top');
|
||||
$this->assertDef('left center');
|
||||
$this->assertDef('right center');
|
||||
$this->assertDef('left bottom');
|
||||
$this->assertDef('center bottom');
|
||||
$this->assertDef('right bottom');
|
||||
|
||||
// reordered due to internal impl details
|
||||
$this->assertDef('top left', 'left top');
|
||||
$this->assertDef('top center', 'top');
|
||||
$this->assertDef('top right', 'right top');
|
||||
$this->assertDef('center left', 'left');
|
||||
$this->assertDef('center center', 'center');
|
||||
$this->assertDef('center right', 'right');
|
||||
$this->assertDef('bottom left', 'left bottom');
|
||||
$this->assertDef('bottom center', 'bottom');
|
||||
$this->assertDef('bottom right', 'right bottom');
|
||||
|
||||
// more cases from the defined syntax
|
||||
$this->assertDef('1.32in 4ex');
|
||||
$this->assertDef('-14% -84.65%');
|
||||
$this->assertDef('-1in -4ex');
|
||||
$this->assertDef('-1pc 2.3%');
|
||||
|
||||
// keyword mixing
|
||||
$this->assertDef('3em top');
|
||||
$this->assertDef('left 50%');
|
||||
|
||||
// fixable keyword mixing
|
||||
$this->assertDef('top 3em', '3em top');
|
||||
$this->assertDef('50% left', 'left 50%');
|
||||
|
||||
// whitespace collapsing
|
||||
$this->assertDef('3em top', '3em top');
|
||||
$this->assertDef("left\n \t foo ", 'left');
|
||||
|
||||
// invalid uses (we're going to be strict on these)
|
||||
$this->assertDef('foo bar', false);
|
||||
$this->assertDef('left left', 'left');
|
||||
$this->assertDef('left right top bottom center left', 'left bottom');
|
||||
$this->assertDef('0fr 9%', '9%');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
29
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/BackgroundTest.php
Executable file
29
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/BackgroundTest.php
Executable file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_BackgroundTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Background($config);
|
||||
|
||||
$valid = '#333 url("chess.png") repeat fixed 50% top';
|
||||
$this->assertDef($valid);
|
||||
$this->assertDef('url(\'chess.png\') #333 50% top repeat fixed', $valid);
|
||||
$this->assertDef(
|
||||
'rgb(34%, 56%, 33%) url(chess.png) repeat fixed top',
|
||||
'rgb(34%,56%,33%) url("chess.png") repeat fixed top'
|
||||
);
|
||||
$this->assertDef(
|
||||
'rgba(74, 12, 85, 0.35) repeat fixed bottom',
|
||||
'rgba(74,12,85,.35) repeat fixed bottom'
|
||||
);
|
||||
$this->assertDef(
|
||||
'hsl(244, 47.4%, 88.1%) right center',
|
||||
'hsl(244,47.4%,88.1%) right center'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
21
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/BorderTest.php
Executable file
21
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/BorderTest.php
Executable file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_BorderTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Border($config);
|
||||
|
||||
$this->assertDef('thick solid red', 'thick solid #FF0000');
|
||||
$this->assertDef('thick solid');
|
||||
$this->assertDef('solid red', 'solid #FF0000');
|
||||
$this->assertDef('1px solid #000');
|
||||
$this->assertDef('1px solid rgb(0, 0, 0)', '1px solid rgb(0,0,0)');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
61
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/ColorTest.php
Executable file
61
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/ColorTest.php
Executable file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_ColorTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Color();
|
||||
|
||||
$this->assertDef('#F00');
|
||||
$this->assertDef('#fff');
|
||||
$this->assertDef('#eeeeee');
|
||||
$this->assertDef('#808080');
|
||||
|
||||
$this->assertDef('rgb(255, 0, 0)', 'rgb(255,0,0)'); // rm spaces
|
||||
$this->assertDef('rgb(100%,0%,0%)');
|
||||
$this->assertDef('rgb(50.5%,23.2%,43.9%)'); // decimals okay
|
||||
$this->assertDef('rgb(-5,0,0)', 'rgb(0,0,0)'); // negative values
|
||||
$this->assertDef('rgb(295,0,0)', 'rgb(255,0,0)'); // max values
|
||||
$this->assertDef('rgb(12%,150%,0%)', 'rgb(12%,100%,0%)'); // percentage max values
|
||||
|
||||
$this->assertDef('rgba(255, 0, 0, 0)', 'rgba(255,0,0,0)'); // rm spaces
|
||||
$this->assertDef('rgba(100%,0%,0%,.4)');
|
||||
$this->assertDef('rgba(38.1%,59.7%,1.8%,0.7)', 'rgba(38.1%,59.7%,1.8%,.7)'); // decimals okay
|
||||
|
||||
$this->assertDef('hsl(275, 45%, 81%)', 'hsl(275,45%,81%)'); // rm spaces
|
||||
$this->assertDef('hsl(100,0%,0%)');
|
||||
$this->assertDef('hsl(38,59.7%,1.8%)', 'hsl(38,59.7%,1.8%)'); // decimals okay
|
||||
$this->assertDef('hsl(-11,-15%,25%)', 'hsl(0,0%,25%)'); // negative values
|
||||
$this->assertDef('hsl(380,125%,0%)', 'hsl(360,100%,0%)'); // max values
|
||||
|
||||
$this->assertDef('hsla(100, 74%, 29%, 0)', 'hsla(100,74%,29%,0)'); // rm spaces
|
||||
$this->assertDef('hsla(154,87%,21%,.4)');
|
||||
$this->assertDef('hsla(45,94.3%,4.1%,0.7)', 'hsla(45,94.3%,4.1%,.7)'); // decimals okay
|
||||
|
||||
$this->assertDef('#G00', false);
|
||||
$this->assertDef('cmyk(40, 23, 43, 23)', false);
|
||||
$this->assertDef('rgb(0%, 23, 68%)', false); // no mixed type
|
||||
$this->assertDef('rgb(231, 144, 28.2%)', false); // no mixed type
|
||||
$this->assertDef('hsl(18%,12%,89%)', false); // integer, percentage, percentage
|
||||
|
||||
// clip numbers outside sRGB gamut
|
||||
$this->assertDef('rgb(200%, -10%, 0%)', 'rgb(100%,0%,0%)');
|
||||
$this->assertDef('rgb(256,-23,34)', 'rgb(255,0,34)');
|
||||
|
||||
// color keywords, of course
|
||||
$this->assertDef('red', '#FF0000');
|
||||
|
||||
// malformed hex declaration
|
||||
$this->assertDef('808080', '#808080');
|
||||
$this->assertDef('000000', '#000000');
|
||||
$this->assertDef('fed', '#fed');
|
||||
|
||||
// maybe hex transformations would be another nice feature
|
||||
// at the very least transform rgb percent to rgb integer
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
82
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/CompositeTest.php
Executable file
82
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/CompositeTest.php
Executable file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_Composite_Testable extends
|
||||
HTMLPurifier_AttrDef_CSS_Composite
|
||||
{
|
||||
|
||||
// we need to pass by ref to get the mocks in
|
||||
public function __construct(&$defs)
|
||||
{
|
||||
$this->defs =& $defs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
protected $def1, $def2;
|
||||
|
||||
public function test()
|
||||
{
|
||||
generate_mock_once('HTMLPurifier_AttrDef');
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$context = new HTMLPurifier_Context();
|
||||
|
||||
// first test: value properly validates on first definition
|
||||
// so second def is never called
|
||||
|
||||
$def1 = new HTMLPurifier_AttrDefMock();
|
||||
$def2 = new HTMLPurifier_AttrDefMock();
|
||||
$defs = array(&$def1, &$def2);
|
||||
$def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
|
||||
$input = 'FOOBAR';
|
||||
$output = 'foobar';
|
||||
$def1_params = array($input, $config, $context);
|
||||
$def1->expectOnce('validate', $def1_params);
|
||||
$def1->returns('validate', $output, $def1_params);
|
||||
$def2->expectNever('validate');
|
||||
|
||||
$result = $def->validate($input, $config, $context);
|
||||
$this->assertIdentical($output, $result);
|
||||
|
||||
// second test, first def fails, second def works
|
||||
|
||||
$def1 = new HTMLPurifier_AttrDefMock();
|
||||
$def2 = new HTMLPurifier_AttrDefMock();
|
||||
$defs = array(&$def1, &$def2);
|
||||
$def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
|
||||
$input = 'BOOMA';
|
||||
$output = 'booma';
|
||||
$def_params = array($input, $config, $context);
|
||||
$def1->expectOnce('validate', $def_params);
|
||||
$def1->returns('validate', false, $def_params);
|
||||
$def2->expectOnce('validate', $def_params);
|
||||
$def2->returns('validate', $output, $def_params);
|
||||
|
||||
$result = $def->validate($input, $config, $context);
|
||||
$this->assertIdentical($output, $result);
|
||||
|
||||
// third test, all fail, so composite faiils
|
||||
|
||||
$def1 = new HTMLPurifier_AttrDefMock();
|
||||
$def2 = new HTMLPurifier_AttrDefMock();
|
||||
$defs = array(&$def1, &$def2);
|
||||
$def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
|
||||
$input = 'BOOMA';
|
||||
$output = false;
|
||||
$def_params = array($input, $config, $context);
|
||||
$def1->expectOnce('validate', $def_params);
|
||||
$def1->returns('validate', false, $def_params);
|
||||
$def2->expectOnce('validate', $def_params);
|
||||
$def2->returns('validate', false, $def_params);
|
||||
|
||||
$result = $def->validate($input, $config, $context);
|
||||
$this->assertIdentical($output, $result);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
29
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/FilterTest.php
Executable file
29
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/FilterTest.php
Executable file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_FilterTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Filter();
|
||||
|
||||
$this->assertDef('none');
|
||||
|
||||
$this->assertDef('alpha(opacity=0)');
|
||||
$this->assertDef('alpha(opacity=100)');
|
||||
$this->assertDef('alpha(opacity=50)');
|
||||
$this->assertDef('alpha(opacity=342)', 'alpha(opacity=100)');
|
||||
$this->assertDef('alpha(opacity=-23)', 'alpha(opacity=0)');
|
||||
|
||||
$this->assertDef('alpha ( opacity = 0 )', 'alpha(opacity=0)');
|
||||
$this->assertDef('alpha(opacity=0,opacity=100)', 'alpha(opacity=0)');
|
||||
|
||||
$this->assertDef('progid:DXImageTransform.Microsoft.Alpha(opacity=20)');
|
||||
|
||||
$this->assertDef('progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1)', false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
53
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/FontFamilyTest.php
Executable file
53
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/FontFamilyTest.php
Executable file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_FontFamilyTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_FontFamily();
|
||||
|
||||
$this->assertDef('Gill, Helvetica, sans-serif');
|
||||
$this->assertDef("'Times New Roman', serif");
|
||||
$this->assertDef("\"Times New Roman\"", "'Times New Roman'");
|
||||
$this->assertDef('01234');
|
||||
$this->assertDef(',', false);
|
||||
$this->assertDef('Times New Roman, serif', "'Times New Roman', serif");
|
||||
$this->assertDef($d = "'\xE5\xAE\x8B\xE4\xBD\x93'");
|
||||
$this->assertDef("\xE5\xAE\x8B\xE4\xBD\x93", $d);
|
||||
$this->assertDef("'\\01'", "''");
|
||||
$this->assertDef("'\\20'", "' '");
|
||||
$this->assertDef("\\0020", "' '");
|
||||
$this->assertDef("'\\000045'", "E");
|
||||
$this->assertDef("','", false);
|
||||
$this->assertDef("',' foobar','", "' foobar'");
|
||||
$this->assertDef("'\\000045a'", "Ea");
|
||||
$this->assertDef("'\\00045 a'", "Ea");
|
||||
$this->assertDef("'\\00045 a'", "'E a'");
|
||||
$this->assertDef("'\\\nf'", "f");
|
||||
// No longer supported, except maybe in NoJS mode (see source
|
||||
// file for more explanation)
|
||||
//$this->assertDef($d = '"John\'s Font"');
|
||||
//$this->assertDef("John's Font", $d);
|
||||
//$this->assertDef("'\\','f'", "\"\\5C \", f");
|
||||
//$this->assertDef("'\\27'", "\"'\"");
|
||||
//$this->assertDef('"\\22"', "\"\\22 \"");
|
||||
//$this->assertDef('"\\""', "\"\\22 \"");
|
||||
//$this->assertDef('"\'"', "\"'\"");
|
||||
}
|
||||
|
||||
public function testAllowed()
|
||||
{
|
||||
$this->config->set('CSS.AllowedFonts', array('serif', 'Times New Roman'));
|
||||
|
||||
$this->assertDef('serif');
|
||||
$this->assertDef('sans-serif', false);
|
||||
$this->assertDef('serif, sans-serif', 'serif');
|
||||
$this->assertDef('Times New Roman', "'Times New Roman'");
|
||||
$this->assertDef("'Times New Roman'");
|
||||
$this->assertDef('foo', false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
34
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/FontTest.php
Executable file
34
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/FontTest.php
Executable file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_FontTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Font($config);
|
||||
|
||||
// hodgepodge of usage cases from W3C spec, but " -> '
|
||||
$this->assertDef('12px/14px sans-serif');
|
||||
$this->assertDef('80% sans-serif');
|
||||
$this->assertDef("x-large/110% 'New Century Schoolbook', serif");
|
||||
$this->assertDef('bold italic large Palatino, serif');
|
||||
$this->assertDef('normal small-caps 120%/120% fantasy');
|
||||
$this->assertDef("300 italic 1.3em/1.7em 'FB Armada', sans-serif");
|
||||
$this->assertDef('600 9px Charcoal');
|
||||
$this->assertDef('600 9px/ 12px Charcoal', '600 9px/12px Charcoal');
|
||||
|
||||
// spacing
|
||||
$this->assertDef('12px / 14px sans-serif', '12px/14px sans-serif');
|
||||
|
||||
// system fonts
|
||||
$this->assertDef('menu');
|
||||
|
||||
$this->assertDef('800', false);
|
||||
$this->assertDef('600 9px//12px Charcoal', false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_ImportantDecoratorTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
/** Mock AttrDef decorator is wrapping */
|
||||
protected $mock;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
generate_mock_once('HTMLPurifier_AttrDef');
|
||||
$this->mock = new HTMLPurifier_AttrDefMock();
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_ImportantDecorator($this->mock, true);
|
||||
}
|
||||
|
||||
protected function setMock($input, $output = null)
|
||||
{
|
||||
if ($output === null) $output = $input;
|
||||
$this->mock->expectOnce('validate', array($input, $this->config, $this->context));
|
||||
$this->mock->returns('validate', $output);
|
||||
}
|
||||
|
||||
public function testImportant()
|
||||
{
|
||||
$this->setMock('23');
|
||||
$this->assertDef('23 !important');
|
||||
}
|
||||
|
||||
public function testImportantInternalDefChanged()
|
||||
{
|
||||
$this->setMock('23', '24');
|
||||
$this->assertDef('23 !important', '24 !important');
|
||||
}
|
||||
|
||||
public function testImportantWithSpace()
|
||||
{
|
||||
$this->setMock('23');
|
||||
$this->assertDef('23 ! important ', '23 !important');
|
||||
}
|
||||
|
||||
public function testFakeImportant()
|
||||
{
|
||||
$this->setMock('! foo important');
|
||||
$this->assertDef('! foo important');
|
||||
}
|
||||
|
||||
public function testStrip()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_ImportantDecorator($this->mock, false);
|
||||
$this->setMock('23');
|
||||
$this->assertDef('23 ! important ', '23');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
49
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/LengthTest.php
Executable file
49
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/LengthTest.php
Executable file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_LengthTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Length();
|
||||
|
||||
$this->assertDef('0');
|
||||
$this->assertDef('0px');
|
||||
$this->assertDef('4.5px');
|
||||
$this->assertDef('-4.5px');
|
||||
$this->assertDef('3ex');
|
||||
$this->assertDef('3em');
|
||||
$this->assertDef('3in');
|
||||
$this->assertDef('3cm');
|
||||
$this->assertDef('3mm');
|
||||
$this->assertDef('3pt');
|
||||
$this->assertDef('3pc');
|
||||
|
||||
$this->assertDef('3PX', '3px');
|
||||
|
||||
$this->assertDef('3', false);
|
||||
$this->assertDef('3miles', false);
|
||||
|
||||
}
|
||||
|
||||
public function testNonNegative()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Length('0');
|
||||
|
||||
$this->assertDef('3cm');
|
||||
$this->assertDef('-3mm', false);
|
||||
|
||||
}
|
||||
|
||||
public function testBounding()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Length('-1in', '1in');
|
||||
$this->assertDef('1cm');
|
||||
$this->assertDef('-1cm');
|
||||
$this->assertDef('0');
|
||||
$this->assertDef('1em', false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
35
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/ListStyleTest.php
Executable file
35
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/ListStyleTest.php
Executable file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_ListStyleTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_ListStyle($config);
|
||||
|
||||
$this->assertDef('lower-alpha');
|
||||
$this->assertDef('upper-roman inside');
|
||||
$this->assertDef('circle outside');
|
||||
$this->assertDef('inside');
|
||||
$this->assertDef('none');
|
||||
$this->assertDef('url("foo.gif")');
|
||||
$this->assertDef('circle url("foo.gif") inside');
|
||||
|
||||
// invalid values
|
||||
$this->assertDef('outside inside', 'outside');
|
||||
|
||||
// ordering
|
||||
$this->assertDef('url(foo.gif) none', 'none url("foo.gif")');
|
||||
$this->assertDef('circle lower-alpha', 'circle');
|
||||
// the spec is ambiguous about what happens in these
|
||||
// cases, so we're going off the W3C CSS validator
|
||||
$this->assertDef('disc none', 'disc');
|
||||
$this->assertDef('none disc', 'none');
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
29
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/MultipleTest.php
Executable file
29
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/MultipleTest.php
Executable file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
// borrowed for the sakes of this test
|
||||
class HTMLPurifier_AttrDef_CSS_MultipleTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Multiple(
|
||||
new HTMLPurifier_AttrDef_Integer()
|
||||
);
|
||||
|
||||
$this->assertDef('1 2 3 4');
|
||||
$this->assertDef('6');
|
||||
$this->assertDef('4 5');
|
||||
$this->assertDef(' 2 54 2 3', '2 54 2 3');
|
||||
$this->assertDef("6\r3", '6 3');
|
||||
|
||||
$this->assertDef('asdf', false);
|
||||
$this->assertDef('a s d f', false);
|
||||
$this->assertDef('1 2 3 4 5', '1 2 3 4');
|
||||
$this->assertDef('1 2 invalid 3', '1 2 3');
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
51
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/NumberTest.php
Executable file
51
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/NumberTest.php
Executable file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_NumberTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Number();
|
||||
|
||||
$this->assertDef('0');
|
||||
$this->assertDef('0.0', '0');
|
||||
$this->assertDef('1.0', '1');
|
||||
$this->assertDef('34');
|
||||
$this->assertDef('4.5');
|
||||
$this->assertDef('.5');
|
||||
$this->assertDef('0.5', '.5');
|
||||
$this->assertDef('-56.9');
|
||||
|
||||
$this->assertDef('0.', '0');
|
||||
$this->assertDef('.0', '0');
|
||||
$this->assertDef('0.0', '0');
|
||||
|
||||
$this->assertDef('1.', '1');
|
||||
$this->assertDef('.1', '.1');
|
||||
|
||||
$this->assertDef('1.0', '1');
|
||||
$this->assertDef('0.1', '.1');
|
||||
|
||||
$this->assertDef('000', '0');
|
||||
$this->assertDef(' 9', '9');
|
||||
$this->assertDef('+5.0000', '5');
|
||||
$this->assertDef('02.20', '2.2');
|
||||
$this->assertDef('2.', '2');
|
||||
|
||||
$this->assertDef('.', false);
|
||||
$this->assertDef('asdf', false);
|
||||
$this->assertDef('0.5.6', false);
|
||||
|
||||
}
|
||||
|
||||
public function testNonNegative()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Number(true);
|
||||
$this->assertDef('23');
|
||||
$this->assertDef('-12', false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
24
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/PercentageTest.php
Executable file
24
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/PercentageTest.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_PercentageTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_Percentage();
|
||||
|
||||
$this->assertDef('10%');
|
||||
$this->assertDef('1.607%');
|
||||
$this->assertDef('-567%');
|
||||
|
||||
$this->assertDef(' 100% ', '100%');
|
||||
|
||||
$this->assertDef('5', false);
|
||||
$this->assertDef('asdf', false);
|
||||
$this->assertDef('%', false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
27
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/TextDecorationTest.php
Executable file
27
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/TextDecorationTest.php
Executable file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_TextDecorationTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function testCaseInsensitive()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_TextDecoration();
|
||||
|
||||
$this->assertDef('none');
|
||||
$this->assertDef('none underline', 'underline');
|
||||
|
||||
$this->assertDef('underline');
|
||||
$this->assertDef('overline');
|
||||
$this->assertDef('line-through overline underline');
|
||||
$this->assertDef('overline line-through');
|
||||
$this->assertDef('UNDERLINE', 'underline');
|
||||
$this->assertDef(' underline line-through ', 'underline line-through');
|
||||
|
||||
$this->assertDef('foobar underline', 'underline');
|
||||
$this->assertDef('blink', false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
29
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/URITest.php
Executable file
29
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSS/URITest.php
Executable file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSS_URITest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS_URI();
|
||||
|
||||
$this->assertDef('', false);
|
||||
|
||||
// we could be nice but we won't be
|
||||
$this->assertDef('http://www.example.com/', false);
|
||||
|
||||
$this->assertDef('url(', false);
|
||||
$this->assertDef('url("")', true);
|
||||
$result = 'url("http://www.example.com/")';
|
||||
$this->assertDef('url(http://www.example.com/)', $result);
|
||||
$this->assertDef('url("http://www.example.com/")', $result);
|
||||
$this->assertDef("url('http://www.example.com/')", $result);
|
||||
$this->assertDef(
|
||||
' url( "http://www.example.com/" ) ', $result);
|
||||
$this->assertDef("url(http://www.example.com/foo,bar\)\'\()",
|
||||
'url("http://www.example.com/foo,bar%29%27%28")');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
190
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSSTest.php
Executable file
190
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/CSSTest.php
Executable file
@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function setup()
|
||||
{
|
||||
parent::setup();
|
||||
$this->def = new HTMLPurifier_AttrDef_CSS();
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
// regular cases, singular
|
||||
$this->assertDef('text-align:right;');
|
||||
$this->assertDef('border-left-style:solid;');
|
||||
$this->assertDef('border-style:solid dotted;');
|
||||
$this->assertDef('clear:right;');
|
||||
$this->assertDef('float:left;');
|
||||
$this->assertDef('font-style:italic;');
|
||||
$this->assertDef('font-variant:small-caps;');
|
||||
$this->assertDef('font-weight:bold;');
|
||||
$this->assertDef('list-style-position:outside;');
|
||||
$this->assertDef('list-style-type:upper-roman;');
|
||||
$this->assertDef('list-style:upper-roman inside;');
|
||||
$this->assertDef('text-transform:capitalize;');
|
||||
$this->assertDef('background-color:rgb(0,0,255);');
|
||||
$this->assertDef('background-color:transparent;');
|
||||
$this->assertDef('background:#333 url("chess.png") repeat fixed 50% top;');
|
||||
$this->assertDef('background:#333 url("che;ss.png") repeat fixed 50% top;');
|
||||
$this->assertDef('color:#F00;');
|
||||
$this->assertDef('border-top-color:#F00;');
|
||||
$this->assertDef('border-color:#F00 #FF0;');
|
||||
$this->assertDef('border-top-width:thin;');
|
||||
$this->assertDef('border-top-width:12px;');
|
||||
$this->assertDef('border-width:5px 1px 4px 2px;');
|
||||
$this->assertDef('border-top-width:-12px;', false);
|
||||
$this->assertDef('letter-spacing:normal;');
|
||||
$this->assertDef('letter-spacing:2px;');
|
||||
$this->assertDef('word-spacing:normal;');
|
||||
$this->assertDef('word-spacing:3em;');
|
||||
$this->assertDef('font-size:200%;');
|
||||
$this->assertDef('font-size:larger;');
|
||||
$this->assertDef('font-size:12pt;');
|
||||
$this->assertDef('line-height:2;');
|
||||
$this->assertDef('line-height:2em;');
|
||||
$this->assertDef('line-height:20%;');
|
||||
$this->assertDef('line-height:normal;');
|
||||
$this->assertDef('line-height:-20%;', false);
|
||||
$this->assertDef('margin-left:5px;');
|
||||
$this->assertDef('margin-right:20%;');
|
||||
$this->assertDef('margin-top:auto;');
|
||||
$this->assertDef('margin:auto 5%;');
|
||||
$this->assertDef('padding-bottom:5px;');
|
||||
$this->assertDef('padding-top:20%;');
|
||||
$this->assertDef('padding:20% 10%;');
|
||||
$this->assertDef('padding-top:-20%;', false);
|
||||
$this->assertDef('text-indent:3em;');
|
||||
$this->assertDef('text-indent:5%;');
|
||||
$this->assertDef('text-indent:-3em;');
|
||||
$this->assertDef('width:50%;');
|
||||
$this->assertDef('width:50px;');
|
||||
$this->assertDef('width:auto;');
|
||||
$this->assertDef('width:-50px;', false);
|
||||
$this->assertDef('min-width:50%;');
|
||||
$this->assertDef('min-width:50px;');
|
||||
$this->assertDef('min-width:auto;');
|
||||
$this->assertDef('min-width:-50px;', false);
|
||||
$this->assertDef('min-width:50ch;');
|
||||
$this->assertDef('min-width:50rem;');
|
||||
$this->assertDef('min-width:50vw;');
|
||||
$this->assertDef('min-width:-50vw;', false);
|
||||
$this->assertDef('text-decoration:underline;');
|
||||
$this->assertDef('font-family:sans-serif;');
|
||||
$this->assertDef("font-family:Gill, 'Times New Roman', sans-serif;");
|
||||
$this->assertDef('font:12px serif;');
|
||||
$this->assertDef('border:1px solid #000;');
|
||||
$this->assertDef('border-bottom:2em double #FF00FA;');
|
||||
$this->assertDef('border-collapse:collapse;');
|
||||
$this->assertDef('border-collapse:separate;');
|
||||
$this->assertDef('caption-side:top;');
|
||||
$this->assertDef('vertical-align:middle;');
|
||||
$this->assertDef('vertical-align:12px;');
|
||||
$this->assertDef('vertical-align:50%;');
|
||||
$this->assertDef('table-layout:fixed;');
|
||||
$this->assertDef('list-style-image:url("nice.jpg");');
|
||||
$this->assertDef('list-style:disc url("nice.jpg") inside;');
|
||||
$this->assertDef('background-image:url("foo.jpg");');
|
||||
$this->assertDef('background-image:none;');
|
||||
$this->assertDef('background-repeat:repeat-y;');
|
||||
$this->assertDef('background-attachment:fixed;');
|
||||
$this->assertDef('background-position:left 90%;');
|
||||
$this->assertDef('border-spacing:1em;');
|
||||
$this->assertDef('border-spacing:1em 2em;');
|
||||
$this->assertDef('border-color: rgb(0, 0, 0) rgb(10,0,10)', 'border-color:rgb(0,0,0) rgb(10,0,10);');
|
||||
$this->assertDef('border: rgb(0, 0, 0)', 'border:rgb(0,0,0);');
|
||||
|
||||
// duplicates
|
||||
$this->assertDef('text-align:right;text-align:left;',
|
||||
'text-align:left;');
|
||||
|
||||
// a few composites
|
||||
$this->assertDef('font-variant:small-caps;font-weight:900;');
|
||||
$this->assertDef('float:right;text-align:right;');
|
||||
|
||||
// selective removal
|
||||
$this->assertDef('text-transform:capitalize;destroy:it;',
|
||||
'text-transform:capitalize;');
|
||||
|
||||
// inherit works for everything
|
||||
$this->assertDef('text-align:inherit;');
|
||||
|
||||
// bad props
|
||||
$this->assertDef('nodice:foobar;', false);
|
||||
$this->assertDef('position:absolute;', false);
|
||||
$this->assertDef('background-image:url(\'javascript:alert\(\)\');', false);
|
||||
|
||||
// airy input
|
||||
$this->assertDef(' font-weight : bold; color : #ff0000',
|
||||
'font-weight:bold;color:#ff0000;');
|
||||
|
||||
// case-insensitivity
|
||||
$this->assertDef('FLOAT:LEFT;', 'float:left;');
|
||||
|
||||
// !important stripping
|
||||
$this->assertDef('float:left !important;', 'float:left;');
|
||||
|
||||
}
|
||||
|
||||
public function testProprietary()
|
||||
{
|
||||
$this->config->set('CSS.Proprietary', true);
|
||||
|
||||
$this->assertDef('scrollbar-arrow-color:#ff0;');
|
||||
$this->assertDef('scrollbar-base-color:#ff6347;');
|
||||
$this->assertDef('scrollbar-darkshadow-color:#ffa500;');
|
||||
$this->assertDef('scrollbar-face-color:#008080;');
|
||||
$this->assertDef('scrollbar-highlight-color:#ff69b4;');
|
||||
$this->assertDef('scrollbar-shadow-color:#f0f;');
|
||||
|
||||
$this->assertDef('-moz-opacity:.2;');
|
||||
$this->assertDef('-khtml-opacity:.2;');
|
||||
$this->assertDef('filter:alpha(opacity=20);');
|
||||
|
||||
$this->assertDef('border-top-left-radius:55pt 25pt;');
|
||||
|
||||
}
|
||||
|
||||
public function testImportant()
|
||||
{
|
||||
$this->config->set('CSS.AllowImportant', true);
|
||||
$this->assertDef('float:left !important;');
|
||||
}
|
||||
|
||||
public function testTricky()
|
||||
{
|
||||
$this->config->set('CSS.AllowTricky', true);
|
||||
$this->assertDef('display:none;');
|
||||
$this->assertDef('visibility:visible;');
|
||||
$this->assertDef('overflow:scroll;');
|
||||
$this->assertDef('opacity:.2;');
|
||||
}
|
||||
|
||||
public function testForbidden()
|
||||
{
|
||||
$this->config->set('CSS.ForbiddenProperties', 'float');
|
||||
$this->assertDef('float:left;', false);
|
||||
$this->assertDef('text-align:right;');
|
||||
}
|
||||
|
||||
public function testTrusted()
|
||||
{
|
||||
$this->config->set('CSS.Trusted', true);
|
||||
$this->assertDef('position:relative;');
|
||||
$this->assertDef('left:2px;');
|
||||
$this->assertDef('right:100%;');
|
||||
$this->assertDef('top:auto;');
|
||||
$this->assertDef('z-index:-2;');
|
||||
}
|
||||
|
||||
public function testAllowDuplicates()
|
||||
{
|
||||
$this->config->set('CSS.AllowDuplicates', true);
|
||||
$this->assertDef('text-align:right;text-align:left;');
|
||||
$this->assertDef('text-align:right;text-align:left;text-align:right;');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
41
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/EnumTest.php
Executable file
41
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/EnumTest.php
Executable file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_EnumTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function testCaseInsensitive()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_Enum(array('one', 'two'));
|
||||
$this->assertDef('one');
|
||||
$this->assertDef('ONE', 'one');
|
||||
}
|
||||
|
||||
public function testCaseSensitive()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_Enum(array('one', 'two'), true);
|
||||
$this->assertDef('one');
|
||||
$this->assertDef('ONE', false);
|
||||
}
|
||||
|
||||
public function testFixing()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_Enum(array('one'));
|
||||
$this->assertDef(' one ', 'one');
|
||||
}
|
||||
|
||||
public function test_make()
|
||||
{
|
||||
$factory = new HTMLPurifier_AttrDef_Enum();
|
||||
|
||||
$def = $factory->make('foo,bar');
|
||||
$def2 = new HTMLPurifier_AttrDef_Enum(array('foo', 'bar'));
|
||||
$this->assertIdentical($def, $def2);
|
||||
|
||||
$def = $factory->make('s:foo,BAR');
|
||||
$def2 = new HTMLPurifier_AttrDef_Enum(array('foo', 'BAR'), true);
|
||||
$this->assertIdentical($def, $def2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
24
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/BoolTest.php
Executable file
24
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/BoolTest.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_BoolTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_Bool('foo');
|
||||
$this->assertDef('foo');
|
||||
$this->assertDef('', 'foo');
|
||||
$this->assertDef('bar', 'foo');
|
||||
}
|
||||
|
||||
public function test_make()
|
||||
{
|
||||
$factory = new HTMLPurifier_AttrDef_HTML_Bool();
|
||||
$def = $factory->make('foo');
|
||||
$def2 = new HTMLPurifier_AttrDef_HTML_Bool('foo');
|
||||
$this->assertIdentical($def, $def2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
53
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/ClassTest.php
Executable file
53
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/ClassTest.php
Executable file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_ClassTest extends HTMLPurifier_AttrDef_HTML_NmtokensTest
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_Class();
|
||||
}
|
||||
public function testAllowedClasses()
|
||||
{
|
||||
$this->config->set('Attr.AllowedClasses', array('foo'));
|
||||
$this->assertDef('foo');
|
||||
$this->assertDef('bar', false);
|
||||
$this->assertDef('foo bar', 'foo');
|
||||
}
|
||||
public function testForbiddenClasses()
|
||||
{
|
||||
$this->config->set('Attr.ForbiddenClasses', array('bar'));
|
||||
$this->assertDef('foo');
|
||||
$this->assertDef('bar', false);
|
||||
$this->assertDef('foo bar', 'foo');
|
||||
}
|
||||
public function testDefault()
|
||||
{
|
||||
$this->assertDef('valid');
|
||||
$this->assertDef('a0-_');
|
||||
$this->assertDef('-valid');
|
||||
$this->assertDef('_valid');
|
||||
$this->assertDef('double valid');
|
||||
|
||||
$this->assertDef('0stillvalid');
|
||||
$this->assertDef('-0');
|
||||
|
||||
// test conditional replacement
|
||||
$this->assertDef('validassoc 0valid', 'validassoc 0valid');
|
||||
|
||||
// test whitespace leniency
|
||||
$this->assertDef(" double\nvalid\r", 'double valid');
|
||||
|
||||
// test case sensitivity
|
||||
$this->assertDef('VALID');
|
||||
|
||||
// test duplicate removal
|
||||
$this->assertDef('valid valid', 'valid');
|
||||
}
|
||||
public function testXHTML11Behavior()
|
||||
{
|
||||
$this->config->set('HTML.Doctype', 'XHTML 1.1');
|
||||
$this->assertDef('0invalid', false);
|
||||
$this->assertDef('valid valid', 'valid');
|
||||
}
|
||||
}
|
22
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php
Executable file
22
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php
Executable file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_ColorTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_Color();
|
||||
$this->assertDef('', false);
|
||||
$this->assertDef('foo', false);
|
||||
$this->assertDef('43', false);
|
||||
$this->assertDef('red', '#FF0000');
|
||||
$this->assertDef('RED', '#FF0000');
|
||||
$this->assertDef('#FF0000');
|
||||
$this->assertDef('#453443');
|
||||
$this->assertDef('453443', '#453443');
|
||||
$this->assertDef('#345', '#334455');
|
||||
$this->assertDef('120', '#112200');
|
||||
}
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
31
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php
Executable file
31
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php
Executable file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_FrameTargetTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function setup()
|
||||
{
|
||||
parent::setup();
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_FrameTarget();
|
||||
}
|
||||
|
||||
public function testNoneAllowed()
|
||||
{
|
||||
$this->assertDef('', false);
|
||||
$this->assertDef('foo', false);
|
||||
$this->assertDef('_blank', false);
|
||||
$this->assertDef('baz', false);
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->config->set('Attr.AllowedFrameTargets', 'foo,_blank');
|
||||
$this->assertDef('', false);
|
||||
$this->assertDef('foo');
|
||||
$this->assertDef('_blank');
|
||||
$this->assertDef('baz', false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
121
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/IDTest.php
Executable file
121
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/IDTest.php
Executable file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$id_accumulator = new HTMLPurifier_IDAccumulator();
|
||||
$this->context->register('IDAccumulator', $id_accumulator);
|
||||
$this->config->set('Attr.EnableID', true);
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_ID();
|
||||
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
// valid ID names
|
||||
$this->assertDef('alpha');
|
||||
$this->assertDef('al_ha');
|
||||
$this->assertDef('a0-:.');
|
||||
$this->assertDef('a');
|
||||
|
||||
// invalid ID names
|
||||
$this->assertDef('<asa', false);
|
||||
$this->assertDef('0123', false);
|
||||
$this->assertDef('.asa', false);
|
||||
|
||||
// test duplicate detection
|
||||
$this->assertDef('once');
|
||||
$this->assertDef('once', false);
|
||||
|
||||
// valid once whitespace stripped, but needs to be amended
|
||||
$this->assertDef(' whee ', 'whee');
|
||||
|
||||
}
|
||||
|
||||
public function testPrefix()
|
||||
{
|
||||
$this->config->set('Attr.IDPrefix', 'user_');
|
||||
|
||||
$this->assertDef('alpha', 'user_alpha');
|
||||
$this->assertDef('<asa', false);
|
||||
$this->assertDef('once', 'user_once');
|
||||
$this->assertDef('once', false);
|
||||
|
||||
// if already prefixed, leave alone
|
||||
$this->assertDef('user_alas');
|
||||
$this->assertDef('user_user_alas'); // how to bypass
|
||||
|
||||
}
|
||||
|
||||
public function testTwoPrefixes()
|
||||
{
|
||||
$this->config->set('Attr.IDPrefix', 'user_');
|
||||
$this->config->set('Attr.IDPrefixLocal', 'story95_');
|
||||
|
||||
$this->assertDef('alpha', 'user_story95_alpha');
|
||||
$this->assertDef('<asa', false);
|
||||
$this->assertDef('once', 'user_story95_once');
|
||||
$this->assertDef('once', false);
|
||||
|
||||
$this->assertDef('user_story95_alas');
|
||||
$this->assertDef('user_alas', 'user_story95_user_alas'); // !
|
||||
}
|
||||
|
||||
public function testLocalPrefixWithoutMainPrefix()
|
||||
{
|
||||
// no effect when IDPrefix isn't set
|
||||
$this->config->set('Attr.IDPrefix', '');
|
||||
$this->config->set('Attr.IDPrefixLocal', 'story95_');
|
||||
$this->expectError('%Attr.IDPrefixLocal cannot be used unless '.
|
||||
'%Attr.IDPrefix is set');
|
||||
$this->assertDef('amherst');
|
||||
|
||||
}
|
||||
|
||||
// reference functionality is disabled for now
|
||||
public function disabled_testIDReference()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
|
||||
|
||||
$this->assertDef('good_id');
|
||||
$this->assertDef('good_id'); // duplicates okay
|
||||
$this->assertDef('<b>', false);
|
||||
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_ID();
|
||||
|
||||
$this->assertDef('good_id');
|
||||
$this->assertDef('good_id', false); // duplicate now not okay
|
||||
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
|
||||
|
||||
$this->assertDef('good_id'); // reference still okay
|
||||
|
||||
}
|
||||
|
||||
public function testRegexp()
|
||||
{
|
||||
$this->config->set('Attr.IDBlacklistRegexp', '/^g_/');
|
||||
|
||||
$this->assertDef('good_id');
|
||||
$this->assertDef('g_bad_id', false);
|
||||
|
||||
}
|
||||
|
||||
public function testRelaxed()
|
||||
{
|
||||
$this->config->set('Attr.ID.HTML5', true);
|
||||
|
||||
$this->assertDef('123');
|
||||
$this->assertDef('x[1]');
|
||||
$this->assertDef('not ok', false);
|
||||
$this->assertDef(' ', false);
|
||||
$this->assertDef('', false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
33
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/LengthTest.php
Executable file
33
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/LengthTest.php
Executable file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_LengthTest extends HTMLPurifier_AttrDef_HTML_PixelsTest
|
||||
{
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_Length();
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
// pixel check
|
||||
parent::test();
|
||||
|
||||
// percent check
|
||||
$this->assertDef('25%');
|
||||
|
||||
// Firefox maintains percent, so will we
|
||||
$this->assertDef('0%');
|
||||
|
||||
// 0% <= percent <= 100%
|
||||
$this->assertDef('-15%', '0%');
|
||||
$this->assertDef('120%', '100%');
|
||||
|
||||
// fractional percents, apparently, aren't allowed
|
||||
$this->assertDef('56.5%', '56%');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
21
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php
Executable file
21
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php
Executable file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_LinkTypesTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function testNull()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_LinkTypes('rel');
|
||||
$this->config->set('Attr.AllowedRel', array('nofollow', 'foo'));
|
||||
|
||||
$this->assertDef('', false);
|
||||
$this->assertDef('nofollow', true);
|
||||
$this->assertDef('nofollow foo', true);
|
||||
$this->assertDef('nofollow bar', 'nofollow');
|
||||
$this->assertDef('bar', false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
29
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/MultiLengthTest.php
Executable file
29
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/MultiLengthTest.php
Executable file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_MultiLengthTest extends HTMLPurifier_AttrDef_HTML_LengthTest
|
||||
{
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_MultiLength();
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
// length check
|
||||
parent::test();
|
||||
|
||||
$this->assertDef('*');
|
||||
$this->assertDef('1*', '*');
|
||||
$this->assertDef('56*');
|
||||
|
||||
$this->assertDef('**', false); // plain old bad
|
||||
|
||||
$this->assertDef('5.4*', '5*'); // no decimals
|
||||
$this->assertDef('-3*', false); // no negatives
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
36
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php
Executable file
36
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php
Executable file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_NmtokensTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_Nmtokens();
|
||||
}
|
||||
|
||||
public function testDefault()
|
||||
{
|
||||
$this->assertDef('valid');
|
||||
$this->assertDef('a0-_');
|
||||
$this->assertDef('-valid');
|
||||
$this->assertDef('_valid');
|
||||
$this->assertDef('double valid');
|
||||
|
||||
$this->assertDef('0invalid', false);
|
||||
$this->assertDef('-0', false);
|
||||
|
||||
// test conditional replacement
|
||||
$this->assertDef('validassoc 0invalid', 'validassoc');
|
||||
|
||||
// test whitespace leniency
|
||||
$this->assertDef(" double\nvalid\r", 'double valid');
|
||||
|
||||
// test case sensitivity
|
||||
$this->assertDef('VALID');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
47
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php
Executable file
47
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php
Executable file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_PixelsTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_Pixels();
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->assertDef('1');
|
||||
$this->assertDef('0');
|
||||
|
||||
$this->assertDef('2px', '2'); // rm px suffix
|
||||
|
||||
$this->assertDef('dfs', false); // totally invalid value
|
||||
|
||||
// conceivably we could repair this value, but we won't for now
|
||||
$this->assertDef('9in', false);
|
||||
|
||||
// test trim
|
||||
$this->assertDef(' 45 ', '45');
|
||||
|
||||
// no negatives
|
||||
$this->assertDef('-2', '0');
|
||||
|
||||
// remove empty
|
||||
$this->assertDef('', false);
|
||||
|
||||
// round down
|
||||
$this->assertDef('4.9', '4');
|
||||
|
||||
}
|
||||
|
||||
public function test_make()
|
||||
{
|
||||
$factory = new HTMLPurifier_AttrDef_HTML_Pixels();
|
||||
$this->def = $factory->make('30');
|
||||
$this->assertDef('25');
|
||||
$this->assertDef('35', '30');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
62
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/IntegerTest.php
Executable file
62
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/IntegerTest.php
Executable file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_IntegerTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_Integer();
|
||||
|
||||
$this->assertDef('0');
|
||||
$this->assertDef('1');
|
||||
$this->assertDef('-1');
|
||||
$this->assertDef('-10');
|
||||
$this->assertDef('14');
|
||||
$this->assertDef('+24', '24');
|
||||
$this->assertDef(' 14 ', '14');
|
||||
$this->assertDef('-0', '0');
|
||||
|
||||
$this->assertDef('-1.4', false);
|
||||
$this->assertDef('3.4', false);
|
||||
$this->assertDef('asdf', false); // must not return zero
|
||||
$this->assertDef('2in', false); // must not return zero
|
||||
|
||||
}
|
||||
|
||||
public function assertRange($negative, $zero, $positive)
|
||||
{
|
||||
$this->assertDef('-100', $negative);
|
||||
$this->assertDef('-1', $negative);
|
||||
$this->assertDef('0', $zero);
|
||||
$this->assertDef('1', $positive);
|
||||
$this->assertDef('42', $positive);
|
||||
}
|
||||
|
||||
public function testRange()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_Integer(false);
|
||||
$this->assertRange(false, true, true); // non-negative
|
||||
|
||||
$this->def = new HTMLPurifier_AttrDef_Integer(false, false);
|
||||
$this->assertRange(false, false, true); // positive
|
||||
|
||||
|
||||
// fringe cases
|
||||
|
||||
$this->def = new HTMLPurifier_AttrDef_Integer(false, false, false);
|
||||
$this->assertRange(false, false, false); // allow none
|
||||
|
||||
$this->def = new HTMLPurifier_AttrDef_Integer(true, false, false);
|
||||
$this->assertRange(true, false, false); // negative
|
||||
|
||||
$this->def = new HTMLPurifier_AttrDef_Integer(false, true, false);
|
||||
$this->assertRange(false, true, false); // zero
|
||||
|
||||
$this->def = new HTMLPurifier_AttrDef_Integer(true, true, false);
|
||||
$this->assertRange(true, true, false); // non-positive
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
85
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/LangTest.php
Executable file
85
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/LangTest.php
Executable file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_LangTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_Lang();
|
||||
|
||||
// basic good uses
|
||||
$this->assertDef('en');
|
||||
$this->assertDef('en-us');
|
||||
|
||||
$this->assertDef(' en ', 'en'); // trim
|
||||
$this->assertDef('EN', 'en'); // case insensitivity
|
||||
|
||||
// (thanks Eugen Pankratz for noticing the typos!)
|
||||
$this->assertDef('En-Us-Edison', 'en-us-edison'); // complex ci
|
||||
|
||||
$this->assertDef('fr en', false); // multiple languages
|
||||
$this->assertDef('%', false); // bad character
|
||||
|
||||
// test overlong language according to syntax
|
||||
$this->assertDef('thisistoolongsoitgetscut', false);
|
||||
|
||||
// primary subtag rules
|
||||
// I'm somewhat hesitant to allow x and i as primary language codes,
|
||||
// because they usually are never used in real life. However,
|
||||
// theoretically speaking, having them alone is permissable, so
|
||||
// I'll be lenient. No XML parser is going to complain anyway.
|
||||
$this->assertDef('x');
|
||||
$this->assertDef('i');
|
||||
// real world use-cases
|
||||
$this->assertDef('x-klingon');
|
||||
$this->assertDef('i-mingo');
|
||||
// because the RFC only defines two and three letter primary codes,
|
||||
// anything with a length of four or greater is invalid, despite
|
||||
// the syntax stipulation of 1 to 8 characters. Because the RFC
|
||||
// specifically states that this reservation is in order to allow
|
||||
// for future versions to expand, the adoption of a new RFC will
|
||||
// require these test cases to be rewritten, even if backwards-
|
||||
// compatibility is largely retained (i.e. this is not forwards
|
||||
// compatible)
|
||||
$this->assertDef('four', false);
|
||||
// for similar reasons, disallow any other one character language
|
||||
$this->assertDef('f', false);
|
||||
|
||||
// second subtag rules
|
||||
// one letter subtags prohibited until revision. This is, however,
|
||||
// less volatile than the restrictions on the primary subtags.
|
||||
// Also note that this test-case tests fix-behavior: chop
|
||||
// off subtags until you get a valid language code.
|
||||
$this->assertDef('en-a', 'en');
|
||||
// however, x is a reserved single-letter subtag that is allowed
|
||||
$this->assertDef('en-x', 'en-x');
|
||||
// 2-8 chars are permitted, but have special meaning that cannot
|
||||
// be checked without maintaining country code lookup tables (for
|
||||
// two characters) or special registration tables (for all above).
|
||||
$this->assertDef('en-uk', true);
|
||||
|
||||
// further subtag rules: only syntactic constraints
|
||||
$this->assertDef('en-us-edison');
|
||||
$this->assertDef('en-us-toolonghaha', 'en-us');
|
||||
$this->assertDef('en-us-a-silly-long-one');
|
||||
|
||||
// rfc 3066 stipulates that if a three letter and a two letter code
|
||||
// are available, the two letter one MUST be used. Without a language
|
||||
// code lookup table, we cannot implement this functionality.
|
||||
|
||||
// although the HTML protocol, technically speaking, allows you to
|
||||
// omit language tags, this implicitly means that the parent element's
|
||||
// language is the one applicable, which, in some cases, is incorrect.
|
||||
// Thus, we allow und, only slightly defying the RFC's SHOULD NOT
|
||||
// designation.
|
||||
$this->assertDef('und');
|
||||
|
||||
// because attributes only allow one language, mul is allowed, complying
|
||||
// with the RFC's SHOULD NOT designation.
|
||||
$this->assertDef('mul');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
37
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/SwitchTest.php
Executable file
37
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/SwitchTest.php
Executable file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_SwitchTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
protected $with, $without;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
generate_mock_once('HTMLPurifier_AttrDef');
|
||||
$this->with = new HTMLPurifier_AttrDefMock();
|
||||
$this->without = new HTMLPurifier_AttrDefMock();
|
||||
$this->def = new HTMLPurifier_AttrDef_Switch('tag', $this->with, $this->without);
|
||||
}
|
||||
|
||||
public function testWith()
|
||||
{
|
||||
$token = new HTMLPurifier_Token_Start('tag');
|
||||
$this->context->register('CurrentToken', $token);
|
||||
$this->with->expectOnce('validate');
|
||||
$this->with->returns('validate', 'foo');
|
||||
$this->assertDef('bar', 'foo');
|
||||
}
|
||||
|
||||
public function testWithout()
|
||||
{
|
||||
$token = new HTMLPurifier_Token_Start('other-tag');
|
||||
$this->context->register('CurrentToken', $token);
|
||||
$this->without->expectOnce('validate');
|
||||
$this->without->returns('validate', 'foo');
|
||||
$this->assertDef('bar', 'foo');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
17
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/TextTest.php
Executable file
17
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/TextTest.php
Executable file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_TextTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_Text();
|
||||
|
||||
$this->assertDef('This is spiffy text!');
|
||||
$this->assertDef(" Casual\tCDATA parse\ncheck. ", 'Casual CDATA parse check.');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
14
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/URI/Email/SimpleCheckTest.php
Executable file
14
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/URI/Email/SimpleCheckTest.php
Executable file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_URI_Email_SimpleCheckTest
|
||||
extends HTMLPurifier_AttrDef_URI_EmailHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_URI_Email_SimpleCheck();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
32
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/URI/EmailHarness.php
Executable file
32
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/URI/EmailHarness.php
Executable file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_URI_EmailHarness extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
/**
|
||||
* Tests common email strings that are obviously pass/fail
|
||||
*/
|
||||
public function testCore()
|
||||
{
|
||||
$this->assertDef('bob@example.com');
|
||||
$this->assertDef(' bob@example.com ', 'bob@example.com');
|
||||
$this->assertDef('bob.thebuilder@example.net');
|
||||
$this->assertDef('Bob_the_Builder-the-2nd@example.org');
|
||||
$this->assertDef('Bob%20the%20Builder@white-space.test');
|
||||
|
||||
// extended format, with real name
|
||||
//$this->assertDef('Bob%20Builder%20%3Cbobby.bob.bob@it.is.example.com%3E');
|
||||
//$this->assertDef('Bob Builder <bobby.bob.bob@it.is.example.com>');
|
||||
|
||||
// time to fail
|
||||
$this->assertDef('bob', false);
|
||||
$this->assertDef('bob@home@work', false);
|
||||
$this->assertDef('@example.com', false);
|
||||
$this->assertDef('bob@', false);
|
||||
$this->assertDef('', false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
64
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/URI/HostTest.php
Executable file
64
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/URI/HostTest.php
Executable file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
// takes a URI formatted host and validates it
|
||||
|
||||
|
||||
class HTMLPurifier_AttrDef_URI_HostTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_URI_Host();
|
||||
|
||||
$this->assertDef('[2001:DB8:0:0:8:800:200C:417A]'); // IPv6
|
||||
$this->assertDef('124.15.6.89'); // IPv4
|
||||
$this->assertDef('www.google.com'); // reg-name
|
||||
|
||||
// more domain name tests
|
||||
$this->assertDef('test.');
|
||||
$this->assertDef('sub.test.');
|
||||
$this->assertDef('.test', false);
|
||||
$this->assertDef('ff');
|
||||
$this->assertDef('1f'); // per RFC 1123
|
||||
// See also http://serverfault.com/questions/638260/is-it-valid-for-a-hostname-to-start-with-a-digit
|
||||
$this->assertDef('-f', false);
|
||||
$this->assertDef('f1');
|
||||
$this->assertDef('f-', false);
|
||||
$this->assertDef('sub.ff');
|
||||
$this->assertDef('sub.1f'); // per RFC 1123
|
||||
$this->assertDef('sub.-f', false);
|
||||
$this->assertDef('sub.f1');
|
||||
$this->assertDef('sub.f-', false);
|
||||
$this->assertDef('ff.top');
|
||||
$this->assertDef('1f.top');
|
||||
$this->assertDef('-f.top', false);
|
||||
$this->assertDef('ff.top');
|
||||
$this->assertDef('f1.top');
|
||||
$this->assertDef('f1_f2.ex.top', false);
|
||||
$this->assertDef('f-.top', false);
|
||||
$this->assertDef('1a');
|
||||
|
||||
$this->assertDef("\xE4\xB8\xAD\xE6\x96\x87.com.cn", 'xn--fiq228c.com.cn', true);
|
||||
|
||||
}
|
||||
|
||||
public function testIDNA()
|
||||
{
|
||||
if (!$GLOBALS['HTMLPurifierTest']['Net_IDNA2'] && !function_exists("idn_to_ascii")) {
|
||||
return false;
|
||||
}
|
||||
$this->config->set('Core.EnableIDNA', true);
|
||||
$this->assertDef("\xE4\xB8\xAD\xE6\x96\x87.com.cn", "xn--fiq228c.com.cn");
|
||||
$this->assertDef("faß.de", "xn--fa-hia.de");
|
||||
$this->assertDef("\xe2\x80\x85.com", false); // rejected
|
||||
}
|
||||
|
||||
function testAllowUnderscore() {
|
||||
$this->config->set('Core.AllowHostnameUnderscore', true);
|
||||
$this->assertDef("foo_bar.example.com");
|
||||
$this->assertDef("foo_.example.com", false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
25
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/URI/IPv4Test.php
Executable file
25
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/URI/IPv4Test.php
Executable file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
// IPv4 test case is spliced from Feyd's IPv6 implementation
|
||||
// we ought to disallow non-routable addresses
|
||||
|
||||
class HTMLPurifier_AttrDef_URI_IPv4Test extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_URI_IPv4();
|
||||
|
||||
$this->assertDef('127.0.0.1'); // standard IPv4, loopback, non-routable
|
||||
$this->assertDef('0.0.0.0'); // standard IPv4, unspecified, non-routable
|
||||
$this->assertDef('255.255.255.255'); // standard IPv4
|
||||
|
||||
$this->assertDef('300.0.0.0', false); // standard IPv4, out of range
|
||||
$this->assertDef('124.15.6.89/60', false); // standard IPv4, prefix not allowed
|
||||
|
||||
$this->assertDef('', false); // nothing
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
43
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/URI/IPv6Test.php
Executable file
43
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/URI/IPv6Test.php
Executable file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
// test case is from Feyd's IPv6 implementation
|
||||
// we ought to disallow non-routable addresses
|
||||
|
||||
class HTMLPurifier_AttrDef_URI_IPv6Test extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_URI_IPv6();
|
||||
|
||||
$this->assertDef('2001:DB8:0:0:8:800:200C:417A'); // unicast, full
|
||||
$this->assertDef('FF01:0:0:0:0:0:0:101'); // multicast, full
|
||||
$this->assertDef('0:0:0:0:0:0:0:1'); // loopback, full
|
||||
$this->assertDef('0:0:0:0:0:0:0:0'); // unspecified, full
|
||||
$this->assertDef('2001:DB8::8:800:200C:417A'); // unicast, compressed
|
||||
$this->assertDef('FF01::101'); // multicast, compressed
|
||||
|
||||
$this->assertDef('::1'); // loopback, compressed, non-routable
|
||||
$this->assertDef('::'); // unspecified, compressed, non-routable
|
||||
$this->assertDef('0:0:0:0:0:0:13.1.68.3'); // IPv4-compatible IPv6 address, full, deprecated
|
||||
$this->assertDef('0:0:0:0:0:FFFF:129.144.52.38'); // IPv4-mapped IPv6 address, full
|
||||
$this->assertDef('::13.1.68.3'); // IPv4-compatible IPv6 address, compressed, deprecated
|
||||
$this->assertDef('::FFFF:129.144.52.38'); // IPv4-mapped IPv6 address, compressed
|
||||
$this->assertDef('2001:0DB8:0000:CD30:0000:0000:0000:0000/60'); // full, with prefix
|
||||
$this->assertDef('2001:0DB8::CD30:0:0:0:0/60'); // compressed, with prefix
|
||||
$this->assertDef('2001:0DB8:0:CD30::/60'); // compressed, with prefix #2
|
||||
$this->assertDef('::/128'); // compressed, unspecified address type, non-routable
|
||||
$this->assertDef('::1/128'); // compressed, loopback address type, non-routable
|
||||
$this->assertDef('FF00::/8'); // compressed, multicast address type
|
||||
$this->assertDef('FE80::/10'); // compressed, link-local unicast, non-routable
|
||||
$this->assertDef('FEC0::/10'); // compressed, site-local unicast, deprecated
|
||||
|
||||
$this->assertDef('2001:DB8:0:0:8:800:200C:417A:221', false); // unicast, full
|
||||
$this->assertDef('FF01::101::2', false); //multicast, compressed
|
||||
$this->assertDef('', false); // nothing
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
168
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/URITest.php
Executable file
168
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDef/URITest.php
Executable file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @todo Aim for complete code coverage with mocks
|
||||
*/
|
||||
class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_URI();
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testIntegration()
|
||||
{
|
||||
$this->assertDef('http://www.google.com/');
|
||||
$this->assertDef('http:', '');
|
||||
$this->assertDef('http:/foo', '/foo');
|
||||
$this->assertDef('javascript:bad_stuff();', false);
|
||||
$this->assertDef('ftp://www.example.com/');
|
||||
$this->assertDef('news:rec.alt');
|
||||
$this->assertDef('nntp://news.example.com/324234');
|
||||
$this->assertDef('mailto:bob@example.com');
|
||||
$this->assertDef('tel:+15555555555');
|
||||
}
|
||||
|
||||
public function testIntegrationWithPercentEncoder()
|
||||
{
|
||||
$this->assertDef(
|
||||
'http://www.example.com/%56%fc%GJ%5%FC',
|
||||
'http://www.example.com/V%FC%25GJ%255%FC'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPercentEncoding()
|
||||
{
|
||||
$this->assertDef(
|
||||
'http:colon:mercenary',
|
||||
'colon%3Amercenary'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPercentEncodingPreserve()
|
||||
{
|
||||
$this->assertDef(
|
||||
'http://www.example.com/abcABC123-_.!~*()\''
|
||||
);
|
||||
}
|
||||
|
||||
public function testEmbeds()
|
||||
{
|
||||
$this->def = new HTMLPurifier_AttrDef_URI(true);
|
||||
$this->assertDef('http://sub.example.com/alas?foo=asd');
|
||||
$this->assertDef('mailto:foo@example.com', false);
|
||||
}
|
||||
|
||||
public function testConfigMunge()
|
||||
{
|
||||
$this->config->set('URI.Munge', 'http://www.google.com/url?q=%s');
|
||||
$this->assertDef(
|
||||
'http://www.example.com/',
|
||||
'http://www.google.com/url?q=http%3A%2F%2Fwww.example.com%2F'
|
||||
);
|
||||
$this->assertDef('index.html');
|
||||
$this->assertDef('javascript:foobar();', false);
|
||||
}
|
||||
|
||||
public function testDefaultSchemeRemovedInBlank()
|
||||
{
|
||||
$this->assertDef('http:', '');
|
||||
}
|
||||
|
||||
public function testDefaultSchemeRemovedInRelativeURI()
|
||||
{
|
||||
$this->assertDef('http:/foo/bar', '/foo/bar');
|
||||
}
|
||||
|
||||
public function testDefaultSchemeNotRemovedInAbsoluteURI()
|
||||
{
|
||||
$this->assertDef('http://example.com/foo/bar');
|
||||
}
|
||||
|
||||
public function testDefaultSchemeNull()
|
||||
{
|
||||
$this->config->set('URI.DefaultScheme', null);
|
||||
$this->assertDef('foo', false);
|
||||
}
|
||||
|
||||
public function testAltSchemeNotRemoved()
|
||||
{
|
||||
$this->assertDef('mailto:this-looks-like-a-path@example.com');
|
||||
}
|
||||
|
||||
public function testResolveNullSchemeAmbiguity()
|
||||
{
|
||||
$this->assertDef('///foo', '/foo');
|
||||
}
|
||||
|
||||
public function testResolveNullSchemeDoubleAmbiguity()
|
||||
{
|
||||
$this->config->set('URI.Host', 'example.com');
|
||||
$this->assertDef('////foo', '//example.com//foo');
|
||||
}
|
||||
|
||||
public function testURIDefinitionValidation()
|
||||
{
|
||||
$parser = new HTMLPurifier_URIParser();
|
||||
$uri = $parser->parse('http://example.com');
|
||||
$this->config->set('URI.DefinitionID', 'HTMLPurifier_AttrDef_URITest->testURIDefinitionValidation');
|
||||
|
||||
generate_mock_once('HTMLPurifier_URIDefinition');
|
||||
$uri_def = new HTMLPurifier_URIDefinitionMock();
|
||||
$uri_def->expectOnce('filter', array($uri, '*', '*'));
|
||||
$uri_def->returns('filter', true, array($uri, '*', '*'));
|
||||
$uri_def->expectOnce('postFilter', array($uri, '*', '*'));
|
||||
$uri_def->returns('postFilter', true, array($uri, '*', '*'));
|
||||
$uri_def->setup = true;
|
||||
|
||||
// Since definitions are no longer passed by reference, we need
|
||||
// to muck around with the cache to insert our mock. This is
|
||||
// technically a little bad, since the cache shouldn't change
|
||||
// behavior, but I don't feel too good about letting users
|
||||
// overload entire definitions.
|
||||
generate_mock_once('HTMLPurifier_DefinitionCache');
|
||||
$cache_mock = new HTMLPurifier_DefinitionCacheMock();
|
||||
$cache_mock->returns('get', $uri_def);
|
||||
|
||||
generate_mock_once('HTMLPurifier_DefinitionCacheFactory');
|
||||
$factory_mock = new HTMLPurifier_DefinitionCacheFactoryMock();
|
||||
$old = HTMLPurifier_DefinitionCacheFactory::instance();
|
||||
HTMLPurifier_DefinitionCacheFactory::instance($factory_mock);
|
||||
$factory_mock->returns('create', $cache_mock);
|
||||
|
||||
$this->assertDef('http://example.com');
|
||||
|
||||
HTMLPurifier_DefinitionCacheFactory::instance($old);
|
||||
}
|
||||
|
||||
public function test_make()
|
||||
{
|
||||
$factory = new HTMLPurifier_AttrDef_URI();
|
||||
$def = $factory->make('');
|
||||
$def2 = new HTMLPurifier_AttrDef_URI();
|
||||
$this->assertIdentical($def, $def2);
|
||||
|
||||
$def = $factory->make('embedded');
|
||||
$def2 = new HTMLPurifier_AttrDef_URI(true);
|
||||
$this->assertIdentical($def, $def2);
|
||||
}
|
||||
|
||||
/*
|
||||
public function test_validate_configWhitelist()
|
||||
{
|
||||
$this->config->set('URI.HostPolicy', 'DenyAll');
|
||||
$this->config->set('URI.HostWhitelist', array(null, 'google.com'));
|
||||
|
||||
$this->assertDef('http://example.com/fo/google.com', false);
|
||||
$this->assertDef('server.txt');
|
||||
$this->assertDef('ftp://www.google.com/?t=a');
|
||||
$this->assertDef('http://google.com.tricky.spamsite.net', false);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
33
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDefHarness.php
Executable file
33
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDefHarness.php
Executable file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDefHarness extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
protected $def;
|
||||
protected $context, $config;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = HTMLPurifier_Config::createDefault();
|
||||
$this->context = new HTMLPurifier_Context();
|
||||
}
|
||||
|
||||
// cannot be used for accumulator
|
||||
public function assertDef($string, $expect = true, $or_false = false)
|
||||
{
|
||||
// $expect can be a string or bool
|
||||
$result = $this->def->validate($string, $this->config, $this->context);
|
||||
if ($expect === true) {
|
||||
if (!($or_false && $result === false)) {
|
||||
$this->assertIdentical($string, $result);
|
||||
}
|
||||
} else {
|
||||
if (!($or_false && $result === false)) {
|
||||
$this->assertIdentical($expect, $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
32
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDefTest.php
Executable file
32
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrDefTest.php
Executable file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
Mock::generatePartial(
|
||||
'HTMLPurifier_AttrDef',
|
||||
'HTMLPurifier_AttrDefTestable',
|
||||
array('validate'));
|
||||
|
||||
class HTMLPurifier_AttrDefTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
public function test_parseCDATA()
|
||||
{
|
||||
$def = new HTMLPurifier_AttrDefTestable();
|
||||
|
||||
$this->assertIdentical('', $def->parseCDATA(''));
|
||||
$this->assertIdentical('', $def->parseCDATA("\t\n\r \t\t"));
|
||||
$this->assertIdentical('foo', $def->parseCDATA("\t\n\r foo\t\t"));
|
||||
$this->assertIdentical('translate to space', $def->parseCDATA("translate\nto\tspace"));
|
||||
|
||||
}
|
||||
|
||||
public function test_make()
|
||||
{
|
||||
$def = new HTMLPurifier_AttrDefTestable();
|
||||
$def2 = $def->make('');
|
||||
$this->assertIdentical($def, $def2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
45
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/BackgroundTest.php
Executable file
45
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/BackgroundTest.php
Executable file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransform_BackgroundTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_Background();
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
public function testBasicTransform()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('background' => 'logo.png'),
|
||||
array('style' => 'background-image:url(logo.png);')
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrependNewCSS()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('background' => 'logo.png', 'style' => 'font-weight:bold'),
|
||||
array('style' => 'background-image:url(logo.png);font-weight:bold')
|
||||
);
|
||||
}
|
||||
|
||||
public function testLenientTreatmentOfInvalidInput()
|
||||
{
|
||||
// notice that we rely on the CSS validator later to fix this invalid
|
||||
// stuff
|
||||
$this->assertResult(
|
||||
array('background' => 'logo.png);foo:('),
|
||||
array('style' => 'background-image:url(logo.png);foo:();')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
34
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/BdoDirTest.php
Executable file
34
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/BdoDirTest.php
Executable file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransform_BdoDirTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_BdoDir();
|
||||
}
|
||||
|
||||
public function testAddDefaultDir()
|
||||
{
|
||||
$this->assertResult( array(), array('dir' => 'ltr') );
|
||||
}
|
||||
|
||||
public function testPreserveExistingDir()
|
||||
{
|
||||
$this->assertResult( array('dir' => 'rtl') );
|
||||
}
|
||||
|
||||
public function testAlternateDefault()
|
||||
{
|
||||
$this->config->set('Attr.DefaultTextDir', 'rtl');
|
||||
$this->assertResult(
|
||||
array(),
|
||||
array('dir' => 'rtl')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
49
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/BgColorTest.php
Executable file
49
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/BgColorTest.php
Executable file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
// we currently rely on the CSS validator to fix any problems.
|
||||
// This means that this transform, strictly speaking, supports
|
||||
// a superset of the functionality.
|
||||
|
||||
class HTMLPurifier_AttrTransform_BgColorTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_BgColor();
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
public function testBasicTransform()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('bgcolor' => '#000000'),
|
||||
array('style' => 'background-color:#000000;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrependNewCSS()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('bgcolor' => '#000000', 'style' => 'font-weight:bold'),
|
||||
array('style' => 'background-color:#000000;font-weight:bold')
|
||||
);
|
||||
}
|
||||
|
||||
public function testLenientTreatmentOfInvalidInput()
|
||||
{
|
||||
// this may change when we natively support the datatype and
|
||||
// validate its contents before forwarding it on
|
||||
$this->assertResult(
|
||||
array('bgcolor' => '#F00'),
|
||||
array('style' => 'background-color:#F00;')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
43
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/BoolToCSSTest.php
Executable file
43
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/BoolToCSSTest.php
Executable file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransform_BoolToCSSTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_BoolToCSS('foo', 'bar:3in;');
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
public function testBasicTransform()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('foo' => 'foo'),
|
||||
array('style' => 'bar:3in;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testIgnoreValueOfBooleanAttribute()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('foo' => 'no'),
|
||||
array('style' => 'bar:3in;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrependCSS()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('foo' => 'foo', 'style' => 'background-color:#F00;'),
|
||||
array('style' => 'bar:3in;background-color:#F00;')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
43
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/BorderTest.php
Executable file
43
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/BorderTest.php
Executable file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransform_BorderTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_Border();
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
public function testBasicTransform()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('border' => '1'),
|
||||
array('style' => 'border:1px solid;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testLenientTreatmentOfInvalidInput()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('border' => '10%'),
|
||||
array('style' => 'border:10%px solid;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrependNewCSS()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('border' => '23', 'style' => 'font-weight:bold;'),
|
||||
array('style' => 'border:23px solid;font-weight:bold;')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
82
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/EnumToCSSTest.php
Executable file
82
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/EnumToCSSTest.php
Executable file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'left' => 'text-align:left;',
|
||||
'right' => 'text-align:right;'
|
||||
));
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
public function testPreserveArraysWithoutInterestingAttributes()
|
||||
{
|
||||
$this->assertResult( array('style' => 'font-weight:bold;') );
|
||||
}
|
||||
|
||||
public function testConvertAlignLeft()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('align' => 'left'),
|
||||
array('style' => 'text-align:left;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testConvertAlignRight()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('align' => 'right'),
|
||||
array('style' => 'text-align:right;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testRemoveInvalidAlign()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('align' => 'invalid'),
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrependNewCSS()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('align' => 'left', 'style' => 'font-weight:bold;'),
|
||||
array('style' => 'text-align:left;font-weight:bold;')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function testCaseInsensitive()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'right' => 'text-align:right;'
|
||||
));
|
||||
$this->assertResult(
|
||||
array('align' => 'RIGHT'),
|
||||
array('style' => 'text-align:right;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testCaseSensitive()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'right' => 'text-align:right;'
|
||||
), true);
|
||||
$this->assertResult(
|
||||
array('align' => 'RIGHT'),
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
61
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php
Executable file
61
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php
Executable file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_ImgRequired();
|
||||
}
|
||||
|
||||
public function testAddMissingAttr()
|
||||
{
|
||||
$this->config->set('Core.RemoveInvalidImg', false);
|
||||
$this->assertResult(
|
||||
array(),
|
||||
array('src' => '', 'alt' => 'Invalid image')
|
||||
);
|
||||
}
|
||||
|
||||
public function testAlternateDefaults()
|
||||
{
|
||||
$this->config->set('Attr.DefaultInvalidImage', 'blank.png');
|
||||
$this->config->set('Attr.DefaultInvalidImageAlt', 'Pawned!');
|
||||
$this->config->set('Attr.DefaultImageAlt', 'not pawned');
|
||||
$this->config->set('Core.RemoveInvalidImg', false);
|
||||
$this->assertResult(
|
||||
array(),
|
||||
array('src' => 'blank.png', 'alt' => 'Pawned!')
|
||||
);
|
||||
}
|
||||
|
||||
public function testGenerateAlt()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('src' => '/path/to/foobar.png'),
|
||||
array('src' => '/path/to/foobar.png', 'alt' => 'foobar.png')
|
||||
);
|
||||
}
|
||||
|
||||
public function testAddDefaultSrc()
|
||||
{
|
||||
$this->config->set('Core.RemoveInvalidImg', false);
|
||||
$this->assertResult(
|
||||
array('alt' => 'intrigue'),
|
||||
array('alt' => 'intrigue', 'src' => '')
|
||||
);
|
||||
}
|
||||
|
||||
public function testAddDefaultAlt()
|
||||
{
|
||||
$this->config->set('Attr.DefaultImageAlt', 'default');
|
||||
$this->assertResult(
|
||||
array('src' => ''),
|
||||
array('src' => '', 'alt' => 'default')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
62
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/ImgSpaceTest.php
Executable file
62
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/ImgSpaceTest.php
Executable file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransform_ImgSpaceTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('vspace');
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
public function testVerticalBasicUsage()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('vspace' => '1'),
|
||||
array('style' => 'margin-top:1px;margin-bottom:1px;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testLenientHandlingOfInvalidInput()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('vspace' => '10%'),
|
||||
array('style' => 'margin-top:10%px;margin-bottom:10%px;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrependNewCSS()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('vspace' => '23', 'style' => 'font-weight:bold;'),
|
||||
array('style' => 'margin-top:23px;margin-bottom:23px;font-weight:bold;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testHorizontalBasicUsage()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('hspace');
|
||||
$this->assertResult(
|
||||
array('hspace' => '1'),
|
||||
array('style' => 'margin-left:1px;margin-right:1px;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidConstructionParameter()
|
||||
{
|
||||
$this->expectError('ispace is not valid space attribute');
|
||||
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('ispace');
|
||||
$this->assertResult(
|
||||
array('ispace' => '1'),
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
105
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/InputTest.php
Executable file
105
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/InputTest.php
Executable file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_Input();
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult(array());
|
||||
}
|
||||
|
||||
public function testInvalidCheckedWithEmpty()
|
||||
{
|
||||
$this->assertResult(array('checked' => 'checked'), array());
|
||||
}
|
||||
|
||||
public function testInvalidCheckedWithPassword()
|
||||
{
|
||||
$this->assertResult(array(
|
||||
'checked' => 'checked',
|
||||
'type' => 'password'
|
||||
), array(
|
||||
'type' => 'password'
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidCheckedWithUcCheckbox()
|
||||
{
|
||||
$this->assertResult(array(
|
||||
'checked' => 'checked',
|
||||
'type' => 'CHECKBOX',
|
||||
'value' => 'bar',
|
||||
));
|
||||
}
|
||||
|
||||
public function testInvalidMaxlength()
|
||||
{
|
||||
$this->assertResult(array(
|
||||
'maxlength' => '10',
|
||||
'type' => 'checkbox',
|
||||
'value' => 'foo',
|
||||
), array(
|
||||
'type' => 'checkbox',
|
||||
'value' => 'foo',
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidMaxLength()
|
||||
{
|
||||
$this->assertResult(array(
|
||||
'maxlength' => '10',
|
||||
));
|
||||
}
|
||||
|
||||
// these two are really bad test-cases
|
||||
|
||||
public function testSizeWithCheckbox()
|
||||
{
|
||||
$this->assertResult(array(
|
||||
'type' => 'checkbox',
|
||||
'value' => 'foo',
|
||||
'size' => '100px',
|
||||
), array(
|
||||
'type' => 'checkbox',
|
||||
'value' => 'foo',
|
||||
'size' => '100',
|
||||
));
|
||||
}
|
||||
|
||||
public function testSizeWithText()
|
||||
{
|
||||
$this->assertResult(array(
|
||||
'type' => 'password',
|
||||
'size' => '100px', // spurious value, to indicate no validation takes place
|
||||
), array(
|
||||
'type' => 'password',
|
||||
'size' => '100px',
|
||||
));
|
||||
}
|
||||
|
||||
public function testInvalidSrc()
|
||||
{
|
||||
$this->assertResult(array(
|
||||
'src' => 'img.png',
|
||||
), array());
|
||||
}
|
||||
|
||||
public function testMissingValue()
|
||||
{
|
||||
$this->assertResult(array(
|
||||
'type' => 'checkbox',
|
||||
), array(
|
||||
'type' => 'checkbox',
|
||||
'value' => '',
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
52
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/LangTest.php
Executable file
52
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/LangTest.php
Executable file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransform_LangTest
|
||||
extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_Lang();
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult(array());
|
||||
}
|
||||
|
||||
public function testCopyLangToXMLLang()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('lang' => 'en'),
|
||||
array('lang' => 'en', 'xml:lang' => 'en')
|
||||
);
|
||||
}
|
||||
|
||||
public function testPreserveAttributes()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('src' => 'vert.png', 'lang' => 'fr'),
|
||||
array('src' => 'vert.png', 'lang' => 'fr', 'xml:lang' => 'fr')
|
||||
);
|
||||
}
|
||||
|
||||
public function testCopyXMLLangToLang()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('xml:lang' => 'en'),
|
||||
array('xml:lang' => 'en', 'lang' => 'en')
|
||||
);
|
||||
}
|
||||
|
||||
public function testXMLLangOverridesLang()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('lang' => 'fr', 'xml:lang' => 'de'),
|
||||
array('lang' => 'de', 'xml:lang' => 'de')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
51
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/LengthTest.php
Executable file
51
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/LengthTest.php
Executable file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransform_LengthTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_Length('width');
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
public function testTransformPixel()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('width' => '10'),
|
||||
array('style' => 'width:10px;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testTransformPercentage()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('width' => '10%'),
|
||||
array('style' => 'width:10%;')
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrependNewCSS()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('width' => '10%', 'style' => 'font-weight:bold'),
|
||||
array('style' => 'width:10%;font-weight:bold')
|
||||
);
|
||||
}
|
||||
|
||||
public function testLenientTreatmentOfInvalidInput()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('width' => 'asdf'),
|
||||
array('style' => 'width:asdf;')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
45
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/NameSyncTest.php
Executable file
45
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/NameSyncTest.php
Executable file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransform_NameSyncTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_NameSync();
|
||||
$this->accumulator = new HTMLPurifier_IDAccumulator();
|
||||
$this->context->register('IDAccumulator', $this->accumulator);
|
||||
$this->config->set('Attr.EnableID', true);
|
||||
}
|
||||
|
||||
public function testEmpty()
|
||||
{
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
public function testAllowSame()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('name' => 'free', 'id' => 'free')
|
||||
);
|
||||
}
|
||||
|
||||
public function testAllowDifferent()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('name' => 'tryit', 'id' => 'thisgood')
|
||||
);
|
||||
}
|
||||
|
||||
public function testCheckName()
|
||||
{
|
||||
$this->accumulator->add('notok');
|
||||
$this->assertResult(
|
||||
array('name' => 'notok', 'id' => 'ok'),
|
||||
array('id' => 'ok')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
35
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/NameTest.php
Executable file
35
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransform/NameTest.php
Executable file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransform_NameTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_Name();
|
||||
}
|
||||
|
||||
public function testEmpty()
|
||||
{
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
public function testTransformNameToID()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('name' => 'free'),
|
||||
array('id' => 'free')
|
||||
);
|
||||
}
|
||||
|
||||
public function testExistingIDOverridesName()
|
||||
{
|
||||
$this->assertResult(
|
||||
array('name' => 'tryit', 'id' => 'tobad'),
|
||||
array('id' => 'tobad')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
14
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransformHarness.php
Executable file
14
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransformHarness.php
Executable file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTransformHarness extends HTMLPurifier_ComplexHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->func = 'transform';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
45
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransformTest.php
Executable file
45
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTransformTest.php
Executable file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
Mock::generatePartial(
|
||||
'HTMLPurifier_AttrTransform',
|
||||
'HTMLPurifier_AttrTransformTestable',
|
||||
array('transform'));
|
||||
|
||||
class HTMLPurifier_AttrTransformTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
public function test_prependCSS()
|
||||
{
|
||||
$t = new HTMLPurifier_AttrTransformTestable();
|
||||
|
||||
$attr = array();
|
||||
$t->prependCSS($attr, 'style:new;');
|
||||
$this->assertIdentical(array('style' => 'style:new;'), $attr);
|
||||
|
||||
$attr = array('style' => 'style:original;');
|
||||
$t->prependCSS($attr, 'style:new;');
|
||||
$this->assertIdentical(array('style' => 'style:new;style:original;'), $attr);
|
||||
|
||||
$attr = array('style' => 'style:original;', 'misc' => 'un-related');
|
||||
$t->prependCSS($attr, 'style:new;');
|
||||
$this->assertIdentical(array('style' => 'style:new;style:original;', 'misc' => 'un-related'), $attr);
|
||||
|
||||
}
|
||||
|
||||
public function test_confiscateAttr()
|
||||
{
|
||||
$t = new HTMLPurifier_AttrTransformTestable();
|
||||
|
||||
$attr = array('flavor' => 'sweet');
|
||||
$this->assertIdentical('sweet', $t->confiscateAttr($attr, 'flavor'));
|
||||
$this->assertIdentical(array(), $attr);
|
||||
|
||||
$attr = array('flavor' => 'sweet');
|
||||
$this->assertIdentical(null, $t->confiscateAttr($attr, 'color'));
|
||||
$this->assertIdentical(array('flavor' => 'sweet'), $attr);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
27
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTypesTest.php
Executable file
27
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrTypesTest.php
Executable file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrTypesTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
public function test_get()
|
||||
{
|
||||
$types = new HTMLPurifier_AttrTypes();
|
||||
|
||||
$this->assertIdentical(
|
||||
$types->get('CDATA'),
|
||||
new HTMLPurifier_AttrDef_Text()
|
||||
);
|
||||
|
||||
$this->expectError('Cannot retrieve undefined attribute type foobar');
|
||||
$types->get('foobar');
|
||||
|
||||
$this->assertIdentical(
|
||||
$types->get('Enum#foo,bar'),
|
||||
new HTMLPurifier_AttrDef_Enum(array('foo', 'bar'))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
72
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrValidator_ErrorsTest.php
Executable file
72
htmlpurifier-4.10.0/tests/HTMLPurifier/AttrValidator_ErrorsTest.php
Executable file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
|
||||
{
|
||||
|
||||
public function setup()
|
||||
{
|
||||
parent::setup();
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$this->language = HTMLPurifier_LanguageFactory::instance()->create($config, $this->context);
|
||||
$this->context->register('Locale', $this->language);
|
||||
$this->collector = new HTMLPurifier_ErrorCollector($this->context);
|
||||
$gen = new HTMLPurifier_Generator($config, $this->context);
|
||||
$this->context->register('Generator', $gen);
|
||||
}
|
||||
|
||||
protected function invoke($input)
|
||||
{
|
||||
$validator = new HTMLPurifier_AttrValidator();
|
||||
$validator->validateToken($input, $this->config, $this->context);
|
||||
}
|
||||
|
||||
public function testAttributesTransformedGlobalPre()
|
||||
{
|
||||
$def = $this->config->getHTMLDefinition(true);
|
||||
generate_mock_once('HTMLPurifier_AttrTransform');
|
||||
$transform = new HTMLPurifier_AttrTransformMock();
|
||||
$input = array('original' => 'value');
|
||||
$output = array('class' => 'value'); // must be valid
|
||||
$transform->returns('transform', $output, array($input, new AnythingExpectation(), new AnythingExpectation()));
|
||||
$def->info_attr_transform_pre[] = $transform;
|
||||
|
||||
$token = new HTMLPurifier_Token_Start('span', $input, 1);
|
||||
$this->invoke($token);
|
||||
|
||||
$result = $this->collector->getRaw();
|
||||
$expect = array(
|
||||
array(1, E_NOTICE, 'Attributes on <span> transformed from original to class', array()),
|
||||
);
|
||||
$this->assertIdentical($result, $expect);
|
||||
}
|
||||
|
||||
public function testAttributesTransformedLocalPre()
|
||||
{
|
||||
$this->config->set('HTML.TidyLevel', 'heavy');
|
||||
$input = array('align' => 'right');
|
||||
$output = array('style' => 'text-align:right;');
|
||||
$token = new HTMLPurifier_Token_Start('p', $input, 1);
|
||||
$this->invoke($token);
|
||||
$result = $this->collector->getRaw();
|
||||
$expect = array(
|
||||
array(1, E_NOTICE, 'Attributes on <p> transformed from align to style', array()),
|
||||
);
|
||||
$this->assertIdentical($result, $expect);
|
||||
}
|
||||
|
||||
// too lazy to check for global post and global pre
|
||||
|
||||
public function testAttributeRemoved()
|
||||
{
|
||||
$token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1);
|
||||
$this->invoke($token);
|
||||
$result = $this->collector->getRaw();
|
||||
$expect = array(
|
||||
array(1, E_ERROR, 'foobar attribute on <p> removed', array()),
|
||||
);
|
||||
$this->assertIdentical($result, $expect);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
44
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/ChameleonTest.php
Executable file
44
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/ChameleonTest.php
Executable file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ChildDef_ChameleonTest extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
protected $isInline;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_ChildDef_Chameleon(
|
||||
'b | i', // allowed only when in inline context
|
||||
'b | i | div' // allowed only when in block context
|
||||
);
|
||||
$this->context->register('IsInline', $this->isInline);
|
||||
}
|
||||
|
||||
public function testInlineAlwaysAllowed()
|
||||
{
|
||||
$this->isInline = true;
|
||||
$this->assertResult(
|
||||
'<b>Allowed.</b>'
|
||||
);
|
||||
}
|
||||
|
||||
public function testBlockNotAllowedInInline()
|
||||
{
|
||||
$this->isInline = true;
|
||||
$this->assertResult(
|
||||
'<div>Not allowed.</div>', ''
|
||||
);
|
||||
}
|
||||
|
||||
public function testBlockAllowedInNonInline()
|
||||
{
|
||||
$this->isInline = false;
|
||||
$this->assertResult(
|
||||
'<div>Allowed.</div>'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
99
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/CustomTest.php
Executable file
99
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/CustomTest.php
Executable file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('(a,b?,c*,d+,(a,b)*)');
|
||||
|
||||
$this->assertEqual($this->obj->elements, array('a' => true,
|
||||
'b' => true, 'c' => true, 'd' => true));
|
||||
|
||||
$this->assertResult('', false);
|
||||
$this->assertResult('<a /><a />', false);
|
||||
|
||||
$this->assertResult('<a /><b /><c /><d /><a /><b />');
|
||||
$this->assertResult('<a /><d>Dob</d><a /><b>foo</b>'.
|
||||
'<a href="moo" /><b>foo</b>');
|
||||
|
||||
}
|
||||
|
||||
public function testNesting()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('(a,b,(c|d))+');
|
||||
$this->assertEqual($this->obj->elements, array('a' => true,
|
||||
'b' => true, 'c' => true, 'd' => true));
|
||||
$this->assertResult('', false);
|
||||
$this->assertResult('<a /><b /><c /><a /><b /><d />');
|
||||
$this->assertResult('<a /><b /><c /><d />', false);
|
||||
}
|
||||
|
||||
public function testNestedEitherOr()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('b,(a|(c|d))+');
|
||||
$this->assertEqual($this->obj->elements, array('a' => true,
|
||||
'b' => true, 'c' => true, 'd' => true));
|
||||
$this->assertResult('', false);
|
||||
$this->assertResult('<b /><a /><c /><d />');
|
||||
$this->assertResult('<b /><d /><a /><a />');
|
||||
$this->assertResult('<b /><a />');
|
||||
$this->assertResult('<acd />', false);
|
||||
}
|
||||
|
||||
public function testNestedQuantifier()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('(b,c+)*');
|
||||
$this->assertEqual($this->obj->elements, array('b' => true, 'c' => true));
|
||||
$this->assertResult('');
|
||||
$this->assertResult('<b /><c />');
|
||||
$this->assertResult('<b /><c /><c /><c />');
|
||||
$this->assertResult('<b /><c /><b /><c />');
|
||||
$this->assertResult('<b /><c /><b />', false);
|
||||
}
|
||||
|
||||
public function testEitherOr()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('a|b');
|
||||
$this->assertEqual($this->obj->elements, array('a' => true, 'b' => true));
|
||||
$this->assertResult('', false);
|
||||
$this->assertResult('<a />');
|
||||
$this->assertResult('<b />');
|
||||
$this->assertResult('<a /><b />', false);
|
||||
|
||||
}
|
||||
|
||||
public function testCommafication()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('a,b');
|
||||
$this->assertEqual($this->obj->elements, array('a' => true, 'b' => true));
|
||||
$this->assertResult('<a /><b />');
|
||||
$this->assertResult('<ab />', false);
|
||||
|
||||
}
|
||||
|
||||
public function testPcdata()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('#PCDATA,a');
|
||||
$this->assertEqual($this->obj->elements, array('#PCDATA' => true, 'a' => true));
|
||||
$this->assertResult('foo<a />');
|
||||
$this->assertResult('<a />', false);
|
||||
}
|
||||
|
||||
public function testWhitespace()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('a');
|
||||
$this->assertEqual($this->obj->elements, array('a' => true));
|
||||
$this->assertResult('foo<a />', false);
|
||||
$this->assertResult('<a />');
|
||||
$this->assertResult(' <a />');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
54
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/ListTest.php
Executable file
54
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/ListTest.php
Executable file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ChildDef_ListTest extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_ChildDef_List();
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult('', false);
|
||||
}
|
||||
|
||||
public function testSingleLi()
|
||||
{
|
||||
$this->assertResult('<li />');
|
||||
}
|
||||
|
||||
public function testSomeLi()
|
||||
{
|
||||
$this->assertResult('<li>asdf</li><li />');
|
||||
}
|
||||
|
||||
public function testOlAtBeginning()
|
||||
{
|
||||
$this->assertResult('<ol />', '<li><ol /></li>');
|
||||
}
|
||||
|
||||
public function testOlAtBeginningWithOtherJunk()
|
||||
{
|
||||
$this->assertResult('<ol /><li />', '<li><ol /></li><li />');
|
||||
}
|
||||
|
||||
public function testOlInMiddle()
|
||||
{
|
||||
$this->assertResult('<li>Foo</li><ol><li>Bar</li></ol>', '<li>Foo<ol><li>Bar</li></ol></li>');
|
||||
}
|
||||
|
||||
public function testMultipleOl()
|
||||
{
|
||||
$this->assertResult('<li /><ol /><ol />', '<li><ol /><ol /></li>');
|
||||
}
|
||||
|
||||
public function testUlAtBeginning()
|
||||
{
|
||||
$this->assertResult('<ul />', '<li><ul /></li>');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
39
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/OptionalTest.php
Executable file
39
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/OptionalTest.php
Executable file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ChildDef_OptionalTest extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_ChildDef_Optional('b | i');
|
||||
}
|
||||
|
||||
public function testBasicUsage()
|
||||
{
|
||||
$this->assertResult('<b>Bold text</b><img />', '<b>Bold text</b>');
|
||||
}
|
||||
|
||||
public function testRemoveForbiddenText()
|
||||
{
|
||||
$this->assertResult('Not allowed text', '');
|
||||
}
|
||||
|
||||
public function testEmpty()
|
||||
{
|
||||
$this->assertResult('');
|
||||
}
|
||||
|
||||
public function testWhitespace()
|
||||
{
|
||||
$this->assertResult(' ');
|
||||
}
|
||||
|
||||
public function testMultipleWhitespace()
|
||||
{
|
||||
$this->assertResult(' ');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
78
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/RequiredTest.php
Executable file
78
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/RequiredTest.php
Executable file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
public function testPrepareString()
|
||||
{
|
||||
$def = new HTMLPurifier_ChildDef_Required('foobar | bang |gizmo');
|
||||
$this->assertIdentical($def->elements,
|
||||
array(
|
||||
'foobar' => true
|
||||
,'bang' => true
|
||||
,'gizmo' => true
|
||||
));
|
||||
}
|
||||
|
||||
public function testPrepareArray()
|
||||
{
|
||||
$def = new HTMLPurifier_ChildDef_Required(array('href', 'src'));
|
||||
$this->assertIdentical($def->elements,
|
||||
array(
|
||||
'href' => true
|
||||
,'src' => true
|
||||
));
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_ChildDef_Required('dt | dd');
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult('', false);
|
||||
}
|
||||
|
||||
public function testRemoveIllegalTagsAndElements()
|
||||
{
|
||||
$this->assertResult(
|
||||
'<dt>Term</dt>Text in an illegal location'.
|
||||
'<dd>Definition</dd><b>Illegal tag</b>',
|
||||
'<dt>Term</dt><dd>Definition</dd>');
|
||||
$this->assertResult('How do you do!', false);
|
||||
}
|
||||
|
||||
public function testIgnoreWhitespace()
|
||||
{
|
||||
// whitespace shouldn't trigger it
|
||||
$this->assertResult("\n<dd>Definition</dd> ");
|
||||
}
|
||||
|
||||
public function testPreserveWhitespaceAfterRemoval()
|
||||
{
|
||||
$this->assertResult(
|
||||
'<dd>Definition</dd> <b></b> ',
|
||||
'<dd>Definition</dd> '
|
||||
);
|
||||
}
|
||||
|
||||
public function testDeleteNodeIfOnlyWhitespace()
|
||||
{
|
||||
$this->assertResult("\t ", false);
|
||||
}
|
||||
|
||||
public function testPCDATAAllowed()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_ChildDef_Required('#PCDATA | b');
|
||||
$this->assertResult('Out <b>Bold text</b><img />', 'Out <b>Bold text</b>');
|
||||
}
|
||||
public function testPCDATAAllowedJump()
|
||||
{
|
||||
$this->obj = new HTMLPurifier_ChildDef_Required('#PCDATA | b');
|
||||
$this->assertResult('A <i>foo</i>', 'A foo');
|
||||
}
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
96
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php
Executable file
96
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php
Executable file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ChildDef_StrictBlockquoteTest
|
||||
extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p');
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult('');
|
||||
}
|
||||
|
||||
public function testPreserveValidP()
|
||||
{
|
||||
$this->assertResult('<p>Valid</p>');
|
||||
}
|
||||
|
||||
public function testPreserveValidDiv()
|
||||
{
|
||||
$this->assertResult('<div>Still valid</div>');
|
||||
}
|
||||
|
||||
public function testWrapTextWithP()
|
||||
{
|
||||
$this->assertResult('Needs wrap', '<p>Needs wrap</p>');
|
||||
}
|
||||
|
||||
public function testNoWrapForWhitespaceOrValidElements()
|
||||
{
|
||||
$this->assertResult('<p>Do not wrap</p> <p>Whitespace</p>');
|
||||
}
|
||||
|
||||
public function testWrapTextNextToValidElements()
|
||||
{
|
||||
$this->assertResult(
|
||||
'Wrap'. '<p>Do not wrap</p>',
|
||||
'<p>Wrap</p><p>Do not wrap</p>'
|
||||
);
|
||||
}
|
||||
|
||||
public function testWrapInlineElements()
|
||||
{
|
||||
$this->assertResult(
|
||||
'<p>Do not</p>'.'<b>Wrap</b>',
|
||||
'<p>Do not</p><p><b>Wrap</b></p>'
|
||||
);
|
||||
}
|
||||
|
||||
public function testWrapAndRemoveInvalidTags()
|
||||
{
|
||||
$this->assertResult(
|
||||
'<li>Not allowed</li>Paragraph.<p>Hmm.</p>',
|
||||
'<p>Not allowedParagraph.</p><p>Hmm.</p>'
|
||||
);
|
||||
}
|
||||
|
||||
public function testWrapComplicatedSring()
|
||||
{
|
||||
$this->assertResult(
|
||||
$var = 'He said<br />perhaps<br />we should <b>nuke</b> them.',
|
||||
"<p>$var</p>"
|
||||
);
|
||||
}
|
||||
|
||||
public function testWrapAndRemoveInvalidTagsComplex()
|
||||
{
|
||||
$this->assertResult(
|
||||
'<foo>Bar</foo><bas /><b>People</b>Conniving.'. '<p>Fools!</p>',
|
||||
'<p>Bar'. '<b>People</b>Conniving.</p><p>Fools!</p>'
|
||||
);
|
||||
}
|
||||
|
||||
public function testAlternateWrapper()
|
||||
{
|
||||
$this->config->set('HTML.BlockWrapper', 'div');
|
||||
$this->assertResult('Needs wrap', '<div>Needs wrap</div>');
|
||||
|
||||
}
|
||||
|
||||
public function testError()
|
||||
{
|
||||
$this->expectError('Cannot use non-block element as block wrapper');
|
||||
$this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p');
|
||||
$this->config->set('HTML.BlockWrapper', 'dav');
|
||||
$this->config->set('Cache.DefinitionImpl', null);
|
||||
$this->assertResult('Needs wrap', '<p>Needs wrap</p>');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
86
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/TableTest.php
Executable file
86
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDef/TableTest.php
Executable file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
// we're using empty tags to compact the tests: under real circumstances
|
||||
// there would be contents in them
|
||||
|
||||
class HTMLPurifier_ChildDef_TableTest extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_ChildDef_Table();
|
||||
}
|
||||
|
||||
public function testEmptyInput()
|
||||
{
|
||||
$this->assertResult('', false);
|
||||
}
|
||||
|
||||
public function testSingleRow()
|
||||
{
|
||||
$this->assertResult('<tr />');
|
||||
}
|
||||
|
||||
public function testComplexContents()
|
||||
{
|
||||
$this->assertResult('<caption /><col /><thead /><tfoot /><tbody>'.
|
||||
'<tr><td>asdf</td></tr></tbody>');
|
||||
$this->assertResult('<col /><col /><col /><tr />');
|
||||
}
|
||||
|
||||
public function testReorderContents()
|
||||
{
|
||||
$this->assertResult(
|
||||
'<col /><colgroup /><tbody /><tfoot /><thead /><tr>1</tr><caption /><tr />',
|
||||
'<caption /><col /><colgroup /><thead /><tfoot /><tbody /><tbody><tr>1</tr><tr /></tbody>');
|
||||
}
|
||||
|
||||
public function testXhtml11Illegal()
|
||||
{
|
||||
$this->assertResult(
|
||||
'<thead><tr><th>a</th></tr></thead><tr><td>a</td></tr>',
|
||||
'<thead><tr><th>a</th></tr></thead><tbody><tr><td>a</td></tr></tbody>'
|
||||
);
|
||||
}
|
||||
|
||||
public function testTrOverflowAndClose()
|
||||
{
|
||||
$this->assertResult(
|
||||
'<tr><td>a</td></tr><tr><td>b</td></tr><tbody><tr><td>c</td></tr></tbody><tr><td>d</td></tr>',
|
||||
'<tbody><tr><td>a</td></tr><tr><td>b</td></tr></tbody><tbody><tr><td>c</td></tr></tbody><tbody><tr><td>d</td></tr></tbody>'
|
||||
);
|
||||
}
|
||||
|
||||
public function testDuplicateProcessing()
|
||||
{
|
||||
$this->assertResult(
|
||||
'<caption>1</caption><caption /><tbody /><tbody /><tfoot>1</tfoot><tfoot />',
|
||||
'<caption>1</caption><tfoot>1</tfoot><tbody /><tbody /><tbody />'
|
||||
);
|
||||
}
|
||||
|
||||
public function testRemoveText()
|
||||
{
|
||||
$this->assertResult('foo', false);
|
||||
}
|
||||
|
||||
public function testStickyWhitespaceOnTr()
|
||||
{
|
||||
$this->config->set('Output.Newline', "\n");
|
||||
$this->assertResult("\n <tr />\n <tr />\n ");
|
||||
}
|
||||
|
||||
public function testStickyWhitespaceOnTSection()
|
||||
{
|
||||
$this->config->set('Output.Newline', "\n");
|
||||
$this->assertResult(
|
||||
"\n\t<tbody />\n\t\t<tfoot />\n\t\t\t",
|
||||
"\n\t<tfoot />\n\t\t\t<tbody />\n\t\t"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
17
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDefHarness.php
Executable file
17
htmlpurifier-4.10.0/tests/HTMLPurifier/ChildDefHarness.php
Executable file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ChildDefHarness extends HTMLPurifier_ComplexHarness
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->obj = null;
|
||||
$this->func = 'validateChildren';
|
||||
$this->to_html = true;
|
||||
$this->to_node_list = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
138
htmlpurifier-4.10.0/tests/HTMLPurifier/ComplexHarness.php
Executable file
138
htmlpurifier-4.10.0/tests/HTMLPurifier/ComplexHarness.php
Executable file
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* General-purpose test-harness that makes testing functions that require
|
||||
* configuration and context objects easier when those two parameters are
|
||||
* meaningless. See HTMLPurifier_ChildDefTest for a good example of usage.
|
||||
*/
|
||||
class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
/**
|
||||
* Instance of the object that will execute the method.
|
||||
* @type object
|
||||
*/
|
||||
protected $obj;
|
||||
|
||||
/**
|
||||
* Name of the function to be executed.
|
||||
* @type string
|
||||
*/
|
||||
protected $func;
|
||||
|
||||
/**
|
||||
* Whether or not the method deals in tokens.
|
||||
* If set to true, assertResult()
|
||||
* will transparently convert HTML to and back from tokens.
|
||||
* @type bool
|
||||
*/
|
||||
protected $to_tokens = false;
|
||||
|
||||
/**
|
||||
* Whether or not the method deals in a node list.
|
||||
* If set to true, assertResult() will transparently convert HTML
|
||||
* to and back from node.
|
||||
* @type bool
|
||||
*/
|
||||
protected $to_node_list = false;
|
||||
|
||||
/**
|
||||
* Whether or not to convert tokens back into HTML before performing
|
||||
* equality check, has no effect on bools.
|
||||
* @type bool
|
||||
*/
|
||||
protected $to_html = false;
|
||||
|
||||
/**
|
||||
* Instance of an HTMLPurifier_Lexer implementation.
|
||||
* @type HTMLPurifier_Lexer
|
||||
*/
|
||||
protected $lexer;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->lexer = new HTMLPurifier_Lexer_DirectLex();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a specific result from a one parameter + config/context function
|
||||
* @param string $input Input parameter
|
||||
* @param bool|string $expect Expectation
|
||||
*/
|
||||
protected function assertResult($input, $expect = true)
|
||||
{
|
||||
// $func may cause $input to change, so "clone" another copy
|
||||
// to sacrifice
|
||||
if ($this->to_node_list && is_string($input)) {
|
||||
$input = HTMLPurifier_Arborize::arborize($this->tokenize($temp = $input), $this->config, $this->context)->children;
|
||||
$input_c = HTMLPurifier_Arborize::arborize($this->tokenize($temp), $this->config, $this->context)->children;
|
||||
} elseif ($this->to_tokens && is_string($input)) {
|
||||
$input = $this->tokenize($temp = $input);
|
||||
$input_c = $this->tokenize($temp);
|
||||
} else {
|
||||
$input_c = $input;
|
||||
}
|
||||
|
||||
// call the function
|
||||
$func = $this->func;
|
||||
$result = $this->obj->$func($input_c, $this->config, $this->context);
|
||||
|
||||
// test a bool result
|
||||
if (is_bool($result)) {
|
||||
$this->assertIdentical($expect, $result);
|
||||
return;
|
||||
} elseif (is_bool($expect)) {
|
||||
$expect = $input;
|
||||
}
|
||||
|
||||
if ($this->to_html) {
|
||||
if ($this->to_node_list) {
|
||||
$result = $this->generateTokens($result);
|
||||
if (is_array($expect) && !empty($expect) && $expect[0] instanceof HTMLPurifier_Node) {
|
||||
$expect = $this->generateTokens($expect);
|
||||
}
|
||||
}
|
||||
$result = $this->generate($result);
|
||||
if (is_array($expect)) {
|
||||
$expect = $this->generate($expect);
|
||||
}
|
||||
}
|
||||
$this->assertIdentical($expect, $result);
|
||||
|
||||
if ($expect !== $result) {
|
||||
echo '<pre>' . var_dump($result) . '</pre>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tokenize HTML into tokens, uses member variables for common variables
|
||||
*/
|
||||
protected function tokenize($html)
|
||||
{
|
||||
return $this->lexer->tokenizeHTML($html, $this->config, $this->context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate textual HTML from tokens
|
||||
*/
|
||||
protected function generate($tokens)
|
||||
{
|
||||
$generator = new HTMLPurifier_Generator($this->config, $this->context);
|
||||
return $generator->generateFromTokens($tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate tokens from node list
|
||||
*/
|
||||
protected function generateTokens($children)
|
||||
{
|
||||
$dummy = new HTMLPurifier_Node_Element("dummy");
|
||||
$dummy->children = $children;
|
||||
return HTMLPurifier_Arborize::flatten($dummy, $this->context, $this->config);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
23
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigSchema/InterchangeTest.php
Executable file
23
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigSchema/InterchangeTest.php
Executable file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_InterchangeTest extends UnitTestCase
|
||||
{
|
||||
|
||||
protected $interchange;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
|
||||
}
|
||||
|
||||
public function testAddDirective()
|
||||
{
|
||||
$v = new HTMLPurifier_ConfigSchema_Interchange_Directive();
|
||||
$v->id = new HTMLPurifier_ConfigSchema_Interchange_Id('Namespace.Directive');
|
||||
$this->interchange->addDirective($v);
|
||||
$this->assertIdentical($v, $this->interchange->directives['Namespace.Directive']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
@ -0,0 +1,13 @@
|
||||
ERROR: Alias 'Ns.BothWantThisName' in aliases in directive 'Ns.Dir2' collides with alias for directive 'Ns.Dir'
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: int
|
||||
DEFAULT: 3
|
||||
ALIASES: Ns.BothWantThisName
|
||||
----
|
||||
Ns.Dir2
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
DEFAULT: 'a'
|
||||
ALIASES: Ns.BothWantThisName
|
@ -0,0 +1,12 @@
|
||||
ERROR: Alias 'Ns.Innocent' in aliases in directive 'Ns.Dir' collides with another directive
|
||||
----
|
||||
Ns.Innocent
|
||||
DESCRIPTION: Innocent directive
|
||||
TYPE: int
|
||||
DEFAULT: 3
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
DEFAULT: 'a'
|
||||
ALIASES: Ns.Innocent
|
@ -0,0 +1,7 @@
|
||||
ERROR: Value 3 in allowed in directive 'Ns.Dir' must be a string
|
||||
----
|
||||
ID: Ns.Dir
|
||||
TYPE: string
|
||||
DESCRIPTION: Description
|
||||
DEFAULT: 'asdf'
|
||||
ALLOWED: 'asdf', 3
|
@ -0,0 +1,7 @@
|
||||
ERROR: Allowed in directive 'Ns.Dir' must not be empty
|
||||
----
|
||||
ID: Ns.Dir
|
||||
TYPE: string
|
||||
DESCRIPTION: Description
|
||||
DEFAULT: 'asdf'
|
||||
ALLOWED:
|
@ -0,0 +1,7 @@
|
||||
ERROR: Default in directive 'Ns.Dir' must be an allowed value
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
DEFAULT: 'a'
|
||||
ALLOWED: 'b'
|
@ -0,0 +1,5 @@
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string/null
|
||||
DEFAULT: null
|
||||
ALLOWED: 'a'
|
@ -0,0 +1,6 @@
|
||||
ERROR: Expected type string, got integer in DEFAULT in directive hash 'Ns.Dir'
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
DEFAULT: 0
|
@ -0,0 +1,5 @@
|
||||
ERROR: Description in directive 'Ns.Dir' must not be empty
|
||||
----
|
||||
Ns.Dir
|
||||
TYPE: int
|
||||
DEFAULT: 0
|
@ -0,0 +1,3 @@
|
||||
Ns
|
||||
DESCRIPTION: Namespace
|
||||
|
@ -0,0 +1,5 @@
|
||||
ERROR: TYPE in directive hash 'Ns.Dir' not defined
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Notice that TYPE is missing
|
||||
DEFAULT: 0
|
@ -0,0 +1,6 @@
|
||||
ERROR: Invalid type 'foobar' in DEFAULT in directive hash 'Ns.Dir'
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: foobar
|
||||
DEFAULT: 0
|
@ -0,0 +1,7 @@
|
||||
ERROR: Type in directive 'Ns.Dir' must be a string type when used with allowed or value aliases
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: int
|
||||
DEFAULT: 3
|
||||
ALLOWED: 1, 2, 3
|
@ -0,0 +1,7 @@
|
||||
ERROR: Type in directive 'Ns.Dir' must be a string type when used with allowed or value aliases
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: int
|
||||
DEFAULT: 3
|
||||
VALUE-ALIASES: 2 => 3
|
@ -0,0 +1,11 @@
|
||||
ERROR: Cannot redefine directive 'Ns.Dir'
|
||||
----
|
||||
ID: Ns.Dir
|
||||
DESCRIPTION: Version 1
|
||||
TYPE: int
|
||||
DEFAULT: 0
|
||||
----
|
||||
ID: Ns.Dir
|
||||
DESCRIPTION: Version 2
|
||||
TYPE: int
|
||||
DEFAULT: 0
|
@ -0,0 +1,7 @@
|
||||
ERROR: Alias 3 in valueAliases in directive 'Ns.Dir' must be a string
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
DEFAULT: 'a'
|
||||
VALUE-ALIASES: 3 => 'a'
|
@ -0,0 +1,8 @@
|
||||
ERROR: Alias 'b' in valueAliases in directive 'Ns.Dir' must not be an allowed value
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
DEFAULT: 'a'
|
||||
ALLOWED: 'a', 'b', 'c'
|
||||
VALUE-ALIASES: 'b' => 'c'
|
@ -0,0 +1,7 @@
|
||||
ERROR: Alias 'bar' in valueAliases in directive 'Ns.Dir' must not be an alias to itself
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
DEFAULT: 'foo'
|
||||
VALUE-ALIASES: 'bar' => 'bar'
|
@ -0,0 +1,8 @@
|
||||
ERROR: Alias 'c' in valueAliases in directive 'Ns.Dir' must be an alias to an allowed value
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
DEFAULT: 'a'
|
||||
ALLOWED: 'a', 'b'
|
||||
VALUE-ALIASES: 'c' => 'd'
|
@ -0,0 +1,7 @@
|
||||
ERROR: Alias target 3 from alias 'b' in valueAliases in directive 'Ns.Dir' must be a string
|
||||
----
|
||||
Ns.Dir
|
||||
DESCRIPTION: Directive
|
||||
TYPE: string
|
||||
DEFAULT: 'a'
|
||||
VALUE-ALIASES: 'b' => 3
|
110
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigSchema/ValidatorAtomTest.php
Executable file
110
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigSchema/ValidatorAtomTest.php
Executable file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_ValidatorAtomTest extends UnitTestCase
|
||||
{
|
||||
|
||||
protected function expectValidationException($msg)
|
||||
{
|
||||
$this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
|
||||
}
|
||||
|
||||
protected function makeAtom($value)
|
||||
{
|
||||
$obj = new stdClass();
|
||||
$obj->property = $value;
|
||||
// Note that 'property' and 'context' are magic wildcard values
|
||||
return new HTMLPurifier_ConfigSchema_ValidatorAtom('context', $obj, 'property');
|
||||
}
|
||||
|
||||
public function testAssertIsString()
|
||||
{
|
||||
$this->makeAtom('foo')->assertIsString();
|
||||
}
|
||||
|
||||
public function testAssertIsStringFail()
|
||||
{
|
||||
$this->expectValidationException("Property in context must be a string");
|
||||
$this->makeAtom(3)->assertIsString();
|
||||
}
|
||||
|
||||
public function testAssertNotNull()
|
||||
{
|
||||
$this->makeAtom('foo')->assertNotNull();
|
||||
}
|
||||
|
||||
public function testAssertNotNullFail()
|
||||
{
|
||||
$this->expectValidationException("Property in context must not be null");
|
||||
$this->makeAtom(null)->assertNotNull();
|
||||
}
|
||||
|
||||
public function testAssertAlnum()
|
||||
{
|
||||
$this->makeAtom('foo2')->assertAlnum();
|
||||
}
|
||||
|
||||
public function testAssertAlnumFail()
|
||||
{
|
||||
$this->expectValidationException("Property in context must be alphanumeric");
|
||||
$this->makeAtom('%a')->assertAlnum();
|
||||
}
|
||||
|
||||
public function testAssertAlnumFailIsString()
|
||||
{
|
||||
$this->expectValidationException("Property in context must be a string");
|
||||
$this->makeAtom(3)->assertAlnum();
|
||||
}
|
||||
|
||||
public function testAssertNotEmpty()
|
||||
{
|
||||
$this->makeAtom('foo')->assertNotEmpty();
|
||||
}
|
||||
|
||||
public function testAssertNotEmptyFail()
|
||||
{
|
||||
$this->expectValidationException("Property in context must not be empty");
|
||||
$this->makeAtom('')->assertNotEmpty();
|
||||
}
|
||||
|
||||
public function testAssertIsBool()
|
||||
{
|
||||
$this->makeAtom(false)->assertIsBool();
|
||||
}
|
||||
|
||||
public function testAssertIsBoolFail()
|
||||
{
|
||||
$this->expectValidationException("Property in context must be a boolean");
|
||||
$this->makeAtom('0')->assertIsBool();
|
||||
}
|
||||
|
||||
public function testAssertIsArray()
|
||||
{
|
||||
$this->makeAtom(array())->assertIsArray();
|
||||
}
|
||||
|
||||
public function testAssertIsArrayFail()
|
||||
{
|
||||
$this->expectValidationException("Property in context must be an array");
|
||||
$this->makeAtom('asdf')->assertIsArray();
|
||||
}
|
||||
|
||||
|
||||
public function testAssertIsLookup()
|
||||
{
|
||||
$this->makeAtom(array('foo' => true))->assertIsLookup();
|
||||
}
|
||||
|
||||
public function testAssertIsLookupFail()
|
||||
{
|
||||
$this->expectValidationException("Property in context must be a lookup array");
|
||||
$this->makeAtom(array('foo' => 4))->assertIsLookup();
|
||||
}
|
||||
|
||||
public function testAssertIsLookupFailIsArray()
|
||||
{
|
||||
$this->expectValidationException("Property in context must be an array");
|
||||
$this->makeAtom('asdf')->assertIsLookup();
|
||||
}
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
111
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigSchema/ValidatorTest.php
Executable file
111
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigSchema/ValidatorTest.php
Executable file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Special test-case for cases that can't be tested using
|
||||
* HTMLPurifier_ConfigSchema_ValidatorTestCase.
|
||||
*/
|
||||
class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
||||
{
|
||||
public $validator, $interchange;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->validator = new HTMLPurifier_ConfigSchema_Validator();
|
||||
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
|
||||
}
|
||||
|
||||
public function testDirectiveIntegrityViolation()
|
||||
{
|
||||
$d = $this->makeDirective('Ns.Dir');
|
||||
$d->id = new HTMLPurifier_ConfigSchema_Interchange_Id('Ns.Dir2');
|
||||
$this->expectValidationException("Integrity violation: key 'Ns.Dir' does not match internal id 'Ns.Dir2'");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
public function testDirectiveTypeNotEmpty()
|
||||
{
|
||||
$d = $this->makeDirective('Ns.Dir');
|
||||
$d->default = 0;
|
||||
$d->description = 'Description';
|
||||
|
||||
$this->expectValidationException("Type in directive 'Ns.Dir' must not be empty");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
public function testDirectiveDefaultInvalid()
|
||||
{
|
||||
$d = $this->makeDirective('Ns.Dir');
|
||||
$d->default = 'asdf';
|
||||
$d->type = 'int';
|
||||
$d->description = 'Description';
|
||||
|
||||
$this->expectValidationException("Default in directive 'Ns.Dir' had error: Expected type int, got string");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
public function testDirectiveIdIsString()
|
||||
{
|
||||
$d = $this->makeDirective(3);
|
||||
$d->default = 0;
|
||||
$d->type = 'int';
|
||||
$d->description = 'Description';
|
||||
|
||||
$this->expectValidationException("Key in id '3' in directive '3' must be a string");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
public function testDirectiveTypeAllowsNullIsBool()
|
||||
{
|
||||
$d = $this->makeDirective('Ns.Dir');
|
||||
$d->default = 0;
|
||||
$d->type = 'int';
|
||||
$d->description = 'Description';
|
||||
$d->typeAllowsNull = 'yes';
|
||||
|
||||
$this->expectValidationException("TypeAllowsNull in directive 'Ns.Dir' must be a boolean");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
public function testDirectiveValueAliasesIsArray()
|
||||
{
|
||||
$d = $this->makeDirective('Ns.Dir');
|
||||
$d->default = 'a';
|
||||
$d->type = 'string';
|
||||
$d->description = 'Description';
|
||||
$d->valueAliases = 2;
|
||||
|
||||
$this->expectValidationException("ValueAliases in directive 'Ns.Dir' must be an array");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
public function testDirectiveAllowedIsLookup()
|
||||
{
|
||||
$d = $this->makeDirective('Ns.Dir');
|
||||
$d->default = 'foo';
|
||||
$d->type = 'string';
|
||||
$d->description = 'Description';
|
||||
$d->allowed = array('foo' => 1);
|
||||
|
||||
$this->expectValidationException("Allowed in directive 'Ns.Dir' must be a lookup array");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
// helper functions
|
||||
|
||||
|
||||
protected function makeDirective($key)
|
||||
{
|
||||
$directive = new HTMLPurifier_ConfigSchema_Interchange_Directive();
|
||||
$directive->id = new HTMLPurifier_ConfigSchema_Interchange_Id($key);
|
||||
$this->interchange->addDirective($directive);
|
||||
return $directive;
|
||||
}
|
||||
|
||||
protected function expectValidationException($msg)
|
||||
{
|
||||
$this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
47
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigSchema/ValidatorTestCase.php
Executable file
47
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigSchema/ValidatorTestCase.php
Executable file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Controller for validator test-cases.
|
||||
*/
|
||||
class HTMLPurifier_ConfigSchema_ValidatorTestCase extends UnitTestCase
|
||||
{
|
||||
|
||||
protected $_path, $_parser, $_builder;
|
||||
public $validator;
|
||||
|
||||
public function __construct($path)
|
||||
{
|
||||
$this->_path = $path;
|
||||
$this->_parser = new HTMLPurifier_StringHashParser();
|
||||
$this->_builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
|
||||
parent::__construct($path);
|
||||
}
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->validator = new HTMLPurifier_ConfigSchema_Validator();
|
||||
}
|
||||
|
||||
public function testValidator()
|
||||
{
|
||||
$hashes = $this->_parser->parseMultiFile($this->_path);
|
||||
$interchange = new HTMLPurifier_ConfigSchema_Interchange();
|
||||
$error = null;
|
||||
foreach ($hashes as $hash) {
|
||||
if (!isset($hash['ID'])) {
|
||||
if (isset($hash['ERROR'])) {
|
||||
$this->expectException(
|
||||
new HTMLPurifier_ConfigSchema_Exception($hash['ERROR'])
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$this->_builder->build($interchange, new HTMLPurifier_StringHash($hash));
|
||||
}
|
||||
$this->validator->validate($interchange);
|
||||
$this->pass();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
104
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigSchemaTest.php
Executable file
104
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigSchemaTest.php
Executable file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
protected $schema;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->schema = new HTMLPurifier_ConfigSchema();
|
||||
}
|
||||
|
||||
public function test_define()
|
||||
{
|
||||
$this->schema->add('Car.Seats', 5, 'int', false);
|
||||
|
||||
$this->assertIdentical($this->schema->defaults['Car.Seats'], 5);
|
||||
$this->assertIdentical($this->schema->info['Car.Seats']->type, HTMLPurifier_VarParser::INT);
|
||||
|
||||
$this->schema->add('Car.Age', null, 'int', true);
|
||||
|
||||
$this->assertIdentical($this->schema->defaults['Car.Age'], null);
|
||||
$this->assertIdentical($this->schema->info['Car.Age']->type, HTMLPurifier_VarParser::INT);
|
||||
|
||||
}
|
||||
|
||||
public function test_defineAllowedValues()
|
||||
{
|
||||
$this->schema->add('QuantumNumber.Spin', 0.5, 'float', false);
|
||||
$this->schema->add('QuantumNumber.Current', 's', 'string', false);
|
||||
$this->schema->add('QuantumNumber.Difficulty', null, 'string', true);
|
||||
|
||||
$this->schema->addAllowedValues( // okay, since default is null
|
||||
'QuantumNumber.Difficulty', array('easy' => true, 'medium' => true, 'hard' => true)
|
||||
);
|
||||
|
||||
$this->assertIdentical($this->schema->defaults['QuantumNumber.Difficulty'], null);
|
||||
$this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->type, HTMLPurifier_VarParser::STRING);
|
||||
$this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->allow_null, true);
|
||||
$this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->allowed,
|
||||
array(
|
||||
'easy' => true,
|
||||
'medium' => true,
|
||||
'hard' => true
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function test_defineValueAliases()
|
||||
{
|
||||
$this->schema->add('Abbrev.HTH', 'Happy to Help', 'string', false);
|
||||
$this->schema->addAllowedValues(
|
||||
'Abbrev.HTH', array(
|
||||
'Happy to Help' => true,
|
||||
'Hope that Helps' => true,
|
||||
'HAIL THE HAND!' => true,
|
||||
)
|
||||
);
|
||||
$this->schema->addValueAliases(
|
||||
'Abbrev.HTH', array(
|
||||
'happy' => 'Happy to Help',
|
||||
'hope' => 'Hope that Helps'
|
||||
)
|
||||
);
|
||||
$this->schema->addValueAliases( // delayed addition
|
||||
'Abbrev.HTH', array(
|
||||
'hail' => 'HAIL THE HAND!'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertIdentical($this->schema->defaults['Abbrev.HTH'], 'Happy to Help');
|
||||
$this->assertIdentical($this->schema->info['Abbrev.HTH']->type, HTMLPurifier_VarParser::STRING);
|
||||
$this->assertIdentical($this->schema->info['Abbrev.HTH']->allowed,
|
||||
array(
|
||||
'Happy to Help' => true,
|
||||
'Hope that Helps' => true,
|
||||
'HAIL THE HAND!' => true
|
||||
)
|
||||
);
|
||||
$this->assertIdentical($this->schema->info['Abbrev.HTH']->aliases,
|
||||
array(
|
||||
'happy' => 'Happy to Help',
|
||||
'hope' => 'Hope that Helps',
|
||||
'hail' => 'HAIL THE HAND!'
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function testAlias()
|
||||
{
|
||||
$this->schema->add('Home.Rug', 3, 'int', false);
|
||||
$this->schema->addAlias('Home.Carpet', 'Home.Rug');
|
||||
|
||||
$this->assertTrue(!isset($this->schema->defaults['Home.Carpet']));
|
||||
$this->assertIdentical($this->schema->info['Home.Carpet']->key, 'Home.Rug');
|
||||
$this->assertIdentical($this->schema->info['Home.Carpet']->isAlias, true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
4
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigTest-create.ini
Executable file
4
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigTest-create.ini
Executable file
@ -0,0 +1,4 @@
|
||||
[Cake]
|
||||
Sprinkles = 42
|
||||
|
||||
; vim: et sw=4 sts=4
|
4
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigTest-finalize.ini
Executable file
4
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigTest-finalize.ini
Executable file
@ -0,0 +1,4 @@
|
||||
[Poem]
|
||||
Meter = alexandrine
|
||||
|
||||
; vim: et sw=4 sts=4
|
6
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigTest-loadIni.ini
Executable file
6
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigTest-loadIni.ini
Executable file
@ -0,0 +1,6 @@
|
||||
[Shortcut]
|
||||
Copy = q
|
||||
Cut = t
|
||||
Paste = p
|
||||
|
||||
; vim: et sw=4 sts=4
|
577
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigTest.php
Executable file
577
htmlpurifier-4.10.0/tests/HTMLPurifier/ConfigTest.php
Executable file
@ -0,0 +1,577 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
protected $schema;
|
||||
protected $oldFactory;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
// set up a dummy schema object for testing
|
||||
$this->schema = new HTMLPurifier_ConfigSchema();
|
||||
}
|
||||
|
||||
// test functionality based on ConfigSchema
|
||||
|
||||
public function testNormal()
|
||||
{
|
||||
$this->schema->add('Element.Abbr', 'H', 'string', false);
|
||||
$this->schema->add('Element.Name', 'hydrogen', 'istring', false);
|
||||
$this->schema->add('Element.Number', 1, 'int', false);
|
||||
$this->schema->add('Element.Mass', 1.00794, 'float', false);
|
||||
$this->schema->add('Element.Radioactive', false, 'bool', false);
|
||||
$this->schema->add('Element.Isotopes', array(1 => true, 2 => true, 3 => true), 'lookup', false);
|
||||
$this->schema->add('Element.Traits', array('nonmetallic', 'odorless', 'flammable'), 'list', false);
|
||||
$this->schema->add('Element.IsotopeNames', array(1 => 'protium', 2 => 'deuterium', 3 => 'tritium'), 'hash', false);
|
||||
$this->schema->add('Element.Object', new stdClass(), 'mixed', false);
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
$config->chatty = false;
|
||||
|
||||
// test default value retrieval
|
||||
$this->assertIdentical($config->get('Element.Abbr'), 'H');
|
||||
$this->assertIdentical($config->get('Element.Name'), 'hydrogen');
|
||||
$this->assertIdentical($config->get('Element.Number'), 1);
|
||||
$this->assertIdentical($config->get('Element.Mass'), 1.00794);
|
||||
$this->assertIdentical($config->get('Element.Radioactive'), false);
|
||||
$this->assertIdentical($config->get('Element.Isotopes'), array(1 => true, 2 => true, 3 => true));
|
||||
$this->assertIdentical($config->get('Element.Traits'), array('nonmetallic', 'odorless', 'flammable'));
|
||||
$this->assertIdentical($config->get('Element.IsotopeNames'), array(1 => 'protium', 2 => 'deuterium', 3 => 'tritium'));
|
||||
$this->assertIdentical($config->get('Element.Object'), new stdClass());
|
||||
|
||||
// test setting values
|
||||
$config->set('Element.Abbr', 'Pu');
|
||||
$config->set('Element.Name', 'PLUTONIUM'); // test decaps
|
||||
$config->set('Element.Number', '94'); // test parsing
|
||||
$config->set('Element.Mass', '244.'); // test parsing
|
||||
$config->set('Element.Radioactive', true);
|
||||
$config->set('Element.Isotopes', array(238, 239)); // test inversion
|
||||
$config->set('Element.Traits', 'nuclear, heavy, actinide'); // test parsing
|
||||
$config->set('Element.IsotopeNames', array(238 => 'Plutonium-238', 239 => 'Plutonium-239'));
|
||||
$config->set('Element.Object', false); // unmodeled
|
||||
|
||||
$this->expectError('Cannot set undefined directive Element.Metal to value');
|
||||
$config->set('Element.Metal', true);
|
||||
|
||||
$this->expectError('Value for Element.Radioactive is of invalid type, should be bool');
|
||||
$config->set('Element.Radioactive', 'very');
|
||||
|
||||
// test value retrieval
|
||||
$this->assertIdentical($config->get('Element.Abbr'), 'Pu');
|
||||
$this->assertIdentical($config->get('Element.Name'), 'plutonium');
|
||||
$this->assertIdentical($config->get('Element.Number'), 94);
|
||||
$this->assertIdentical($config->get('Element.Mass'), 244.);
|
||||
$this->assertIdentical($config->get('Element.Radioactive'), true);
|
||||
$this->assertIdentical($config->get('Element.Isotopes'), array(238 => true, 239 => true));
|
||||
$this->assertIdentical($config->get('Element.Traits'), array('nuclear', 'heavy', 'actinide'));
|
||||
$this->assertIdentical($config->get('Element.IsotopeNames'), array(238 => 'Plutonium-238', 239 => 'Plutonium-239'));
|
||||
$this->assertIdentical($config->get('Element.Object'), false);
|
||||
|
||||
$this->expectError('Cannot retrieve value of undefined directive Element.Metal');
|
||||
$config->get('Element.Metal');
|
||||
|
||||
}
|
||||
|
||||
public function testEnumerated()
|
||||
{
|
||||
// case sensitive
|
||||
$this->schema->add('Instrument.Manufacturer', 'Yamaha', 'string', false);
|
||||
$this->schema->addAllowedValues('Instrument.Manufacturer', array(
|
||||
'Yamaha' => true, 'Conn-Selmer' => true, 'Vandoren' => true,
|
||||
'Laubin' => true, 'Buffet' => true, 'other' => true));
|
||||
$this->schema->addValueAliases('Instrument.Manufacturer', array(
|
||||
'Selmer' => 'Conn-Selmer'));
|
||||
|
||||
// case insensitive
|
||||
$this->schema->add('Instrument.Family', 'woodwind', 'istring', false);
|
||||
$this->schema->addAllowedValues('Instrument.Family', array(
|
||||
'brass' => true, 'woodwind' => true, 'percussion' => true,
|
||||
'string' => true, 'keyboard' => true, 'electronic' => true));
|
||||
$this->schema->addValueAliases('Instrument.Family', array(
|
||||
'synth' => 'electronic'));
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
$config->chatty = false;
|
||||
|
||||
// case sensitive
|
||||
|
||||
$config->set('Instrument.Manufacturer', 'Vandoren');
|
||||
$this->assertIdentical($config->get('Instrument.Manufacturer'), 'Vandoren');
|
||||
|
||||
$config->set('Instrument.Manufacturer', 'Selmer');
|
||||
$this->assertIdentical($config->get('Instrument.Manufacturer'), 'Conn-Selmer');
|
||||
|
||||
$this->expectError('Value not supported, valid values are: Yamaha, Conn-Selmer, Vandoren, Laubin, Buffet, other');
|
||||
$config->set('Instrument.Manufacturer', 'buffet');
|
||||
|
||||
// case insensitive
|
||||
|
||||
$config->set('Instrument.Family', 'brass');
|
||||
$this->assertIdentical($config->get('Instrument.Family'), 'brass');
|
||||
|
||||
$config->set('Instrument.Family', 'PERCUSSION');
|
||||
$this->assertIdentical($config->get('Instrument.Family'), 'percussion');
|
||||
|
||||
$config->set('Instrument.Family', 'synth');
|
||||
$this->assertIdentical($config->get('Instrument.Family'), 'electronic');
|
||||
|
||||
$config->set('Instrument.Family', 'Synth');
|
||||
$this->assertIdentical($config->get('Instrument.Family'), 'electronic');
|
||||
|
||||
}
|
||||
|
||||
public function testNull()
|
||||
{
|
||||
$this->schema->add('ReportCard.English', null, 'string', true);
|
||||
$this->schema->add('ReportCard.Absences', 0, 'int', false);
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
$config->chatty = false;
|
||||
|
||||
$config->set('ReportCard.English', 'B-');
|
||||
$this->assertIdentical($config->get('ReportCard.English'), 'B-');
|
||||
|
||||
$config->set('ReportCard.English', null); // not yet graded
|
||||
$this->assertIdentical($config->get('ReportCard.English'), null);
|
||||
|
||||
// error
|
||||
$this->expectError('Value for ReportCard.Absences is of invalid type, should be int');
|
||||
$config->set('ReportCard.Absences', null);
|
||||
|
||||
}
|
||||
|
||||
public function testAliases()
|
||||
{
|
||||
$this->schema->add('Home.Rug', 3, 'int', false);
|
||||
$this->schema->addAlias('Home.Carpet', 'Home.Rug');
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
$config->chatty = false;
|
||||
|
||||
$this->assertIdentical($config->get('Home.Rug'), 3);
|
||||
|
||||
$this->expectError('Cannot get value from aliased directive, use real name Home.Rug');
|
||||
$config->get('Home.Carpet');
|
||||
|
||||
$this->expectError('Home.Carpet is an alias, preferred directive name is Home.Rug');
|
||||
$config->set('Home.Carpet', 999);
|
||||
$this->assertIdentical($config->get('Home.Rug'), 999);
|
||||
|
||||
}
|
||||
|
||||
// test functionality based on method
|
||||
|
||||
public function test_getBatch()
|
||||
{
|
||||
$this->schema->add('Variables.TangentialAcceleration', 'a_tan', 'string', false);
|
||||
$this->schema->add('Variables.AngularAcceleration', 'alpha', 'string', false);
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
$config->chatty = false;
|
||||
|
||||
// grab a namespace
|
||||
$this->assertIdentical(
|
||||
$config->getBatch('Variables'),
|
||||
array(
|
||||
'TangentialAcceleration' => 'a_tan',
|
||||
'AngularAcceleration' => 'alpha'
|
||||
)
|
||||
);
|
||||
|
||||
// grab a non-existant namespace
|
||||
$this->expectError('Cannot retrieve undefined namespace Constants');
|
||||
$config->getBatch('Constants');
|
||||
|
||||
}
|
||||
|
||||
public function test_loadIni()
|
||||
{
|
||||
$this->schema->add('Shortcut.Copy', 'c', 'istring', false);
|
||||
$this->schema->add('Shortcut.Paste', 'v', 'istring', false);
|
||||
$this->schema->add('Shortcut.Cut', 'x', 'istring', false);
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
|
||||
$config->loadIni(dirname(__FILE__) . '/ConfigTest-loadIni.ini');
|
||||
|
||||
$this->assertIdentical($config->get('Shortcut.Copy'), 'q');
|
||||
$this->assertIdentical($config->get('Shortcut.Paste'), 'p');
|
||||
$this->assertIdentical($config->get('Shortcut.Cut'), 't');
|
||||
|
||||
}
|
||||
|
||||
public function test_getHTMLDefinition()
|
||||
{
|
||||
// we actually want to use the old copy, because the definition
|
||||
// generation routines have dependencies on configuration values
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->set('HTML.Doctype', 'XHTML 1.0 Strict');
|
||||
$config->autoFinalize = false;
|
||||
|
||||
$def = $config->getCSSDefinition();
|
||||
$this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
|
||||
|
||||
$def = $config->getHTMLDefinition();
|
||||
$def2 = $config->getHTMLDefinition();
|
||||
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
|
||||
$this->assertTrue($def === $def2);
|
||||
$this->assertTrue($def->setup);
|
||||
|
||||
$old_def = clone $def2;
|
||||
|
||||
$config->set('HTML.Doctype', 'HTML 4.01 Transitional');
|
||||
$def = $config->getHTMLDefinition();
|
||||
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
|
||||
$this->assertTrue($def !== $old_def);
|
||||
$this->assertTrue($def->setup);
|
||||
|
||||
}
|
||||
|
||||
public function test_getHTMLDefinition_deprecatedRawError()
|
||||
{
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->chatty = false;
|
||||
// test deprecated retrieval of raw definition
|
||||
$config->set('HTML.DefinitionID', 'HTMLPurifier_ConfigTest->test_getHTMLDefinition()');
|
||||
$config->set('HTML.DefinitionRev', 3);
|
||||
$this->expectError("Useless DefinitionID declaration");
|
||||
$def = $config->getHTMLDefinition(true);
|
||||
$this->assertEqual(false, $def->setup);
|
||||
|
||||
// auto initialization
|
||||
$config->getHTMLDefinition();
|
||||
$this->assertTrue($def->setup);
|
||||
}
|
||||
|
||||
public function test_getHTMLDefinition_optimizedRawError()
|
||||
{
|
||||
$this->expectException(new HTMLPurifier_Exception("Cannot set optimized = true when raw = false"));
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->getHTMLDefinition(false, true);
|
||||
}
|
||||
|
||||
public function test_getHTMLDefinition_rawAfterSetupError()
|
||||
{
|
||||
$this->expectException(new HTMLPurifier_Exception("Cannot retrieve raw definition after it has already been setup"));
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->chatty = false;
|
||||
$config->getHTMLDefinition();
|
||||
$config->getHTMLDefinition(true);
|
||||
}
|
||||
|
||||
public function test_getHTMLDefinition_inconsistentOptimizedError()
|
||||
{
|
||||
$this->expectError("Useless DefinitionID declaration");
|
||||
$this->expectException(new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals"));
|
||||
$config = HTMLPurifier_Config::create(array('HTML.DefinitionID' => 'HTMLPurifier_ConfigTest->test_getHTMLDefinition_inconsistentOptimizedError'));
|
||||
$config->chatty = false;
|
||||
$config->getHTMLDefinition(true, false);
|
||||
$config->getHTMLDefinition(true, true);
|
||||
}
|
||||
|
||||
public function test_getHTMLDefinition_inconsistentOptimizedError2()
|
||||
{
|
||||
$this->expectException(new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals"));
|
||||
$config = HTMLPurifier_Config::create(array('HTML.DefinitionID' => 'HTMLPurifier_ConfigTest->test_getHTMLDefinition_inconsistentOptimizedError2'));
|
||||
$config->chatty = false;
|
||||
$config->getHTMLDefinition(true, true);
|
||||
$config->getHTMLDefinition(true, false);
|
||||
}
|
||||
|
||||
public function test_getHTMLDefinition_rawError()
|
||||
{
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$this->expectException(new HTMLPurifier_Exception('Cannot retrieve raw version without specifying %HTML.DefinitionID'));
|
||||
$def = $config->getHTMLDefinition(true, true);
|
||||
}
|
||||
|
||||
public function test_getCSSDefinition()
|
||||
{
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$def = $config->getCSSDefinition();
|
||||
$this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
|
||||
}
|
||||
|
||||
public function test_getDefinition()
|
||||
{
|
||||
$this->schema->add('Cache.DefinitionImpl', null, 'string', true);
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$this->expectException(new HTMLPurifier_Exception("Definition of Crust type not supported"));
|
||||
$config->getDefinition('Crust');
|
||||
}
|
||||
|
||||
public function test_loadArray()
|
||||
{
|
||||
// setup a few dummy namespaces/directives for our testing
|
||||
$this->schema->add('Zoo.Aadvark', 0, 'int', false);
|
||||
$this->schema->add('Zoo.Boar', 0, 'int', false);
|
||||
$this->schema->add('Zoo.Camel', 0, 'int', false);
|
||||
$this->schema->add('Zoo.Others', array(), 'list', false);
|
||||
|
||||
$config_manual = new HTMLPurifier_Config($this->schema);
|
||||
$config_loadabbr = new HTMLPurifier_Config($this->schema);
|
||||
$config_loadfull = new HTMLPurifier_Config($this->schema);
|
||||
|
||||
$config_manual->set('Zoo.Aadvark', 3);
|
||||
$config_manual->set('Zoo.Boar', 5);
|
||||
$config_manual->set('Zoo.Camel', 2000); // that's a lotta camels!
|
||||
$config_manual->set('Zoo.Others', array('Peacock', 'Dodo')); // wtf!
|
||||
|
||||
// condensed form
|
||||
$config_loadabbr->loadArray(array(
|
||||
'Zoo.Aadvark' => 3,
|
||||
'Zoo.Boar' => 5,
|
||||
'Zoo.Camel' => 2000,
|
||||
'Zoo.Others' => array('Peacock', 'Dodo')
|
||||
));
|
||||
|
||||
// fully expanded form
|
||||
$config_loadfull->loadArray(array(
|
||||
'Zoo' => array(
|
||||
'Aadvark' => 3,
|
||||
'Boar' => 5,
|
||||
'Camel' => 2000,
|
||||
'Others' => array('Peacock', 'Dodo')
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertIdentical($config_manual, $config_loadabbr);
|
||||
$this->assertIdentical($config_manual, $config_loadfull);
|
||||
|
||||
}
|
||||
|
||||
public function test_create()
|
||||
{
|
||||
$this->schema->add('Cake.Sprinkles', 666, 'int', false);
|
||||
$this->schema->add('Cake.Flavor', 'vanilla', 'string', false);
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->set('Cake.Sprinkles', 42);
|
||||
|
||||
// test flat pass-through
|
||||
$created_config = HTMLPurifier_Config::create($config, $this->schema);
|
||||
$this->assertIdentical($config, $created_config);
|
||||
|
||||
// test loadArray
|
||||
$created_config = HTMLPurifier_Config::create(array('Cake.Sprinkles' => 42), $this->schema);
|
||||
$this->assertIdentical($config, $created_config);
|
||||
|
||||
// test loadIni
|
||||
$created_config = HTMLPurifier_Config::create(dirname(__FILE__) . '/ConfigTest-create.ini', $this->schema);
|
||||
$this->assertIdentical($config, $created_config);
|
||||
|
||||
}
|
||||
|
||||
public function test_finalize()
|
||||
{
|
||||
// test finalization
|
||||
|
||||
$this->schema->add('Poem.Meter', 'iambic', 'string', false);
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
$config->chatty = false;
|
||||
|
||||
$config->set('Poem.Meter', 'irregular');
|
||||
|
||||
$config->finalize();
|
||||
|
||||
$this->expectError('Cannot set directive after finalization');
|
||||
$config->set('Poem.Meter', 'vedic');
|
||||
|
||||
$this->expectError('Cannot load directives after finalization');
|
||||
$config->loadArray(array('Poem.Meter' => 'octosyllable'));
|
||||
|
||||
$this->expectError('Cannot load directives after finalization');
|
||||
$config->loadIni(dirname(__FILE__) . '/ConfigTest-finalize.ini');
|
||||
|
||||
}
|
||||
|
||||
public function test_loadArrayFromForm()
|
||||
{
|
||||
$this->schema->add('Pancake.Mix', 'buttermilk', 'string', false);
|
||||
$this->schema->add('Pancake.Served', true, 'bool', false);
|
||||
$this->schema->add('Toppings.Syrup', true, 'bool', false);
|
||||
$this->schema->add('Toppings.Flavor', 'maple', 'string', false);
|
||||
$this->schema->add('Toppings.Strawberries', 3, 'int', false);
|
||||
$this->schema->add('Toppings.Calories', 2000, 'int', true);
|
||||
$this->schema->add('Toppings.DefinitionID', null, 'string', true);
|
||||
$this->schema->add('Toppings.DefinitionRev', 1, 'int', false);
|
||||
$this->schema->add('Toppings.Protected', 1, 'int', false);
|
||||
|
||||
$get = array(
|
||||
'breakfast' => array(
|
||||
'Pancake.Mix' => 'nasty',
|
||||
'Pancake.Served' => '0',
|
||||
'Toppings.Syrup' => '0',
|
||||
'Toppings.Flavor' => "juice",
|
||||
'Toppings.Strawberries' => '999',
|
||||
'Toppings.Calories' => '',
|
||||
'Null_Toppings.Calories' => '1',
|
||||
'Toppings.DefinitionID' => '<argh>',
|
||||
'Toppings.DefinitionRev' => '65',
|
||||
'Toppings.Protected' => '4',
|
||||
)
|
||||
);
|
||||
|
||||
$config_expect = HTMLPurifier_Config::create(array(
|
||||
'Pancake.Served' => false,
|
||||
'Toppings.Syrup' => false,
|
||||
'Toppings.Flavor' => "juice",
|
||||
'Toppings.Strawberries' => 999,
|
||||
'Toppings.Calories' => null
|
||||
), $this->schema);
|
||||
|
||||
$config_result = HTMLPurifier_Config::loadArrayFromForm(
|
||||
$get, 'breakfast',
|
||||
array('Pancake.Served', 'Toppings', '-Toppings.Protected'),
|
||||
false, // mq fix
|
||||
$this->schema
|
||||
);
|
||||
|
||||
$this->assertEqual($config_expect, $config_result);
|
||||
|
||||
/*
|
||||
MAGIC QUOTES NOT TESTED!!!
|
||||
|
||||
$get = array(
|
||||
'breakfast' => array(
|
||||
'Pancake.Mix' => 'n\\asty'
|
||||
)
|
||||
);
|
||||
$config_expect = HTMLPurifier_Config::create(array(
|
||||
'Pancake.Mix' => 'n\\asty'
|
||||
));
|
||||
$config_result = HTMLPurifier_Config::loadArrayFromForm($get, 'breakfast', true, false);
|
||||
$this->assertEqual($config_expect, $config_result);
|
||||
*/
|
||||
}
|
||||
|
||||
public function test_getAllowedDirectivesForForm()
|
||||
{
|
||||
$this->schema->add('Unused.Unused', 'Foobar', 'string', false);
|
||||
$this->schema->add('Partial.Allowed', true, 'bool', false);
|
||||
$this->schema->add('Partial.Unused', 'Foobar', 'string', false);
|
||||
$this->schema->add('All.Allowed', true, 'bool', false);
|
||||
$this->schema->add('All.Blacklisted', 'Foobar', 'string', false); // explicitly blacklisted
|
||||
$this->schema->add('All.DefinitionID', 'Foobar', 'string', true); // auto-blacklisted
|
||||
$this->schema->add('All.DefinitionRev', 2, 'int', false); // auto-blacklisted
|
||||
|
||||
$input = array('Partial.Allowed', 'All', '-All.Blacklisted');
|
||||
$output = HTMLPurifier_Config::getAllowedDirectivesForForm($input, $this->schema);
|
||||
$expect = array(
|
||||
array('Partial', 'Allowed'),
|
||||
array('All', 'Allowed')
|
||||
);
|
||||
|
||||
$this->assertEqual($output, $expect);
|
||||
|
||||
}
|
||||
|
||||
public function testDeprecatedAPI()
|
||||
{
|
||||
$this->schema->add('Foo.Bar', 2, 'int', false);
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->chatty = false;
|
||||
$this->expectError('Using deprecated API: use $config->set(\'Foo.Bar\', ...) instead');
|
||||
$config->set('Foo', 'Bar', 4);
|
||||
$this->expectError('Using deprecated API: use $config->get(\'Foo.Bar\') instead');
|
||||
$this->assertIdentical($config->get('Foo', 'Bar'), 4);
|
||||
}
|
||||
|
||||
public function testInherit()
|
||||
{
|
||||
$this->schema->add('Phantom.Masked', 25, 'int', false);
|
||||
$this->schema->add('Phantom.Unmasked', 89, 'int', false);
|
||||
$this->schema->add('Phantom.Latemasked', 11, 'int', false);
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->set('Phantom.Masked', 800);
|
||||
$subconfig = HTMLPurifier_Config::inherit($config);
|
||||
$config->set('Phantom.Latemasked', 100, 'int', false);
|
||||
$this->assertIdentical($subconfig->get('Phantom.Masked'), 800);
|
||||
$this->assertIdentical($subconfig->get('Phantom.Unmasked'), 89);
|
||||
$this->assertIdentical($subconfig->get('Phantom.Latemasked'), 100);
|
||||
}
|
||||
|
||||
public function testSerialize()
|
||||
{
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->set('HTML.Allowed', 'a');
|
||||
$config2 = unserialize($config->serialize());
|
||||
$this->assertIdentical($config->get('HTML.Allowed'), $config2->get('HTML.Allowed'));
|
||||
}
|
||||
|
||||
public function testDefinitionCachingNothing()
|
||||
{
|
||||
list($mock, $config) = $this->setupCacheMock('HTML');
|
||||
// should not touch the cache
|
||||
$mock->expectNever('get');
|
||||
$mock->expectNever('add');
|
||||
$mock->expectNever('set');
|
||||
$config->getDefinition('HTML', true);
|
||||
$config->getDefinition('HTML', true);
|
||||
$config->getDefinition('HTML');
|
||||
$this->teardownCacheMock();
|
||||
}
|
||||
|
||||
public function testDefinitionCachingOptimized()
|
||||
{
|
||||
list($mock, $config) = $this->setupCacheMock('HTML');
|
||||
$mock->expectNever('set');
|
||||
$config->set('HTML.DefinitionID', 'HTMLPurifier_ConfigTest->testDefinitionCachingOptimized');
|
||||
$mock->expectOnce('get');
|
||||
$mock->returns('get', null);
|
||||
$this->assertTrue($config->maybeGetRawHTMLDefinition());
|
||||
$this->assertTrue($config->maybeGetRawHTMLDefinition());
|
||||
$mock->expectOnce('add');
|
||||
$config->getDefinition('HTML');
|
||||
$this->teardownCacheMock();
|
||||
}
|
||||
|
||||
public function testDefinitionCachingOptimizedHit()
|
||||
{
|
||||
$fake_config = HTMLPurifier_Config::createDefault();
|
||||
$fake_def = $fake_config->getHTMLDefinition();
|
||||
list($mock, $config) = $this->setupCacheMock('HTML');
|
||||
// should never frob cache
|
||||
$mock->expectNever('add');
|
||||
$mock->expectNever('set');
|
||||
$config->set('HTML.DefinitionID', 'HTMLPurifier_ConfigTest->testDefinitionCachingOptimizedHit');
|
||||
$mock->expectOnce('get');
|
||||
$mock->returns('get', $fake_def);
|
||||
$this->assertNull($config->maybeGetRawHTMLDefinition());
|
||||
$config->getDefinition('HTML');
|
||||
$config->getDefinition('HTML');
|
||||
$this->teardownCacheMock();
|
||||
}
|
||||
|
||||
protected function setupCacheMock($type)
|
||||
{
|
||||
// inject our definition cache mock globally (borrowed from
|
||||
// DefinitionFactoryTest)
|
||||
generate_mock_once("HTMLPurifier_DefinitionCacheFactory");
|
||||
$factory = new HTMLPurifier_DefinitionCacheFactoryMock();
|
||||
$this->oldFactory = HTMLPurifier_DefinitionCacheFactory::instance();
|
||||
HTMLPurifier_DefinitionCacheFactory::instance($factory);
|
||||
generate_mock_once("HTMLPurifier_DefinitionCache");
|
||||
$mock = new HTMLPurifier_DefinitionCacheMock();
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$factory->returns('create', $mock, array($type, $config));
|
||||
return array($mock, $config);
|
||||
}
|
||||
protected function teardownCacheMock()
|
||||
{
|
||||
HTMLPurifier_DefinitionCacheFactory::instance($this->oldFactory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user