Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| tool_autoflow_generator | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
| create_workflow | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | // This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>. |
| 16 | |
| 17 | /** |
| 18 | * Test data generator for tool_autoflow. |
| 19 | * |
| 20 | * @package tool_autoflow |
| 21 | * @category test |
| 22 | * @copyright 2026 DevLMS <contact@devlms.com> |
| 23 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 24 | */ |
| 25 | class tool_autoflow_generator extends component_generator_base { |
| 26 | /** |
| 27 | * Create a workflow: a manual trigger followed by a log node with the given message. |
| 28 | * |
| 29 | * @param array $record name, message, enabled |
| 30 | * @return int Workflow id. |
| 31 | */ |
| 32 | public function create_workflow(array $record = []): int { |
| 33 | $graph = json_encode([ |
| 34 | 'nodes' => [ |
| 35 | ['id' => 't', 'type' => 'trigger.manual', 'data' => [], 'position' => ['x' => 0, 'y' => 0]], |
| 36 | ['id' => 'log', 'type' => 'action.log', 'data' => ['params' => ['message' => $record['message'] ?? 'Hello']], |
| 37 | 'position' => ['x' => 0, 'y' => 120]], |
| 38 | ], |
| 39 | 'edges' => [['id' => 't-log', 'source' => 't', 'target' => 'log']], |
| 40 | ]); |
| 41 | return \tool_autoflow\local\workflow_store::save( |
| 42 | 0, |
| 43 | $record['name'] ?? 'Workflow', |
| 44 | $graph, |
| 45 | (bool) ($record['enabled'] ?? true) |
| 46 | )['id']; |
| 47 | } |
| 48 | } |