186 lines
3.2 KiB
PHP
186 lines
3.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
class SESanityTest
|
||
|
|
{
|
||
|
|
// This should be generated by the child class based on the options given
|
||
|
|
var $name;
|
||
|
|
|
||
|
|
var $category;
|
||
|
|
|
||
|
|
// The test type
|
||
|
|
var $type;
|
||
|
|
|
||
|
|
// Was it successful?
|
||
|
|
var $result = FALSE;
|
||
|
|
|
||
|
|
// Error level, 0 - none, 2 - notice, 4 - warning, 8 - fatal
|
||
|
|
var $error = 0;
|
||
|
|
|
||
|
|
var $is_recommendation = FALSE;
|
||
|
|
|
||
|
|
var $is_critical = FALSE;
|
||
|
|
|
||
|
|
var $lang_title;
|
||
|
|
|
||
|
|
var $lang_message;
|
||
|
|
|
||
|
|
var $custom_message;
|
||
|
|
|
||
|
|
|
||
|
|
// Options
|
||
|
|
var $level_default;
|
||
|
|
var $callback;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function SESanityTest($options)
|
||
|
|
{
|
||
|
|
$this->setOptions($options);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
public static function &getInstance($type, $options)
|
||
|
|
{
|
||
|
|
$type = strtolower(preg_replace('/[^A-Z0-9_\.-]/i', '', $type));
|
||
|
|
$class = 'SESanityTest'.ucfirst($type);
|
||
|
|
|
||
|
|
if( !class_exists($class) )
|
||
|
|
{
|
||
|
|
$path = dirname(__FILE__).DIRECTORY_SEPARATOR.'test'.DIRECTORY_SEPARATOR.$type.'.php';
|
||
|
|
if( file_exists($path) )
|
||
|
|
{
|
||
|
|
require_once($path);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
die('Unable to load test class: '.$type);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$instance = new $class($options);
|
||
|
|
$instance->type = $type;
|
||
|
|
|
||
|
|
return $instance;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function setOptions($options)
|
||
|
|
{
|
||
|
|
if( isset($options['level']) )
|
||
|
|
$this->level_default = $options['level'];
|
||
|
|
|
||
|
|
if( isset($options['category']) )
|
||
|
|
$this->category = $options['category'];
|
||
|
|
|
||
|
|
if( isset($options['critical']) )
|
||
|
|
$this->is_critical = $options['critical'];
|
||
|
|
|
||
|
|
if( isset($options['lang_title']) )
|
||
|
|
$this->lang_title = $options['lang_title'];
|
||
|
|
|
||
|
|
if( isset($options['lang_message']) )
|
||
|
|
$this->lang_message = $options['lang_message'];
|
||
|
|
|
||
|
|
if( isset($options['recommendation']) )
|
||
|
|
$this->is_recommendation = $options['recommendation'];
|
||
|
|
|
||
|
|
if( isset($options['callback']) && is_callable($options['callback']) )
|
||
|
|
$this->level_default = $options['callback'];
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function preset()
|
||
|
|
{
|
||
|
|
$name = $this->getName();
|
||
|
|
|
||
|
|
if( is_callable(array('SESanityHelpers', $name)) )
|
||
|
|
{
|
||
|
|
call_user_func_array(array('SESanityHelpers', $name), array($name));
|
||
|
|
}
|
||
|
|
elseif( $this->callback )
|
||
|
|
{
|
||
|
|
call_user_func_array($this->callback, array($name));
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
return FALSE;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
return TRUE;
|
||
|
|
|
||
|
|
/*
|
||
|
|
if( !$this->callback && is_callable(array('SESanityHelpers', $name)) )
|
||
|
|
{
|
||
|
|
$this->callback = array('SESanityHelpers', $name);
|
||
|
|
}
|
||
|
|
|
||
|
|
if( !is_callable($this->callback) )
|
||
|
|
return FALSE;
|
||
|
|
|
||
|
|
call_user_func_array($this->callback, array(&$this));
|
||
|
|
return TRUE;
|
||
|
|
*/
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function getType()
|
||
|
|
{
|
||
|
|
return $this->type;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function getName()
|
||
|
|
{
|
||
|
|
return $this->name;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
// Functions that must be implemented by the child classes
|
||
|
|
function execute() { }
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function merge() { }
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function getValue() { }
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function getTitle()
|
||
|
|
{
|
||
|
|
return $this->lang_title;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function getCategory()
|
||
|
|
{
|
||
|
|
$sanity = SESanity::getInstance();
|
||
|
|
return $sanity->categories[$this->category]['lang_title'];
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function getMessage()
|
||
|
|
{
|
||
|
|
return $this->lang_message;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function getCustomMessage()
|
||
|
|
{
|
||
|
|
return $this->custom_message;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
?>
|