diff options
author | Vitor Mattos <vitor@php.rio> | 2022-01-14 17:14:52 +0300 |
---|---|---|
committer | Vitor Mattos <vitor@php.rio> | 2022-01-21 14:39:39 +0300 |
commit | f7cd9956127be66dfd3141e1f05b6d3cfaceea05 (patch) | |
tree | 27a035e7accd6442c61360093c42dcc704d2defb /tests | |
parent | 1ce894a50c2720a5881b22533d730062b7b4b426 (diff) |
Order the reaction summary, improvements on validations
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Comments/ManagerTest.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php index 2a837a02abf..9e34cce6476 100644 --- a/tests/lib/Comments/ManagerTest.php +++ b/tests/lib/Comments/ManagerTest.php @@ -1139,4 +1139,88 @@ class ManagerTest extends TestCase { ], ]; } + + /** + * @dataProvider providerTestReactionMessageSize + */ + public function testReactionMessageSize($reactionString, $valid) { + if (!$valid) { + $this->expectException(\UnexpectedValueException::class); + } + + $manager = $this->getManager(); + $comment = new Comment(); + $comment->setMessage($reactionString) + ->setVerb('reaction') + ->setActor('users', 'alice') + ->setObject('files', 'file64'); + $status = $manager->save($comment); + $this->assertTrue($status); + } + + public function providerTestReactionMessageSize(): array { + return [ + ['a', true], + ['1', true], + ['12345678', true], + ['123456789', false], + ['👍', true], + ['👍👍', true], + ['👍🏽', true], + ['👍🏽👍', false], + ['👍🏽👍🏽', false], + ]; + } + + /** + * @dataProvider providerTestReactionsSummarizeOrdered + */ + public function testReactionsSummarizeOrdered(array $comments, $expected) { + $this->skipIfNotSupport4ByteUTF(); + $manager = $this->getManager(); + + $buffer = []; + foreach ($comments as $comment) { + [$message, $actorId, $verb, $parentText] = $comment; + $parentId = null; + if ($parentText) { + $parentId = (string) $buffer[$parentText]->getId(); + } + $comment = $this->testSaveNew($message, $actorId, $verb, $parentId); + if (!$parentId) { + $buffer[$comment->getMessage()] = $comment; + } + } + $actual = $manager->get($comment->getParentId()); + $this->assertSame($expected, $actual->getReactions()); + } + + public function providerTestReactionsSummarizeOrdered(): array { + return [ + [ + [ + ['message', 'alice', 'comment', null], + ['👍', 'alice', 'reaction', 'message'], + ], + ['👍' => 1], + ], + [ + [ + ['message', 'alice', 'comment', null], + ['👎', 'John', 'reaction', 'message'], + ['👍', 'Paul', 'reaction', 'message'], + ['👍', 'Peter', 'reaction', 'message'], + ['💜', 'Matthew', 'reaction', 'message'], + ['💜', 'Mark', 'reaction', 'message'], + ['💜', 'Luke', 'reaction', 'message'], + ], + [ + + '💜' => 3, + '👍' => 2, + '👎' => 1, + ], + ], + ]; + } } |