| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Registration\ExtensionJsonValidationError; |
| 22 |
use MediaWiki\Registration\ExtensionJsonValidator; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
class ExtensionJsonValidatorTest extends MediaWikiUnitTestCase { |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function testValidate( $file, $expected ) { |
| 33 |
|
| 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 |
} |