Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
12 / 16
50.00% covered (danger)
50.00%
3 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
ValidationService
75.00% covered (warning)
75.00%
12 / 16
50.00% covered (danger)
50.00%
3 / 6
12.89
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
5
 getContentValidationSchema
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getManifestValidationSchema
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getSchemas
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 getContentValidation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getManifestValidation
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
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) 2015-2024 (original work) Open Assessment Technologies SA;
19 */
20
21namespace oat\taoQtiItem\model;
22
23use oat\oatbox\service\ConfigurableService;
24
25class ValidationService extends ConfigurableService
26{
27    public const SERVICE_ID = 'taoQtiItem/validation';
28
29    private $contentValidation = [
30        'http://www.imsglobal.org/xsd/imsqti_v2p0' => [
31            '/qti/data/qtiv2p0/imsqti_v2p0.xsd'
32        ],
33        'http://www.imsglobal.org/xsd/apip/apipv1p0/qtiitem/imsqti_v2p1' => [
34            '/qti/data/apipv1p0/Core_Level/Package/apipv1p0_qtiitemv2p1_v1p0.xsd'
35        ],
36        'http://www.imsglobal.org/xsd/apip/apipv1p0/qtiitem/imsqti_v2p2' => [
37            '/qti/data/apipv1p0final/Core_Level/Package/apipv1p0_qtiitemv2p2_v1p0.xsd'
38        ],
39        'http://www.imsglobal.org/xsd/imsqti_v2p2' => [
40            '/qti/data/qtiv2p2p4/imsqti_v2p2p4.xsd',
41            '/qti/data/apipv1p0final/Core_Level/Package/apipv1p0_qtiitemv2p2_v1p0.xsd',
42            '/qti/data/w3/mathml3/mathml3-presentation.xsd'
43        ],
44        'http://www.imsglobal.org/xsd/imsqtiasi_v3p0' => [
45            '/qti/data/qtiv3p0/imsqti_asiv3p0_v1p0.xsd'
46        ],
47        'http://www.imsglobal.org/xsd/qti/qtiv3p0/imscp_v1p1' => [
48            '/qti/data/qtiv3p0/imsqtiv3p0_imscpv1p2_v1p0.xsd'
49        ],
50        'http://www.imsglobal.org/xsd/imscp_v1p1' => [
51            '/qti/data/imscp_v1p1.xsd'
52        ],
53        'default' => [
54            '/qti/data/qtiv2p1p1/imsqti_v2p1p1.xsd'
55        ]
56    ];
57
58    private $manifestValidation = [
59        'http://www.imsglobal.org/xsd/qti/qtiv3p0/imscp_v1p1' => [
60            '/qti/data/imscp_v1p1.xsd',
61            '/qti/data/qtiv3p0/imsqtiv3p0_imscpv1p2_v1p0.xsd'
62        ],
63        'default' => [
64            '/qti/data/imscp_v1p1.xsd',
65            '/qti/data/qtiv2p2/qtiv2p2_imscpv1p2_v1p0.xsd',
66            '/qti/data/apipv1p0/Core_Level/Package/apipv1p0_imscpv1p2_v1p0.xsd',
67            '/qti/data/apipv1p0final/Core_Level/Package/apipv1p0_imscpv1p2_v1p0.xsd',
68            '/qti/data/qtiv3p0/imsqtiv3p0_imscpv1p2_v1p0.xsd'
69        ],
70        'http://www.imsglobal.org/xsd/imscp_v1p1' => [
71            '/qti/data/imscp_v1p1.xsd'
72        ],
73    ];
74
75    public function __construct(array $options = [])
76    {
77        parent::__construct($options);
78        foreach ($this->contentValidation as $key => &$array) {
79            foreach ($array as &$value) {
80                $value = __DIR__ . $value;
81            }
82        }
83        foreach ($this->manifestValidation as $key => &$array) {
84            foreach ($array as &$value) {
85                $value = __DIR__ . $value;
86            }
87        }
88    }
89
90    /**
91     * @param string $key the namespace of content to validate
92     * @return array of schema for content validation
93     */
94    public function getContentValidationSchema($key)
95    {
96        $validationArray = $this->getContentValidation();
97
98        return $this->getSchemas($validationArray, $key);
99    }
100
101    /**
102     * @param string $key the namespace of manifest to validate
103     * @return array of schema for manifest validation
104     */
105    public function getManifestValidationSchema($key)
106    {
107        $validationArray = $this->getManifestValidation();
108
109        return $this->getSchemas($validationArray, $key);
110    }
111
112    /**
113     * @param array $validationArray list of xsds for namespaces
114     * @param string $key the namespace
115     * @return array schemas for validation
116     */
117    protected function getSchemas($validationArray, $key)
118    {
119        if (isset($validationArray[$key])) {
120            return $validationArray[$key];
121        }
122
123        return $validationArray['default'];
124    }
125
126    /**
127     * @return array
128     */
129    protected function getContentValidation()
130    {
131        return $this->contentValidation;
132    }
133
134    /**
135     * @return array
136     */
137    protected function getManifestValidation()
138    {
139        return $this->manifestValidation;
140    }
141}