Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / UpdateExtensionJsonSchemaTest.php
blob544da7e60bec91180d57e0dc43b92600d6d8d952
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use MediaWiki\Json\FormatJson;
6 use MediaWiki\Registration\ExtensionRegistry;
7 use UpdateExtensionJsonSchema;
9 /**
10 * @covers \ValidateRegistrationFile
11 * @author Dreamy Jazz
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 );
31 fclose( $testFile );
32 return $testFilename;
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',
46 ] ) );
47 $this->maintenance->setArg( 'path', $filename );
48 $this->expectOutputString( 'Already at the latest version: ' . ExtensionRegistry::MANIFEST_VERSION . "\n" );
49 $this->maintenance->execute();