Fix various errors in PHPUnit tests on PHP 8

This commit is contained in:
Damien Regad 2021-02-06 01:19:42 +01:00
parent 049a05cf60
commit 056bf31f71
13 changed files with 38 additions and 28 deletions

View File

@ -18,6 +18,7 @@ class BulkSubscriptionsSenderTest extends DokuWikiTest
global $conf;
$this->originalSubscriptionConfig = $conf['subscribers'];
$conf['subscribers'] = true;
$conf['mailfromnobody'] = 'phpunit@example.com';
}
protected function tearDown() : void

View File

@ -140,7 +140,7 @@ class changelog_getlastrevisionat_test extends DokuWikiTest {
//save settings
$oldSuperUser = $conf['superuser'];
$oldUseacl = $conf['useacl'];
$oldRemoteUser = $_SERVER['REMOTE_USER'];
$oldRemoteUser = isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] : null;
$conf['superuser'] = 'admin';
$conf['useacl'] = 1;
@ -165,7 +165,9 @@ class changelog_getlastrevisionat_test extends DokuWikiTest {
$this->assertLessThanOrEqual(time(), $current);
//restore settings
$_SERVER['REMOTE_USER'] = $oldRemoteUser;
if ($oldRemoteUser !== null) {
$_SERVER['REMOTE_USER'] = $oldRemoteUser;
}
$conf['superuser'] = $oldSuperUser;
$conf['useacl'] = $oldUseacl;
}

View File

@ -227,12 +227,12 @@ class input_test extends DokuWikiTest {
$INPUT = new Input();
$INPUT->remove('string');
$this->assertNull($_REQUEST['string']);
$this->assertNull($_POST['string']);
$this->assertNull($_GET['string']);
$this->assertArrayNotHasKey('string', $_REQUEST);
$this->assertArrayNotHasKey('string', $_POST);
$this->assertArrayNotHasKey('string', $_GET);
$INPUT->post->remove('int');
$this->assertNull($_POST['int']);
$this->assertArrayNotHasKey('int', $_POST);
$this->assertEquals(17, $_GET['int']);
$this->assertEquals(17, $_REQUEST['int']);
}
@ -245,13 +245,13 @@ class input_test extends DokuWikiTest {
$INPUT->set('test','foo');
$this->assertEquals('foo',$_REQUEST['test']);
$this->assertNull($_POST['test']);
$this->assertNull($_GET['test']);
$this->assertArrayNotHasKey('test', $_POST);
$this->assertArrayNotHasKey('test', $_GET);
$INPUT->get->set('test2','foo');
$this->assertEquals('foo',$_GET['test2']);
$this->assertEquals('foo',$_REQUEST['test2']);
$this->assertNull($_POST['test']);
$this->assertArrayNotHasKey('test', $_POST);
}
public function test_ref(){

View File

@ -368,7 +368,7 @@ class remote_test extends DokuWikiTest {
$remoteApi = new Api();
try {
$remoteApi->call('dose not exist');
$remoteApi->call('does.not exist');
$this->fail('Expects RemoteException to be raised');
} catch (RemoteException $th) {
$this->assertEquals(-32603, $th->getCode());

View File

@ -44,7 +44,10 @@ class Save extends AbstractAction {
throw new ActionException('edit');
}
//conflict check
if($DATE != 0 && $INFO['meta']['date']['modified'] > $DATE) {
if($DATE != 0
&& isset($INFO['meta']['date']['modified'])
&& $INFO['meta']['date']['modified'] > $DATE
) {
throw new ActionException('conflict');
}

View File

@ -178,10 +178,9 @@ class HTTPClient {
// parse URL into bits
$uri = parse_url($url);
$server = $uri['host'];
$path = $uri['path'];
if(empty($path)) $path = '/';
$path = !empty($uri['path']) ? $uri['path'] : '/';
$uriPort = !empty($uri['port']) ? $uri['port'] : null;
if(!empty($uri['query'])) $path .= '?'.$uri['query'];
if(!empty($uri['port'])) $port = $uri['port'];
if(isset($uri['user'])) $this->user = $uri['user'];
if(isset($uri['pass'])) $this->pass = $uri['pass'];
@ -209,8 +208,8 @@ class HTTPClient {
// prepare headers
$headers = $this->headers;
$headers['Host'] = $uri['host'];
if(!empty($uri['port'])) $headers['Host'].= ':'.$uri['port'];
$headers['Host'] = $uri['host']
. ($uriPort ? ':' . $uriPort : '');
$headers['User-Agent'] = $this->agent;
$headers['Referer'] = $this->referer;
@ -370,10 +369,10 @@ class HTTPClient {
// handle non-RFC-compliant relative redirects
if (!preg_match('/^http/i', $this->resp_headers['location'])){
if($this->resp_headers['location'][0] != '/'){
$this->resp_headers['location'] = $uri['scheme'].'://'.$uri['host'].':'.$uri['port'].
dirname($uri['path']).'/'.$this->resp_headers['location'];
$this->resp_headers['location'] = $uri['scheme'].'://'.$uri['host'].':'.$uriPort.
dirname($path).'/'.$this->resp_headers['location'];
}else{
$this->resp_headers['location'] = $uri['scheme'].'://'.$uri['host'].':'.$uri['port'].
$this->resp_headers['location'] = $uri['scheme'].'://'.$uri['host'].':'.$uriPort.
$this->resp_headers['location'];
}
}
@ -511,7 +510,7 @@ class HTTPClient {
if(!$this->useProxyForUrl($requesturl)) return false;
$requestinfo = parse_url($requesturl);
if($requestinfo['scheme'] != 'https') return false;
if(!$requestinfo['port']) $requestinfo['port'] = 443;
if(empty($requestinfo['port'])) $requestinfo['port'] = 443;
// build request
$request = "CONNECT {$requestinfo['host']}:{$requestinfo['port']} HTTP/1.0".HTTP_NL;

View File

@ -92,7 +92,8 @@ class Api
if ($args === null) {
$args = array();
}
list($type, $pluginName, /* $call */) = explode('.', $method, 3);
// Ensure we have at least one '.' in $method
list($type, $pluginName, /* $call */) = explode('.', $method . '.', 3);
if ($type === 'plugin') {
return $this->callPlugin($pluginName, $method, $args);
}

View File

@ -822,7 +822,7 @@ function clientIP($single = false) {
if(empty($ip[$i])) unset($ip[$i]);
}
$ip = array_values(array_unique($ip));
if(!$ip[0]) $ip[0] = '0.0.0.0'; // for some strange reason we don't have a IP
if(empty($ip) || !$ip[0]) $ip[0] = '0.0.0.0'; // for some strange reason we don't have a IP
if(!$single) return join(',', $ip);

View File

@ -889,7 +889,7 @@ abstract class Doku_Renderer extends Plugin {
$url = $url.rawurlencode($reference);
}
//handle as wiki links
if($url[0] === ':') {
if($url && $url[0] === ':') {
$urlparam = null;
$id = $url;
if (strpos($url, '?') !== false) {

View File

@ -1887,7 +1887,9 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$url = ml($file, '', true, '&');
$linkType = 'internalmedia';
}
$title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(\dokuwiki\Utf8\PhpString::basename(noNS($file)));
$title = !empty($atts['title'])
? $atts['title']
: $this->_xmlEntities(\dokuwiki\Utf8\PhpString::basename(noNS($file)));
$out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
// alternative content (just a link to the file)

View File

@ -411,7 +411,7 @@ function p_set_metadata($id, $data, $render=false, $persistent=true){
function p_purge_metadata($id) {
$meta = p_read_metadata($id);
foreach($meta['current'] as $key => $value) {
if(is_array($meta[$key])) {
if(isset($meta[$key]) && is_array($meta[$key])) {
$meta['current'][$key] = array();
} else {
$meta['current'][$key] = '';
@ -463,7 +463,9 @@ function p_save_metadata($id, $meta) {
global $cache_metadata, $INFO;
if (isset($cache_metadata[$id])) $cache_metadata[$id] = $meta;
if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; }
if (!empty($INFO) && isset($INFO['id']) && ($id == $INFO['id'])) {
$INFO['meta'] = $meta['current'];
}
return io_saveFile(metaFN($id, '.meta'), serialize($meta));
}

View File

@ -1068,7 +1068,7 @@ function tpl_get_img_meta() {
if (!empty($tag[0])) {
$t = array($tag[0]);
}
if(is_array($tag[3])) {
if(isset($tag[3]) && is_array($tag[3])) {
$t = array_merge($t,$tag[3]);
}
$value = tpl_img_getTag($t);

View File

@ -110,7 +110,7 @@ class Writer {
'/*',
' * ' . $this->header,
' * Auto-generated by config plugin',
' * Run for user: ' . $_SERVER['REMOTE_USER'],
' * Run for user: ' . (isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] : 'Unknown'),
' * Date: ' . date('r'),
' */',
'',