mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-22 08:21:52 +00:00
Kick the auto-prepend habit.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@91 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
ac1e62e043
commit
de5ab5e6a0
145
tests/Debugger.php
Normal file
145
tests/Debugger.php
Normal file
@ -0,0 +1,145 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
* 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
|
||||
{
|
||||
|
||||
var $shouldPaint = false;
|
||||
var $paints = 0;
|
||||
var $current_scopes = array();
|
||||
var $scope_nextID = 1;
|
||||
var $add_pre = true;
|
||||
|
||||
function Debugger() {
|
||||
$this->add_pre = !extension_loaded('xdebug');
|
||||
}
|
||||
|
||||
function &instance() {
|
||||
static $soleInstance = false;
|
||||
if (!$soleInstance) $soleInstance = new Debugger();
|
||||
return $soleInstance;
|
||||
}
|
||||
|
||||
function paintIf($mixed, $conditional) {
|
||||
if (!$conditional) return;
|
||||
$this->paint($mixed);
|
||||
}
|
||||
|
||||
function paintWhen($mixed, $scopes = array()) {
|
||||
if (!$this->isInScopes($scopes)) return;
|
||||
$this->paint($mixed);
|
||||
}
|
||||
|
||||
function paintIfWhen($mixed, $conditional, $scopes = array()) {
|
||||
if (!$conditional) return;
|
||||
if (!$this->isInScopes($scopes)) return;
|
||||
$this->paint($mixed);
|
||||
}
|
||||
|
||||
function paint($mixed) {
|
||||
$this->paints++;
|
||||
if($this->add_pre) echo '<pre>';
|
||||
var_dump($mixed);
|
||||
if($this->add_pre) echo '</pre>';
|
||||
}
|
||||
|
||||
function addScope($id = false) {
|
||||
if ($id == false) {
|
||||
$id = $this->scope_nextID++;
|
||||
}
|
||||
$this->current_scopes[$id] = true;
|
||||
}
|
||||
|
||||
function removeScope($id) {
|
||||
if (isset($this->current_scopes[$id])) unset($this->current_scopes[$id]);
|
||||
}
|
||||
|
||||
function resetScopes() {
|
||||
$this->current_scopes = array();
|
||||
$this->scope_nextID = 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,6 +1,12 @@
|
||||
<?php
|
||||
|
||||
load_simpletest(); // includes all relevant simpletest files
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once 'simpletest/unit_tester.php';
|
||||
require_once 'simpletest/reporter.php';
|
||||
require_once 'simpletest/mock_objects.php';
|
||||
|
||||
require_once 'Debugger.php';
|
||||
|
||||
// emulates inserting a dir called HTMLPurifier into your class dir
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../library');
|
||||
|
Loading…
Reference in New Issue
Block a user