-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathViewTestController.php
More file actions
114 lines (103 loc) · 3.18 KB
/
ViewTestController.php
File metadata and controls
114 lines (103 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace App\Http\Controllers;
use CDash\Controller\Api\ViewTest;
use CDash\Database;
use CDash\Model\Build;
use Illuminate\Http\JsonResponse;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\StreamedResponse;
final class ViewTestController extends AbstractBuildController
{
public function viewTest(): View
{
$this->setBuildById(request()->integer('buildid'));
return $this->view('test.view-test', 'Tests');
}
/**
* View tests of a particular build.
*
* GET /viewTest.php
* Required Params:
* buildid=[integer] The ID of the build
*
* Optional Params:
*
* date=[YYYY-mm-dd]
* tests=[array of test names]
* If tests is passed the following parameters apply:
* Required:
* projectid=[integer]
* groupid=[integer]
* Optional:
* previous_builds=[comma separated list of build ids]
* time_begin=[SQL compliant comparable to timestamp]
* time_end=[SQL compliant comparable to timestamp]
* onlypassed=[presence]
* onlyfailed=[presence]
* onlytimestatus=[presence]
* onlynotrun=[presence]
* onlydelta=[presence]
* filterstring
* export=[presence]
*
* TODO: figure out the return type for this function...
**/
public function fetchPageContent(): JsonResponse|StreamedResponse
{
$db = Database::getInstance();
$controller = new ViewTest($db, self::get_request_build());
$response = $controller->getResponse();
if ($controller->JSONEncodeResponse) {
return response()->json(cast_data_for_JSON($response));
}
$headers = [
'Content-Type' => 'text/csv',
];
return response()->streamDownload(function () use ($response): void {
echo $response;
}, 'test-export.csv', $headers);
}
/**
* Returns a build based on the id extracted from the request and returns it if the user has
* necessary access to the project
*
* @param bool $required
*/
private static function get_request_build($required = true): ?Build
{
$id = self::get_request_build_id($required);
if (null === $id) {
return null;
}
$build = new Build();
$build->Id = $id;
if ($required && !$build->Exists()) {
abort(400, 'This build does not exist. Maybe it has been deleted.');
}
if ($id) {
$build->FillFromId($id);
}
return can_access_project($build->ProjectId) ? $build : null;
}
/**
* Pulls the buildid from the request
*
* @param bool $required
*/
private static function get_request_build_id($required = true): ?int
{
$buildid = self::get_int_param('buildid', $required);
return $buildid;
}
private static function get_int_param($name, $required = true): ?int
{
$value = get_param($name, $required);
if (null === $value) {
return null;
}
if ($required && !is_numeric($value)) {
abort(400, "Valid $name required");
}
return (int) $value;
}
}