Exemple #1
0
        return 0;
    }
}
function test($mask)
{
    global $status;
    return ($status & $mask) == $mask;
}
//тестируем запрос клиента
$status += test_post(HAS_REQUEST_PAGE, 'user_page');
$status += test_post(HAS_LOGIN, 'user_login');
$status += test_post(HAS_PASSWORD, 'user_pass');
$status += test_post(HAS_HASH, 'user_code');
$status += test_post(HAS_REQUEST_ID, 'user_file');
$status += test_http(HAS_AJAX, 'HTTP_X_REQUESTED_WITH', 'xmlhttprequest');
$status += test_http(HAS_ADDRESS, 'REMOTE_ADDR', 0);
$status += test_file(HAS_NAME, 'file_name', 'name');
$status += test_file(HAS_TMP_NAME, 'file_name', 'tmp_name');
$status += test_file(HAS_SIZE, 'file_name', 'size');
$status += test_file(HAS_ERROR, 'file_name', 'error');
//проверяем корректность формата
if (test(HAS_LOGIN) && preg_match("/^[0-9a-zA-Z\\._-]+@[0-9a-zA-Z\\._-]+\\.[a-zA-Z]{2,4}\$/", $_POST['user_login'])) {
    $status += ACCESS_LOGIN;
}
if (test(HAS_PASSWORD) && preg_match("/^.{8,50}\$/", $_POST['user_pass'])) {
    $status += ACCESS_PASSWORD;
}
if (test(HAS_REQUEST_PAGE) && preg_match("/^\\d{1,3}\$/", $_POST['user_page'])) {
    $status += ACCESS_PAGE;
}
//всеряем логин и пароль по БД
    if ($expected !== $actual) {
        echo "error: single HTTPS request does not give proper tag\n";
        echo "expected: {$expected}";
        echo "\n";
        echo "actual..: {$actual}";
        echo "\n";
        return 1;
    }
    $scripts = array('example1', 'example2');
    $expected = '<script charset="ISO-8859-1" src="https://fast.wistia.com/static/concat/example1%2Cexample2.js"></script>';
    $actual = $wam->concat_script_tag($scripts);
    if ($expected !== $actual) {
        echo "error: multi HTTPS request does not give proper tag\n";
        echo "expected: {$expected}";
        echo "\n";
        echo "actual..: {$actual}";
        return 1;
    }
    return 0;
}
$exit_code = 0;
echo "Running http tests\n";
$exit_code += test_http();
echo "Running https tests\n";
$exit_code += test_https();
if ($exit_code == 0) {
    echo "Passed all tests!\n";
} else {
    echo "Failed Travis Tests\n";
}
exit($exit_code);