mediawiki-extensions-Echo/tests/phpunit/EchoSummaryParserTest.php
Umherirrender 680e91c75c tests: Make PHPUnit data providers static
Initally used a new sniff with autofix (T333745)

Bug: T332865
Change-Id: I8b6fbfc300d62a10da770c8a1ca61756c7d7bf59
2023-05-20 20:36:33 +02:00

71 lines
1.8 KiB
PHP

<?php
/**
* @group Echo
*/
class EchoSummaryParserTest extends MediaWikiIntegrationTestCase {
/** @var string[] */
private $existingUsers = [
'Werdna',
'Jorm',
'Jim Carter',
];
/**
* @covers \EchoSummaryParser::parse
* @dataProvider provideParse
*
* @param string $summary
* @param string[] $expectedUsers
*/
public function testParse( $summary, array $expectedUsers ) {
$parser = new EchoSummaryParser( function ( User $user ) {
if ( in_array( $user->getName(), $this->existingUsers ) ) {
return crc32( $user->getName() );
}
return 0;
} );
$users = $parser->parse( $summary );
foreach ( $users as $name => $user ) {
$this->assertInstanceof( User::class, $user );
$this->assertEquals( $name, $user->getName() );
}
$users = array_keys( $users );
$this->assertArrayEquals( $expectedUsers, $users );
}
public static function provideParse() {
return [
[ '', [] ],
[ " \t\r\n ", [] ],
[ 'foo bar', [] ],
[ 'Werdna', [] ],
[ 'User:Werdna', [] ],
[ '[User:Werdna]', [] ],
[ '[[]]', [] ],
[ '[[:]]', [] ],
[ '[[|]]', [] ],
[ '[[:|]]', [] ],
[ '[[:|test]]', [] ],
[ '[[User:Nonexistent]]', [] ],
[ '/* [[User:Werdna */', [] ],
[ '[[User talk:Werdna]]', [] ],
[ '[[User:Werdna]]', [ 'Werdna' ] ],
[ 'this is [[ [[User:Werdna]] ]]', [ 'Werdna' ] ],
[ '[[User:Werdna|]]', [ 'Werdna' ] ],
[ '[[User:Werdna| ]]', [ 'Werdna' ] ],
[ '[[User:Werdna|Wer | d[n]a]]', [ 'Werdna' ] ],
[ '[[User:Werdna]][[User:Werdna]][[User:Werdna]]', [ 'Werdna' ] ],
[ '/**/[[User:Werdna]][[user:jorm]]', [ 'Werdna', 'Jorm' ] ],
[ '/* [[User:Werdna]] */ [[ user : jim_ Carter_]]', [ 'Jim Carter' ] ],
[ '[[User:/* Jorm */]][[User:/* remove me */Werdna]]', [] ],
[ '[[:User:Werdna]]', [] ],
[ '[[:User:Werdna|]]', [] ],
[ '[[:User:Werdna|foo]]', [] ],
];
}
}