Skip to content

Commit

Permalink
code cleanup, php8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed Jan 3, 2023
1 parent 3795686 commit 99c631e
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 148 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/phpTestLinux.yml
@@ -0,0 +1,52 @@
name: PHP Tests on Linux

on: [push, pull_request]

jobs:
testLinux:
name: PHP ${{ matrix.php-versions }} DokuWiki ${{ matrix.dokuwiki-branch }}
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
dokuwiki-branch: [ 'master', 'stable']
exclude:
- dokuwiki-branch: 'stable'
php-versions: '8.0'
fail-fast: false

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, PDO, pdo_sqlite, bz2

- name: Setup problem matchers
run: |
echo ::add-matcher::${{ runner.tool_cache }}/php.json
echo ::add-matcher::${{ runner.tool_cache }}/phpunit.json
- name: Download DokuWiki Test-setup
run: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh

- name: Run DokuWiki Test-setup
env:
CI_SERVER: 1
DOKUWIKI: ${{ matrix.dokuwiki-branch }}
run: sh travis.sh

- name: Setup PHPUnit
run: |
php _test/fetchphpunit.php
cd _test
- name: Run PHPUnit
run: |
cd _test
php phpunit.phar --verbose --stderr --group plugin_tplinc
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

86 changes: 86 additions & 0 deletions _test/GeneralTest.php
@@ -0,0 +1,86 @@
<?php

namespace dokuwiki\plugin\tplinc\test;

use DokuWikiTest;

/**
* General tests for the tplinc plugin
*
* @group plugin_tplinc
* @group plugins
*/
class GeneralTest extends DokuWikiTest
{

/**
* Simple test to make sure the plugin.info.txt is in correct format
*/
public function testPluginInfo(): void
{
$file = __DIR__ . '/../plugin.info.txt';
$this->assertFileExists($file);

$info = confToHash($file);

$this->assertArrayHasKey('base', $info);
$this->assertArrayHasKey('author', $info);
$this->assertArrayHasKey('email', $info);
$this->assertArrayHasKey('date', $info);
$this->assertArrayHasKey('name', $info);
$this->assertArrayHasKey('desc', $info);
$this->assertArrayHasKey('url', $info);

$this->assertEquals('tplinc', $info['base']);
$this->assertRegExp('/^https?:\/\//', $info['url']);
$this->assertTrue(mail_isvalid($info['email']));
$this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
$this->assertTrue(false !== strtotime($info['date']));
}

/**
* Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in
* conf/metadata.php.
*/
public function testPluginConf(): void
{
$conf_file = __DIR__ . '/../conf/default.php';
$meta_file = __DIR__ . '/../conf/metadata.php';

if (!file_exists($conf_file) && !file_exists($meta_file)) {
self::markTestSkipped('No config files exist -> skipping test');
}

if (file_exists($conf_file)) {
include($conf_file);
}
if (file_exists($meta_file)) {
include($meta_file);
}

$this->assertEquals(
gettype($conf),
gettype($meta),
'Both ' . DOKU_PLUGIN . 'tplinc/conf/default.php and ' . DOKU_PLUGIN . 'tplinc/conf/metadata.php have to exist and contain the same keys.'
);

if ($conf !== null && $meta !== null) {
foreach ($conf as $key => $value) {
$this->assertArrayHasKey(
$key,
$meta,
'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'tplinc/conf/metadata.php'
);
}

foreach ($meta as $key => $value) {
$this->assertArrayHasKey(
$key,
$conf,
'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'tplinc/conf/default.php'
);
}
}

}
}
61 changes: 0 additions & 61 deletions _test/general.test.php

This file was deleted.

42 changes: 22 additions & 20 deletions admin.php
@@ -1,41 +1,42 @@
<?php

/**
* DokuWiki Plugin tplinc (Admin Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <dokuwiki@cosmocode.de>
*/

// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();

class admin_plugin_tplinc extends DokuWiki_Admin_Plugin {
class admin_plugin_tplinc extends DokuWiki_Admin_Plugin
{

/** @var helper_plugin_tplinc */
protected $helper;

/**
* admin_plugin_tplinc constructor.
*/
public function __construct() {
public function __construct()
{
$this->helper = plugin_load('helper', 'tplinc');
}

/**
* @return bool true if only access for superuser, false is for superusers and moderators
*/
public function forAdminOnly() {
public function forAdminOnly()
{
return true;
}

/**
* Should carry out any processing required by the plugin.
*/
public function handle() {
public function handle()
{
global $INPUT;

if($INPUT->str('action') == 'save' && checkSecurityToken()) {
if($this->helper->saveAssignments($INPUT->arr('a'))) {
if ($INPUT->str('action') == 'save' && checkSecurityToken()) {
if ($this->helper->saveAssignments($INPUT->arr('a'))) {
msg($this->getLang('saved'), 1);
}
}
Expand All @@ -44,7 +45,8 @@ public function handle() {
/**
* Render HTML output, e.g. helpful text and a form
*/
public function html() {
public function html()
{
global $ID;
echo $this->locale_xhtml('intro');

Expand All @@ -70,13 +72,13 @@ public function html() {
// existing assignments
$assignments = $this->helper->loadAssignments();
$row = 0;
foreach($assignments as $assignment) {
foreach ($assignments as $assignment) {
$this->assignmentRow($assignment, $row);
$row++;
}

// three more rows for new ones
for($i = 0; $i < 3; $i++) {
for ($i = 0; $i < 3; $i++) {
$this->assignmentRow(array('', '', '', ''), $row);
$row++;
}
Expand All @@ -103,7 +105,8 @@ public function html() {
* @param array $assignment
* @param int $row the row counter
*/
protected function assignmentRow($assignment, $row) {
protected function assignmentRow($assignment, $row)
{
list($pattern, $page, $location, $skipacl) = $assignment;
echo '<tr>';
echo '<td><input type="text" name="a[x' . $row . '][0]" value="' . hsc($pattern) . '" /></td>';
Expand All @@ -129,14 +132,15 @@ protected function assignmentRow($assignment, $row) {
* @param string $name the parameter name
* @param string $loc the current location value
*/
protected function locationBox($name, $loc) {
protected function locationBox($name, $loc)
{
$locations = null;
if($locations === null) $locations = $this->helper->getLocations();
if ($locations === null) $locations = $this->helper->getLocations();

if(!isset($locations[$loc])) $loc = '';
if (!isset($locations[$loc])) $loc = '';

echo '<select name="' . $name . '">';
foreach($locations as $location => $label) {
foreach ($locations as $location => $label) {
$selected = ($location == $loc) ? 'selected="selected"' : '';
echo '<option value="' . hsc($location) . '" ' . $selected . '>';
echo hsc($label);
Expand All @@ -145,5 +149,3 @@ protected function locationBox($name, $loc) {
echo '</select>';
}
}

// vim:ts=4:sw=4:et:

0 comments on commit 99c631e

Please sign in to comment.