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
|
<?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]]', [] ],
];
}
}
|