PredefinedStatusServiceTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\UserStatus\Tests\Service;
  8. use OCA\UserStatus\Service\PredefinedStatusService;
  9. use OCP\IL10N;
  10. use Test\TestCase;
  11. class PredefinedStatusServiceTest extends TestCase {
  12. /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
  13. protected $l10n;
  14. /** @var PredefinedStatusService */
  15. protected $service;
  16. protected function setUp(): void {
  17. parent::setUp();
  18. $this->l10n = $this->createMock(IL10N::class);
  19. $this->service = new PredefinedStatusService($this->l10n);
  20. }
  21. public function testGetDefaultStatuses(): void {
  22. $this->l10n->expects($this->exactly(7))
  23. ->method('t')
  24. ->withConsecutive(
  25. ['In a meeting'],
  26. ['Commuting'],
  27. ['Working remotely'],
  28. ['Out sick'],
  29. ['Vacationing'],
  30. ['In a call'],
  31. )
  32. ->willReturnArgument(0);
  33. $actual = $this->service->getDefaultStatuses();
  34. $this->assertEquals([
  35. [
  36. 'id' => 'meeting',
  37. 'icon' => '📅',
  38. 'message' => 'In a meeting',
  39. 'clearAt' => [
  40. 'type' => 'period',
  41. 'time' => 3600,
  42. ],
  43. ],
  44. [
  45. 'id' => 'commuting',
  46. 'icon' => '🚌',
  47. 'message' => 'Commuting',
  48. 'clearAt' => [
  49. 'type' => 'period',
  50. 'time' => 1800,
  51. ],
  52. ],
  53. [
  54. 'id' => 'remote-work',
  55. 'icon' => '🏡',
  56. 'message' => 'Working remotely',
  57. 'clearAt' => [
  58. 'type' => 'end-of',
  59. 'time' => 'day',
  60. ],
  61. ],
  62. [
  63. 'id' => 'sick-leave',
  64. 'icon' => '🤒',
  65. 'message' => 'Out sick',
  66. 'clearAt' => [
  67. 'type' => 'end-of',
  68. 'time' => 'day',
  69. ],
  70. ],
  71. [
  72. 'id' => 'vacationing',
  73. 'icon' => '🌴',
  74. 'message' => 'Vacationing',
  75. 'clearAt' => null,
  76. ],
  77. [
  78. 'id' => 'call',
  79. 'icon' => '💬',
  80. 'message' => 'In a call',
  81. 'clearAt' => null,
  82. 'visible' => false,
  83. ],
  84. [
  85. 'id' => 'out-of-office',
  86. 'icon' => '🛑',
  87. 'message' => 'Out of office',
  88. 'clearAt' => null,
  89. 'visible' => false,
  90. ],
  91. ], $actual);
  92. }
  93. /**
  94. * @param string $id
  95. * @param string|null $expectedIcon
  96. *
  97. * @dataProvider getIconForIdDataProvider
  98. */
  99. public function testGetIconForId(string $id, ?string $expectedIcon): void {
  100. $actual = $this->service->getIconForId($id);
  101. $this->assertEquals($expectedIcon, $actual);
  102. }
  103. /**
  104. * @return array
  105. */
  106. public function getIconForIdDataProvider(): array {
  107. return [
  108. ['meeting', '📅'],
  109. ['commuting', '🚌'],
  110. ['sick-leave', '🤒'],
  111. ['vacationing', '🌴'],
  112. ['remote-work', '🏡'],
  113. ['call', '💬'],
  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. ['call', 'In a call'],
  140. ['unknown-id', null],
  141. ];
  142. }
  143. /**
  144. * @param string $id
  145. * @param bool $expected
  146. *
  147. * @dataProvider isValidIdDataProvider
  148. */
  149. public function testIsValidId(string $id, bool $expected): void {
  150. $actual = $this->service->isValidId($id);
  151. $this->assertEquals($expected, $actual);
  152. }
  153. /**
  154. * @return array
  155. */
  156. public function isValidIdDataProvider(): array {
  157. return [
  158. ['meeting', true],
  159. ['commuting', true],
  160. ['sick-leave', true],
  161. ['vacationing', true],
  162. ['remote-work', true],
  163. ['call', true],
  164. ['unknown-id', false],
  165. ];
  166. }
  167. public function testGetDefaultStatusById(): void {
  168. $this->l10n->expects($this->exactly(7))
  169. ->method('t')
  170. ->withConsecutive(
  171. ['In a meeting'],
  172. ['Commuting'],
  173. ['Working remotely'],
  174. ['Out sick'],
  175. ['Vacationing'],
  176. ['In a call'],
  177. )
  178. ->willReturnArgument(0);
  179. $this->assertEquals([
  180. 'id' => 'call',
  181. 'icon' => '💬',
  182. 'message' => 'In a call',
  183. 'clearAt' => null,
  184. 'visible' => false,
  185. ], $this->service->getDefaultStatusById('call'));
  186. }
  187. public function testGetDefaultStatusByUnknownId(): void {
  188. $this->assertNull($this->service->getDefaultStatusById('unknown'));
  189. }
  190. }