Merge pull request #3406 from dregad/phpunit8

PHPUnit 8 fixes
This commit is contained in:
Andreas Gohr 2021-02-08 09:56:06 +01:00 committed by GitHub
commit 7566f8035a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 70 additions and 56 deletions

31
.gitignore vendored
View File

@ -1,3 +1,17 @@
# Editor and temporary files
*.swp
*.bak
*.old
*~
*.DS_Store
*.iml
.idea/
.buildpath
.project
.settings/
# DokuWiki
.htaccess
/conf/*.local.conf
/conf/acl.auth.php
/conf/local.php
@ -10,19 +24,6 @@
/conf/plugin_lang/*
/conf/plugins.local.*
/conf/tpl/*
.htaccess
*.swp
*.bak
*.old
*~
*.DS_Store
*.iml
.idea/
# Eclipse IDE
.buildpath
.project
.settings/
# DokuWiki
/data/attic/*
/data/cache/*
/data/index/*
@ -91,3 +92,7 @@ vendor/splitbrain/php-cli/screenshot*
vendor/splitbrain/php-cli/generate-api.sh
vendor/splitbrain/php-cli/apigen.neon
# PHPUnit tests
phpunit.phar
.phpunit.result.cache
_test/data/

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('test2', $_POST);
}
public function test_ref(){

View File

@ -366,13 +366,12 @@ class remote_test extends DokuWikiTest {
global $conf;
$conf['remote'] = 1;
$this->expectException(RemoteException::class);
$this->expectExceptionCode(-32603);
$remoteApi = new Api();
try {
$remoteApi->call('dose not exist');
$this->fail('Expects RemoteException to be raised');
} catch (RemoteException $th) {
$this->assertEquals(-32603, $th->getCode());
}
$remoteApi->call('invalid method'); // no '.'
$remoteApi->call('does.not exist'); // unknown method type
}
function test_publicCallCore() {

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'];
@ -194,7 +193,7 @@ class HTTPClient {
$use_tls = $this->proxy_ssl;
}else{
$request_url = $path;
if (!isset($port)) $port = ($uri['scheme'] == 'https') ? 443 : 80;
$port = $uriPort ?: ($uri['scheme'] == 'https' ? 443 : 80);
$use_tls = ($uri['scheme'] == 'https');
}
@ -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

@ -38,7 +38,7 @@ function parseChangelogLine($line) {
}
/**
* Add's an entry to the changelog and saves the metadata for the page
* Adds an entry to the changelog and saves the metadata for the page
*
* @param int $date Timestamp of the change
* @param String $id Name of the affected page
@ -94,12 +94,12 @@ function addLogEntry($date, $id, $type=DOKU_CHANGE_TYPE_EDIT, $summary='', $extr
$wasReverted = ($type===DOKU_CHANGE_TYPE_REVERT);
// update metadata
if (!$wasRemoved) {
$oldmeta = p_read_metadata($id);
$oldmeta = p_read_metadata($id)['persistent'];
$meta = array();
if (
$wasCreated && (
empty($oldmeta['persistent']['date']['created']) ||
$oldmeta['persistent']['date']['created'] === $created
empty($oldmeta['date']['created']) ||
$oldmeta['date']['created'] === $created
)
){
// newly created
@ -108,11 +108,11 @@ function addLogEntry($date, $id, $type=DOKU_CHANGE_TYPE_EDIT, $summary='', $extr
$meta['creator'] = isset($INFO) ? $INFO['userinfo']['name'] : null;
$meta['user'] = $user;
}
} elseif (($wasCreated || $wasReverted) && !empty($oldmeta['persistent']['date']['created'])) {
} elseif (($wasCreated || $wasReverted) && !empty($oldmeta['date']['created'])) {
// re-created / restored
$meta['date']['created'] = $oldmeta['persistent']['date']['created'];
$meta['date']['created'] = $oldmeta['date']['created'];
$meta['date']['modified'] = $created; // use the files ctime here
$meta['creator'] = $oldmeta['persistent']['creator'];
$meta['creator'] = isset($oldmeta['creator']) ? $oldmeta['creator'] : null;
if ($user) $meta['contributor'][$user] = isset($INFO) ? $INFO['userinfo']['name'] : null;
} elseif (!$minor) { // non-minor modification
$meta['date']['modified'] = $date;

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

@ -297,7 +297,7 @@ function tpl_metaheaders($alt = true) {
}
}
// setup robot tags apropriate for different modes
// setup robot tags appropriate for different modes
if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
if($INFO['exists']) {
//delay indexing:
@ -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

@ -3,7 +3,7 @@
use dokuwiki\Extension\Event;
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
define('DOKU_MEDIADETAIL',1);
if(!defined('DOKU_MEDIADETAIL')) define('DOKU_MEDIADETAIL',1);
// define all DokuWiki globals here (needed within test requests but also helps to keep track)
global $INPUT, $IMG, $ID, $REV, $SRC, $ERROR, $AUTH;

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'),
' */',
'',