示例#1
0
<?php

define('INSTALL_ROOT', realpath(__DIR__ . '/../../') . '/');
// We always work with UTF8 encoding
mb_internal_encoding('UTF-8');
// Make sure we have a timezone set
date_default_timezone_set('Europe/Paris');
require __DIR__ . '/../../vendor/autoload.php';
// Launch PHP dev server in the background
chdir(INSTALL_ROOT);
exec('./start.sh -remote > /dev/null 2>&1 & echo $!', $output);
// We will need the pid to kill it, beware, this is the pid of the bash process started with start.sh
$pid = $output[0];
// Pause to let time for the dev server to launch in the background
sleep(3);
$paths = [['', 400, '{"error":"No service requested"}'], ['v1/', 400, '{"error":"Not enough parameters for this query."}'], ['v1/entity/central/?id=browser/chrome/browser/syncQuota.properties:collection.bookmarks.label', 200, '{"en-US":"Bookmarks","fr":"Marque-pages"}'], ['v1/entity/central/?id=browser/chrome/browser/IdontExist', 400, '{"error":"Entity not available"}'], ['v1/search/strings/central/en-US/fr/New%2Bbookmarks/', 200, '{"browser\\/chrome\\/browser\\/places\\/bookmarkProperties.properties:dialogTitleAddMulti":{"New Bookmarks":"Nouveaux marque-pages"}}'], ['v1/search/strings/central/en-US/fr/tralala/', 200, '[]'], ['v1/locales/central/', 200, '["ar","ast","cs","de","en-GB","en-US","eo","es-AR","es-CL","es-ES","es-MX","fa","fr","fy-NL","gl","he","hu","id","it","ja","ja-JP-mac","kk","ko","lt","lv","nb-NO","nl","nn-NO","pl","pt-BR","pt-PT","ru","sk","sl","sv-SE","th","tr","uk","vi","zh-CN","zh-TW"]'], ['v1/locales/iDontExist/', 400, '{"error":"The repo queried (iDontExist) doesn\'t exist."}'], ['v1/repositories/', 200, '["release","beta","aurora","central","gaia_1_3","gaia_1_4","gaia_2_0","gaia_2_1","gaia","mozilla_org"]'], ['v1/tm/central/en-US/fr/Bookmark/?max_results=3&min_quality=80', 200, '[{"source":"Bookmark","target":"Marquer cette page","quality":100},{"source":"Bookmark","target":"Marque-page","quality":100},{"source":"Bookmarks","target":"Marque-pages","quality":88.888888888889}]'], ['v1/versions/', 200, '{"v1":"stable"}']];
$obj = new \pchevrel\Verif('Check API HTTP responses');
$obj->setHost('localhost:8082')->setPathPrefix('api/');
$check = function ($object, $paths) {
    foreach ($paths as $values) {
        list($path, $http_code, $content) = $values;
        $object->setPath($path)->fetchContent()->hasResponseCode($http_code)->isJson()->isEqualTo($content);
    }
};
$check($obj, $paths);
$obj->report();
// Kill PHP dev server by killing all children processes of the bash process we opened in the background
exec('pkill -P ' . $pid);
die($obj->returnStatus());
示例#2
0
// Make sure we have a timezone set
date_default_timezone_set('Europe/Paris');
require __DIR__ . '/../../vendor/autoload.php';
// Set an environment variable so that the instance will use content from test files
putenv("AUTOMATED_TESTS=true");
// Launch PHP dev server in the background
chdir(INSTALL_ROOT);
exec('php -S 0.0.0.0:8083 > /dev/null 2>&1 & echo $!', $output);
// We will need the pid to kill it, beware, this is the pid of the php server started above
$pid = $output[0];
// Pause to let time for the dev server to launch in the background
sleep(3);
$json = [['?action=listlocales&project=snippets&json', 200, "[\n    \"fr\",\n    \"it\"\n]"], ['?action=listlocales&json', 400, "[\n    \"Please check you request: provide a project name, or a valid couple website+file.\"\n]"], ['?action=listlocales&website=2&file=page.lang&json', 200, "[\n    \"en-US\",\n    \"it\"\n]"], ['?action=count&json', 200, "{\n    \"it\": 6,\n    \"fr\": 0,\n    \"en-US\": 0\n}"], ['?website=2&file=page.lang&json&locale=it', 200, "{\n    \"page.lang\": {\n        \"it\": {\n            \"Identical\": 2,\n            \"Translated\": 13,\n            \"Missing\": 1,\n            \"Obsolete\": 1,\n            \"tags\": [],\n            \"activated\": true\n        }\n    }\n}"], ['?website=2&file=page.lang&json', 200, "{\n    \"page.lang\": {\n        \"it\": {\n            \"Identical\": 2,\n            \"Translated\": 13,\n            \"Missing\": 1,\n            \"Obsolete\": 1,\n            \"tags\": [],\n            \"activated\": true\n        }\n    }\n}"], ['?website=foo&file=main.lang&json', 400, "{\n    \"error\": \"foo is not a supported website. Check the value and try again.\"\n}"], ['?action=snippets&locale=it', 200, "{\n    \"@@this is a test, do not remove@@\": \"Questo \\u00e8 un test\",\n    \"Email\": \"Email\",\n    \"Fifth string with %(one)s, %(two)s\": \"Quinta stringa con %(one)s, %(two)s e ancora %(two)s\",\n    \"Fourth string with 90%% coverage\": \"Quarta stringa con copertura al 90%\",\n    \"Hello\": \"Ciao\",\n    \"Obsolete string\": \"Stringa obsoleta\",\n    \"Press center\": \"Sala stampa\",\n    \"Save file\": \"Salva file troppo lungo\",\n    \"Second string with %(num)s tags\": \"Seconda stringa con %(num)s etichette\",\n    \"Sixth string with %(one)s\": \"Sesta stringa con %(one)s e %(two)s\",\n    \"String with %(num)s tags\": \"Stringa con etichette e variabile sbagliata\",\n    \"String with multiple comments\": \"String con pi\\u00f9 commenti\",\n    \"Third string with %s tags\": \"Terza stringa con variabile mancante\"\n}"], ['?action=coverage&locales=foo', 400, "{\n    \"error\": \"ERROR: locales is not an array.\"\n}"], ['?action=coverage', 400, "{\n    \"error\": \"ERROR: missing list of locales.\"\n}"], ['?website=2&file=main.lang&json', 400, "{\n    \"error\": \"File main.lang does not exist. Check the value and try again.\"\n}"], ['?action=translate&file=foo.lang&json', 400, "{\n    \"error\": \"<p>ERROR: file foo.lang does not exist<\\/p>\"\n}"], ['?action=translate&file=page.lang&json', 200, "{\n    \"Email\": {\n        \"it\": \"Email\"\n    },\n    \"Hello\": {\n        \"it\": \"Ciao\"\n    },\n    \"Save file\": {\n        \"it\": \"Salva file troppo lungo\"\n    },\n    \"01\": {\n        \"it\": \"1\"\n    },\n    \"String with multiple comments\": {\n        \"it\": \"String con pi\\u00f9 commenti\"\n    },\n    \"Press center\": {\n        \"it\": \"Sala stampa\"\n    },\n    \"@@this is a test, do not remove@@\": {\n        \"it\": \"Questo \\u00e8 un test\"\n    },\n    \"String with %(num)s tags\": {\n        \"it\": \"Stringa con etichette e variabile sbagliata\"\n    },\n    \"Second string with %(num)s tags\": {\n        \"it\": \"Seconda stringa con %(num)s etichette\"\n    },\n    \"Third string with %s tags\": {\n        \"it\": \"Terza stringa con variabile mancante\"\n    },\n    \"Fourth string with 90%% coverage\": {\n        \"it\": \"Quarta stringa con copertura al 90%\"\n    },\n    \"Fifth string with %(one)s, %(two)s\": {\n        \"it\": \"Quinta stringa con %(one)s, %(two)s e ancora %(two)s\"\n    },\n    \"Sixth string with %(one)s\": {\n        \"it\": \"Sesta stringa con %(one)s e %(two)s\"\n    }\n}"]];
$text = [['?action=api&file=page.lang', 200, "<ul>\n<li><a href='?action=api&file=page.lang&stringid=54a2cf5e634dbba0be2bf8a55f79252f5c790bdb'>Browser</a></li>\n<li><a href='?action=api&file=page.lang&stringid=84add5b2952787581cb9a8851eef63d1ec75d22b'>Email</a></li>\n<li><a href='?action=api&file=page.lang&stringid=f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0'>Hello</a></li>\n<li><a href='?action=api&file=page.lang&stringid=640ab2bae07bedc4c163f679a746f7ab7fb5d1fa'>Test</a></li>\n<li><a href='?action=api&file=page.lang&stringid=bedc846b24ca06a457bf9b9208de6b146969362f'>Save file</a></li>\n<li><a href='?action=api&file=page.lang&stringid=ddfe163345d338193ac2bdc183f8e9dcff904b43'>01</a></li>\n<li><a href='?action=api&file=page.lang&stringid=e27ab9a3b203bd8831760183e2bbff78878c5dac'>String with multiple comments</a></li>\n<li><a href='?action=api&file=page.lang&stringid=1c037c4d9e72bbf474008cf56eae8734368093e4'>Press center</a></li>\n<li><a href='?action=api&file=page.lang&stringid=a7b3f41052019d22a389a41e375534e65dd9dff3'>@@this is a test, do not remove@@</a></li>\n<li><a href='?action=api&file=page.lang&stringid=b075e68c4e2ae16b7e5fe1dec55ede7584706f55'>String with tag</a></li>\n<li><a href='?action=api&file=page.lang&stringid=268fbfe819c694d4d179d4943de7f7d4cec4b042'>String with %(num)s tags</a></li>\n<li><a href='?action=api&file=page.lang&stringid=9f13ceddb7ca0399b59b942f0c1d884870225f76'>Second string with %(num)s tags</a></li>\n<li><a href='?action=api&file=page.lang&stringid=4747af9ac14c7aa4985890e850b6452faf0ab649'>Third string with %s tags</a></li>\n<li><a href='?action=api&file=page.lang&stringid=c1b92fc8ff9a988f1729f7ffac55efab58cffc00'>Fourth string with 90%% coverage</a></li>\n<li><a href='?action=api&file=page.lang&stringid=f99de591a4f4f53a7335f41d68f0f28c422a8f10'>Fifth string with %(one)s, %(two)s</a></li>\n<li><a href='?action=api&file=page.lang&stringid=3a5667ca2f63ce4baeb13bb10395e1197d041572'>Sixth string with %(one)s</a></li>\n</ul>\n"]];
$number = [['?action=coverage&locales[]=it&locales[]=fr', 200, '1.92'], ['?action=coverage&locales[]=fr', 200, '0.32'], ['?action=coverage&locales[]=foo', 200, '0.00']];
$obj = new \pchevrel\Verif('Check API HTTP responses');
$obj->setHost('localhost:8083');
$check = function ($paths, $type) use($obj) {
    foreach ($paths as $values) {
        list($path, $http_code, $content) = $values;
        $obj->setPath($path)->fetchContent()->hasResponseCode($http_code)->isEqualTo($content);
        switch ($type) {
            case 'json':
                $obj->isJson();
                break;
            case 'number':
                $obj->isNumeric();
                break;
            default:
                break;
        }