Skip to content

Commit

Permalink
unified unit and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sarnowski committed Apr 16, 2012
1 parent 1101eda commit ae4cb59
Show file tree
Hide file tree
Showing 130 changed files with 122 additions and 54 deletions.
6 changes: 2 additions & 4 deletions _testing/README
Expand Up @@ -28,9 +28,7 @@ Bad tests are tests that do not run out of the box.
* inc/parser/xhtml_links


==== Integration Tests ====
> phpunit -c inttests.xml

==== TODO ====
* integration tests (+plugins)
* plugin tests
* cross platform compatible: especially test windows (hint: tmp dir location)

95 changes: 79 additions & 16 deletions _testing/inttests.php → _testing/bootstrap.php
@@ -1,7 +1,6 @@
<?php

/**
* Integration Test Library for DokuWiki
* Test Library for DokuWiki
*
* Simulates a full DokuWiki HTTP Request and allows
* runtime inspection.
Expand All @@ -26,31 +25,95 @@ function rcopy($destdir, $source) {
}
}

// helper for recursive rmdir()/unlink()
function rdelete($target) {
if (!is_dir($target)) {
unlink($target);
} else {
$dh = dir($target);
while (false !== ($entry = $dh->read())) {
if ($entry == '.' || $entry == '..') {
continue;
}
rdelete("$target/$entry");
}
$dh->close();
rmdir($target);
}
}

// helper to append text to a file
function fappend($file, $text) {
$fh = fopen($file, 'a');
fwrite($fh, $text);
fclose($fh);
}

// if someone really wants a special handling during tests
define('DOKU_UNITTEST', true);
define('SIMPLE_TEST', true);

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

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

// prepare temporary directories
define('DOKU_INC', dirname(dirname(__FILE__)).'/');
define('TMP_DIR', '/tmp/dwinttests-'.microtime(true));
define('DOKU_CONF', TMP_DIR.'/inttests.conf/');
define('DOKU_PLUGIN', TMP_DIR.'/plugins/');
define('DOKU_TMP_DATA', TMP_DIR.'/inttests.data/');
define('TMP_DIR', '/tmp/dwtests-'.microtime(true));
define('DOKU_CONF', TMP_DIR.'/conf/');
define('DOKU_TMP_DATA', TMP_DIR.'/data/');

// create temp directories
mkdir(TMP_DIR);
mkdir(DOKU_PLUGIN);

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

// cleanup dir after exit
register_shutdown_function(function() {
// TODO delete recursive tmp dir
// rdelete(TMP_DIR);
});

// TODO disable all non-default plugins in config
// TODO if plugin test, enable plugin
// TODO load plugin descriptor and enable dependent plugins
// populate default dirs
rcopy(TMP_DIR, dirname(__FILE__).'/conf');
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 == '..' || $entry == 'index.html') {
continue;
}

if (substr($entry, strlen($entry) - 4) == '.php') {
$plugin = substr($entry, 0, strlen($entry) - 4);
} else {
$plugin = $entry;
}

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

// TODO set global variables, phpunit will restore them for every test (test that)
// TODO setup default global variables
$_SERVER['REMOTE_ADDR'] = '173.194.69.138';

// load dw
require_once(DOKU_INC.'inc/init.php');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions _testing/inttests.xml

This file was deleted.

12 changes: 7 additions & 5 deletions _testing/phpunit.xml
@@ -1,13 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="unittests/bootstrap.php"
convertNoticesToExceptions="false">
bootstrap="bootstrap.php"
convertNoticesToExceptions="false"
backupGlobals="yes"
colors="true">

<testsuites>
<testsuite name="Default Unit Tests">
<directory suffix=".test.php">unittests/</directory>
<testsuite name="DokuWiki Tests">
<directory suffix=".test.php">tests/</directory>
</testsuite>
<testsuite name="Plugin tests">
<testsuite name="Plugin Tests">
<directory suffix=".test.php">../lib/plugins/*/_testing</directory>
</testsuite>
</testsuites>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,6 +1,9 @@
<?php

class BasicTest extends PHPUnit_Framework_TestCase {
/**
* @group integration
*/
class InttestsBasicTest extends PHPUnit_Framework_TestCase {
/**
* Execute the simplest possible request and expect
* a dokuwiki page which obviously has the word "DokuWiki"
Expand Down
22 changes: 22 additions & 0 deletions _testing/tests/testing/inttests_globals.test.php
@@ -0,0 +1,22 @@
<?php

/**
* @group integration
*/
class InttestsGlobalsTest extends PHPUnit_Framework_TestCase {
/**
* Global variables should be restored for every test case.
*/
function testFirstRun() {
$this->assertEquals('173.194.69.138', $_SERVER['REMOTE_ADDR'], 'Global var not set as expected');

$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
}

/**
* @depends testFirstRun
*/
function testSecondRun() {
$this->assertEquals('173.194.69.138', $_SERVER['REMOTE_ADDR'], 'Global var not set as expected');
}
}
@@ -1,6 +1,9 @@
<?php

class HooksTest extends PHPUnit_Framework_TestCase {
/**
* @group integration
*/
class InttestsHooksTest extends PHPUnit_Framework_TestCase {

function testHookTriggering() {
$request = new TestRequest();
Expand Down
@@ -1,6 +1,9 @@
<?php

class ScopeTest extends PHPUnit_Framework_TestCase {
/**
* @group integration
*/
class InttestsScopeTest extends PHPUnit_Framework_TestCase {
/**
* It should be possible to have two test cases within one test class.
*/
Expand Down
10 changes: 0 additions & 10 deletions _testing/unittests/bootstrap.php

This file was deleted.

0 comments on commit ae4cb59

Please sign in to comment.