Skip to content

Commit

Permalink
Merge pull request #96 from dom-mel/phpunit
Browse files Browse the repository at this point in the history
Replace SimpleTest with PHPUnit
  • Loading branch information
splitbrain committed May 1, 2012
2 parents e67fdd7 + 1831d8a commit 3c0d44f
Show file tree
Hide file tree
Showing 164 changed files with 8,917 additions and 5,540 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -37,6 +37,7 @@
!/lib/plugins/popularity
!/lib/plugins/revert
!/lib/plugins/safefnrecode
!/lib/plugins/testing
!/lib/plugins/usermanager
!/lib/plugins/action.php
!/lib/plugins/admin.php
Expand Down
166 changes: 82 additions & 84 deletions _test/README
@@ -1,84 +1,82 @@
--------------------------------------------------------------------------------
Dokuwiki Unit Test Suite
--------------------------------------------------------------------------------
$Date: 2004/02/14 02:14:50 $

Credits: to the WACT team - http://www.phpwact.org, from whom the basis of
this test suite was stolen

--------------------------------------------------------------------------------
INSTALLING & SETUP

1. Grab a copy of the SimpleTest unit testing framework an extract somewhere

http://www.lastcraft.com/simple_test.php
or
http://sourceforge.net/projects/simpletest

2. Edit ./tests.ini

- TEST_ENABLED - set to "1" to allow the test suite to be used
by vistors to your site. Generally best to leave as 0 for
a productive site - running tests alot will hammer the server
Note: you will still be able to run the tests from the command
line even when this is set to 0

- WEB_TEST_URL - this is for running "web tests" where SimpleTest
acts as a web browser and executes HTTP requests against pages.
Should point at your Dokuwiki URL e.g.

http://localhost/dokuwiki

- PROXY - if you're behind a proxy, specify it here
Note: username / password are optional e.g.

http://proxyuser:proxypwd@proxy.yourdomain.com:8080

- REMOTE_TEST_URL - it's possible to run the full test suite
remotely (over HTTP) with some XML goodness. This should
point at the URL of the test suite you want to test
See the following URL for more info;
http://www.sitepoint.com/blogs/2004/06/15/simple-test-remote-testing/

- Simple Test
Update the library_path to point at the directory where you installed
Simple Test

--------------------------------------------------------------------------------
RUNNING THE TESTS

You can run the tests in three ways. From the command line:

$ ./runtests.php -h

Using a web browser;

http://localhost/dokuwiki/_test/index.php

As remote tests run on a remote serveri (specified in tests.ini with REMOTE_TEST_URL) and driven locally from the command line using;

$ ./remotetests.php -h


--------------------------------------------------------------------------------
ADDING TESTS

The test cases are kept in the './cases' directory in a directory structure
mirroring that of the Dokuwiki's

Files with the extension .group.php are group tests (collections of
one or more seperate unit test files) - there should be one group
test per file in Dokuwiki's real directory.

Individual tests files have the extension .test.php

To add tests, create a .test.php file in the correct directory under ./cases
Probably best to use one of the existing scripts as a basis

The test will not be executable via one of the test runners (see above).

To add it to a group of tests, modify the corresponding .group.php file.

One exception to the naming convention - files named .webtest.php and
.webgroup.php are run using SimpleTest's browser simulator.

====== DokuWiki Test Suite ======

This is the test suit to automatically test various parts of DokuWiki.

===== Requirements =====

* PHPUnit 3.6.10+ http://www.phpunit.de/
* PHP 5.3+ http://www.php.net

===== PHPUnit Installation ======

via PEAR:

pear config-set auto_discover 1
pear upgrade
pear install pear.phpunit.de/PHPUnit

on Windows:

FIXME


===== Running all Tests =====

Just change to the ''_test'' directory and run phpunit:

cd _testing/
phpunit

PHPUnit will fail on some systems with a //headers already sent// error.
This is a known problem with PHPUnit, the error can be avoided by passing the
'--stderr' flag to phpunit:

phpunit --stderr

On windows you may have to enable OpenSSL support for https tests.
Some of them point to httpclient_http.tests.php on the failure.
To enable HTTPS support copy the ''libeay32.dll'' and ''ssleay32.dll'' to your ''windows\system32'' folder
and add the following line to your php.ini in the extension section:
<code ini>
extension=php_openssl.dll
</code>

===== Running selected Tests =====

You can run a single test file by providing it as an argument to phpunit:

phpunit --stderr tests/inc/common_cleanText.test.php

You can also use groups to exclude certain test from running. For example use
the following command to avoid long running test or tests accessing the
Internet.

phpunit --stderr --exclude-group slow,internet

===== Create new Tests =====

To create a test for DokuWiki, create a *.test.php file within the tests/
folder. Please respect the folder structure and naming convention. Inside the
file, implement a class, extending 'DokuWikiTest'. Every method, starting
with 'test' will be called as a test (e.g. 'testIfThisIsValid');


===== TODO for the test framework =====

* test cross platform compatibility: especially test windows
* update http://www.dokuwiki.org/devel:unittesting
* optional: add helper methods to TestRequest for easy form submission
* createForm(), ...
* check PHP Unit test_helpers https://github.com/sebastianbergmann/php-test-helpers


===== Migration Protocol =====

The following tests were not migrated:

* inc/indexer_idx_indexlengths (fs dependencies)
* inc/mail_send (integration test)
* inc/parser/parser_formatting
* inc/parser/xhtml_htmlphp (runkit)
* inc/parser/xhtml_links

107 changes: 107 additions & 0 deletions _test/bootstrap.php
@@ -0,0 +1,107 @@
<?php
/**
* Test Suite bootstrapping for DokuWiki
*/

if(!defined('DOKU_UNITTEST')) define('DOKU_UNITTEST',dirname(__FILE__).'/');
require_once DOKU_UNITTEST.'core/phpQuery-onefile.php';
require_once DOKU_UNITTEST.'core/DokuWikiTest.php';
require_once DOKU_UNITTEST.'core/TestResponse.php';
require_once DOKU_UNITTEST.'core/TestRequest.php';
require_once DOKU_UNITTEST.'core/TestUtils.php';


// backward compatibility to old test suite
define('SIMPLE_TEST', true);

// basic behaviours
error_reporting(E_ALL);
set_time_limit(0);
ini_set('memory_limit','2048M');

// prepare temporary directories
define('DOKU_INC', dirname(dirname(__FILE__)).'/');
define('TMP_DIR', sys_get_temp_dir().'/dwtests-'.microtime(true));
define('DOKU_CONF', TMP_DIR.'/conf/');
define('DOKU_TMP_DATA', TMP_DIR.'/data/');

// default plugins
$default_plugins = array(
'acl',
'config',
'info',
'plugin',
'popularity',
'revert',
'safefnrecode',
'usermanager'
);

// default server variables
$default_server_vars = array(
'QUERY_STRING' => '?id=',
'REQUEST_METHOD' => 'GET',
'CONTENT_TYPE' => '',
'CONTENT_LENGTH' => '',
'SCRIPT_NAME' => '/doku.php',
'REQUEST_URI' => '/doku.php?id=',
'DOCUMENT_URI' => '/doku.php',
'DOCUMENT_ROOT' => DOKU_INC,
'SERVER_PROTOCOL' => 'HTTP/1.1',
'SERVER_SOFTWARE' => 'nginx/0.7.67',
'REMOTE_ADDR' => '87.142.120.6',
'REMOTE_PORT' => '21418',
'SERVER_ADDR' => '46.38.241.24',
'SERVER_PORT' => '443',
'SERVER_NAME' => 'wiki.example.com',
'REDIRECT_STATUS' => '200',
'SCRIPT_FILENAME' => DOKU_INC.'doku.php',
'HTTP_HOST' => 'wiki.example.com',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; OpenBSD amd64; rv:11.0) Gecko/20100101 Firefox/11.0',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_CACHE_CONTROL' => 'max-age=0',
'PHP_SELF' => '/doku.php',
'REQUEST_TIME' => time(),
);

// create temp directories
mkdir(TMP_DIR);

// cleanup dir after exit
if (getenv('PRESERVE_TMP') != 'true') {
register_shutdown_function(function() {
TestUtils::rdelete(TMP_DIR);
});
} else {
echo ">>>> Preserving temporary directory: ".TMP_DIR."\n";
}

// populate default dirs
TestUtils::rcopy(TMP_DIR, DOKU_INC.'/conf');
TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/conf');
TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/data');

// disable all non-default plugins by default
$dh = dir(DOKU_INC.'lib/plugins/');
while (false !== ($entry = $dh->read())) {
if ($entry == '.' || $entry == '..') {
continue;
}

if (!is_dir(DOKU_INC.'lib/plugins/'.$entry)) {
continue;
}

if (!in_array($entry, $default_plugins)) {
// disable this plugin
TestUtils::fappend(DOKU_CONF.'plugins.local.php', "\$plugins['$entry'] = 0;\n");
}
}
$dh->close();

// load dw
require_once(DOKU_INC.'inc/init.php');

31 changes: 0 additions & 31 deletions _test/cases/inc/DifferenceEngine.test.php

This file was deleted.

0 comments on commit 3c0d44f

Please sign in to comment.