PredefinedStatusServiceTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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(6))
  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. ], $actual);
  103. }
  104. /**
  105. * @param string $id
  106. * @param string|null $expectedIcon
  107. *
  108. * @dataProvider getIconForIdDataProvider
  109. */
  110. public function testGetIconForId(string $id, ?string $expectedIcon): void {
  111. $actual = $this->service->getIconForId($id);
  112. $this->assertEquals($expectedIcon, $actual);
  113. }
  114. /**
  115. * @return array
  116. */
  117. public function getIconForIdDataProvider(): array {
  118. return [
  119. ['meeting', '📅'],
  120. ['commuting', '🚌'],
  121. ['sick-leave', '🤒'],
  122. ['vacationing', '🌴'],
  123. ['remote-work', '🏡'],
  124. ['call', '💬'],
  125. ['unknown-id', null],
  126. ];
  127. }
  128. /**
  129. * @param string $id
  130. * @param string|null $expected
  131. *
  132. * @dataProvider getTranslatedStatusForIdDataProvider
  133. */
  134. public function testGetTranslatedStatusForId(string $id, ?string $expected): void {
  135. $this->l10n->method('t')
  136. ->willReturnArgument(0);
  137. $actual = $this->service->getTranslatedStatusForId($id);
  138. $this->assertEquals($expected, $actual);
  139. }
  140. /**
  141. * @return array
  142. */
  143. public function getTranslatedStatusForIdDataProvider(): array {
  144. return [
  145. ['meeting', 'In a meeting'],
  146. ['commuting', 'Commuting'],
  147. ['sick-leave', 'Out sick'],
  148. ['vacationing', 'Vacationing'],
  149. ['remote-work', 'Working remotely'],
  150. ['call', 'In a call'],
  151. ['unknown-id', null],
  152. ];
  153. }
  154. /**
  155. * @param string $id
  156. * @param bool $expected
  157. *
  158. * @dataProvider isValidIdDataProvider
  159. */
  160. public function testIsValidId(string $id, bool $expected): void {
  161. $actual = $this->service->isValidId($id);
  162. $this->assertEquals($expected, $actual);
  163. }
  164. /**
  165. * @return array
  166. */
  167. public function isValidIdDataProvider(): array {
  168. return [
  169. ['meeting', true],
  170. ['commuting', true],
  171. ['sick-leave', true],
  172. ['vacationing', true],
  173. ['remote-work', true],
  174. ['call', true],
  175. ['unknown-id', false],
  176. ];
  177. }
  178. public function testGetDefaultStatusById(): void {
  179. $this->l10n->expects($this->exactly(6))
  180. ->method('t')
  181. ->withConsecutive(
  182. ['In a meeting'],
  183. ['Commuting'],
  184. ['Working remotely'],
  185. ['Out sick'],
  186. ['Vacationing'],
  187. ['In a call'],
  188. )
  189. ->willReturnArgument(0);
  190. $this->assertEquals([
  191. 'id' => 'call',
  192. 'icon' => '💬',
  193. 'message' => 'In a call',
  194. 'clearAt' => null,
  195. 'visible' => false,
  196. ], $this->service->getDefaultStatusById('call'));
  197. }
  198. public function testGetDefaultStatusByUnknownId(): void {
  199. $this->assertNull($this->service->getDefaultStatusById('unknown'));
  200. }
  201. }