- $data = json_decode( file_get_contents( $path ) );
- $this->assertInstanceOf( 'stdClass', $data, "$path is not valid JSON" );
-
- $this->assertObjectHasAttribute( 'manifest_version', $data,
- "$path does not have manifest_version set." );
- $version = $data->manifest_version;
- if ( $version !== ExtensionRegistry::MANIFEST_VERSION ) {
- $schemaPath = __DIR__ . "/../../../docs/extension.schema.v$version.json";
- } else {
- $schemaPath = __DIR__ . '/../../../docs/extension.schema.json';
- }
-
- // Not too old
- $this->assertTrue(
- $version >= ExtensionRegistry::OLDEST_MANIFEST_VERSION,
- "$path is using a non-supported schema version"
- );
- // Not too new
- $this->assertTrue(
- $version <= ExtensionRegistry::MANIFEST_VERSION,
- "$path is using a non-supported schema version"
- );
-
- $licenseError = false;
- if ( class_exists( SpdxLicenses::class ) && isset( $data->{'license-name'} )
- // Check if it's a string, if not, schema validation will display an error
- && is_string( $data->{'license-name'} )
- ) {
- $licenses = new SpdxLicenses();
- $valid = $licenses->validate( $data->{'license-name'} );
- if ( !$valid ) {
- $licenseError = '[license-name] Invalid SPDX license identifier, '
- . 'see <https://spdx.org/licenses/>';
- }
- }
-
- $validator = new Validator;
- $validator->check( $data, (object)[ '$ref' => 'file://' . $schemaPath ] );
- if ( $validator->isValid() && !$licenseError ) {
- // All good.