Debian Codegraph @

tests/phpunit/unit/includes/registration/ExtensionJsonValidatorTest.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright (C) 2018 Kunal Mehta <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21 use MediaWiki\Registration\ExtensionJsonValidationError;
22 use MediaWiki\Registration\ExtensionJsonValidator;
23
24 /**
25 * @covers \MediaWiki\Registration\ExtensionJsonValidator
26 */
27 class ExtensionJsonValidatorTest extends MediaWikiUnitTestCase {
28
29 /**
30 * @dataProvider provideValidate
31 */
32 public function testValidate( $file, $expected ) {
33 // If a dependency is missing, skip this test.
34 $validator = new ExtensionJsonValidator( function ( $msg ) {
35 $this->markTestSkipped( $msg );
36 } );
37
38 if ( is_string( $expected ) ) {
39 $this->expectException( ExtensionJsonValidationError::class );
40 $this->expectExceptionMessage( $expected );
41 }
42
43 $dir = __DIR__ . '/../../../data/registration/';
44 $this->assertSame(
45 $expected,
46 $validator->validate( $dir . $file )
47 );
48 }
49
50 public static function provideValidate() {
51 return [
52 [
53 'notjson.txt',
54 'notjson.txt is not valid JSON'
55 ],
56 [
57 'duplicate_keys.json',
58 'Duplicate key: name'
59 ],
60 [
61 'no_manifest_version.json',
62 'no_manifest_version.json does not have manifest_version set.'
63 ],
64 [
65 'old_manifest_version.json',
66 'old_manifest_version.json is using a non-supported schema version'
67 ],
68 [
69 'newer_manifest_version.json',
70 'newer_manifest_version.json is using a non-supported schema version'
71 ],
72 [
73 'bad_spdx.json',
74 "bad_spdx.json did not pass validation.
75 [license-name] Invalid SPDX license identifier, see <https://spdx.org/licenses/>"
76 ],
77 [
78 'invalid.json',
79 "invalid.json did not pass validation.
80 [license-name] Array value found, but a string is required"
81 ],
82 [
83 'good.json',
84 true
85 ],
86 [
87 'good_with_license_expressions.json',
88 true
89 ],
90 [
91 'bad_url.json', 'bad_url.json did not pass validation.
92 [url] Should use HTTPS for www.mediawiki.org URLs'
93 ],
94 [
95 'bad_url2.json', 'bad_url2.json did not pass validation.
96 [url] Should use www.mediawiki.org domain
97 [url] Should use HTTPS for www.mediawiki.org URLs'
98 ]
99 ];
100 }
101
102 }