| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Unit\Settings\Source; |
| 4 |
|
| 5 |
use MediaWiki\Settings\SettingsBuilderException; |
| 6 |
use MediaWiki\Settings\Source\FileSource; |
| 7 |
use MediaWiki\Settings\Source\Format\JsonFormat; |
| 8 |
use PHPUnit\Framework\TestCase; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class FileSourceTest extends TestCase { |
| 14 |
public function testAllowsStaleLoad() { |
| 15 |
$source = new FileSource( __DIR__ . 'foo.json' ); |
| 16 |
$this->assertFalse( $source->allowsStaleLoad() ); |
| 17 |
} |
| 18 |
|
| 19 |
public function testLoad() { |
| 20 |
$source = new FileSource( __DIR__ . '/fixtures/settings.json' ); |
| 21 |
|
| 22 |
$this->assertSame( |
| 23 |
[ 'config' => [ 'MySetting' => 'BlaBla' ] ], |
| 24 |
$source->load() |
| 25 |
); |
| 26 |
} |
| 27 |
|
| 28 |
public function testLoadFormat() { |
| 29 |
$source = new FileSource( __DIR__ . '/fixtures/settings.json', new JsonFormat() ); |
| 30 |
|
| 31 |
$this->assertSame( |
| 32 |
[ 'config' => [ 'MySetting' => 'BlaBla' ] ], |
| 33 |
$source->load() |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
public function testLoadBadFormat() { |
| 38 |
$source = new FileSource( __DIR__ . '/fixtures/bad.txt', new JsonFormat() ); |
| 39 |
|
| 40 |
$this->expectException( SettingsBuilderException::class ); |
| 41 |
|
| 42 |
$settings = $source->load(); |
| 43 |
} |
| 44 |
|
| 45 |
public function testLoadDirectory() { |
| 46 |
$source = new FileSource( __DIR__ . '/fixtures/dir.json' ); |
| 47 |
|
| 48 |
$this->expectException( SettingsBuilderException::class ); |
| 49 |
|
| 50 |
$settings = $source->load(); |
| 51 |
} |
| 52 |
|
| 53 |
public function testLoadNoSuitableFormats() { |
| 54 |
$source = new FileSource( __DIR__ . '/fixtures/settings.toml', new JsonFormat() ); |
| 55 |
|
| 56 |
$this->expectException( SettingsBuilderException::class ); |
| 57 |
|
| 58 |
$settings = $source->load(); |
| 59 |
} |
| 60 |
|
| 61 |
public function testGetHashKey() { |
| 62 |
$source = new FileSource( __DIR__ . '/fixtures/settings.json' ); |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
$this->assertNotEmpty( $source->getHashKey() ); |
| 67 |
} |
| 68 |
} |