1<?php
2
3require_once dirname(__FILE__).'/accesscheck.php';
4
5//# some kind of attempt to make a test suite for certain elements of phplist
6
7echo '<h3>'.$GLOBALS['I18N']->get('phplist test suite').'</h3>';
8
9if (empty($GLOBALS['developer_email'])) {
10    echo 'Only available in developer mode';
11
12    return;
13}
14
15$tests = array();
16// generic class that's extended by all tests
17include_once dirname(__FILE__).'/defaulttest.php';
18
19$testdir = dirname(__FILE__).'/tests';
20if (is_dir($testdir)) {
21    if ($dh = opendir($testdir)) {
22        while (($file = readdir($dh)) !== false) {
23            if (preg_match("/\.php$/", $file) && is_file($testdir.'/'.$file)) {
24                require_once $testdir.'/'.$file;
25                $class = basename($file, '.php');
26                eval('$test = new $class();');
27                if (method_exists($test, 'runtest')) {
28                    $tests[$class] = $test;
29                }
30            }
31        }
32        closedir($dh);
33    }
34}
35
36if (!empty($_GET['runtest']) && in_array($_GET['runtest'], array_keys($tests))) {
37    echo '<h3>Running test:  '.$tests[$_GET['runtest']]->name.'</h3>';
38    $testresult = $tests[$_GET['runtest']]->runtest();
39    if ($testresult) {
40        echo $GLOBALS['I18N']->get('Test passed');
41    } else {
42        echo $GLOBALS['I18N']->get('Test failed');
43    }
44    echo '<br/><br/>';
45}
46
47$ls = new WebblerListing($GLOBALS['I18N']->get('Tests available'));
48
49foreach ($tests as $testclassname => $testclass) {
50    $el = $GLOBALS['I18N']->get($testclass->name);
51    $ls->addElement($el, PageUrl2('tests&runtest='.$testclassname));
52    $ls->addColumn($el, $GLOBALS['I18N']->get('Purpose'), $GLOBALS['I18N']->get($testclass->purpose));
53}
54echo $ls->display();
55