summaryrefslogtreecommitdiff
blob: b1c218f554a67d9e32c7b209f83b5688107ae977 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
 * The IniFFS class is responsible for loading messages from .ini
 * files, which are sometimes used for translations.
 * @author Niklas Laxström
 * @copyright Copyright © 2012-2013, Niklas Laxström
 * @license GPL-2.0-or-later
 * @file
 */

class IniFFSTest extends MediaWikiIntegrationTestCase {

	protected $groupConfiguration = [
		'BASIC' => [
			'class' => FileBasedMessageGroup::class,
			'id' => 'test-id',
			'label' => 'Test Label',
			'namespace' => 'NS_MEDIAWIKI',
			'description' => 'Test description',
		],
		'FILES' => [
			'class' => IniFFS::class,
			'sourcePattern' => 'ignored',
		],
	];

	public function testParsing() {
		$file = file_get_contents( __DIR__ . '/../data/IniFFSTest1.ini' );

		/** @var FileBasedMessageGroup $group */
		$group = MessageGroupBase::factory( $this->groupConfiguration );
		$ffs = new IniFFS( $group );

		$this->assertTrue( IniFFS::isValid( $file ) );

		$parsed = $ffs->readFromVariable( $file );
		$expected = [
			'hello' => 'Hello',
			'world' => 'World!',
			'all' => 'all = all',
			'foo.bar' => 'bar',
			'quote' => "We're having fun?",
		];
		$expected = [
			'MESSAGES' => $expected,
			'AUTHORS' => [ 'The king of very small kingdom' ]
		];
		$this->assertEquals( $expected, $parsed );

		$invalidContent = 'Invalid-Ini-Content';
		$this->assertFalse( IniFFS::isValid( $invalidContent ) );
	}

	public function testExport() {
		global $wgSitename;
		$file = file_get_contents( __DIR__ . '/../data/IniFFSTest2.ini' );
		$file = str_replace( '$wgSitename', $wgSitename, $file );

		$collection = new MockMessageCollectionForExport();
		/** @var FileBasedMessageGroup $group */
		$group = MessageGroupBase::factory( $this->groupConfiguration );
		$ffs = new IniFFS( $group );
		$this->assertEquals( $file, $ffs->writeIntoVariable( $collection ) );
	}
}