mirror of
https://github.com/splitbrain/dokuwiki-plugin-captcha.git
synced 2025-08-20 16:35:27 +00:00
update tests
This commit is contained in:
52
.github/workflows/phpTestLinux.yml
vendored
Normal file
52
.github/workflows/phpTestLinux.yml
vendored
Normal file
@ -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_captcha
|
13
.travis.yml
13
.travis.yml
@ -1,13 +0,0 @@
|
||||
language: php
|
||||
php:
|
||||
- "7.3"
|
||||
- "7.2"
|
||||
- "7.1"
|
||||
- "7.0"
|
||||
- "5.6"
|
||||
env:
|
||||
- DOKUWIKI=master
|
||||
- DOKUWIKI=stable
|
||||
before_install: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh
|
||||
install: sh travis.sh
|
||||
script: cd _test && ./phpunit.phar --stderr --group plugin_captcha
|
86
_test/GeneralTest.php
Normal file
86
_test/GeneralTest.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\captcha\test;
|
||||
|
||||
use DokuWikiTest;
|
||||
|
||||
/**
|
||||
* General tests for the captcha plugin
|
||||
*
|
||||
* @group plugin_captcha
|
||||
* @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('captcha', $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 . 'captcha/conf/default.php and ' . DOKU_PLUGIN . 'captcha/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 . 'captcha/conf/metadata.php'
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($meta as $key => $value) {
|
||||
$this->assertArrayHasKey(
|
||||
$key,
|
||||
$conf,
|
||||
'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'captcha/conf/default.php'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,46 +1,33 @@
|
||||
<?php
|
||||
|
||||
class helper_plugin_captcha_public extends helper_plugin_captcha {
|
||||
namespace dokuwiki\plugin\captcha\test;
|
||||
|
||||
public function get_field_in() {
|
||||
return $this->field_in;
|
||||
}
|
||||
|
||||
public function get_field_sec() {
|
||||
return $this->field_sec;
|
||||
}
|
||||
|
||||
public function get_field_hp() {
|
||||
return $this->field_hp;
|
||||
}
|
||||
|
||||
public function storeCaptchaCookie($fixed, $rand) {
|
||||
parent::storeCaptchaCookie($fixed, $rand);
|
||||
}
|
||||
}
|
||||
use DokuWikiTest;
|
||||
|
||||
/**
|
||||
* @group plugin_captcha
|
||||
* @group plugins
|
||||
*/
|
||||
class helper_plugin_captcha_test extends DokuWikiTest {
|
||||
class HelperTest extends DokuWikiTest
|
||||
{
|
||||
|
||||
protected $pluginsEnabled = array('captcha');
|
||||
|
||||
public function testConfig() {
|
||||
public function testConfig()
|
||||
{
|
||||
global $conf;
|
||||
$conf['plugin']['captcha']['lettercount'] = 20;
|
||||
|
||||
$helper = new helper_plugin_captcha_public();
|
||||
$helper = new \helper_plugin_captcha();
|
||||
|
||||
// generateCAPTCHA generates a maximum of 16 chars
|
||||
$code = $helper->_generateCAPTCHA("fixed", 0);
|
||||
$this->assertEquals(16, strlen($code));
|
||||
}
|
||||
|
||||
public function testDecrypt() {
|
||||
|
||||
$helper = new helper_plugin_captcha_public();
|
||||
public function testDecrypt()
|
||||
{
|
||||
$helper = new \helper_plugin_captcha();
|
||||
|
||||
$rand = "12345";
|
||||
$secret = $helper->encrypt($rand);
|
||||
@ -51,45 +38,47 @@ class helper_plugin_captcha_test extends DokuWikiTest {
|
||||
$this->assertFalse($helper->decrypt('X'));
|
||||
}
|
||||
|
||||
public function testCheck() {
|
||||
public function testCheck()
|
||||
{
|
||||
|
||||
global $INPUT, $ID;
|
||||
|
||||
$helper = new helper_plugin_captcha_public();
|
||||
$helper = new \helper_plugin_captcha();
|
||||
|
||||
$INPUT->set($helper->get_field_hp(), '');
|
||||
$INPUT->set($helper->get_field_in(), 'X');
|
||||
$INPUT->set($helper->get_field_sec(), '');
|
||||
$INPUT->set($this->getInaccessibleProperty($helper, 'field_hp'), '');
|
||||
$INPUT->set($this->getInaccessibleProperty($helper, 'field_in'), 'X');
|
||||
$INPUT->set($this->getInaccessibleProperty($helper, 'field_sec'), '');
|
||||
|
||||
$this->assertFalse($helper->check(false));
|
||||
$INPUT->set($helper->get_field_sec(), 'X');
|
||||
$INPUT->set($this->getInaccessibleProperty($helper, 'field_sec'), 'X');
|
||||
$this->assertFalse($helper->check(false));
|
||||
|
||||
// create the captcha and store the cookie
|
||||
$rand = 0;
|
||||
$code = $helper->_generateCAPTCHA($helper->_fixedIdent(), $rand);
|
||||
$helper->storeCaptchaCookie($helper->_fixedIdent(), $rand);
|
||||
|
||||
$this->callInaccessibleMethod($helper, 'storeCaptchaCookie', [$helper->_fixedIdent(), $rand]);
|
||||
|
||||
// check with missing secrect -> fail
|
||||
$INPUT->set($helper->get_field_in(), $code);
|
||||
$INPUT->set($this->getInaccessibleProperty($helper, 'field_in'), $code);
|
||||
$this->assertFalse($helper->check(false));
|
||||
|
||||
// set secret -> success
|
||||
$INPUT->set($helper->get_field_sec(), $helper->encrypt($rand));
|
||||
$INPUT->set($this->getInaccessibleProperty($helper, 'field_sec'), $helper->encrypt($rand));
|
||||
$this->assertTrue($helper->check(false));
|
||||
|
||||
// try again, cookie is gone -> fail
|
||||
$this->assertFalse($helper->check(true));
|
||||
|
||||
// set the cookie but change the ID -> fail
|
||||
$helper->storeCaptchaCookie($helper->_fixedIdent(), $rand);
|
||||
$this->callInaccessibleMethod($helper, 'storeCaptchaCookie', [$helper->_fixedIdent(), $rand]);
|
||||
$ID = 'test:fail';
|
||||
$this->assertFalse($helper->check(false));
|
||||
}
|
||||
|
||||
public function testGenerate() {
|
||||
|
||||
$helper = new helper_plugin_captcha_public();
|
||||
public function testGenerate()
|
||||
{
|
||||
$helper = new \helper_plugin_captcha();
|
||||
|
||||
$rand = 0;
|
||||
$code = $helper->_generateCAPTCHA($helper->_fixedIdent(), $rand);
|
||||
@ -99,7 +88,8 @@ class helper_plugin_captcha_test extends DokuWikiTest {
|
||||
$this->assertNotEquals($newcode, $code);
|
||||
}
|
||||
|
||||
public function testCleanup() {
|
||||
public function testCleanup()
|
||||
{
|
||||
// we need a complete fresh environment:
|
||||
$this->setUpBeforeClass();
|
||||
|
||||
@ -107,14 +97,14 @@ class helper_plugin_captcha_test extends DokuWikiTest {
|
||||
$path = $conf['tmpdir'] . '/captcha/';
|
||||
$today = "$path/" . date('Y-m-d');
|
||||
|
||||
$helper = new helper_plugin_captcha_public();
|
||||
$helper = new \helper_plugin_captcha();
|
||||
|
||||
// nothing at all
|
||||
$dirs = glob("$path/*");
|
||||
$this->assertEquals(array(), $dirs);
|
||||
|
||||
// store a cookie
|
||||
$helper->storeCaptchaCookie('test', 0);
|
||||
$this->callInaccessibleMethod($helper, 'storeCaptchaCookie', ['test', 0]);
|
||||
|
||||
// nothing but today's data
|
||||
$dirs = glob("$path/*");
|
||||
@ -134,7 +124,7 @@ class helper_plugin_captcha_test extends DokuWikiTest {
|
||||
"$path/2017-01-02",
|
||||
"$path/2017-01-03",
|
||||
"$path/2017-01-04",
|
||||
$today
|
||||
$today,
|
||||
),
|
||||
$dirs
|
||||
);
|
Reference in New Issue
Block a user