summaryrefslogtreecommitdiff
blob: 961a335ff4ef20739e8725201bb51b0cbb725bcf (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
<?php
/**
 * @file
 * @author Niklas Laxström
 * @license GPL-2.0-or-later
 */

class XliffFFSTest extends MediaWikiIntegrationTestCase {
	protected $groupConfiguration = [
		'BASIC' => [
			'class' => FileBasedMessageGroup::class,
			'id' => 'test-id',
			'label' => 'Test Label',
			'namespace' => 'NS_MEDIAWIKI',
			'description' => 'Test description',
		],
		'FILES' => [
			'class' => XliffFFS::class,
			'sourcePattern' => '',
		],
	];

	public function testParsing() {
		/** @var FileBasedMessageGroup $group */
		$group = MessageGroupBase::factory( $this->groupConfiguration );
		$ffs = new XliffFFS( $group );

		$file = file_get_contents( __DIR__ . '/../data/minimal.xlf' );
		$parsed = $ffs->readFromVariable( $file, 'target' );
		$expected = [
			'1' => 'Hei maailma',
			'2' => TRANSLATE_FUZZY . 'Fuzzy translation',
			'3' => 'Tämä on <g id="1" ctype="bold">paksu</g>.',
		];
		$expected = [ 'MESSAGES' => $expected ];
		$this->assertEquals( $expected, $parsed );

		$parsed = $ffs->readFromVariable( $file, 'source' );
		$expected = [
			'1' => 'Hello world',
			'2' => 'Fuzzy message',
			'3' => 'This is <g id="1" ctype="bold">bold</g>.',
		];
		$expected = [ 'MESSAGES' => $expected ];
		$this->assertEquals( $expected, $parsed );
	}
}