Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2021-01-28 21:58:02 +0300
committerJoas Schilling <coding@schilljs.com>2021-01-29 13:15:15 +0300
commite65fa8d289d277ce9b9591ba68022aad25e67ba9 (patch)
tree469bb9a4213b8d864c84416a97ad01ac1e730269 /tests
parentb699ff66b15fe0d37473481f086ae904ed220570 (diff)
Add unit tests for subname mentions
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/php/Chat/Parser/UserMentionTest.php87
1 files changed, 79 insertions, 8 deletions
diff --git a/tests/php/Chat/Parser/UserMentionTest.php b/tests/php/Chat/Parser/UserMentionTest.php
index a454d48c3..672421c76 100644
--- a/tests/php/Chat/Parser/UserMentionTest.php
+++ b/tests/php/Chat/Parser/UserMentionTest.php
@@ -174,6 +174,80 @@ class UserMentionTest extends \Test\TestCase {
$this->assertEquals($expectedMessageParameters, $chatMessage->getMessageParameters());
}
+ public function dataGetRichMessageWithMentionsFullyIncludedInOtherMentions() {
+ // Based on valid characters from server/lib/private/User/Manager.php
+ return [
+ ['testUser', 'testUser1', false],
+ ['testUser', 'testUser1', true],
+ ['testUser', 'testUser_1', false],
+ ['testUser', 'testUser_1', true],
+ ['testUser', 'testUser.1', false],
+ ['testUser', 'testUser.1', true],
+ ['testUser', 'testUser@1', false],
+ ['testUser', 'testUser@1', true],
+ ['testUser', 'testUser-1', false],
+ ['testUser', 'testUser-1', true],
+ ['testUser', 'testUser\'1', false],
+ ['testUser', 'testUser\'1', true],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetRichMessageWithMentionsFullyIncludedInOtherMentions
+ */
+ public function testGetRichMessageWithMentionsFullyIncludedInOtherMentions(string $baseId, string $longerId, bool $quoted) {
+ $mentions = [
+ ['type' => 'user', 'id' => $baseId],
+ ['type' => 'user', 'id' => $longerId],
+ ];
+ $comment = $this->newComment($mentions);
+
+ $this->commentsManager->expects($this->exactly(2))
+ ->method('resolveDisplayName')
+ ->willReturnCallback(function ($type, $id) {
+ return $id . ' display name';
+ });
+
+ $this->userManager->expects($this->exactly(2))
+ ->method('get')
+ ->withConsecutive(
+ [$longerId],
+ [$baseId]
+ )
+ ->willReturn($this->createMock(IUser::class));
+
+ /** @var Room|MockObject $room */
+ $room = $this->createMock(Room::class);
+ /** @var Participant|MockObject $participant */
+ $participant = $this->createMock(Participant::class);
+ /** @var IL10N|MockObject $l */
+ $l = $this->createMock(IL10N::class);
+ $chatMessage = new Message($room, $participant, $comment, $l);
+ if ($quoted) {
+ $chatMessage->setMessage('Mention to @"' . $baseId . '" and @"' . $longerId . '"', []);
+ } else {
+ $chatMessage->setMessage('Mention to @' . $baseId . ' and @' . $longerId, []);
+ }
+
+ $this->parser->parseMessage($chatMessage);
+
+ $expectedMessageParameters = [
+ 'mention-user1' => [
+ 'type' => 'user',
+ 'id' => $longerId,
+ 'name' => $longerId . ' display name'
+ ],
+ 'mention-user2' => [
+ 'type' => 'user',
+ 'id' => $baseId,
+ 'name' => $baseId . ' display name'
+ ],
+ ];
+
+ $this->assertEquals('Mention to {mention-user2} and {mention-user1}', $chatMessage->getMessage());
+ $this->assertEquals($expectedMessageParameters, $chatMessage->getMessageParameters());
+ }
+
public function testGetRichMessageWithSeveralMentions() {
$mentions = [
['type' => 'user', 'id' => 'testUser1'],
@@ -249,15 +323,12 @@ class UserMentionTest extends \Test\TestCase {
->with('user', 'testUser')
->willReturn('testUser display name');
- $this->userManager->expects($this->at(0))
- ->method('get')
- ->with('me')
- ->willReturn(null);
-
- $this->userManager->expects($this->at(1))
+ $this->userManager->expects($this->exactly(2))
->method('get')
- ->with('testUser')
- ->willReturn($this->createMock(IUser::class));
+ ->willReturnMap([
+ ['me', null],
+ ['testUser', $this->createMock(IUser::class)],
+ ]);
/** @var Room|MockObject $room */
$room = $this->createMock(Room::class);