3 namespace MediaWiki\Tests\Maintenance
;
5 use MediaWiki\Json\FormatJson
;
6 use MediaWiki\Registration\ExtensionRegistry
;
7 use ValidateRegistrationFile
;
10 * @covers \ValidateRegistrationFile
13 class ValidateRegistrationFileTest
extends MaintenanceBaseTestCase
{
15 protected function getMaintenanceClass() {
16 return ValidateRegistrationFile
::class;
19 private function getFileWithContent( string $content ): string {
20 $testFilename = $this->getNewTempFile();
21 $testFile = fopen( $testFilename, 'w' );
22 fwrite( $testFile, $content );
27 public function testExecuteForInvalidRegistrationFile() {
28 // Get a fake extension.json with an invalid manifest version.
29 $this->maintenance
->setArg( 'path', $this->getFileWithContent(
30 FormatJson
::encode( [ 'manifest_version' => ExtensionRegistry
::MANIFEST_VERSION +
1 ] )
32 // Expect a fatal error with an error about the invalid manifest version
33 $this->expectCallToFatalError();
34 $this->expectOutputRegex( '/non-supported schema version/' );
35 $this->maintenance
->execute();
38 public function testExecuteForValidRegistrationFile() {
39 // Get a fake extension.json which is valid
40 $filename = $this->getFileWithContent( FormatJson
::encode( [
41 'manifest_version' => ExtensionRegistry
::MANIFEST_VERSION
,
42 'name' => 'FakeExtension',
44 $this->maintenance
->setArg( 'path', $filename );
45 // Expect a fatal error with an error about the invalid manifest version
46 $this->expectOutputRegex(
47 '/' . preg_quote( $filename, '/' ) . ' validates against the schema/'
49 $this->maintenance
->execute();