summaryrefslogtreecommitdiff
blob: 53944e02796acfc5c0f609bf13aad31ff5de03d9 (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
66
67
68
69
70
71
72
73
74
<?php
/**
 * The AppleInfoPListFfs class is responsible for loading messages from .strings
 * files, which are used in many iOS and Mac OS X projects.
 * These tests check that the message keys are loaded, mangled and unmangled
 * correctly.
 *
 * @file
 */

/** @covers AppleInfoPlistFfs */
class AppleInfoPlistFfsTest extends MediaWikiIntegrationTestCase {

	protected $groupConfigurationInfoPList = [
		'BASIC' => [
			'class' => FileBasedMessageGroup::class,
			'id' => 'test-id',
			'label' => 'Test Label',
			'namespace' => 'NS_MEDIAWIKI',
			'description' => 'Test description',
		],
		'FILES' => [
			'class' => AppleInfoPlistFfs::class,
		],
	];

	/**
	 * @covers AppleInfoPlistFfs::readRow
	 * @dataProvider stringProvider
	 */
	public function testInfoPlistException( $input, $exceptionMessage ) {
		$this->expectException( RuntimeException::class );
		$this->expectExceptionMessage( $exceptionMessage );

		$group = MessageGroupBase::factory( $this->groupConfigurationInfoPList );
		$ffs = new AppleInfoPlistFfs( $group );
		$ffs->readFromVariable( $input );
	}

	/**
	 * @covers AppleInfoPlistFfs::readRow
	 * @covers AppleInfoPlistFfs::writeRow
	 */
	public function testInfoPlistFileRoundtrip() {
		$infile = file_get_contents( __DIR__ . '/../data/AppleInfoPlistFfsTest1.strings' );
		/** @var FileBasedMessageGroup $group */
		$group = MessageGroupBase::factory( $this->groupConfigurationInfoPList );
		$ffs = new AppleInfoPlistFfs( $group );
		$parsed = $ffs->readFromVariable( $infile );

		$outfile = '';
		foreach ( $parsed['MESSAGES'] as $key => $value ) {
			$outfile .= AppleInfoPlistFfs::writeRow( $key, $value );
		}
		$reparsed = $ffs->readFromVariable( $outfile );

		$this->assertSame( $parsed['MESSAGES'], $reparsed['MESSAGES'],
			'Messages survive roundtrip through write and read' );
	}

	public function stringProvider() {
		$input = <<<STRINGS
website = "<nowiki>http://en.wikipedia.org/</nowiki>";
"language" = "English";
STRINGS;
		yield [ $input, 'Empty or invalid key in line: "language" = "English"' ];

		$input = <<<STRINGS
website = "<nowiki>http://en.wikipedia.org/</nowiki>";
language key = "English";
STRINGS;
		yield [ $input, 'Key with space found in line: language key = "English"' ];
	}
}