Page MenuHomeWickedGov Phorge

EscapeCharacterValidatorTest.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

EscapeCharacterValidatorTest.php

<?php
declare( strict_types = 1 );
use MediaWiki\Extension\Translate\MessageLoading\FatMessage;
use MediaWiki\Extension\Translate\Validation\Validators\EscapeCharacterValidator;
/**
* @license GPL-2.0-or-later
* @covers \MediaWiki\Extension\Translate\Validation\Validators\EscapeCharacterValidator
*/
class EscapeCharacterValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
public function test( $constructorParams, ...$params ) {
$validator = new EscapeCharacterValidator( $constructorParams );
$this->runValidatorTests( $validator, 'escape', ...$params );
}
public static function provideTestCases() {
$message = new FatMessage( 'key', 'Hello' );
yield [
[ 'values' => [ '\n', '\\\\' ] ],
'Hello',
'Hello\n',
[],
'Correct escape is not an issue'
];
yield [
[ 'values' => [ '\b' ] ],
'Hello',
'Hello\n',
[ 'invalid' ],
'Unsupported escape is an issue'
];
yield [
[ 'values' => [ '\\\\', '\n' ] ],
'Hello',
'Hello\b',
[ 'invalid' ],
'Unsupported escape is an issue'
];
yield [
[ 'values' => [ '\\\\', '\n' ] ],
'Hello',
'Hello\\\\',
[],
'Correct escape is not an issue'
];
}
public function testEmptyValues() {
$this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessageMatches( '/no values provided/i' );
new EscapeCharacterValidator( [
'values' => [],
] );
}
public function testInvalidEscape() {
$this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessageMatches( '/invalid escape character/i' );
new EscapeCharacterValidator( [
'values' => [ '\c' ],
] );
}
}

File Metadata

Mime Type
text/x-php
Expires
Sun, Nov 22, 21:31 (2 d, 2 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
bd/46/436219f8b7cb43c6d7f1088d17ef
Default Alt Text
EscapeCharacterValidatorTest.php (1 KB)

Event Timeline