Passed
Push — master ( 8f5e6a...061d3e )
by Felipe
03:26
created

TestDriver   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 86
rs 10
c 0
b 0
f 0
wmc 24
1
<?php // content="text/plain; charset=utf-8"
2
//=======================================================================
3
// File:    TESTSUIT.PHP
4
// Description:    Run all the example script in current directory
5
// Created:     2002-07-11
6
// Ver:        $Id: testsuit.php,v 1.1.2.1 2004/03/27 12:43:07 aditus Exp $
7
//
8
// License:    This code is released under QPL 1.0
9
// Copyright (C) 2001,2002 Johan Persson
10
//========================================================================
11
12
//-------------------------------------------------------------------------
13
//
14
// Usage: testsuit.php[?type=1]    Generates all non image map scripts
15
//        testsuit.php?type=2      Generates client side image map scripts
16
//
17
//-------------------------------------------------------------------------
18
class TestDriver
19
{
20
    private $iType;
21
    private $iDir;
22
23
    public function TestDriver($aType = 1, $aDir = '')
24
    {
25
        $this->iType = $aType;
26
        if ($aDir == '') {
27
            $aDir = getcwd();
28
        }
29
        if (!chdir($aDir)) {
30
            die("PANIC: Can't access directory : $aDir");
31
        }
32
        $this->iDir = $aDir;
33
    }
34
35
    public function GetFiles()
36
    {
37
        $d = @dir($this->iDir);
38
        $a = array();
39
        while ($entry = $d->Read()) {
40
            //echo $entry . ':' . (is_dir($entry) ? 'folder' : 'file') . '<br>';
41
            if (is_dir($entry) && ($entry == "examples_pie")) {
42
                $examplefolder = @dir($entry);
43
                while ($file = $examplefolder->Read()) {
44
                    if (strstr($file, ".php") && strstr($file, "x") && !strstr($file, "show") && !strstr($file, "csim")) {
45
                        $a[] = $entry . '/' . $file;
46
                    }
47
                }
48
            }
49
        }
50
        $d->Close();
51
        if (count($a) == 0) {
52
            die("PANIC: Apache/PHP does not have enough permission to read the scripts in directory: $this->iDir");
53
        }
54
        sort($a);
55
        return $a;
56
    }
57
58
    public function GetCSIMFiles()
59
    {
60
        $d = @dir($this->iDir);
61
        $a = array();
62
        while ($entry = $d->Read()) {
63
            if (strstr($entry, ".php") && strstr($entry, "csim")) {
64
                $a[] = $entry;
65
            }
66
        }
67
        $d->Close();
68
        if (count($a) == 0) {
69
            die("PANIC: Apache/PHP does not have enough permission to read the CSIM scripts in directory: $this->iDir");
70
        }
71
        sort($a);
72
        return $a;
73
    }
74
75
    public function Run()
76
    {
77
        switch ($this->iType) {
78
            case 1:
79
                $files = $this->GetFiles();
80
                break;
81
            case 2:
82
                $files = $this->GetCSIMFiles();
83
                break;
84
            default:
85
                die('Panic: Unknown type of test');
86
                break;
87
        }
88
        $n = count($files);
89
        echo "<h2>Visual test suit for JpGraph</h2>";
90
        echo "Testtype: " . ($this->iType == 1 ? ' Standard images ' : ' Image map tests ');
91
        echo "<br>Number of tests: $n<p>";
92
        echo "<ol>";
93
94
        for ($i = 0; $i < $n; ++$i) {
95
            if ($this->iType == 1) {
96
                echo '<li style="border:1px solid #CCC;padding:10px;"><a href="show-example.php?target=' . urlencode($files[$i]) . '"><img src="' . $files[$i] . '" border=0 align=top></a><br><strong>Filename:</strong> <i><a href="' . $files[$i] . '">' . basename($files[$i]) . "</a></i>\n";
97
            } else {
98
                echo '<li><a href="show-example.php?target=' . urlencode($files[$i]) . '">' . $files[$i] . "</a>\n";
99
            }
100
        }
101
        echo "</ol>";
102
103
        echo "<p>Done.</p>";
104
    }
105
}
106
107
$type = @$_GET['type'];
108
if (empty($type)) {
109
    $type = 1;
110
}
111
112
$driver = new TestDriver($type);
113
$driver->Run();
114