| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use MediaWiki\Json\FormatJson; |
| 6 |
use MediaWiki\Registration\ExtensionRegistry; |
| 7 |
use UpdateExtensionJsonSchema; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class UpdateExtensionJsonSchemaTest extends MaintenanceBaseTestCase { |
| 14 |
|
| 15 |
protected function getMaintenanceClass() { |
| 16 |
return UpdateExtensionJsonSchema::class; |
| 17 |
} |
| 18 |
|
| 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(); |
| 25 |
} |
| 26 |
|
| 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; |
| 33 |
} |
| 34 |
|
| 35 |
public function testExecuteForInvalidJson() { |
| 36 |
$this->maintenance->setArg( 'path', $this->getFileWithContent( '{' ) ); |
| 37 |
$this->expectCallToFatalError(); |
| 38 |
$this->expectOutputRegex( '/Error: Invalid JSON/' ); |
| 39 |
$this->maintenance->execute(); |
| 40 |
} |
| 41 |
|
| 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(); |
| 50 |
} |
| 51 |
} |