mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 16:04:35 +00:00
967a0b54e9
Not all tools require these to be absolute, full qualified class names. But some do. This does make the code more compatible with all kinds of tools. Change-Id: Ie7f9d9469b7a48b2fe908d3428fca9ec0120f855
70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group Echo
|
|
*/
|
|
class EchoSummaryParserTest extends MediaWikiTestCase {
|
|
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->assertType( User::class, $user );
|
|
$this->assertEquals( $name, $user->getName() );
|
|
}
|
|
|
|
$users = array_keys( $users );
|
|
|
|
$this->assertArrayEquals( $expectedUsers, $users );
|
|
}
|
|
|
|
public 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]]', [] ],
|
|
];
|
|
}
|
|
}
|