| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use MediaWiki\Json\FormatJson; |
| 6 |
use MediaWiki\Registration\ExtensionRegistry; |
| 7 |
use ValidateRegistrationFile; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class ValidateRegistrationFileTest extends MaintenanceBaseTestCase { |
| 14 |
|
| 15 |
protected function getMaintenanceClass() { |
| 16 |
return ValidateRegistrationFile::class; |
| 17 |
} |
| 18 |
|
| 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; |
| 25 |
} |
| 26 |
|
| 27 |
public function testExecuteForInvalidRegistrationFile() { |
| 28 |
|
| 29 |
$this->maintenance->setArg( 'path', $this->getFileWithContent( |
| 30 |
FormatJson::encode( [ 'manifest_version' => ExtensionRegistry::MANIFEST_VERSION + 1 ] ) |
| 31 |
) ); |
| 32 |
|
| 33 |
$this->expectCallToFatalError(); |
| 34 |
$this->expectOutputRegex( '/non-supported schema version/' ); |
| 35 |
$this->maintenance->execute(); |
| 36 |
} |
| 37 |
|
| 38 |
public function testExecuteForValidRegistrationFile() { |
| 39 |
|
| 40 |
$filename = $this->getFileWithContent( FormatJson::encode( [ |
| 41 |
'manifest_version' => ExtensionRegistry::MANIFEST_VERSION, |
| 42 |
'name' => 'FakeExtension', |
| 43 |
] ) ); |
| 44 |
$this->maintenance->setArg( 'path', $filename ); |
| 45 |
|
| 46 |
$this->expectOutputRegex( |
| 47 |
'/' . preg_quote( $filename, '/' ) . ' validates against the schema/' |
| 48 |
); |
| 49 |
$this->maintenance->execute(); |
| 50 |
} |
| 51 |
} |