1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-10-16 22:46:06 +02:00

Convert to PHP 5 only codebase, adding visibility modifiers to all members and methods in the main library area (function only for test methods)

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1458 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2007-11-25 02:24:39 +00:00
parent 85a23bacb6
commit 43f01925cd
195 changed files with 1003 additions and 1064 deletions

View File

@@ -112,10 +112,8 @@ class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
'attr1' => 'Color',
'attr2*' => 'URI'
);
$c_object = new HTMLPurifier_AttrDef();
$c_object->_name = 'Color'; // for testing purposes only
$u_object = new HTMLPurifier_AttrDef();
$u_object->_name = 'URL'; // for testing purposes only
$c_object = new HTMLPurifier_AttrDef_HTML_Color();
$u_object = new HTMLPurifier_AttrDef_URI();
$types->setReturnValue('get', $c_object, array('Color'));
$types->setReturnValue('get', $u_object, array('URI'));

View File

@@ -17,7 +17,7 @@ class HTMLPurifier_AttrDef_CSS_Composite_Testable extends
class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
{
var $def1, $def2;
protected $def1, $def2;
function test() {

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDefHarness extends HTMLPurifier_Harness
{
var $def;
var $context, $config;
protected $def;
protected $context, $config;
function setUp() {
$this->config = HTMLPurifier_Config::createDefault();

View File

@@ -2,12 +2,17 @@
require_once 'HTMLPurifier/AttrDef.php';
Mock::generatePartial(
'HTMLPurifier_AttrDef',
'HTMLPurifier_AttrDefTestable',
array('validate'));
class HTMLPurifier_AttrDefTest extends HTMLPurifier_Harness
{
function test_parseCDATA() {
$def = new HTMLPurifier_AttrDef();
$def = new HTMLPurifier_AttrDefTestable();
$this->assertIdentical('', $def->parseCDATA(''));
$this->assertIdentical('', $def->parseCDATA("\t\n\r \t\t"));
@@ -19,7 +24,7 @@ class HTMLPurifier_AttrDefTest extends HTMLPurifier_Harness
function test_make() {
$def = new HTMLPurifier_AttrDef();
$def = new HTMLPurifier_AttrDefTestable();
$def2 = $def->make('');
$this->assertIdentical($def, $def2);

View File

@@ -2,12 +2,17 @@
require_once 'HTMLPurifier/AttrTransform.php';
Mock::generatePartial(
'HTMLPurifier_AttrTransform',
'HTMLPurifier_AttrTransformTestable',
array('transform'));
class HTMLPurifier_AttrTransformTest extends HTMLPurifier_Harness
{
function test_prependCSS() {
$t = new HTMLPurifier_AttrTransform();
$t = new HTMLPurifier_AttrTransformTestable();
$attr = array();
$t->prependCSS($attr, 'style:new;');
@@ -25,7 +30,7 @@ class HTMLPurifier_AttrTransformTest extends HTMLPurifier_Harness
function test_confiscateAttr() {
$t = new HTMLPurifier_AttrTransform();
$t = new HTMLPurifier_AttrTransformTestable();
$attr = array('flavor' => 'sweet');
$this->assertIdentical('sweet', $t->confiscateAttr($attr, 'flavor'));

View File

@@ -6,7 +6,7 @@ require_once 'HTMLPurifier/ChildDef/Chameleon.php';
class HTMLPurifier_ChildDef_ChameleonTest extends HTMLPurifier_ChildDefHarness
{
var $isInline;
protected $isInline;
function setUp() {
parent::setUp();

View File

@@ -13,44 +13,44 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
/**
* Instance of the object that will execute the method
*/
var $obj;
protected $obj;
/**
* Name of the function to be executed
*/
var $func;
protected $func;
/**
* Whether or not the method deals in tokens. If set to true, assertResult()
* will transparently convert HTML to and back from tokens.
*/
var $to_tokens = false;
protected $to_tokens = false;
/**
* Whether or not to convert tokens back into HTML before performing
* equality check, has no effect on bools.
*/
var $to_html = false;
protected $to_html = false;
/**
* Instance of an HTMLPurifier_Lexer implementation.
*/
var $lexer;
protected $lexer;
/**
* Instance of HTMLPurifier_Generator
*/
var $generator;
protected $generator;
/**
* Default config to fall back on if no config is available
*/
var $config;
protected $config;
/**
* Default context to fall back on if no context is available
*/
var $context;
protected $context;
function HTMLPurifier_ComplexHarness() {
$this->lexer = new HTMLPurifier_Lexer_DirectLex();

View File

@@ -12,17 +12,17 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
/**
* Munged name of current file.
*/
var $file;
protected $file;
/**
* Copy of the real ConfigSchema to revert to.
*/
var $old_copy;
protected $old_copy;
/**
* Copy of dummy ConfigSchema for testing purposes.
*/
var $our_copy;
protected $our_copy;
function setUp() {
// yes, I know this is slightly convoluted, but that's the price

View File

@@ -9,7 +9,7 @@ if (!class_exists('CS')) {
class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
{
var $our_copy, $old_copy;
protected $our_copy, $old_copy;
function setUp() {
// set up a dummy schema object for testing

View File

@@ -8,7 +8,7 @@ require_once 'HTMLPurifier/IDAccumulator.php';
class HTMLPurifier_ContextTest extends HTMLPurifier_Harness
{
var $context;
protected $context;
function setUp() {
$this->context = new HTMLPurifier_Context();

View File

@@ -66,7 +66,7 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
function test_errors() {
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
$def = new HTMLPurifier_Definition();
$def = $this->generateDefinition();
$def->setup = true;
$def->type = 'NotTest';
$config = $this->generateConfigMock('testfoo');

View File

@@ -5,8 +5,8 @@ require_once 'HTMLPurifier/DefinitionCacheFactory.php';
class HTMLPurifier_DefinitionCacheFactoryTest extends HTMLPurifier_Harness
{
var $newFactory;
var $oldFactory;
protected $newFactory;
protected $oldFactory;
function setup() {
$new = new HTMLPurifier_DefinitionCacheFactory();

View File

@@ -1,5 +1,7 @@
<?php
require_once 'HTMLPurifier/DefinitionTestable.php';
class HTMLPurifier_DefinitionCacheHarness extends HTMLPurifier_Harness
{
@@ -20,7 +22,7 @@ class HTMLPurifier_DefinitionCacheHarness extends HTMLPurifier_Harness
* Returns an anonymous def that has been setup and named Test
*/
function generateDefinition($member_vars = array()) {
$def = new HTMLPurifier_Definition();
$def = new HTMLPurifier_DefinitionTestable();
$def->setup = true;
$def->type = 'Test';
foreach ($member_vars as $key => $val) {

View File

@@ -6,7 +6,8 @@ class HTMLPurifier_DefinitionCacheTest extends HTMLPurifier_Harness
{
function test_isOld() {
$cache = new HTMLPurifier_DefinitionCache('Test'); // non-functional
// using null subclass because parent is abstract
$cache = new HTMLPurifier_DefinitionCache_Null('Test');
$old_copy = HTMLPurifier_ConfigSchema::instance();
$o = new HTMLPurifier_ConfigSchema();

View File

@@ -1,32 +1,22 @@
<?php
require_once 'HTMLPurifier/Definition.php';
Mock::generatePartial(
'HTMLPurifier_Definition',
'HTMLPurifier_Definition_Testable',
array('doSetup'));
require_once 'HTMLPurifier/DefinitionTestable.php';
class HTMLPurifier_DefinitionTest extends HTMLPurifier_Harness
{
function test_setup() {
$def = new HTMLPurifier_Definition_Testable();
$def = new HTMLPurifier_DefinitionTestable();
$config = HTMLPurifier_Config::createDefault();
$def->expectOnce('doSetup', array($config));
$def->setup($config);
}
function test_setup_redundant() {
$def = new HTMLPurifier_Definition_Testable();
$def = new HTMLPurifier_DefinitionTestable();
$config = HTMLPurifier_Config::createDefault();
$def->expectNever('doSetup');
$def->setup = true;
$def->setup($config);
}
function test_doSetup_abstract() {
$def = new HTMLPurifier_Definition();
$this->expectError('Cannot call abstract method');
$config = HTMLPurifier_Config::createDefault();
$def->doSetup($config);
}
}

View File

@@ -0,0 +1,7 @@
<?php
Mock::generatePartial(
'HTMLPurifier_Definition',
'HTMLPurifier_DefinitionTestable',
array('doSetup'));

View File

@@ -5,7 +5,7 @@ require_once 'HTMLPurifier/Encoder.php';
class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
{
var $_entity_lookup;
protected $_entity_lookup;
function setUp() {
$this->_entity_lookup = HTMLPurifier_EntityLookup::instance();

View File

@@ -5,7 +5,7 @@ require_once 'HTMLPurifier/EntityParser.php';
class HTMLPurifier_EntityParserTest extends HTMLPurifier_Harness
{
var $EntityParser;
protected $EntityParser;
function setUp() {
$this->EntityParser = new HTMLPurifier_EntityParser();
@@ -75,9 +75,11 @@ class HTMLPurifier_EntityParserTest extends HTMLPurifier_Harness
}
function test_specialEntityCallback() {
$this->assertIdentical("'",$this->EntityParser->specialEntityCallback(
array('&#39;', null, '39', null) ));
function test_substituteSpecialEntities() {
$this->assertIdentical(
"'",
$this->EntityParser->substituteSpecialEntities('&#39;')
);
}
}

View File

@@ -10,22 +10,22 @@ generate_mock_once('HTMLPurifier_ErrorCollector');
class HTMLPurifier_ErrorCollectorEMock extends HTMLPurifier_ErrorCollectorMock
{
var $_context;
var $_expected_context = array();
var $_expected_context_at = array();
private $_context;
private $_expected_context = array();
private $_expected_context_at = array();
function prepare(&$context) {
public function prepare(&$context) {
$this->_context =& $context;
}
function expectContext($key, $value) {
public function expectContext($key, $value) {
$this->_expected_context[$key] = $value;
}
function expectContextAt($step, $key, $value) {
public function expectContextAt($step, $key, $value) {
$this->_expected_context_at[$step][$key] = $value;
}
function send() {
public function send($v1, $v2) {
// test for context
$context =& SimpleTest::getContext();
$test =& $context->getTest();

View File

@@ -10,8 +10,8 @@ require_once 'HTMLPurifier/Lexer/DirectLex.php';
class HTMLPurifier_ErrorsHarness extends HTMLPurifier_Harness
{
var $config, $context;
var $collector, $generator, $callCount;
protected $config, $context;
protected $collector, $generator, $callCount;
function setup() {
$this->config = HTMLPurifier_Config::create(array('Core.CollectErrors' => true));

View File

@@ -8,8 +8,9 @@ require_once 'HTMLPurifier/ComplexHarness.php';
class HTMLPurifier_GeneratorTest extends HTMLPurifier_ComplexHarness
{
var $gen;
var $_entity_lookup;
protected $gen;
protected $_entity_lookup;
protected $config;
function HTMLPurifier_GeneratorTest() {
$this->HTMLPurifier_Harness();
@@ -121,7 +122,6 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_ComplexHarness
}
var $config;
function assertGeneration($tokens, $expect) {
$context = new HTMLPurifier_Context();
$result = $this->gen->generateFromTokens(

View File

@@ -9,8 +9,7 @@ class HTMLPurifier_HTMLModuleManagerTest extends HTMLPurifier_Harness
$manager = new HTMLPurifier_HTMLModuleManager();
$manager->doctypes->register('Blank'); // doctype normally is blank...
$attrdef_nmtokens = new HTMLPurifier_AttrDef();
$attrdef_nmtokens->_name = 'nmtokens'; // for testing only
$attrdef_nmtokens = new HTMLPurifier_AttrDef_HTML_Nmtokens();
generate_mock_once('HTMLPurifier_AttrDef');
$attrdef = new HTMLPurifier_AttrDefMock();

View File

@@ -12,7 +12,7 @@ class HTMLPurifier_Harness extends UnitTestCase
parent::UnitTestCase();
}
var $config, $context;
protected $config, $context;
/**
* Generates easily accessible default config/context

View File

@@ -2,10 +2,13 @@
require_once 'HTMLPurifier/Language.php';
/**
* @todo Fix usage of HTMLPurifier_Language->_loaded using something else
*/
class HTMLPurifier_LanguageTest extends HTMLPurifier_Harness
{
var $lang;
protected $lang;
function generateEnLanguage() {
$factory = HTMLPurifier_LanguageFactory::instance();

View File

@@ -5,7 +5,7 @@ require_once 'HTMLPurifier/Lexer/DirectLex.php';
class HTMLPurifier_Lexer_DirectLexTest extends HTMLPurifier_Harness
{
var $DirectLex;
protected $DirectLex;
function setUp() {
$this->DirectLex = new HTMLPurifier_Lexer_DirectLex();

View File

@@ -5,7 +5,7 @@ require_once 'HTMLPurifier/Lexer/DirectLex.php';
class HTMLPurifier_LexerTest extends HTMLPurifier_Harness
{
var $_has_pear = false;
protected $_has_pear = false;
function HTMLPurifier_LexerTest() {
parent::HTMLPurifier_Harness();

View File

@@ -5,8 +5,8 @@ require_once 'HTMLPurifier/PercentEncoder.php';
class HTMLPurifier_PercentEncoderTest extends HTMLPurifier_Harness
{
var $PercentEncoder;
var $func;
protected $PercentEncoder;
protected $func;
function setUp() {
$this->PercentEncoder = new HTMLPurifier_PercentEncoder();

View File

@@ -8,7 +8,7 @@ class HTMLPurifier_Strategy_Composite_Test
extends HTMLPurifier_Strategy_Composite
{
function HTMLPurifier_Strategy_Composite_Test(&$strategies) {
public function __construct(&$strategies) {
$this->strategies =& $strategies;
}

View File

@@ -7,26 +7,28 @@ class HTMLPurifier_URIDefinitionTest extends HTMLPurifier_URIHarness
{
function createFilterMock($expect = true, $result = true) {
static $i = 0;
generate_mock_once('HTMLPurifier_URIFilter');
$mock = new HTMLPurifier_URIFilterMock();
if ($expect) $mock->expectOnce('filter');
else $mock->expectNever('filter');
$mock->setReturnValue('filter', $result);
$mock->name = $i++;
return $mock;
}
function test_filter() {
$def = new HTMLPurifier_URIDefinition();
$def->filters[] = $this->createFilterMock();
$def->filters[] = $this->createFilterMock();
$def->addFilter($this->createFilterMock(), $this->config);
$def->addFilter($this->createFilterMock(), $this->config);
$uri = $this->createURI('test');
$this->assertTrue($def->filter($uri, $this->config, $this->context));
}
function test_filter_earlyAbortIfFail() {
$def = new HTMLPurifier_URIDefinition();
$def->filters[] = $this->createFilterMock(true, false);
$def->filters[] = $this->createFilterMock(false); // never called
$def->addFilter($this->createFilterMock(true, false), $this->config);
$def->addFilter($this->createFilterMock(false), $this->config); // never called
$uri = $this->createURI('test');
$this->assertFalse($def->filter($uri, $this->config, $this->context));
}
@@ -36,7 +38,7 @@ class HTMLPurifier_URIDefinitionTest extends HTMLPurifier_URIHarness
$this->config->set('URI', 'Base', $base = 'http://sub.example.com/foo/bar.html');
$this->config->set('URI', 'DefaultScheme', 'ftp');
$def = new HTMLPurifier_URIDefinition();
$def->setupMemberVariables($this->config);
$def->setup($this->config);
$this->assertIdentical($def->host, $host);
$this->assertIdentical($def->base, $this->createURI($base));
$this->assertIdentical($def->defaultScheme, 'http'); // not ftp!
@@ -45,14 +47,14 @@ class HTMLPurifier_URIDefinitionTest extends HTMLPurifier_URIHarness
function test_setupMemberVariables_onlyScheme() {
$this->config->set('URI', 'DefaultScheme', 'ftp');
$def = new HTMLPurifier_URIDefinition();
$def->setupMemberVariables($this->config);
$def->setup($this->config);
$this->assertIdentical($def->defaultScheme, 'ftp');
}
function test_setupMemberVariables_onlyBase() {
$this->config->set('URI', 'Base', 'http://sub.example.com/foo/bar.html');
$def = new HTMLPurifier_URIDefinition();
$def->setupMemberVariables($this->config);
$def->setup($this->config);
$this->assertIdentical($def->host, 'sub.example.com');
}

View File

@@ -17,7 +17,7 @@ class HTMLPurifier_URITest extends HTMLPurifier_URIHarness
$this->assertIdentical($uri1, $uri2);
}
var $oldRegistry;
protected $oldRegistry;
function &setUpSchemeRegistryMock() {
$this->oldRegistry = HTMLPurifier_URISchemeRegistry::instance();