Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 44 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
TestRunnerClientConfigRegistry | |
0.00% |
0 / 44 |
|
0.00% |
0 / 3 |
240 | |
0.00% |
0 / 1 |
registerQtiTools | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
registerPlugin | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
110 | |||
removePlugin | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | /* |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; under version 2 |
7 | * of the License (non-upgradable). |
8 | * |
9 | * This program 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 this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * |
18 | * Copyright (c) 2015 (original work) Open Assessment Technologies SA ; |
19 | * |
20 | */ |
21 | |
22 | namespace oat\taoQtiTest\models; |
23 | |
24 | use oat\tao\model\ClientLibConfigRegistry; |
25 | |
26 | /** |
27 | * Description of TestRunnerConfigRegistry |
28 | * |
29 | * @author sam |
30 | * |
31 | * @deprecated use oat\taoTests\models\runner\plugins\PluginRegistry instead |
32 | */ |
33 | class TestRunnerClientConfigRegistry extends ClientLibConfigRegistry |
34 | { |
35 | public const AMD = 'taoQtiTest/controller/runtime/testRunner'; |
36 | |
37 | /** |
38 | * Path to the runner controller module |
39 | */ |
40 | public const RUNNER = 'taoQtiTest/controller/runner/runner'; |
41 | |
42 | /** |
43 | * Path to the runner controller module in production mode |
44 | */ |
45 | public const RUNNER_PROD = 'taoQtiTest/qtiTestRunner.min'; |
46 | |
47 | /** |
48 | * Register a qti tools in the client lib config registry |
49 | * |
50 | * @param string $name |
51 | * @param array $toolConfig |
52 | */ |
53 | public function registerQtiTools($name, $toolConfig) |
54 | { |
55 | $newConfig = ['qtiTools' => []]; |
56 | //@todo validate tool config structure before registration |
57 | $newConfig['qtiTools'][$name] = $toolConfig; |
58 | $this->register(self::AMD, $newConfig); |
59 | } |
60 | |
61 | /** |
62 | * Register a runner plugin |
63 | * @param string $module |
64 | * @param string $category |
65 | * @param string|int $position |
66 | * @throws \common_exception_InvalidArgumentType |
67 | */ |
68 | public function registerPlugin($module, $category, $position = null) |
69 | { |
70 | if (!is_string($module)) { |
71 | throw new \common_exception_InvalidArgumentType('The module path must be a string!'); |
72 | } |
73 | |
74 | if (!is_string($category)) { |
75 | throw new \common_exception_InvalidArgumentType('The category name must be a string!'); |
76 | } |
77 | |
78 | if (!is_null($position) && !is_string($position) && !is_numeric($position)) { |
79 | throw new \common_exception_InvalidArgumentType('The position must be a string or a number!'); |
80 | } |
81 | |
82 | $config = []; |
83 | $registry = self::getRegistry(); |
84 | if ($registry->isRegistered(self::RUNNER)) { |
85 | $config = $registry->get(self::RUNNER); |
86 | } |
87 | |
88 | $plugins = []; |
89 | if (isset($config['plugins'])) { |
90 | foreach ($config['plugins'] as $plugin) { |
91 | if ($plugin['module'] != $module) { |
92 | $plugins[] = $plugin; |
93 | } |
94 | } |
95 | } |
96 | |
97 | $plugins[] = [ |
98 | 'module' => $module, |
99 | 'category' => $category, |
100 | 'position' => $position, |
101 | ]; |
102 | |
103 | $config['plugins'] = $plugins; |
104 | $registry->set(self::RUNNER, $config); |
105 | $registry->set(self::RUNNER_PROD, $config); |
106 | |
107 | // TODO: store the list of plugins into json file to compile the controller with dependencies |
108 | // example: file_put_contents($jsonPath, json_encode($plugins, JSON_PRETTY_PRINT)); |
109 | } |
110 | |
111 | /** |
112 | * @param $module |
113 | * @param $category |
114 | * @param null|int $position |
115 | */ |
116 | public function removePlugin($module, $category, $position = null) |
117 | { |
118 | $config = []; |
119 | $registry = self::getRegistry(); |
120 | |
121 | if ($registry->isRegistered(self::RUNNER)) { |
122 | $config = $registry->get(self::RUNNER); |
123 | } |
124 | |
125 | if (!isset($config['plugins'])) { |
126 | return; |
127 | } |
128 | |
129 | $plugins = $config['plugins']; |
130 | |
131 | $plugin = [ |
132 | 'module' => $module, |
133 | 'category' => $category, |
134 | 'position' => $position, |
135 | ]; |
136 | |
137 | $key = array_search($plugin, $plugins); |
138 | if (is_numeric($key)) { |
139 | unset($plugins[$key]); |
140 | } |
141 | |
142 | $config['plugins'] = $plugins; |
143 | $registry->set(self::RUNNER, $config); |
144 | $registry->set(self::RUNNER_PROD, $config); |
145 | } |
146 | } |