Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / ValidateRegistrationFileTest.php
blobafaec891c13e71283755c85fad3eb9012ea0213d
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use MediaWiki\Json\FormatJson;
6 use MediaWiki\Registration\ExtensionRegistry;
7 use ValidateRegistrationFile;
9 /**
10 * @covers \ValidateRegistrationFile
11 * @author Dreamy Jazz
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 );
23 fclose( $testFile );
24 return $testFilename;
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 ] )
31 ) );
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',
43 ] ) );
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();