3 namespace MediaWiki\Tests\Maintenance
;
5 use MediaWiki\Json\FormatJson
;
6 use MediaWiki\Registration\ExtensionRegistry
;
7 use UpdateExtensionJsonSchema
;
10 * @covers \ValidateRegistrationFile
13 class UpdateExtensionJsonSchemaTest
extends MaintenanceBaseTestCase
{
15 protected function getMaintenanceClass() {
16 return UpdateExtensionJsonSchema
::class;
19 public function testExecuteForNonExistingFilename() {
20 $filename = __DIR__
. '/NonExistentPathForTest/abcdef.json';
21 $this->maintenance
->setArg( 'path', $filename );
22 $this->expectCallToFatalError();
23 $this->expectOutputRegex( '/Error: Unable to read ' . preg_quote( $filename, '/' ) . '/' );
24 $this->maintenance
->execute();
27 private function getFileWithContent( string $content ): string {
28 $testFilename = $this->getNewTempFile();
29 $testFile = fopen( $testFilename, 'w' );
30 fwrite( $testFile, $content );
35 public function testExecuteForInvalidJson() {
36 $this->maintenance
->setArg( 'path', $this->getFileWithContent( '{' ) );
37 $this->expectCallToFatalError();
38 $this->expectOutputRegex( '/Error: Invalid JSON/' );
39 $this->maintenance
->execute();
42 public function testExecuteForLatestManifestVersion() {
43 $filename = $this->getFileWithContent( FormatJson
::encode( [
44 'manifest_version' => ExtensionRegistry
::MANIFEST_VERSION
,
45 'name' => 'FakeExtension',
47 $this->maintenance
->setArg( 'path', $filename );
48 $this->expectOutputString( 'Already at the latest version: ' . ExtensionRegistry
::MANIFEST_VERSION
. "\n" );
49 $this->maintenance
->execute();