Пример #1
0
/**
 * Handles upload of a source file for lab submission.
 * Renames uploaded file for handling by test script.
 * @param $file file to be uploaded
 * @param $lab_id id number of lab for submission
 * @param $username name of user
 * @return array
 */
function uploadFile($file, $lab_id, $username)
{
    // get file upload location
    require_once "model.php";
    $target_dir = getConfigProperty('upload_directory');
    // rename uploaded file with username and lab id
    $file = $username . "_Lab_" . $lab_id . "." . pathinfo($_FILES["fileToUpload"]["name"])['extension'];
    $target_file = $target_dir . $file;
    //if file already exists
    if (file_exists($target_file)) {
        unlink($target_file);
    }
    // Check file size
    if ($_FILES["fileToUpload"]["size"] > 500000) {
        return array('success' => false, 'message' => 'File too large');
    }
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        $result = runTests($target_file);
        // run tests for that filename
        return array('success' => true, 'message' => "The file has been uploaded successfully.", 'scriptResult' => $result);
    } else {
        return array('success' => false, 'message' => "Sorry, there was an error uploading your file.");
    }
}
Пример #2
0
    /* Serialize the TEST categories +++++++++++++*/
    //print "\nTests:\n";
    $tests = array();
    for ($i = 0; $i < count($_GET['sut_tests']); ++$i) {
        $tests[] = new XML_RPC_Value($_GET['sut_tests'][$i], 'string');
    }
    $xtests = new XML_RPC_Value($tests, "array");
    /*--------------------------------------------*/
    /* Serialize the userTEST categories +++++++++++++*/
    for ($i = 0; $i < count($_GET['sut_usertests']); ++$i) {
        $tests[] = new XML_RPC_Value($_GET['sut_usertests'][$i], 'string');
    }
    $xtests = new XML_RPC_Value($tests, "array");
    /*--------------------------------------------*/
    $refresh = "n";
    if ($_REQUEST['refresh']) {
        $refresh = "y";
    }
    /* Serialize Method parameter ++++++++++++++++*/
    $request = new XML_RPC_Value(array("sut_username" => new XML_RPC_Value($_SESSION["username"], "string"), "sut_tests" => $xtests, "sut_versions" => $xversions, "sut_os" => $xoses, "sut_build" => new XML_RPC_Value($_GET['sut_build'], 'string'), "sut_refresh" => new XML_RPC_Value($refresh, 'string')), "struct");
    $params = array($request);
    $msg = new XML_RPC_Message('runTests', $params);
    /*--------------------------------------------*/
    $resp = $cli->send($msg);
    if (hasErrors($resp)) {
        return;
    }
}
$cli = new XML_RPC_Client('/RPCSERVER', $_SESSION["host"], $_SESSION["port"]);
runTests($cli);
header("location:index.php");
Пример #3
0
            $changedTests = true;
            break;
        }
    }
    if ($changedTests) {
        $failures = runTests($tree, 'all');
    } elseif ($failures <= 0) {
        $failures = runTests($tree, $changes);
    } else {
        if ($changes == $previous_changes) {
            $failures = runTests($tree, $changes);
            if ($failures <= 0) {
                $failures = runTests($tree, 'all');
            }
        } else {
            $failures = runTests($tree, 'all');
        }
    }
    if ($failures > 0) {
        $previous_changes = $changes;
    }
}
function buildCodeTree($base, $paths)
{
    $tree = array();
    foreach ($paths as $path) {
        $tree[$path] = array('files' => array(), 'dirs' => array());
        foreach (scandir($base . '/' . $path) as $file) {
            if ($file != '.' && $file != '..' && $file != '.svn') {
                if (is_dir($base . '/' . $path . '/' . $file)) {
                    $tree[$path]['dirs'][] = $file;
Пример #4
0
        echo '<FONT COLOR="#990000"><BIG>Fail!</BIG></FONT><BR>';
        $msg = preg_replace(array('/&/', '/</', '/>/'), array('&amp;', '&lt;', '&gt;'), $msg);
        echo '<pre><code>' . $msg . '</code></pre><BR>';
        $test_bad++;
    }
}
function runTests()
{
    $tests = array('testDiffCommonPrefix', 'testDiffCommonSuffix', 'testDiffHalfMatch', 'testDiffLinesToChars', 'testDiffCharsToLines', 'testDiffCleanupMerge', 'testDiffCleanupSemanticLossless', 'testDiffCleanupSemantic', 'testDiffCleanupEfficiency', 'testDiffPrettyHtml', 'testDiffText', 'testDiffDelta', 'testDiffXIndex', 'testDiffLevenshtein', 'testDiffPath', 'testMatchAlphabet', 'testMatchBitap', 'testMatchMain', 'testPatchObj', 'testPatchFromText', 'testPatchToText', 'testPatchAddContext', 'testPatchMake', 'testPatchSplitMax', 'testPatchAddPadding', 'testPatchApply');
    foreach ($tests as $test) {
        echo '<H3>' . $test . ':</H3>';
        eval($test . '();');
    }
}
$startTime = microtime(true);
runTests();
$endTime = microtime(true);
echo '<H3>Done.</H3>';
echo '<P>Tests passed: ' . $test_good . '<BR>Tests failed: ' . $test_bad . '</P>';
echo '<P>Total time: ' . ($endTime - $startTime) . ' ms</P>';
//////////////////////////////////////////////////////////////////////////////////////////
// functions
//////////////////////////////////////////////////////////////////////////////////////////
// If expected and actual are the equivalent, pass the test.
function assertEquivalent($msg, $expected, $actual = null)
{
    if (!$actual === null) {
        // msg is optional.
        $actual = $expected;
        $expected = $msg;
        $msg = 'Expected: \'' . $expected . '\' Actual: \'' . $actual . '\'';
Пример #5
0
function runTests($directory, $indent = "")
{
    global $failedTests;
    if ($directory[strlen($directory) - 1] != "/") {
        $directory .= "/";
    }
    $baseName = basename($directory);
    $testCount = 0;
    $testFileCount = 0;
    $entries = scandir($directory);
    foreach ($entries as $entry) {
        $filename = $directory . $entry;
        if (stripos($entry, '.php') && is_file($filename)) {
            $key = substr($filename, 0, strlen($filename) - 4);
            runPhpTest($key, $filename);
        } else {
            if (stripos($entry, '.json') && is_file($filename)) {
                $testFileCount++;
                $tests = json_decode(file_get_contents($filename));
                if ($tests == NULL) {
                    $testCount++;
                    $failedTests[$filename] = "Error parsing JSON";
                    continue;
                }
                if (!is_array($tests)) {
                    $tests = array($tests);
                }
                foreach ($tests as $index => $test) {
                    $key = substr($filename, 0, strlen($filename) - 5);
                    if (isset($test->title)) {
                        $key .= ": {$test->title}";
                    } else {
                        $key .= ": #{$index}";
                    }
                    runJsonTest($key, $test);
                    $testCount++;
                }
            }
        }
    }
    if ($testCount) {
        echo "{$indent}{$baseName}/   \t({$testCount} tests in {$testFileCount} files)\n";
    } else {
        echo "{$indent}{$baseName}/\n";
    }
    foreach ($entries as $entry) {
        $filename = $directory . $entry;
        if (strpos($entry, '.') === FALSE && is_dir($filename)) {
            runTests($filename, $indent . str_repeat(" ", strlen($baseName) + 1));
        }
    }
}
Пример #6
0
    $content .= "\nLes erreurs suivantes ont été détectées :\n";
    $content .= " - " . implode("\n - ", $errors);
    $content .= "\n\n Vous ne recevrez plus de message d'erreurs jusqu'au retour à la normale";
    email_send(getMailTo(), "Une erreur s'est produite sur OpenNAS", $content, $outError);
    return !$outError;
}
function sendSuccessReport()
{
    $xml = simplexml_load_file('/conf/config.xml');
    $name = $xml->xpath('/opennas/system/hostname');
    email_send(getMailTo(), "Plus d'erreur détectées sur OpenNAS", "Aucune erreur n'a été détectée sur l'OpenNAS \"" . $name['0'] . "\" ( " . get_hast_role() . " ).", $outError);
    return !$outError;
}
if (!validEmailTo()) {
    echo "Please enter a valid email address (-d option)";
    exit(1);
}
$errors = runTests();
if (count($errors)) {
    if (!hasPreviousError()) {
        if (sendErrorReport($errors)) {
            saveErrorState(true);
        }
    }
} else {
    if (hasPreviousError()) {
        if (sendSuccessReport()) {
            saveErrorState(false);
        }
    }
}
Пример #7
0
    $tbl = new HTMLTable();
    /*
     * Table definitions matching the testdata table in the testdata.sqlite table.
     */
    $colDefsSubset = [['displayName' => 'Name', 'propertyName' => 'name'], ['displayName' => 'Age', 'propertyName' => 'age']];
    $tbl->setColumns($colDefsSubset);
    $out = "<h3>Output some columns</h3>\n" . "<p>Print only the name and age columns</p>\n";
    $res = readTestdata();
    $out .= $tbl->create($res);
    return $out;
}
/**
 * Run all test cases.
 *
 * @return string the HTML code.
 */
function runTests()
{
    $out = getHeader();
    $out .= "<h2>Basic tests</h2>\n" . "<p>Do some basic tests on CHTMLTable. Note that testdata includes " . "some rows with null values in one or more columns</p>\n";
    // Print without defined header
    $out .= testWriteTableNoDefs();
    // Print with defined header
    $out .= testWriteTableWithDefs();
    // Print only some columns
    $out .= testWriteTableSubset();
    $out .= "</body></html>";
    return $out;
}
echo runTests();
Пример #8
0
function showTests()
{
    createHtmlPage("Ember: Tests");
    echo '<div style="white-space:nowrap;">';
    echo 'Test results:<br>';
    echo runTests();
    echo '</div>';
    endHtmlPage();
}