Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass through PHP notices, warnings, and errors to test harness and fix resulting failures #4074

Merged
merged 56 commits into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
b9d4961
Turn off web error handler for CLI (breaks a lot of stuff!)
Deltik Jan 17, 2020
be36462
Null coalescing for $_SERVER keys in e107_class.php
Deltik Jan 17, 2020
c232613
Fix mkdir() failure in e107::_init() if parent not exists
Deltik Jan 17, 2020
bcba1e0
Null coalescing for $_SERVER keys in iphandler_class.php
Deltik Jan 17, 2020
a49b532
Stop stepping on E107_DBG_* constants in tests
Deltik Jan 17, 2020
6fe4bf1
Null coalescing for $_SERVER keys in online_class.php
Deltik Jan 17, 2020
4321c1b
Null coalescing for $_SERVER keys in session_handler.php
Deltik Jan 17, 2020
ef34ef7
Removed obsolete ALLOW_AUTO_FIELD_DEFS constant
Deltik Jan 17, 2020
bfad3f7
Suppressed constant already defined errors in e_db_mysqlTest
Deltik Jan 17, 2020
62a547a
Fixed E_NOTICE in plugin install/uninstall process
Deltik Jan 17, 2020
b4e48f8
Fix duplicate constant in lancheckTest
Deltik Jan 17, 2020
78a5c2a
Disabled e_onlineTest::testGoOnline() – has no assertions
Deltik Jan 17, 2020
66a9765
Corrected subset check in user_classTest::testGetUsersInClass()
Deltik Jan 17, 2020
8e0b047
array_diff_recursive() type check for recursion
Deltik Jan 17, 2020
c604b30
Fixed type check in e_form::option_multi()
Deltik Jan 17, 2020
b2bd676
Null checks for e107TinyMceParserTest
Deltik Jan 17, 2020
98911f0
Guard type errors in e_db::insert() implementations
Deltik Jan 17, 2020
1561992
Removed unused variable from e107plugin::XmlAdminLinks()
Deltik Jan 17, 2020
82499f7
Debug variable scope fix in e107plugin::XmlTables()
Deltik Jan 17, 2020
24fe5c8
Updated pclzip.lib.php to v2.8.4 to fix math error
Deltik Jan 17, 2020
ce51015
Removed useless STRPTIME_COMPAT constant
Deltik Jan 17, 2020
1d72d48
Type checks for db_verify::prepareResults()
Deltik Jan 17, 2020
dbdb5f4
Fix e_arrayTest::testUnserialize()
Deltik Jan 17, 2020
509b9ff
Type check for online_shortcodes::sc_online_member_user()
Deltik Jan 17, 2020
d2d0105
Null check for UserHandler::userClassUpdate()
Deltik Jan 17, 2020
15de2e2
Null check for e_file::file_size_decode()
Deltik Jan 17, 2020
46b5418
Fixed array key absence check in e_db_abstractTest::testDb_Fetch()
Deltik Jan 17, 2020
622be85
Type checks involving e_formTest
Deltik Jan 18, 2020
fc6b81f
Fix undefined constant by importing LAN in e_marketplace
Deltik Jan 17, 2020
b8d6b9e
Type and null checks for pluginsTest
Deltik Jan 18, 2020
a0f4489
Disabled db_verifyTest::testGetIndex() due to no assertions
Deltik Jan 18, 2020
91660a2
Test isolation fixes for e_db_abstractTest
Deltik Jan 17, 2020
f5f1454
Eliminated notice failures in e107Test
Deltik Jan 18, 2020
cf8dc0b
Null coalescing for e_theme constructor
Deltik Jan 18, 2020
f56bf44
Ignore redefines of EUF_* constants in e107_user_extended
Deltik Jan 18, 2020
d6eafdc
Null check for e_user_model::isBot()
Deltik Jan 18, 2020
a1560b1
Strict fixes for e_tree_model::flattenTree()
Deltik Jan 18, 2020
9506f98
Empty check for e_tohtml_linkwords::linksproc()
Deltik Jan 18, 2020
76c0f7e
Type validation for navigation_shortcode()
Deltik Jan 18, 2020
638412a
Null coalesce optional variable in link.bb
Deltik Jan 18, 2020
207ce81
Bring class2Test::testCheckClass() back to passing (workaround)
Deltik Jan 18, 2020
d1bdfb8
Type checks and corrections for e_parse::thumbSrcSet()
Deltik Jan 17, 2020
d55fe8a
Import LAN for e_formTest::testRenderElement()
Deltik Jan 18, 2020
524229b
Fixed a bunch of PHP 7.4 syntax errors
Deltik Jan 18, 2020
4454b01
Fix PHP 7.3 deprecation warning in lan_ren_help.php
Deltik Jan 18, 2020
be8f2bb
Fixed PHP 7.3 warnings
Deltik Jan 18, 2020
52116ad
Silence debug prints clearly not meant for CLI
Deltik Jan 18, 2020
510d8e2
Fix flaky e_pluginTest::testBuildAddonPrefList()
Deltik Jan 18, 2020
970f65b
Null check for optional query string in e107::url()
Deltik Jan 18, 2020
72d3f07
PHP 5.6 fixes for e_db_mysql
Deltik Jan 19, 2020
c789767
Removed PDO from e_db_mysql
Deltik Jan 19, 2020
4a26ac5
Removed unused USE_PERSISTANT_DB constant
Deltik Jan 19, 2020
8c528de
e_db_mysql: Replaced mysql with mysqli
Deltik Jan 19, 2020
1fd0a17
CI now installs mysqli extension
Deltik Jan 19, 2020
8b354ad
Don't spam database server with connections
Deltik Jan 19, 2020
f2a7590
Workaround for old phpunit/php-code-coverage missing mkdir()
Deltik Jan 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ jobs:
- name: Install PHP pdo_mysql extension
run: docker-php-ext-install pdo_mysql

- name: Install PHP mysqli extension
run: docker-php-ext-install mysqli

- uses: actions/checkout@v2

- name: Install Composer
Expand Down
19 changes: 8 additions & 11 deletions class2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* e107 website system
*
* Copyright (C) 2008-2010 e107 Inc (e107.org)
* Copyright (C) 2008-2020 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
Expand Down Expand Up @@ -143,8 +143,8 @@
// D: Setup PHP error handling
// (Now we can see PHP errors) -- but note that DEBUG is not yet enabled!
//
global $error_handler;
$error_handler = new error_handler();
set_error_handler(array(&$error_handler, 'handle_error'));

//
// E: Setup other essential PHP parameters
Expand Down Expand Up @@ -391,7 +391,7 @@
// e107_require_once(e_HANDLER.'mysql_class.php');

//DEPRECATED, BC, $e107->sql caught by __get()
/** @var e_db_mysql $sql */
/** @var e_db $sql */
$sql = e107::getDb(); //TODO - find & replace $sql, $e107->sql
$sql->db_SetErrorReporting(false);

Expand Down Expand Up @@ -1418,12 +1418,6 @@ function systemTimeZoneIsValid($zone = '')
// ----------------------------------------------------------------------------
$sql->db_Mark_Time('Find/Load Theme');

if(e_ADMIN_AREA) // Load admin phrases ASAP
{
e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_admin.php');
}


if(!defined('THEME'))
{

Expand Down Expand Up @@ -2033,6 +2027,7 @@ function init_session()
define('USERNAME', 'e107-cli');
define('USERTHEME', false);
define('ADMIN', true);
define('ADMINPERMS', false);
define('GUEST', false);
define('USERCLASS', '');
define('USEREMAIL', '');
Expand Down Expand Up @@ -2418,8 +2413,8 @@ function force_userupdate($currentUser)
class error_handler
{

var $errors;
var $debug = false;
public $errors = [];
public $debug = false;
protected $xdebug = false;
protected $docroot = '';
protected $label = array();
Expand Down Expand Up @@ -2462,6 +2457,8 @@ function __construct()
{
error_reporting(E_ERROR | E_PARSE);
}

set_error_handler(array(&$this, 'handle_error'));
}

/**
Expand Down
8 changes: 0 additions & 8 deletions e107_admin/lancheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
require_once("../class2.php");
}

/*
if (!getperms("L"))
{
e107::redirect('admin');
exit;
}
*/

e107::coreLan('lancheck', true);

$e_sub_cat = 'language';
Expand Down
2 changes: 1 addition & 1 deletion e107_core/bbcodes/link.bb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ global $pref;
$parm .= ']';
}

list($link,$extras) = explode(" ",$parm);
list($link,$extras) = array_pad(explode(" ",$parm), 2, null);

if(!$parm) $link = $code_text;

Expand Down
21 changes: 11 additions & 10 deletions e107_core/shortcodes/single/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,29 @@ function navigation_shortcode($parm=null)
'alt6' => 6,
);


if(is_array($parm) && !empty($parm))
$category = 1;
$tmpl = 'main';
if (!is_array($parm))
{
$category = isset($types[$parm]) ? $types[$parm] : 1;
$tmpl = $parm ?: 'main';
}
elseif (!empty($parm))
{
$category = 1;
$tmpl = 'main';

if(!empty($parm['type']))
if (!empty($parm['type']))
{
$cat = $parm['type'];
$category = varset($types[$cat], 1);
}

if(!empty($parm['layout']))
if (!empty($parm['layout']))
{
$tmpl= $parm['layout'];
$tmpl = $parm['layout'];
}
}
else
{
$category = varset($types[$parm], 1);
$tmpl = vartrue($parm, 'main');
}

$nav = e107::getNav();

Expand Down
1 change: 1 addition & 0 deletions e107_handlers/bbcode_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ function imgToBBcode($html, $fromDB = false)
print_a($arr);
}

$arr['img'] = isset($arr['img']) && is_array($arr['img']) ? $arr['img'] : [];
foreach($arr['img'] as $img)
{
if(/*substr($img['src'],0,4) == 'http' ||*/ strpos($img['src'], e_IMAGE_ABS.'emotes/')!==false) // dont resize external images or emoticons.
Expand Down
4 changes: 2 additions & 2 deletions e107_handlers/core_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function array_diff_recursive($array1, $array2)

foreach($array1 as $key => $val)
{
if(array_key_exists($key, $array2))
if(is_array($array2) && array_key_exists($key, $array2))
{
if(is_array($val))
{
Expand Down Expand Up @@ -457,7 +457,7 @@ public function unserialize($sourceArrayData)

// e107::getDebug()->log("Json data found");

if(json_last_error() != JSON_ERROR_NONE && (e_DEBUG === true))
if(json_last_error() != JSON_ERROR_NONE && e_DEBUG === true && !e107::isCli())
{
echo "<div class='alert alert-danger'><h4>e107::unserialize() Parser Error (json)</h4></div>";
echo "<pre>";
Expand Down
2 changes: 1 addition & 1 deletion e107_handlers/date_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ function computeLapse($older_date, $newer_date = FALSE, $mode = FALSE, $show_sec
*/
public function strptime($str, $format)
{
if(STRPTIME_COMPAT !== TRUE && function_exists('strptime')) // Unix Only.
if(function_exists('strptime')) // Unix Only.
{
$vals = strptime($str,$format); // PHP5 is more accurate than below.
$vals['tm_amon'] = strftime('%b', mktime(0,0,0, $vals['tm_mon'] +1) );
Expand Down
6 changes: 4 additions & 2 deletions e107_handlers/db_verify_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ private function load()
*/
private function diffStructurePermissive($expected, $actual)
{
$expected['default'] = isset($expected['default']) ? $expected['default'] : '';
$actual['default'] = isset($actual['default']) ? $actual['default'] : '';

if($expected['type'] === 'JSON') // Fix for JSON alias MySQL 5.7+
{
$expected['type'] = 'LONGTEXT';
}


// Permit actual text types that default to null even when
// expected does not explicitly default to null
if(0 === strcasecmp($expected['type'], $actual['type']) &&
Expand Down Expand Up @@ -410,7 +412,7 @@ public function prepareResults($tbl, $selection, $sqlData, $fileData)
{
$this->{$results}[$tbl][$key]['_status'] = 'ok';

if(!is_array($sqlData[$type][$key]))
if(!isset($sqlData[$type][$key]) || !is_array($sqlData[$type][$key]))
{
$this->errors[$tbl]['_status'] = 'error'; // table status
$this->{$results}[$tbl][$key]['_status'] = "missing_$type"; // type status
Expand Down
2 changes: 1 addition & 1 deletion e107_handlers/debug_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
define('E107_DEBUG_LEVEL', $e107_debug_level);
}
}
else
elseif (!defined('E107_DEBUG_LEVEL'))
{
define('E107_DEBUG_LEVEL', 0);
}
Expand Down
49 changes: 38 additions & 11 deletions e107_handlers/e107_class.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,12 @@ protected function _init($e107_paths, $e107_root_path, $e107_config_mysql_info,

if(!is_dir(e_SYSTEM))
{
mkdir(e_SYSTEM, 0755);
mkdir(e_SYSTEM, 0755, true);
}

if(!is_dir(e_CACHE_IMAGE))
{
mkdir(e_CACHE_IMAGE, 0755);
mkdir(e_CACHE_IMAGE, 0755, true);
}

// Prepare essential directories.
Expand Down Expand Up @@ -2821,7 +2821,7 @@ public static function getCoreTemplate($id, $key = null, $override = true, $merg
*/
public static function getTemplate($plug_name, $id = null, $key = null, $override = true, $merge = false, $info = false)
{
if(null === $plug_name)
if(!$plug_name)
{
return self::getCoreTemplate($id, $key, $override, $merge, $info);
}
Expand All @@ -2837,6 +2837,15 @@ public static function getTemplate($plug_name, $id = null, $key = null, $overrid
self::getMessage()->addDebug( "Attempting to load Template File: ".$path );
}

/**
* "front" and "global" LANs might not be loaded come self::_getTemplate(),
* so the following calls to self::plugLan() fix that.
*/
self::plugLan($plug_name, null, true);
self::plugLan($plug_name, null, false);
self::plugLan($plug_name, 'global', true);
self::plugLan($plug_name, 'global', false);

$id = str_replace('/', '_', $id);
$ret = self::_getTemplate($id, $key, $reg_path, $path, $info);

Expand Down Expand Up @@ -3145,6 +3154,11 @@ public static function includeLan($path, $force = false)
*/
public static function coreLan($fname, $admin = false)
{
if ($admin)
{
e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_admin.php');
}

$cstring = 'corelan/'.e_LANGUAGE.'_'.$fname.($admin ? '_admin' : '_front');
if(self::getRegistry($cstring)) return;

Expand Down Expand Up @@ -3545,7 +3559,7 @@ public static function url($plugin = '', $key = null, $row = array(), $options =

// Avoid duplicate query keys. eg. URL has ?id=x and $options['query']['id'] exists.
// @see forum/e_url.php - topic/redirect and forum/view_shortcodes.php sc_post_url()
list($legacyUrl, $tmp) = explode("?", $legacyUrl);
list($legacyUrl, $tmp) = array_pad(explode("?", $legacyUrl), 2, null);

if (!empty($tmp))
{
Expand Down Expand Up @@ -3852,7 +3866,12 @@ public function prepare_request($checkS = true)
if(isset($GLOBALS['_E107']) && is_array($GLOBALS['_E107'])) $this->_E107 = & $GLOBALS['_E107'];

// remove ajax_used=1 from query string to avoid SELF problems, ajax should always be detected via e_AJAX_REQUEST constant
$_SERVER['QUERY_STRING'] = trim(str_replace(array('ajax_used=1', '&&'), array('', '&'), $_SERVER['QUERY_STRING']), '&');
$_SERVER['QUERY_STRING'] = trim(
str_replace(
array('ajax_used=1', '&&'),
array('', '&'),
(isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '')
), '&');

/* PathInfo doesn't break anything, URLs should be always absolute. Disabling the below forever.
// e107 uses relative url's, which are broken by "pretty" URL's. So for now we don't support / after .php
Expand Down Expand Up @@ -4100,13 +4119,16 @@ public function set_constants()
$subdomain = false;

// Define the domain name and subdomain name.
if(is_numeric(str_replace(".","",$_SERVER['HTTP_HOST'])))
if (is_numeric(str_replace(".", "",
(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '')
)))
{
$domain = false;
$subdomain = false;
}
else
{
$_SERVER['SERVER_NAME'] = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
$host = !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$domain = preg_replace('/^www\.|:\d*$/', '', $host); // remove www. and port numbers.

Expand Down Expand Up @@ -4182,9 +4204,12 @@ public function set_paths()
{
// ssl_enabled pref not needed anymore, scheme is auto-detected
$this->HTTP_SCHEME = 'http';
if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443)
if (
(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ||
(!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)
)
{
$this->HTTP_SCHEME = 'https';
$this->HTTP_SCHEME = 'https';
}

$path = ""; $i = 0;
Expand Down Expand Up @@ -4232,6 +4257,7 @@ public function set_paths()


$this->relative_base_path = (!self::isCli()) ? $path : e_ROOT;
$_SERVER['HTTP_HOST'] = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
$this->http_path = filter_var("http://{$_SERVER['HTTP_HOST']}{$this->server_path}", FILTER_SANITIZE_URL);
$this->https_path = filter_var("https://{$_SERVER['HTTP_HOST']}{$this->server_path}", FILTER_SANITIZE_URL);

Expand Down Expand Up @@ -4259,11 +4285,11 @@ public function set_paths()
}

//BC temporary fixes
if (!isset($this->e107_dirs['UPLOADS_SERVER']) && $this->e107_dirs['UPLOADS_DIRECTORY']{0} == "/")
if (!isset($this->e107_dirs['UPLOADS_SERVER']) && $this->e107_dirs['UPLOADS_DIRECTORY'][0] == "/")
{
$this->e107_dirs['UPLOADS_SERVER'] = $this->e107_dirs['UPLOADS_DIRECTORY'];
}
if (!isset($this->e107_dirs['DOWNLOADS_SERVER']) && $this->e107_dirs['DOWNLOADS_DIRECTORY']{0} == "/")
if (!isset($this->e107_dirs['DOWNLOADS_SERVER']) && $this->e107_dirs['DOWNLOADS_DIRECTORY'][0] == "/")
{
$this->e107_dirs['DOWNLOADS_SERVER'] = $this->e107_dirs['DOWNLOADS_DIRECTORY'];
}
Expand Down Expand Up @@ -4518,6 +4544,7 @@ public function set_urls($no_cbrace = true)
$isPluginDir = strpos($_self,'/'.$PLUGINS_DIRECTORY) !== FALSE; // True if we're in a plugin
$e107Path = str_replace($this->base_path, '', $_self); // Knock off the initial bits
$curPage = basename($_SERVER['SCRIPT_FILENAME']);
$_SERVER['REQUEST_URI'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';

if (
(!$isPluginDir && strpos($e107Path, $ADMIN_DIRECTORY) === 0 ) // Core admin directory
Expand Down Expand Up @@ -5088,7 +5115,7 @@ public function __get($name)
break;
}

$this->{$name} = $ret;
$this->$name = $ret;
return $ret;
}

Expand Down
Loading