You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EmojiServiceTest.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020, Georg Ehrke
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\UserStatus\Tests\Service;
  24. use OCA\UserStatus\Service\EmojiService;
  25. use OCP\IDBConnection;
  26. use Test\TestCase;
  27. class EmojiServiceTest extends TestCase {
  28. /** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */
  29. private $db;
  30. /** @var EmojiService */
  31. private $service;
  32. protected function setUp(): void {
  33. parent::setUp();
  34. $this->db = $this->createMock(IDBConnection::class);
  35. $this->service = new EmojiService($this->db);
  36. }
  37. /**
  38. * @param bool $supports4ByteText
  39. * @param bool $expected
  40. *
  41. * @dataProvider doesPlatformSupportEmojiDataProvider
  42. */
  43. public function testDoesPlatformSupportEmoji(bool $supports4ByteText, bool $expected): void {
  44. $this->db->expects($this->once())
  45. ->method('supports4ByteText')
  46. ->willReturn($supports4ByteText);
  47. $this->assertEquals($expected, $this->service->doesPlatformSupportEmoji());
  48. }
  49. /**
  50. * @return array
  51. */
  52. public function doesPlatformSupportEmojiDataProvider(): array {
  53. return [
  54. [true, true],
  55. [false, false],
  56. ];
  57. }
  58. /**
  59. * @param string $emoji
  60. * @param bool $expected
  61. *
  62. * @dataProvider isValidEmojiDataProvider
  63. */
  64. public function testIsValidEmoji(string $emoji, bool $expected): void {
  65. $actual = $this->service->isValidEmoji($emoji);
  66. $this->assertEquals($expected, $actual);
  67. }
  68. public function isValidEmojiDataProvider(): array {
  69. return [
  70. ['🏝', true],
  71. ['📱', true],
  72. ['🏢', true],
  73. ['📱📠', false],
  74. ['a', false],
  75. ['0', false],
  76. ['$', false],
  77. // Test some more complex emojis with modifiers and zero-width-joiner
  78. ['👩🏿‍💻', true],
  79. ['🤷🏼‍♀️', true],
  80. ['🏳️‍🌈', true],
  81. ['👨‍👨‍👦‍👦', true],
  82. ['👩‍❤️‍👩', true]
  83. ];
  84. }
  85. }