3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
20 * Validates all loaded extensions and skins using the ExtensionRegistry
21 * against the extension.json schema in the docs/ folder.
23 class ExtensionJsonValidationTest
extends PHPUnit_Framework_TestCase
{
25 public function setUp() {
27 if ( !class_exists( 'JsonSchema\Uri\UriRetriever' ) ) {
28 $this->markTestSkipped(
29 'The JsonSchema library cannot be found,' .
30 ' please install it through composer to run extension.json validation tests.'
34 if ( !ExtensionRegistry
::getInstance()->getAllThings() ) {
35 $this->markTestSkipped(
36 'There are no extensions or skins loaded via the ExtensionRegistry'
41 public static function providePassesValidation() {
43 foreach ( ExtensionRegistry
::getInstance()->getAllThings() as $thing ) {
44 $values[] = [ $thing['path'] ];
51 * @dataProvider providePassesValidation
52 * @param string $path Path to thing's json file
54 public function testPassesValidation( $path ) {
55 $data = json_decode( file_get_contents( $path ) );
56 $this->assertInstanceOf( 'stdClass', $data, "$path is not valid JSON" );
58 $this->assertObjectHasAttribute( 'manifest_version', $data,
59 "$path does not have manifest_version set." );
60 $version = $data->manifest_version
;
61 if ( $version !== ExtensionRegistry
::MANIFEST_VERSION
) {
62 $schemaPath = __DIR__
. "/../../../docs/extension.schema.v$version.json";
64 $schemaPath = __DIR__
. '/../../../docs/extension.schema.json';
69 $version >= ExtensionRegistry
::OLDEST_MANIFEST_VERSION
,
70 "$path is using a non-supported schema version"
74 $version <= ExtensionRegistry
::MANIFEST_VERSION
,
75 "$path is using a non-supported schema version"
77 $retriever = new JsonSchema\Uri\
UriRetriever();
78 $schema = $retriever->retrieve( 'file://' . $schemaPath );
80 $validator = new JsonSchema\
Validator();
81 $validator->check( $data, $schema );
82 if ( $validator->isValid() ) {
84 $this->assertTrue( true );
86 $out = "$path did pass validation.\n";
87 foreach ( $validator->getErrors() as $error ) {
88 $out .= "[{$error['property']}] {$error['message']}\n";
90 $this->assertTrue( false, $out );