Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.86% |
13 / 14 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| PortableElementModelValidator | |
92.86% |
13 / 14 |
|
66.67% |
2 / 3 |
4.01 | |
0.00% |
0 / 1 |
| getConstraints | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| getAssetConstraints | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| isOptionalConstraint | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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) 2016 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiItem\model\portableElement\validator; |
| 23 | |
| 24 | abstract class PortableElementModelValidator extends PortableElementAssetValidator |
| 25 | { |
| 26 | protected $assetConstraints = [ |
| 27 | 'runtime' => [ |
| 28 | 'hook', |
| 29 | 'libraries', |
| 30 | 'stylesheets', |
| 31 | 'mediaFiles', |
| 32 | 'src' |
| 33 | ], |
| 34 | 'creator' => [ |
| 35 | 'icon', |
| 36 | 'hook', |
| 37 | 'libraries', |
| 38 | 'stylesheets', |
| 39 | 'mediaFiles', |
| 40 | 'src' |
| 41 | ] |
| 42 | ]; |
| 43 | |
| 44 | protected $optional = [ |
| 45 | 'runtime' => [ |
| 46 | 'libraries', |
| 47 | 'stylesheets', |
| 48 | 'mediaFiles', |
| 49 | 'modules', |
| 50 | 'config', |
| 51 | 'src' |
| 52 | ], |
| 53 | 'creator' => [ |
| 54 | 'libraries', |
| 55 | 'stylesheets', |
| 56 | 'mediaFiles', |
| 57 | 'src' |
| 58 | ] |
| 59 | ]; |
| 60 | |
| 61 | public function getConstraints() |
| 62 | { |
| 63 | return [ |
| 64 | 'typeIdentifier' => [Validator::isTypeIdentifier, Validator::NotEmpty], |
| 65 | 'short' => [Validator::isString, Validator::NotEmpty], |
| 66 | 'description' => [Validator::isString, Validator::NotEmpty], |
| 67 | 'version' => [Validator::isVersion, Validator::isSemVer], |
| 68 | 'author' => [Validator::isString, Validator::NotEmpty], |
| 69 | 'email' => [Validator::Email, Validator::NotEmpty], |
| 70 | 'tags' => [Validator::isArray], |
| 71 | 'runtime' => [Validator::NotEmpty, Validator::isArray], |
| 72 | ]; |
| 73 | } |
| 74 | |
| 75 | public function getAssetConstraints($key) |
| 76 | { |
| 77 | if (!isset($this->assetConstraints[$key])) { |
| 78 | return []; |
| 79 | } |
| 80 | return $this->assetConstraints[$key]; |
| 81 | } |
| 82 | |
| 83 | public function isOptionalConstraint($key, $constraint) |
| 84 | { |
| 85 | return in_array($constraint, $this->optional[$key]); |
| 86 | } |
| 87 | } |