2019-10-15 07:37:59 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
global $utopia, $request, $response;
|
|
|
|
|
|
|
|
use Utopia\Validator\Numeric;
|
|
|
|
use Utopia\Validator\Text;
|
2019-10-19 12:58:17 +13:00
|
|
|
use Utopia\Validator\ArrayList;
|
2019-10-20 01:52:17 +13:00
|
|
|
use Storage\Validators\File;
|
2019-10-15 07:37:59 +13:00
|
|
|
|
|
|
|
$result = [];
|
|
|
|
|
|
|
|
$utopia->get('/v1/mock/tests/foo')
|
|
|
|
->desc('Mock a get request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'foo')
|
|
|
|
->label('sdk.method', 'get')
|
|
|
|
->label('sdk.description', 'Mock a get request for SDK tests')
|
|
|
|
->param('x', '', function () { return new Text(100); }, 'Sample string param')
|
|
|
|
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
|
2019-10-19 12:58:17 +13:00
|
|
|
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
|
2019-10-15 07:37:59 +13:00
|
|
|
->action(
|
2019-10-19 09:07:31 +13:00
|
|
|
function ($x, $y, $z) {
|
|
|
|
|
2019-10-15 07:37:59 +13:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$utopia->post('/v1/mock/tests/foo')
|
|
|
|
->desc('Mock a post request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'foo')
|
|
|
|
->label('sdk.method', 'post')
|
|
|
|
->label('sdk.description', 'Mock a post request for SDK tests')
|
|
|
|
->param('x', '', function () { return new Text(100); }, 'Sample string param')
|
|
|
|
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
|
2019-10-19 12:58:17 +13:00
|
|
|
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
|
2019-10-15 07:37:59 +13:00
|
|
|
->action(
|
2019-10-19 09:07:31 +13:00
|
|
|
function ($x, $y, $z) {
|
|
|
|
|
2019-10-15 07:37:59 +13:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$utopia->patch('/v1/mock/tests/foo')
|
|
|
|
->desc('Mock a patch request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'foo')
|
|
|
|
->label('sdk.method', 'patch')
|
|
|
|
->label('sdk.description', 'Mock a get request for SDK tests')
|
|
|
|
->param('x', '', function () { return new Text(100); }, 'Sample string param')
|
|
|
|
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
|
2019-10-19 12:58:17 +13:00
|
|
|
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
|
2019-10-15 07:37:59 +13:00
|
|
|
->action(
|
2019-10-19 09:07:31 +13:00
|
|
|
function ($x, $y, $z) {
|
|
|
|
|
2019-10-15 07:37:59 +13:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$utopia->put('/v1/mock/tests/foo')
|
|
|
|
->desc('Mock a put request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'foo')
|
|
|
|
->label('sdk.method', 'put')
|
|
|
|
->label('sdk.description', 'Mock a put request for SDK tests')
|
|
|
|
->param('x', '', function () { return new Text(100); }, 'Sample string param')
|
|
|
|
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
|
2019-10-19 12:58:17 +13:00
|
|
|
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
|
2019-10-15 07:37:59 +13:00
|
|
|
->action(
|
2019-10-19 09:07:31 +13:00
|
|
|
function ($x, $y, $z) {
|
|
|
|
|
2019-10-15 07:37:59 +13:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$utopia->delete('/v1/mock/tests/foo')
|
|
|
|
->desc('Mock a delete request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'foo')
|
|
|
|
->label('sdk.method', 'delete')
|
|
|
|
->label('sdk.description', 'Mock a delete request for SDK tests')
|
|
|
|
->param('x', '', function () { return new Text(100); }, 'Sample string param')
|
|
|
|
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
|
2019-10-19 12:58:17 +13:00
|
|
|
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
|
2019-10-15 07:37:59 +13:00
|
|
|
->action(
|
2019-10-19 09:07:31 +13:00
|
|
|
function ($x, $y, $z) {
|
|
|
|
|
2019-10-15 07:37:59 +13:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$utopia->get('/v1/mock/tests/bar')
|
|
|
|
->desc('Mock a get request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'bar')
|
|
|
|
->label('sdk.method', 'get')
|
|
|
|
->label('sdk.description', 'Mock a get request for SDK tests')
|
|
|
|
->param('x', '', function () { return new Text(100); }, 'Sample string param')
|
|
|
|
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
|
2019-10-19 12:58:17 +13:00
|
|
|
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
|
2019-10-15 07:37:59 +13:00
|
|
|
->action(
|
2019-10-19 09:07:31 +13:00
|
|
|
function ($x, $y, $z) {
|
|
|
|
|
2019-10-15 07:37:59 +13:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$utopia->post('/v1/mock/tests/bar')
|
|
|
|
->desc('Mock a post request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'bar')
|
|
|
|
->label('sdk.method', 'post')
|
|
|
|
->label('sdk.description', 'Mock a post request for SDK tests')
|
|
|
|
->param('x', '', function () { return new Text(100); }, 'Sample string param')
|
|
|
|
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
|
2019-10-19 12:58:17 +13:00
|
|
|
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
|
2019-10-15 07:37:59 +13:00
|
|
|
->action(
|
2019-10-19 09:07:31 +13:00
|
|
|
function ($x, $y, $z) {
|
|
|
|
|
2019-10-15 07:37:59 +13:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$utopia->patch('/v1/mock/tests/bar')
|
|
|
|
->desc('Mock a patch request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'bar')
|
|
|
|
->label('sdk.method', 'patch')
|
|
|
|
->label('sdk.description', 'Mock a get request for SDK tests')
|
|
|
|
->param('x', '', function () { return new Text(100); }, 'Sample string param')
|
|
|
|
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
|
2019-10-19 12:58:17 +13:00
|
|
|
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
|
2019-10-15 07:37:59 +13:00
|
|
|
->action(
|
2019-10-19 09:07:31 +13:00
|
|
|
function ($x, $y, $z) {
|
|
|
|
|
2019-10-15 07:37:59 +13:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$utopia->put('/v1/mock/tests/bar')
|
|
|
|
->desc('Mock a put request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'bar')
|
|
|
|
->label('sdk.method', 'put')
|
|
|
|
->label('sdk.description', 'Mock a put request for SDK tests')
|
|
|
|
->param('x', '', function () { return new Text(100); }, 'Sample string param')
|
|
|
|
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
|
2019-10-19 12:58:17 +13:00
|
|
|
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
|
2019-10-15 07:37:59 +13:00
|
|
|
->action(
|
2019-10-19 09:07:31 +13:00
|
|
|
function ($x, $y, $z) {
|
|
|
|
|
2019-10-15 07:37:59 +13:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-12-25 09:59:31 +13:00
|
|
|
$utopia->delete('/v1/mock/tests/bar')
|
2019-10-15 07:37:59 +13:00
|
|
|
->desc('Mock a delete request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'bar')
|
|
|
|
->label('sdk.method', 'delete')
|
|
|
|
->label('sdk.description', 'Mock a delete request for SDK tests')
|
|
|
|
->param('x', '', function () { return new Text(100); }, 'Sample string param')
|
|
|
|
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
|
2019-10-19 12:58:17 +13:00
|
|
|
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
|
2019-10-15 07:37:59 +13:00
|
|
|
->action(
|
2019-10-19 09:07:31 +13:00
|
|
|
function ($x, $y, $z) {
|
|
|
|
|
2019-10-15 07:37:59 +13:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-12-25 19:31:09 +13:00
|
|
|
$utopia->post('/v1/mock/tests/general/upload')
|
2019-10-20 01:52:17 +13:00
|
|
|
->desc('Mock a post request for SDK tests')
|
2019-10-15 07:37:59 +13:00
|
|
|
->label('scope', 'public')
|
2019-12-25 09:59:31 +13:00
|
|
|
->label('sdk.namespace', 'general')
|
2019-10-20 01:52:17 +13:00
|
|
|
->label('sdk.method', 'upload')
|
|
|
|
->label('sdk.description', 'Mock a delete request for SDK tests')
|
|
|
|
->label('sdk.consumes', 'multipart/form-data')
|
|
|
|
->param('x', '', function () { return new Text(100); }, 'Sample string param')
|
|
|
|
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
|
|
|
|
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
|
|
|
|
->param('file', [], function () { return new File(); }, 'Sample file param', false)
|
2019-10-15 07:37:59 +13:00
|
|
|
->action(
|
2019-10-20 01:52:17 +13:00
|
|
|
function ($x, $y, $z, $file) use ($request) {
|
|
|
|
$file = $request->getFiles('file');
|
|
|
|
$file['tmp_name'] = (is_array($file['tmp_name'])) ? $file['tmp_name'] : [$file['tmp_name']];
|
|
|
|
|
|
|
|
foreach ($file['tmp_name'] as $i => $tmpName) {
|
|
|
|
if(md5(file_get_contents($tmpName)) !== 'asdasdasd') {
|
|
|
|
throw new Exception('Wrong file uploaded', 400);
|
|
|
|
}
|
2019-10-15 07:37:59 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-12-25 19:31:09 +13:00
|
|
|
$utopia->get('/v1/mock/tests/general/redirect')
|
2019-12-25 09:59:31 +13:00
|
|
|
->desc('Mock a post request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'general')
|
|
|
|
->label('sdk.method', 'redirect')
|
|
|
|
->label('sdk.description', 'Mock a redirect request for SDK tests')
|
|
|
|
->action(
|
2019-12-26 04:18:38 +13:00
|
|
|
function () use ($response) {
|
2019-12-25 19:31:09 +13:00
|
|
|
$response->redirect('/v1/mock/tests/general/redirected');
|
2019-12-25 09:59:31 +13:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-12-25 19:31:09 +13:00
|
|
|
$utopia->get('/v1/mock/tests/general/redirected')
|
2019-12-25 09:59:31 +13:00
|
|
|
->desc('Mock a post request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'general')
|
2019-12-25 19:31:09 +13:00
|
|
|
->label('sdk.method', 'redirected')
|
2019-12-25 09:59:31 +13:00
|
|
|
->label('sdk.description', 'Mock a redirected request for SDK tests')
|
|
|
|
->action(
|
2019-12-26 04:18:38 +13:00
|
|
|
function () {
|
2019-12-25 09:59:31 +13:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-12-25 19:31:09 +13:00
|
|
|
$utopia->get('/v1/mock/tests/general/empty')
|
|
|
|
->desc('Mock a post request for SDK tests')
|
|
|
|
->label('scope', 'public')
|
|
|
|
->label('sdk.namespace', 'general')
|
|
|
|
->label('sdk.method', 'empty')
|
|
|
|
->label('sdk.description', 'Mock a redirected request for SDK tests')
|
|
|
|
->action(
|
|
|
|
function () use ($response) {
|
|
|
|
$response->noContent();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-10-15 07:37:59 +13:00
|
|
|
$utopia->shutdown(function() use ($response, $request, &$result, $utopia) {
|
|
|
|
|
|
|
|
$route = $utopia->match($request);
|
|
|
|
$path = '/storage/cache/tests.json';
|
|
|
|
$tests = (file_exists($path)) ? json_decode(file_get_contents($path), true) : [];
|
|
|
|
|
|
|
|
if(!is_array($tests)) {
|
|
|
|
throw new Exception('Failed to read results', 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
$result[$route->getMethod() . ':' . $route->getURL()] = true;
|
|
|
|
|
|
|
|
$tests = array_merge($tests, $result);
|
|
|
|
|
|
|
|
if(!file_put_contents($path, json_encode($tests), LOCK_EX)) {
|
|
|
|
throw new Exception('Failed to save resutls', 500);
|
|
|
|
}
|
2019-10-16 01:48:19 +13:00
|
|
|
|
|
|
|
$response->json(['result' => $route->getMethod() . ':' . $route->getURL() . ':passed']);
|
2019-10-15 07:37:59 +13:00
|
|
|
});
|