summaryrefslogtreecommitdiff
blob: 5303fef237519f1145023078c7b131ab948f0bde (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
75
<?php
declare( strict_types = 1 );

use MediaWiki\Extension\Translate\Validation\Validators\SmartFormatPluralValidator;

/**
 * @license GPL-2.0-or-later
 * @covers \MediaWiki\Extension\Translate\Validation\Validators\SmartFormatPluralValidator
 */
class SmartFormatPluralValidatorTest extends BaseValidatorTestCase {
	/** @dataProvider provideTestCases */
	public function test( ...$params ) {
		$this->runValidatorTests( new SmartFormatPluralValidator(), 'plural', ...$params );
	}

	public function provideTestCases() {
		yield [
			'{0:message|messages}',
			'{1:test|tests}{0:message|messages}',
			[ 'unsupported' ],
			'Using plural on an unsupported parameter is an issue'
		];

		yield [
			'{0:message|messages}',
			'translation',
			[ 'missing' ],
			'Missing plural on an unsupported parameter is an issue'
		];

		yield [
			'{0:message|messages}',
			'{0:message|messages|messages}',
			[ 'forms' ],
			'Extra plural form is an issue'
		];

		yield [
			'{0:message|messages}',
			'{0:message|messages}',
			[],
			'Correct plural forms are not an issue'
		];
	}

	/** @dataProvider provideInsertable */
	public function testInsertable( $text, $displayText, $preText = '', $postText = '' ) {
		$validator = new SmartFormatPluralValidator();

		$insertables = $validator->getInsertables( $text );

		if ( $displayText === null ) {
			$this->assertSame( [], $insertables );
		} else {
			$this->assertCount( 1, $insertables );
			$this->assertSame( $insertables[0]->getPreText(), $preText );
			$this->assertSame( $insertables[0]->getPostText(), $postText );
			$this->assertSame( $insertables[0]->getDisplayText(), $displayText );
		}
	}

	public static function provideInsertable() {
		yield [
			'{0:message|messages}',
			'{0:|}',
			'{0:',
			'|}'
		];

		yield [
			'contains no pluralization',
			null
		];
	}
}