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.

PredefinedStatusServiceTest.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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\PredefinedStatusService;
  25. use OCP\IL10N;
  26. use Test\TestCase;
  27. class PredefinedStatusServiceTest extends TestCase {
  28. /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
  29. protected $l10n;
  30. /** @var PredefinedStatusService */
  31. protected $service;
  32. protected function setUp(): void {
  33. parent::setUp();
  34. $this->l10n = $this->createMock(IL10N::class);
  35. $this->service = new PredefinedStatusService($this->l10n);
  36. }
  37. public function testGetDefaultStatuses(): void {
  38. $this->l10n->expects($this->exactly(5))
  39. ->method('t')
  40. ->withConsecutive(
  41. ['In a meeting'],
  42. ['Commuting'],
  43. ['Working remotely'],
  44. ['Out sick'],
  45. ['Vacationing']
  46. )
  47. ->willReturnArgument(0);
  48. $actual = $this->service->getDefaultStatuses();
  49. $this->assertEquals([
  50. [
  51. 'id' => 'meeting',
  52. 'icon' => '📅',
  53. 'message' => 'In a meeting',
  54. 'clearAt' => [
  55. 'type' => 'period',
  56. 'time' => 3600,
  57. ],
  58. ],
  59. [
  60. 'id' => 'commuting',
  61. 'icon' => '🚌',
  62. 'message' => 'Commuting',
  63. 'clearAt' => [
  64. 'type' => 'period',
  65. 'time' => 1800,
  66. ],
  67. ],
  68. [
  69. 'id' => 'remote-work',
  70. 'icon' => '🏡',
  71. 'message' => 'Working remotely',
  72. 'clearAt' => [
  73. 'type' => 'end-of',
  74. 'time' => 'day',
  75. ],
  76. ],
  77. [
  78. 'id' => 'sick-leave',
  79. 'icon' => '🤒',
  80. 'message' => 'Out sick',
  81. 'clearAt' => [
  82. 'type' => 'end-of',
  83. 'time' => 'day',
  84. ],
  85. ],
  86. [
  87. 'id' => 'vacationing',
  88. 'icon' => '🌴',
  89. 'message' => 'Vacationing',
  90. 'clearAt' => null,
  91. ],
  92. ], $actual);
  93. }
  94. /**
  95. * @param string $id
  96. * @param string|null $expectedIcon
  97. *
  98. * @dataProvider getIconForIdDataProvider
  99. */
  100. public function testGetIconForId(string $id, ?string $expectedIcon): void {
  101. $actual = $this->service->getIconForId($id);
  102. $this->assertEquals($expectedIcon, $actual);
  103. }
  104. /**
  105. * @return array
  106. */
  107. public function getIconForIdDataProvider(): array {
  108. return [
  109. ['meeting', '📅'],
  110. ['commuting', '🚌'],
  111. ['sick-leave', '🤒'],
  112. ['vacationing', '🌴'],
  113. ['remote-work', '🏡'],
  114. ['unknown-id', null],
  115. ];
  116. }
  117. /**
  118. * @param string $id
  119. * @param string|null $expected
  120. *
  121. * @dataProvider getTranslatedStatusForIdDataProvider
  122. */
  123. public function testGetTranslatedStatusForId(string $id, ?string $expected): void {
  124. $this->l10n->method('t')
  125. ->willReturnArgument(0);
  126. $actual = $this->service->getTranslatedStatusForId($id);
  127. $this->assertEquals($expected, $actual);
  128. }
  129. /**
  130. * @return array
  131. */
  132. public function getTranslatedStatusForIdDataProvider(): array {
  133. return [
  134. ['meeting', 'In a meeting'],
  135. ['commuting', 'Commuting'],
  136. ['sick-leave', 'Out sick'],
  137. ['vacationing', 'Vacationing'],
  138. ['remote-work', 'Working remotely'],
  139. ['unknown-id', null],
  140. ];
  141. }
  142. /**
  143. * @param string $id
  144. * @param bool $expected
  145. *
  146. * @dataProvider isValidIdDataProvider
  147. */
  148. public function testIsValidId(string $id, bool $expected): void {
  149. $actual = $this->service->isValidId($id);
  150. $this->assertEquals($expected, $actual);
  151. }
  152. /**
  153. * @return array
  154. */
  155. public function isValidIdDataProvider(): array {
  156. return [
  157. ['meeting', true],
  158. ['commuting', true],
  159. ['sick-leave', true],
  160. ['vacationing', true],
  161. ['remote-work', true],
  162. ['unknown-id', false],
  163. ];
  164. }
  165. }