MediaWiki  1.27.2
ExtensionJsonValidationTest.php
Go to the documentation of this file.
1 <?php
23 class ExtensionJsonValidationTest extends PHPUnit_Framework_TestCase {
24 
25  public function setUp() {
26  parent::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.'
31  );
32  }
33 
34  if ( !ExtensionRegistry::getInstance()->getAllThings() ) {
35  $this->markTestSkipped(
36  'There are no extensions or skins loaded via the ExtensionRegistry'
37  );
38  }
39  }
40 
41  public static function providePassesValidation() {
42  $values = [];
43  foreach ( ExtensionRegistry::getInstance()->getAllThings() as $thing ) {
44  $values[] = [ $thing['path'] ];
45  }
46 
47  return $values;
48  }
49 
54  public function testPassesValidation( $path ) {
55  $data = json_decode( file_get_contents( $path ) );
56  $this->assertInstanceOf( 'stdClass', $data, "$path is not valid JSON" );
57 
58  $this->assertObjectHasAttribute( 'manifest_version', $data,
59  "$path does not have manifest_version set." );
60  $version = $data->manifest_version;
62  $schemaPath = __DIR__ . "/../../../docs/extension.schema.v$version.json";
63  } else {
64  $schemaPath = __DIR__ . '/../../../docs/extension.schema.json';
65  }
66 
67  // Not too old
68  $this->assertTrue(
70  "$path is using a non-supported schema version"
71  );
72  // Not too new
73  $this->assertTrue(
75  "$path is using a non-supported schema version"
76  );
77  $retriever = new JsonSchema\Uri\UriRetriever();
78  $schema = $retriever->retrieve( 'file://' . $schemaPath );
79 
80  $validator = new JsonSchema\Validator();
81  $validator->check( $data, $schema );
82  if ( $validator->isValid() ) {
83  // All good.
84  $this->assertTrue( true );
85  } else {
86  $out = "$path did pass validation.\n";
87  foreach ( $validator->getErrors() as $error ) {
88  $out .= "[{$error['property']}] {$error['message']}\n";
89  }
90  $this->assertTrue( false, $out );
91  }
92  }
93 }
const MANIFEST_VERSION
Version of the highest supported manifest version.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:762
testPassesValidation($path)
providePassesValidation
const OLDEST_MANIFEST_VERSION
Version of the oldest supported manifest version.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$version
Definition: parserTests.php:85
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...