MediaWiki  1.28.1
ExtensionJsonValidationTest.php
Go to the documentation of this file.
1 <?php
21 
26 class ExtensionJsonValidationTest extends PHPUnit_Framework_TestCase {
27 
28  public function setUp() {
29  parent::setUp();
30  if ( !class_exists( Validator::class ) ) {
31  $this->markTestSkipped(
32  'The JsonSchema library cannot be found,' .
33  ' please install it through composer to run extension.json validation tests.'
34  );
35  }
36 
37  if ( !ExtensionRegistry::getInstance()->getAllThings() ) {
38  $this->markTestSkipped(
39  'There are no extensions or skins loaded via the ExtensionRegistry'
40  );
41  }
42  }
43 
44  public static function providePassesValidation() {
45  $values = [];
46  foreach ( ExtensionRegistry::getInstance()->getAllThings() as $thing ) {
47  $values[] = [ $thing['path'] ];
48  }
49 
50  return $values;
51  }
52 
57  public function testPassesValidation( $path ) {
58  $data = json_decode( file_get_contents( $path ) );
59  $this->assertInstanceOf( 'stdClass', $data, "$path is not valid JSON" );
60 
61  $this->assertObjectHasAttribute( 'manifest_version', $data,
62  "$path does not have manifest_version set." );
63  $version = $data->manifest_version;
64  if ( $version !== ExtensionRegistry::MANIFEST_VERSION ) {
65  $schemaPath = __DIR__ . "/../../../docs/extension.schema.v$version.json";
66  } else {
67  $schemaPath = __DIR__ . '/../../../docs/extension.schema.json';
68  }
69 
70  // Not too old
71  $this->assertTrue(
73  "$path is using a non-supported schema version"
74  );
75  // Not too new
76  $this->assertTrue(
78  "$path is using a non-supported schema version"
79  );
80 
81  $licenseError = false;
82  if ( class_exists( SpdxLicenses::class ) && isset( $data->{'license-name'} )
83  // Check if it's a string, if not, schema validation will display an error
84  && is_string( $data->{'license-name'} )
85  ) {
86  $licenses = new SpdxLicenses();
87  $valid = $licenses->validate( $data->{'license-name'} );
88  if ( !$valid ) {
89  $licenseError = '[license-name] Invalid SPDX license identifier, '
90  . 'see <https://spdx.org/licenses/>';
91  }
92  }
93 
94  $validator = new Validator;
95  $validator->check( $data, (object) [ '$ref' => 'file://' . $schemaPath ] );
96  if ( $validator->isValid() && !$licenseError ) {
97  // All good.
98  $this->assertTrue( true );
99  } else {
100  $out = "$path did pass validation.\n";
101  foreach ( $validator->getErrors() as $error ) {
102  $out .= "[{$error['property']}] {$error['message']}\n";
103  }
104  if ( $licenseError ) {
105  $out .= "$licenseError\n";
106  }
107  $this->assertTrue( false, $out );
108  }
109  }
110 }
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:802
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
Validates all loaded extensions and skins using the ExtensionRegistry against the extension...