| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Unit\Settings\Source\Format; |
| 4 |
|
| 5 |
use MediaWiki\Settings\Source\Format\JsonFormat; |
| 6 |
use PHPUnit\Framework\TestCase; |
| 7 |
use UnexpectedValueException; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class JsonFormatTest extends TestCase { |
| 13 |
public function testDecode() { |
| 14 |
$format = new JsonFormat(); |
| 15 |
|
| 16 |
$this->assertSame( |
| 17 |
[ 'config' => [ 'MySetting' => 'BlaBla' ] ], |
| 18 |
$format->decode( '{ "config": { "MySetting": "BlaBla" } }' ) |
| 19 |
); |
| 20 |
} |
| 21 |
|
| 22 |
public function testDecodeBadJSON() { |
| 23 |
$format = new JsonFormat(); |
| 24 |
$this->expectException( UnexpectedValueException::class ); |
| 25 |
|
| 26 |
$format->decode( '{ bad }' ); |
| 27 |
} |
| 28 |
|
| 29 |
public static function provideSupportsFileExtension() { |
| 30 |
yield 'Supported' => [ 'json', true ]; |
| 31 |
yield 'Supported, uppercase' => [ 'JSON', true ]; |
| 32 |
yield 'Unsupported' => [ 'txt', false ]; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public function testSupportsFileExtension( $extension, $expected ) { |
| 39 |
$this->assertSame( $expected, JsonFormat::supportsFileExtension( $extension ) ); |
| 40 |
} |
| 41 |
} |