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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
<?php
/**
* Tests for MediaWikiExtensionFFS
* @author Niklas Laxström
* @file
* @copyright Copyright © 2012-2013, Niklas Laxström
* @license GPL-2.0+
*/
/**
* @see MediaWikiExtensionFFS
*/
class MediaWikiExtensionFFSTest extends MediaWikiTestCase {
protected $conf = array(
'BASIC' => array(
'class' => 'MediaWikiExtensionMessageGroup',
'id' => 'test-id',
'label' => 'Test Label',
'namespace' => 'NS_MEDIAWIKI',
'description' => 'Test description',
),
'FILES' => array(
'class' => 'MediaWikiExtensionFFS',
),
);
protected function setUp() {
parent::setUp();
$this->setMwGlobals( array(
'wgTranslateDocumentationLanguageCode' => 'qqq',
) );
}
public function testWriteReal() {
if ( !method_exists( 'LanguageNames', 'getNames' ) ) {
$this->markTestSkipped( 'Cldr extension is not installed' );
}
$this->conf['FILES']['sourcePattern'] = __DIR__ . '/../data/Example.i18n.php';
$ffs = MessageGroupBase::factory( $this->conf )->getFFS();
$obj = new ReflectionObject( $ffs );
$method = $obj->getMethod( 'writeReal' );
$method->setAccessible( true );
$collection = new MockMessageCollectionForExport();
$result = $method->invoke( $ffs, $collection );
$expected = file_get_contents( __DIR__ . '/../data/Example-result.i18n.php' );
$this->assertEquals( $expected, $result );
}
public function testGenerateMessageBlock() {
$ffs = MessageGroupBase::factory( $this->conf )->getFFS();
$obj = new ReflectionObject( $ffs );
$method = $obj->getMethod( 'generateMessageBlock' );
$method->setAccessible( true );
$collection = new MockMessageCollectionForExport();
$mangler = StringMatcher::EmptyMatcher();
$result = $method->invoke( $ffs, $collection, $mangler );
$expected = "\n\t'translatedmsg' => 'translation',\n\t'fuzzymsg' => 'translation', # Fuzzy\n";
$this->assertEquals( $expected, $result );
}
/**
* @dataProvider provideQuotableStrings
*/
public function testQuote( $source, $expected ) {
$class = new ReflectionClass( 'MediaWikiExtensionFFS' );
$method = $class->getMethod( 'quote' );
$method->setAccessible( true );
$result = $method->invoke( null, $source );
$this->assertEquals( $expected, $result );
}
public static function provideQuotableStrings() {
return array(
array( 'key', "'key'" ),
array( 'normal $1 variable', "'normal $1 variable'" ),
array( 'abnormal $foo variable', "'abnormal \$foo variable'" ),
array( 'quote " and quote \'', "'quote \" and quote \\''" ),
array( 'quote " and quote \' twice \'', "\"quote \\\" and quote ' twice '\"" ),
);
}
/**
* @dataProvider provideComments
*/
public function testParseAuthorsFromString( $source, $expected ) {
$class = new ReflectionClass( 'MediaWikiExtensionFFS' );
$method = $class->getMethod( 'parseAuthorsFromString' );
$method->setAccessible( true );
$result = $method->invoke( null, $source );
$this->assertEquals( $expected, $result );
}
public static function provideComments() {
$comment =
<<<PHP
/** Message documentation (Message documentation)
* @author Purodha
* @author The Evil IP address
*/
PHP;
return array(
array( $comment, array( 'Purodha', 'The Evil IP address' ) ),
);
}
}
|