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

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-03-24 17:57:17 +0300
committerVitor Mattos <vitor@php.rio>2022-04-28 13:09:44 +0300
commit902476fa20516ac3abe3c79dd10aad1c8b60910e (patch)
tree15f277f69f714ecdba91c62356cbd7e1f96b4dee /tests
parent768da60ae2bc11b415b52624121d70316c1e9de6 (diff)
Extract the EmojiService from user status and add an OCP interface
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Comments/ManagerTest.php2
-rw-r--r--tests/lib/EmojiHelperTest.php98
2 files changed, 99 insertions, 1 deletions
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php
index 961f8dfdd41..6bcd0dec8ed 100644
--- a/tests/lib/Comments/ManagerTest.php
+++ b/tests/lib/Comments/ManagerTest.php
@@ -3,8 +3,8 @@
namespace Test\Comments;
use OC\Comments\Comment;
-use OC\Comments\EmojiHelper;
use OC\Comments\Manager;
+use OC\EmojiHelper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsEventHandler;
diff --git a/tests/lib/EmojiHelperTest.php b/tests/lib/EmojiHelperTest.php
new file mode 100644
index 00000000000..cdcbf358481
--- /dev/null
+++ b/tests/lib/EmojiHelperTest.php
@@ -0,0 +1,98 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020, Georg Ehrke
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace Test;
+
+use OC\EmojiHelper;
+use OCP\IDBConnection;
+use OCP\IEmojiHelper;
+
+class EmojiHelperTest extends TestCase {
+
+ /** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */
+ private $db;
+
+ private IEmojiHelper $helper;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->db = $this->createMock(IDBConnection::class);
+ $this->helper = new EmojiHelper($this->db);
+ }
+
+ /**
+ * @param bool $supports4ByteText
+ * @param bool $expected
+ *
+ * @dataProvider doesPlatformSupportEmojiDataProvider
+ */
+ public function testDoesPlatformSupportEmoji(bool $supports4ByteText, bool $expected): void {
+ $this->db->expects($this->once())
+ ->method('supports4ByteText')
+ ->willReturn($supports4ByteText);
+
+ $this->assertEquals($expected, $this->helper->doesPlatformSupportEmoji());
+ }
+
+ /**
+ * @return array
+ */
+ public function doesPlatformSupportEmojiDataProvider(): array {
+ return [
+ [true, true],
+ [false, false],
+ ];
+ }
+
+ /**
+ * @param string $emoji
+ * @param bool $expected
+ *
+ * @dataProvider isValidSingleEmojiDataProvider
+ */
+ public function testIsValidSingleEmoji(string $emoji, bool $expected): void {
+ $actual = $this->helper->isValidSingleEmoji($emoji);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ public function isValidSingleEmojiDataProvider(): array {
+ return [
+ ['🏝', true],
+ ['📱', true],
+ ['🏢', true],
+ ['📱📠', false],
+ ['a', false],
+ ['0', false],
+ ['$', false],
+ // Test some more complex emojis with modifiers and zero-width-joiner
+ ['👩🏿‍💻', true],
+ ['🤷🏼‍♀️', true],
+ ['🏳️‍🌈', true],
+ ['👨‍👨‍👦‍👦', true],
+ ['👩‍❤️‍👩', true]
+ ];
+ }
+}