aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_status/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-03-24 15:57:17 +0100
committerVitor Mattos <vitor@php.rio>2022-04-28 07:09:44 -0300
commit902476fa20516ac3abe3c79dd10aad1c8b60910e (patch)
tree15f277f69f714ecdba91c62356cbd7e1f96b4dee /apps/user_status/tests
parent768da60ae2bc11b415b52624121d70316c1e9de6 (diff)
downloadnextcloud-server-902476fa20516ac3abe3c79dd10aad1c8b60910e.tar.gz
nextcloud-server-902476fa20516ac3abe3c79dd10aad1c8b60910e.zip
Extract the EmojiService from user status and add an OCP interface
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/user_status/tests')
-rw-r--r--apps/user_status/tests/Unit/CapabilitiesTest.php12
-rw-r--r--apps/user_status/tests/Unit/Service/EmojiServiceTest.php100
-rw-r--r--apps/user_status/tests/Unit/Service/StatusServiceTest.php16
3 files changed, 14 insertions, 114 deletions
diff --git a/apps/user_status/tests/Unit/CapabilitiesTest.php b/apps/user_status/tests/Unit/CapabilitiesTest.php
index af36900d3bc..02874fcbf6d 100644
--- a/apps/user_status/tests/Unit/CapabilitiesTest.php
+++ b/apps/user_status/tests/Unit/CapabilitiesTest.php
@@ -26,13 +26,13 @@ declare(strict_types=1);
namespace OCA\UserStatus\Tests;
use OCA\UserStatus\Capabilities;
-use OCA\UserStatus\Service\EmojiService;
+use OCP\IEmojiHelper;
use Test\TestCase;
class CapabilitiesTest extends TestCase {
- /** @var EmojiService|\PHPUnit\Framework\MockObject\MockObject */
- private $emojiService;
+ /** @var IEmojiHelper|\PHPUnit\Framework\MockObject\MockObject */
+ private $emojiHelper;
/** @var Capabilities */
private $capabilities;
@@ -40,8 +40,8 @@ class CapabilitiesTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->emojiService = $this->createMock(EmojiService::class);
- $this->capabilities = new Capabilities($this->emojiService);
+ $this->emojiHelper = $this->createMock(IEmojiHelper::class);
+ $this->capabilities = new Capabilities($this->emojiHelper);
}
/**
@@ -50,7 +50,7 @@ class CapabilitiesTest extends TestCase {
* @dataProvider getCapabilitiesDataProvider
*/
public function testGetCapabilities(bool $supportsEmojis): void {
- $this->emojiService->expects($this->once())
+ $this->emojiHelper->expects($this->once())
->method('doesPlatformSupportEmoji')
->willReturn($supportsEmojis);
diff --git a/apps/user_status/tests/Unit/Service/EmojiServiceTest.php b/apps/user_status/tests/Unit/Service/EmojiServiceTest.php
deleted file mode 100644
index 454f1d75a0d..00000000000
--- a/apps/user_status/tests/Unit/Service/EmojiServiceTest.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?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 OCA\UserStatus\Tests\Service;
-
-use OCA\UserStatus\Service\EmojiService;
-use OCP\IDBConnection;
-use Test\TestCase;
-
-class EmojiServiceTest extends TestCase {
-
- /** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */
- private $db;
-
- /** @var EmojiService */
- private $service;
-
- protected function setUp(): void {
- parent::setUp();
-
- $this->db = $this->createMock(IDBConnection::class);
- $this->service = new EmojiService($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->service->doesPlatformSupportEmoji());
- }
-
- /**
- * @return array
- */
- public function doesPlatformSupportEmojiDataProvider(): array {
- return [
- [true, true],
- [false, false],
- ];
- }
-
- /**
- * @param string $emoji
- * @param bool $expected
- *
- * @dataProvider isValidEmojiDataProvider
- */
- public function testIsValidEmoji(string $emoji, bool $expected): void {
- $actual = $this->service->isValidEmoji($emoji);
-
- $this->assertEquals($expected, $actual);
- }
-
- public function isValidEmojiDataProvider(): 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]
- ];
- }
-}
diff --git a/apps/user_status/tests/Unit/Service/StatusServiceTest.php b/apps/user_status/tests/Unit/Service/StatusServiceTest.php
index 3dd397e1d36..df31cf0d5ad 100644
--- a/apps/user_status/tests/Unit/Service/StatusServiceTest.php
+++ b/apps/user_status/tests/Unit/Service/StatusServiceTest.php
@@ -35,13 +35,13 @@ use OCA\UserStatus\Exception\InvalidMessageIdException;
use OCA\UserStatus\Exception\InvalidStatusIconException;
use OCA\UserStatus\Exception\InvalidStatusTypeException;
use OCA\UserStatus\Exception\StatusMessageTooLongException;
-use OCA\UserStatus\Service\EmojiService;
use OCA\UserStatus\Service\PredefinedStatusService;
use OCA\UserStatus\Service\StatusService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\Exception;
use OCP\IConfig;
+use OCP\IEmojiHelper;
use OCP\UserStatus\IUserStatus;
use Test\TestCase;
@@ -56,8 +56,8 @@ class StatusServiceTest extends TestCase {
/** @var PredefinedStatusService|\PHPUnit\Framework\MockObject\MockObject */
private $predefinedStatusService;
- /** @var EmojiService|\PHPUnit\Framework\MockObject\MockObject */
- private $emojiService;
+ /** @var IEmojiHelper|\PHPUnit\Framework\MockObject\MockObject */
+ private $emojiHelper;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $config;
@@ -71,7 +71,7 @@ class StatusServiceTest extends TestCase {
$this->mapper = $this->createMock(UserStatusMapper::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->predefinedStatusService = $this->createMock(PredefinedStatusService::class);
- $this->emojiService = $this->createMock(EmojiService::class);
+ $this->emojiHelper = $this->createMock(IEmojiHelper::class);
$this->config = $this->createMock(IConfig::class);
@@ -84,7 +84,7 @@ class StatusServiceTest extends TestCase {
$this->service = new StatusService($this->mapper,
$this->timeFactory,
$this->predefinedStatusService,
- $this->emojiService,
+ $this->emojiHelper,
$this->config);
}
@@ -138,7 +138,7 @@ class StatusServiceTest extends TestCase {
$this->service = new StatusService($this->mapper,
$this->timeFactory,
$this->predefinedStatusService,
- $this->emojiService,
+ $this->emojiHelper,
$this->config);
$this->assertEquals([], $this->service->findAllRecentStatusChanges(20, 50));
@@ -155,7 +155,7 @@ class StatusServiceTest extends TestCase {
$this->service = new StatusService($this->mapper,
$this->timeFactory,
$this->predefinedStatusService,
- $this->emojiService,
+ $this->emojiHelper,
$this->config);
$this->assertEquals([], $this->service->findAllRecentStatusChanges(20, 50));
@@ -519,7 +519,7 @@ class StatusServiceTest extends TestCase {
->willThrowException(new DoesNotExistException(''));
}
- $this->emojiService->method('isValidEmoji')
+ $this->emojiHelper->method('isValidSingleEmoji')
->with($statusIcon)
->willReturn($supportsEmoji);