Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ManageableFeature | |
0.00% |
0 / 29 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
6 | |||
| getLabel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAllPlugins | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| __toPhpCode | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| 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) 2018 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoTests\models\runner\features; |
| 23 | |
| 24 | use oat\taoTests\models\runner\plugins\TestPluginService; |
| 25 | use oat\taoTests\models\runner\plugins\TestPlugin; |
| 26 | |
| 27 | /** |
| 28 | * Class ManageableFeature |
| 29 | * |
| 30 | * NOTE: Feature configuration stored in the config file and changing of it's configuration using interface requires |
| 31 | * synchronization of configs in case of multi server configuration. |
| 32 | * |
| 33 | * @package oat\taoTests\models\runner\features |
| 34 | * @author Aleh Hutnikau, <hutnikau@1pt.com> |
| 35 | */ |
| 36 | class ManageableFeature extends TestRunnerFeature |
| 37 | { |
| 38 | /** @var string */ |
| 39 | protected $label; |
| 40 | /** @var string */ |
| 41 | protected $description; |
| 42 | |
| 43 | public const OPTION_ID = 'identifier'; |
| 44 | public const OPTION_DESCRIPTION = 'description'; |
| 45 | public const OPTION_ACTIVE = 'active'; |
| 46 | public const OPTION_LABEL = 'label'; |
| 47 | public const OPTION_ENABLED_BY_DEFAULT = 'enabledByDefault'; |
| 48 | public const OPTION_PLUGIN_IDS = 'pluginIds'; |
| 49 | |
| 50 | /** |
| 51 | * ManageableFeature constructor. |
| 52 | * @param array $options |
| 53 | * @throws \common_exception_InconsistentData |
| 54 | */ |
| 55 | public function __construct(array $options) |
| 56 | { |
| 57 | $missedOptions = array_diff_key([ |
| 58 | self::OPTION_ID => self::OPTION_ID, |
| 59 | self::OPTION_DESCRIPTION => self::OPTION_DESCRIPTION, |
| 60 | self::OPTION_LABEL => self::OPTION_LABEL, |
| 61 | self::OPTION_ACTIVE => self::OPTION_ACTIVE, |
| 62 | self::OPTION_ENABLED_BY_DEFAULT => self::OPTION_ENABLED_BY_DEFAULT, |
| 63 | self::OPTION_PLUGIN_IDS => self::OPTION_PLUGIN_IDS, |
| 64 | ], $options); |
| 65 | if (!empty($missedOptions)) { |
| 66 | throw new \common_exception_InconsistentData('Required options missed in ' . static::class . ': ' |
| 67 | . implode(',', array_keys($missedOptions))); |
| 68 | } |
| 69 | $this->id = $options[self::OPTION_ID]; |
| 70 | $this->label = $options[self::OPTION_LABEL]; |
| 71 | $this->description = $options[self::OPTION_DESCRIPTION]; |
| 72 | $this->active = $options[self::OPTION_ACTIVE]; |
| 73 | $this->isEnabledByDefault = $options[self::OPTION_ENABLED_BY_DEFAULT]; |
| 74 | $this->pluginsIds = $options[self::OPTION_PLUGIN_IDS]; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @inheritdoc |
| 79 | */ |
| 80 | public function getLabel() |
| 81 | { |
| 82 | return $this->label; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @inheritdoc |
| 87 | */ |
| 88 | public function getDescription() |
| 89 | { |
| 90 | return $this->description; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @return TestPlugin[] |
| 95 | */ |
| 96 | protected function getAllPlugins() |
| 97 | { |
| 98 | $pluginService = $this->getServiceLocator()->get(TestPluginService::SERVICE_ID); |
| 99 | return $pluginService->getAllPlugins(); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @return string |
| 104 | * @throws \common_exception_Error |
| 105 | * |
| 106 | * phpcs:disable Generic.Files.LineLength |
| 107 | */ |
| 108 | public function __toPhpCode() |
| 109 | { |
| 110 | return 'new ' . get_class($this) . '([' . PHP_EOL |
| 111 | . ' \'' . self::OPTION_ID . '\'=>' . \common_Utils::toPHPVariableString($this->getId()) . ',' . PHP_EOL |
| 112 | . ' \'' . self::OPTION_DESCRIPTION . '\'=>__(' . \common_Utils::toPHPVariableString($this->getDescription()) . '),' . PHP_EOL |
| 113 | . ' \'' . self::OPTION_LABEL . '\'=>__(' . \common_Utils::toPHPVariableString($this->getLabel()) . '),' . PHP_EOL |
| 114 | . ' \'' . self::OPTION_ACTIVE . '\'=>' . \common_Utils::toPHPVariableString($this->isActive()) . ',' . PHP_EOL |
| 115 | . ' \'' . self::OPTION_ENABLED_BY_DEFAULT . '\'=>' . \common_Utils::toPHPVariableString($this->isEnabledByDefault()) . ',' . PHP_EOL |
| 116 | . ' \'' . self::OPTION_PLUGIN_IDS . '\'=>' . \common_Utils::toPHPVariableString($this->getPluginsIds()) . ',' . PHP_EOL |
| 117 | . '])'; |
| 118 | } |
| 119 | // phpcs:enable Generic.Files.LineLength |
| 120 | } |