PredefinedStatusServiceTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020, Georg Ehrke
  5. *
  6. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\UserStatus\Tests\Service;
  26. use OCA\UserStatus\Service\PredefinedStatusService;
  27. use OCP\IL10N;
  28. use Test\TestCase;
  29. class PredefinedStatusServiceTest extends TestCase {
  30. /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
  31. protected $l10n;
  32. /** @var PredefinedStatusService */
  33. protected $service;
  34. protected function setUp(): void {
  35. parent::setUp();
  36. $this->l10n = $this->createMock(IL10N::class);
  37. $this->service = new PredefinedStatusService($this->l10n);
  38. }
  39. public function testGetDefaultStatuses(): void {
  40. $this->l10n->expects($this->exactly(7))
  41. ->method('t')
  42. ->withConsecutive(
  43. ['In a meeting'],
  44. ['Commuting'],
  45. ['Working remotely'],
  46. ['Out sick'],
  47. ['Vacationing'],
  48. ['In a call'],
  49. )
  50. ->willReturnArgument(0);
  51. $actual = $this->service->getDefaultStatuses();
  52. $this->assertEquals([
  53. [
  54. 'id' => 'meeting',
  55. 'icon' => '📅',
  56. 'message' => 'In a meeting',
  57. 'clearAt' => [
  58. 'type' => 'period',
  59. 'time' => 3600,
  60. ],
  61. ],
  62. [
  63. 'id' => 'commuting',
  64. 'icon' => '🚌',
  65. 'message' => 'Commuting',
  66. 'clearAt' => [
  67. 'type' => 'period',
  68. 'time' => 1800,
  69. ],
  70. ],
  71. [
  72. 'id' => 'remote-work',
  73. 'icon' => '🏡',
  74. 'message' => 'Working remotely',
  75. 'clearAt' => [
  76. 'type' => 'end-of',
  77. 'time' => 'day',
  78. ],
  79. ],
  80. [
  81. 'id' => 'sick-leave',
  82. 'icon' => '🤒',
  83. 'message' => 'Out sick',
  84. 'clearAt' => [
  85. 'type' => 'end-of',
  86. 'time' => 'day',
  87. ],
  88. ],
  89. [
  90. 'id' => 'vacationing',
  91. 'icon' => '🌴',
  92. 'message' => 'Vacationing',
  93. 'clearAt' => null,
  94. ],
  95. [
  96. 'id' => 'call',
  97. 'icon' => '💬',
  98. 'message' => 'In a call',
  99. 'clearAt' => null,
  100. 'visible' => false,
  101. ],
  102. [
  103. 'id' => 'out-of-office',
  104. 'icon' => '🛑',
  105. 'message' => 'Out of office',
  106. 'clearAt' => null,
  107. 'visible' => false,
  108. ],
  109. ], $actual);
  110. }
  111. /**
  112. * @param string $id
  113. * @param string|null $expectedIcon
  114. *
  115. * @dataProvider getIconForIdDataProvider
  116. */
  117. public function testGetIconForId(string $id, ?string $expectedIcon): void {
  118. $actual = $this->service->getIconForId($id);
  119. $this->assertEquals($expectedIcon, $actual);
  120. }
  121. /**
  122. * @return array
  123. */
  124. public function getIconForIdDataProvider(): array {
  125. return [
  126. ['meeting', '📅'],
  127. ['commuting', '🚌'],
  128. ['sick-leave', '🤒'],
  129. ['vacationing', '🌴'],
  130. ['remote-work', '🏡'],
  131. ['call', '💬'],
  132. ['unknown-id', null],
  133. ];
  134. }
  135. /**
  136. * @param string $id
  137. * @param string|null $expected
  138. *
  139. * @dataProvider getTranslatedStatusForIdDataProvider
  140. */
  141. public function testGetTranslatedStatusForId(string $id, ?string $expected): void {
  142. $this->l10n->method('t')
  143. ->willReturnArgument(0);
  144. $actual = $this->service->getTranslatedStatusForId($id);
  145. $this->assertEquals($expected, $actual);
  146. }
  147. /**
  148. * @return array
  149. */
  150. public function getTranslatedStatusForIdDataProvider(): array {
  151. return [
  152. ['meeting', 'In a meeting'],
  153. ['commuting', 'Commuting'],
  154. ['sick-leave', 'Out sick'],
  155. ['vacationing', 'Vacationing'],
  156. ['remote-work', 'Working remotely'],
  157. ['call', 'In a call'],
  158. ['unknown-id', null],
  159. ];
  160. }
  161. /**
  162. * @param string $id
  163. * @param bool $expected
  164. *
  165. * @dataProvider isValidIdDataProvider
  166. */
  167. public function testIsValidId(string $id, bool $expected): void {
  168. $actual = $this->service->isValidId($id);
  169. $this->assertEquals($expected, $actual);
  170. }
  171. /**
  172. * @return array
  173. */
  174. public function isValidIdDataProvider(): array {
  175. return [
  176. ['meeting', true],
  177. ['commuting', true],
  178. ['sick-leave', true],
  179. ['vacationing', true],
  180. ['remote-work', true],
  181. ['call', true],
  182. ['unknown-id', false],
  183. ];
  184. }
  185. public function testGetDefaultStatusById(): void {
  186. $this->l10n->expects($this->exactly(7))
  187. ->method('t')
  188. ->withConsecutive(
  189. ['In a meeting'],
  190. ['Commuting'],
  191. ['Working remotely'],
  192. ['Out sick'],
  193. ['Vacationing'],
  194. ['In a call'],
  195. )
  196. ->willReturnArgument(0);
  197. $this->assertEquals([
  198. 'id' => 'call',
  199. 'icon' => '💬',
  200. 'message' => 'In a call',
  201. 'clearAt' => null,
  202. 'visible' => false,
  203. ], $this->service->getDefaultStatusById('call'));
  204. }
  205. public function testGetDefaultStatusByUnknownId(): void {
  206. $this->assertNull($this->service->getDefaultStatusById('unknown'));
  207. }
  208. }