2018-01-19 21:26:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group Echo
|
|
|
|
*/
|
|
|
|
class EchoSummaryParserTest extends MediaWikiTestCase {
|
|
|
|
private $existingUsers = [
|
|
|
|
'Werdna',
|
|
|
|
'Jorm',
|
|
|
|
'Jim Carter',
|
|
|
|
];
|
2019-07-14 10:57:45 +00:00
|
|
|
|
2018-01-19 21:26:49 +00:00
|
|
|
/**
|
2019-10-23 10:23:09 +00:00
|
|
|
* @covers \EchoSummaryParser::parse
|
2018-01-19 21:26:49 +00:00
|
|
|
* @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 ) {
|
2020-01-14 15:56:49 +00:00
|
|
|
$this->assertInstanceof( User::class, $user );
|
2018-01-19 21:26:49 +00:00
|
|
|
$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]', [] ],
|
2018-03-07 20:50:48 +00:00
|
|
|
[ '[[]]', [] ],
|
|
|
|
[ '[[:]]', [] ],
|
|
|
|
[ '[[|]]', [] ],
|
|
|
|
[ '[[:|]]', [] ],
|
|
|
|
[ '[[:|test]]', [] ],
|
2018-01-19 21:26:49 +00:00
|
|
|
[ '[[User:Nonexistent]]', [] ],
|
|
|
|
[ '/* [[User:Werdna */', [] ],
|
2018-03-08 22:36:58 +00:00
|
|
|
[ '[[User talk:Werdna]]', [] ],
|
2018-01-19 21:26:49 +00:00
|
|
|
[ '[[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]]', [] ],
|
2018-03-07 20:50:48 +00:00
|
|
|
[ '[[:User:Werdna]]', [] ],
|
|
|
|
[ '[[:User:Werdna|]]', [] ],
|
|
|
|
[ '[[:User:Werdna|foo]]', [] ],
|
2018-01-19 21:26:49 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|