Add a unit test for guests as well

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-07-11 10:24:27 +02:00
parent 77918356d6
commit 092d34d9df
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with 18 additions and 4 deletions

View File

@ -155,13 +155,21 @@ class CommentTest extends TestCase {
[ [
'Also @"user with spaces" are now supported', ['user with spaces'] 'Also @"user with spaces" are now supported', ['user with spaces']
], ],
[
'Also @"guest/0123456789abcdef" are now supported', [], null, ['guest/0123456789abcdef']
],
]; ];
} }
/** /**
* @dataProvider mentionsProvider * @dataProvider mentionsProvider
*
* @param string $message
* @param array $expectedUids
* @param string|null $author
* @param array $expectedGuests
*/ */
public function testMentions($message, $expectedUids, $author = null) { public function testMentions(string $message, array $expectedUids, ?string $author = null, array $expectedGuests = []): void {
$comment = new Comment(); $comment = new Comment();
$comment->setMessage($message); $comment->setMessage($message);
if(!is_null($author)) { if(!is_null($author)) {
@ -169,9 +177,15 @@ class CommentTest extends TestCase {
} }
$mentions = $comment->getMentions(); $mentions = $comment->getMentions();
while($mention = array_shift($mentions)) { while($mention = array_shift($mentions)) {
$uid = array_shift($expectedUids); if ($mention['type'] === 'user') {
$this->assertSame('user', $mention['type']); $id = array_shift($expectedUids);
$this->assertSame($uid, $mention['id']); } else if ($mention['type'] === 'guest') {
$id = array_shift($expectedGuests);
} else {
$this->fail('Unexpected mention type');
continue;
}
$this->assertSame($id, $mention['id']);
} }
$this->assertEmpty($mentions); $this->assertEmpty($mentions);
$this->assertEmpty($expectedUids); $this->assertEmpty($expectedUids);