1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace tool_generator\output;
|
|
|
18 |
|
|
|
19 |
use renderable;
|
|
|
20 |
use renderer_base;
|
|
|
21 |
use templatable;
|
|
|
22 |
use tool_generator\local\testscenario\parsedfeature;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* A report to show the feature file parsing process.
|
|
|
26 |
*
|
|
|
27 |
* @package tool_generator
|
|
|
28 |
* @copyright 2023 Ferran Recio <ferran@moodle.com>
|
|
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
30 |
*/
|
|
|
31 |
class parsingresult implements renderable, templatable {
|
|
|
32 |
|
|
|
33 |
/** @var parsedfeature the processed feature object. */
|
|
|
34 |
protected $parsedfeature;
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Constructor.
|
|
|
38 |
*
|
|
|
39 |
* @param parsedfeature $parsedfeature
|
|
|
40 |
*/
|
|
|
41 |
public function __construct(parsedfeature $parsedfeature) {
|
|
|
42 |
$this->parsedfeature = $parsedfeature;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* Export for template.
|
|
|
47 |
*
|
|
|
48 |
* @param renderer_base $output The renderer.
|
|
|
49 |
* @return array
|
|
|
50 |
*/
|
|
|
51 |
public function export_for_template(renderer_base $output): array {
|
|
|
52 |
$data = [
|
|
|
53 |
'scenarios' => [],
|
|
|
54 |
'isvalid' => $this->parsedfeature->is_valid(),
|
|
|
55 |
'generalerror' => $this->parsedfeature->get_general_error(),
|
|
|
56 |
];
|
|
|
57 |
$haslines = false;
|
|
|
58 |
foreach ($this->parsedfeature->get_scenarios() as $scenario) {
|
|
|
59 |
$scenariodata = [
|
|
|
60 |
'type' => $scenario->type,
|
|
|
61 |
'name' => $scenario->name,
|
|
|
62 |
'steps' => [],
|
|
|
63 |
];
|
|
|
64 |
if (!empty($scenario->error)) {
|
|
|
65 |
$scenariodata['scenarioerror'] = $scenario->error;
|
|
|
66 |
}
|
|
|
67 |
foreach ($scenario->steps as $step) {
|
|
|
68 |
$scenariodata['steps'][] = [
|
|
|
69 |
'text' => $step->get_text(),
|
|
|
70 |
'arguments' => $step->get_arguments_string(),
|
|
|
71 |
'hasarguments' => !empty($step->get_arguments_string()),
|
|
|
72 |
'isvalid' => $step->is_valid(),
|
|
|
73 |
'error' => $step->get_error(),
|
|
|
74 |
'isexecuted' => $step->is_executed(),
|
|
|
75 |
];
|
|
|
76 |
$haslines = true;
|
|
|
77 |
}
|
|
|
78 |
if (!empty($scenariodata['steps'])) {
|
|
|
79 |
$scenariodata['hassteps'] = true;
|
|
|
80 |
}
|
|
|
81 |
$data['scenarios'][] = $scenariodata;
|
|
|
82 |
}
|
|
|
83 |
if ($haslines) {
|
|
|
84 |
$data['haslines'] = $haslines;
|
|
|
85 |
}
|
|
|
86 |
return $data;
|
|
|
87 |
}
|
|
|
88 |
}
|