Example #1
0
<?php

require 'server.inc';
function do_test($version, $connection)
{
    $options = ['http' => ['protocol_version' => $version]];
    if ($connection) {
        $options['http']['header'] = "Connection: {$connection}";
    }
    $ctx = stream_context_create($options);
    $responses = ["data://text/plain,HTTP/{$version} 204 No Content\r\n\r\n"];
    $pid = http_server('tcp://127.0.0.1:12342', $responses, $output);
    $fd = fopen('http://127.0.0.1:12342/', 'rb', false, $ctx);
    fseek($output, 0, SEEK_SET);
    echo stream_get_contents($output);
    http_server_kill($pid);
}
echo "HTTP/1.0, default behaviour:\n";
do_test('1.0', null);
echo "HTTP/1.0, connection: close:\n";
do_test('1.0', 'close');
echo "HTTP/1.0, connection: keep-alive:\n";
do_test('1.0', 'keep-alive');
echo "HTTP/1.1, default behaviour:\n";
do_test('1.1', null);
echo "HTTP/1.1, connection: close:\n";
do_test('1.1', 'close');
echo "HTTP/1.1, connection: keep-alive:\n";
do_test('1.1', 'keep-alive');
Example #2
0
<?php

require 'server.inc';
function do_test($follow)
{
    $options = ['http' => ['method' => 'POST', 'follow_location' => $follow]];
    $ctx = stream_context_create($options);
    $responses = ["data://text/plain,HTTP/1.1 308\r\nLocation: /foo\r\n\r\n", "data://text/plain,HTTP/1.1 200\r\nConnection: close\r\n\r\n"];
    $pid = http_server('tcp://127.0.0.1:12342', $responses, $output);
    $fd = fopen('http://127.0.0.1:12342/', 'rb', false, $ctx);
    fseek($output, 0, SEEK_SET);
    echo stream_get_contents($output);
    http_server_kill($pid);
}
do_test(true);
do_test(false);
?>
Done
Example #3
0
<?php

require 'server.inc';
function do_test($header)
{
    $options = ['http' => ['method' => 'POST', 'header' => $header, 'follow_location' => true]];
    $ctx = stream_context_create($options);
    $responses = ["data://text/plain,HTTP/1.1 201\r\nLocation: /foo\r\n\r\n", "data://text/plain,HTTP/1.1 200\r\nConnection: close\r\n\r\n"];
    $pid = http_server('tcp://127.0.0.1:12342', $responses, $output);
    $fd = fopen('http://127.0.0.1:12342/', 'rb', false, $ctx);
    fseek($output, 0, SEEK_SET);
    echo stream_get_contents($output);
    http_server_kill($pid);
}
do_test("First:1\nSecond:2\nContent-type: text/plain");
do_test("First:1\nSecond:2\nContent-type: text/plain\n");
do_test("First:1\nSecond:2\nContent-type: text/plain\nThird:");
do_test("First:1\nContent-type:text/plain\nSecond:2");
do_test("First:1\nContent-type:text/plain\nSecond:2\n");
do_test("First:1\nContent-type:text/plain\nSecond:2\nThird:");
?>
Done
Example #4
0
function test_file($filename, $simplexml_mode = false)
{
    $testfile = file_get_contents($filename);
    if (!$testfile) {
        throw new Exception("Couldn't find test file {$filename}");
        return false;
    }
    $tests = json_decode($testfile, 1);
    if (is_null($tests)) {
        throw new Exception("Error json-decoding test file {$filename}");
    }
    $success = true;
    foreach ($tests as $test) {
        if (isset($test['disabled']) && $test['disabled']) {
            continue;
        }
        if (!do_test($test, $simplexml_mode)) {
            $success = false;
        }
        if (!$simplexml_mode && !diff_test($test)) {
            $success = false;
        }
    }
    return $success;
}
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
date_default_timezone_set('Europe/Lisbon');
function do_test(IntlTimeZone $tz, $proc = false)
{
    var_dump($tz->getID(), $tz->getRawOffset());
    if (!$proc) {
        $dtz = $tz->toDateTimeZone();
    } else {
        $dtz = intltz_to_date_time_zone($tz);
    }
    var_dump($dtz->getName(), $dtz->getOffset(new DateTime('2012-01-01 00:00:00')));
}
do_test(IntlTimeZone::createTimeZone('CET'));
do_test(IntlTimeZone::createTimeZone('Europe/Amsterdam'));
do_test(IntlTimeZone::createTimeZone('GMT+0405'), true);
Example #6
0
function do_test($context_options)
{
    $context = stream_context_create(array('http' => $context_options));
    $responses = array("data://text/plain,HTTP/1.0 302 Moved Temporarily\r\nLocation: http://127.0.0.1:12342/foo/bar2\r\n\r\n1", "data://text/plain,HTTP/1.0 301 Moved Permanently\r\nLocation: http://127.0.0.1:12342/foo/bar3\r\n\r\n", "data://text/plain,HTTP/1.0 302 Moved Temporarily\r\nLocation: http://127.0.0.1:12342/foo/bar4\r\n\r\n3", "data://text/plain,HTTP/1.0 200 OK\r\n\r\ndone.");
    $pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
    $fd = fopen('http://127.0.0.1:12342/foo/bar', 'rb', false, $context);
    var_dump($fd);
    if ($fd) {
        $meta_data = stream_get_meta_data($fd);
        var_dump($meta_data['wrapper_data']);
        var_dump(stream_get_contents($fd));
    }
    fseek($output, 0, SEEK_SET);
    var_dump(stream_get_contents($output));
    http_server_kill($pid);
}
echo "-- Test: follow all redirections --\n";
do_test(array(), 4);
echo "-- Test: fail after 2 redirections --\n";
do_test(array('max_redirects' => 2), 2);
echo "-- Test: fail at first redirection --\n";
do_test(array('max_redirects' => 0), 1);
echo "-- Test: fail at first redirection (2) --\n";
do_test(array('max_redirects' => 1), 1);
echo "-- Test: return at first redirection --\n";
do_test(array('max_redirects' => 0, 'ignore_errors' => 1), 1);
echo "-- Test: return at first redirection (2) --\n";
do_test(array('max_redirects' => 1, 'ignore_errors' => 1), 1);
echo "-- Test: return at second redirection --\n";
do_test(array('max_redirects' => 2, 'ignore_errors' => 1), 2);
Example #7
0
    public $publico = 'hehe';
}
class Foo extends Baz
{
    private $_handle;
    public function __construct()
    {
        $this->_handle = fopen(__FILE__, 'r');
    }
    protected $segundo_proc = 'adios';
    private $other_priv = array();
    public $Fooque = 'publico';
}
class DummyClass
{
    public $field;
}
?>
<!doctype html>
<html>
    <head>
        <title>Dump test</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <h1>Dump test</h1>
        <?php 
do_test();
?>
    </body>
</html>
Example #8
0
        }
    } else {
        update_status("STA005", "Program executed successfully");
    }
    // Profile
    if ($run_result['status'] != EXECUTION_CRASH && $task['profile'] === "true" && $profiler) {
        // Recompile with debug compiler_options
        $compile_result_debug = do_compile($filelist, $debug_exe_file, $compiler, $task['compiler_options_debug'], $instance);
        if ($compile_result_debug['status'] === COMPILE_SUCCESS) {
            $profile_result = do_profile($debug_exe_file, $profiler, $filelist, $task['running_params'], $instance);
            update_status("STA007", "Program profiled");
        }
    }
}
// Don't interfere with testing
unlink($exe_file);
if (file_exists($debug_exe_file)) {
    unlink($debug_exe_file);
}
// Unit test
if ($task['test'] === "true") {
    $global_symbols = extract_global_symbols($filelist, $task['language']);
    $count = 1;
    foreach ($task['test_specifications'] as $test) {
        $test_result = do_test($filelist, $global_symbols, $test, $compiler, $debugger, $profiler, $task, $instance);
        $test_results[$test['id']] = $test_result;
        update_status("STA008", "Test " . $count++ . " finished");
    }
}
update_status("STA009", "Task completed");
done();
Example #9
0
                $tests_to_run[] = $filename;
            }
        }
    } elseif ($name == '-all') {
        # Each 'section' in the config file becomes a key in the array.
        # The section name plus .php is the test script name.
        foreach (array_keys($val_data) as $test_name) {
            $tests_to_run[] = $test_name . '.php';
        }
    } elseif ($name == '-match') {
        if (++$arg >= $argc) {
            break;
        }
        $match_pattern = $argv[$arg];
    } else {
        $tests_to_run[] = $name;
    }
}
# Apply a match pattern (-match pattern) to limit the tests to run:
if (!empty($match_pattern)) {
    $tests_to_run = array_values(array_filter($tests_to_run, create_function('$s', "return fnmatch('{$match_pattern}', \$s);")));
}
$total_tests = count($tests_to_run);
preface();
$start_time = microtime(TRUE);
foreach ($tests_to_run as $name) {
    do_test($name);
}
summarize(microtime(TRUE) - $start_time);
cleanup();
exit(0);
Example #10
0
<?php

require 'server.inc';
function do_test($context_options)
{
    $context = stream_context_create(array('http' => $context_options));
    $responses = array("data://text/plain,HTTP/1.0 200 Ok\r\nX-Foo: bar\r\n\r\n1", "data://text/plain,HTTP/1.0 404 Not found\r\nX-bar: baz\r\n\r\n2");
    $pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
    foreach ($responses as $r) {
        $fd = fopen('http://127.0.0.1:12342/foo/bar', 'rb', false, $context);
        var_dump($fd);
        if ($fd) {
            $meta_data = stream_get_meta_data($fd);
            var_dump($meta_data['wrapper_data']);
            var_dump(stream_get_contents($fd));
        }
        fseek($output, 0, SEEK_SET);
        var_dump(stream_get_contents($output));
        fseek($output, 0, SEEK_SET);
    }
    http_server_kill($pid);
}
echo "-- Test: requests without ignore_errors --\n";
do_test(array());
echo "-- Test: requests with ignore_errors --\n";
do_test(array('ignore_errors' => true));
echo "-- Test: requests with ignore_errors (2) --\n";
do_test(array('ignore_errors' => 1));
Example #11
0
<?php

require 'server.inc';
function do_test($context_options)
{
    $context = stream_context_create(array('http' => $context_options));
    $responses = array("data://text/plain,HTTP/1.0 200 OK\r\n\r\n");
    $pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
    foreach ($responses as $r) {
        $fd = fopen('http://127.0.0.1:12342/', 'rb', false, $context);
        fseek($output, 0, SEEK_SET);
        var_dump(stream_get_contents($output));
        fseek($output, 0, SEEK_SET);
    }
    http_server_kill($pid);
}
echo "-- Test: requests with 'header' as array --\n";
do_test(array('header' => array('X-Foo: bar', 'Content-Type: text/plain'), 'method' => 'POST', 'content' => 'ohai'));
echo "-- Test: requests with 'header' as string --\n";
do_test(array('header' => "X-Foo: bar\r\nContent-Type: text/plain", 'method' => 'POST', 'content' => 'ohai'));
Example #12
0
$dbtest = array();
$allow_next = false;
$cms->theme->assign_by_ref('dbtest', $dbtest);
$cms->theme->assign_by_ref('db_errors', $db->errors);
$cms->theme->assign_by_ref('db_queries', $db->queries);
$cms->theme->assign(array('min_db_version' => $min_db_version));
if ($ajax_request) {
    //	sleep(1);
    do_test($dbtest);
    save_db_opts();
    $pagename = 'go-db-results';
    $cms->tiny_page($pagename, $pagename);
    exit;
} else {
    if ($dbhost != '') {
        do_test($dbtest, true);
        if (!$db->connected or !$dbtest['selected']) {
            $dbtest['tested'] = false;
        }
    }
    save_db_opts();
}
function do_test(&$t, $skip_create = false)
{
    global $cms, $db, $min_db_version, $allow_next, $conf;
    global $dbhost, $dbport, $dbname, $dbuser, $dbpass, $dbtblprefix;
    load_db_opts($conf);
    $db->config(array('dbhost' => $dbhost, 'dbport' => $dbport, 'dbname' => $dbname, 'dbuser' => $dbuser, 'dbpass' => $dbpass, 'dbtblprefix' => $dbtblprefix));
    $db->clear_errors();
    $t['tested'] = true;
    $t['type'] = $db->type();