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.

StatusServiceTest.php 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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\Db\UserStatus;
  25. use OCA\UserStatus\Db\UserStatusMapper;
  26. use OCA\UserStatus\Exception\InvalidClearAtException;
  27. use OCA\UserStatus\Exception\InvalidMessageIdException;
  28. use OCA\UserStatus\Exception\InvalidStatusIconException;
  29. use OCA\UserStatus\Exception\InvalidStatusTypeException;
  30. use OCA\UserStatus\Exception\StatusMessageTooLongException;
  31. use OCA\UserStatus\Service\EmojiService;
  32. use OCA\UserStatus\Service\PredefinedStatusService;
  33. use OCA\UserStatus\Service\StatusService;
  34. use OCP\AppFramework\Db\DoesNotExistException;
  35. use OCP\AppFramework\Utility\ITimeFactory;
  36. use Test\TestCase;
  37. class StatusServiceTest extends TestCase {
  38. /** @var UserStatusMapper|\PHPUnit\Framework\MockObject\MockObject */
  39. private $mapper;
  40. /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
  41. private $timeFactory;
  42. /** @var PredefinedStatusService|\PHPUnit\Framework\MockObject\MockObject */
  43. private $predefinedStatusService;
  44. /** @var EmojiService|\PHPUnit\Framework\MockObject\MockObject */
  45. private $emojiService;
  46. /** @var StatusService */
  47. private $service;
  48. protected function setUp(): void {
  49. parent::setUp();
  50. $this->mapper = $this->createMock(UserStatusMapper::class);
  51. $this->timeFactory = $this->createMock(ITimeFactory::class);
  52. $this->predefinedStatusService = $this->createMock(PredefinedStatusService::class);
  53. $this->emojiService = $this->createMock(EmojiService::class);
  54. $this->service = new StatusService($this->mapper,
  55. $this->timeFactory,
  56. $this->predefinedStatusService,
  57. $this->emojiService);
  58. }
  59. public function testFindAll(): void {
  60. $status1 = $this->createMock(UserStatus::class);
  61. $status2 = $this->createMock(UserStatus::class);
  62. $this->mapper->expects($this->once())
  63. ->method('findAll')
  64. ->with(20, 50)
  65. ->willReturn([$status1, $status2]);
  66. $this->assertEquals([
  67. $status1,
  68. $status2,
  69. ], $this->service->findAll(20, 50));
  70. }
  71. public function testFindByUserId(): void {
  72. $status = $this->createMock(UserStatus::class);
  73. $this->mapper->expects($this->once())
  74. ->method('findByUserId')
  75. ->with('john.doe')
  76. ->willReturn($status);
  77. $this->assertEquals($status, $this->service->findByUserId('john.doe'));
  78. }
  79. public function testFindByUserIdDoesNotExist(): void {
  80. $this->mapper->expects($this->once())
  81. ->method('findByUserId')
  82. ->with('john.doe')
  83. ->willThrowException(new DoesNotExistException(''));
  84. $this->expectException(DoesNotExistException::class);
  85. $this->service->findByUserId('john.doe');
  86. }
  87. public function testFindAllAddDefaultMessage(): void {
  88. $status = new UserStatus();
  89. $status->setMessageId('commuting');
  90. $this->predefinedStatusService->expects($this->once())
  91. ->method('getDefaultStatusById')
  92. ->with('commuting')
  93. ->willReturn([
  94. 'id' => 'commuting',
  95. 'icon' => '🚌',
  96. 'message' => 'Commuting',
  97. 'clearAt' => [
  98. 'type' => 'period',
  99. 'time' => 1800,
  100. ],
  101. ]);
  102. $this->mapper->expects($this->once())
  103. ->method('findByUserId')
  104. ->with('john.doe')
  105. ->willReturn($status);
  106. $this->assertEquals($status, $this->service->findByUserId('john.doe'));
  107. $this->assertEquals('🚌', $status->getCustomIcon());
  108. $this->assertEquals('Commuting', $status->getCustomMessage());
  109. }
  110. public function testFindAllClearStatus(): void {
  111. $status = new UserStatus();
  112. $status->setClearAt(50);
  113. $status->setMessageId('commuting');
  114. $this->timeFactory->expects($this->once())
  115. ->method('getTime')
  116. ->willReturn(60);
  117. $this->predefinedStatusService->expects($this->never())
  118. ->method('getDefaultStatusById');
  119. $this->mapper->expects($this->once())
  120. ->method('findByUserId')
  121. ->with('john.doe')
  122. ->willReturn($status);
  123. $this->assertEquals($status, $this->service->findByUserId('john.doe'));
  124. $this->assertNull($status->getClearAt());
  125. $this->assertNull($status->getMessageId());
  126. }
  127. /**
  128. * @param string $userId
  129. * @param string $status
  130. * @param int|null $statusTimestamp
  131. * @param bool $isUserDefined
  132. * @param bool $expectExisting
  133. * @param bool $expectSuccess
  134. * @param bool $expectTimeFactory
  135. * @param bool $expectException
  136. * @param string|null $expectedExceptionClass
  137. * @param string|null $expectedExceptionMessage
  138. *
  139. * @dataProvider setStatusDataProvider
  140. */
  141. public function testSetStatus(string $userId,
  142. string $status,
  143. ?int $statusTimestamp,
  144. bool $isUserDefined,
  145. bool $expectExisting,
  146. bool $expectSuccess,
  147. bool $expectTimeFactory,
  148. bool $expectException,
  149. ?string $expectedExceptionClass,
  150. ?string $expectedExceptionMessage): void {
  151. $userStatus = new UserStatus();
  152. if ($expectExisting) {
  153. $userStatus->setId(42);
  154. $userStatus->setUserId($userId);
  155. $this->mapper->expects($this->once())
  156. ->method('findByUserId')
  157. ->with($userId)
  158. ->willReturn($userStatus);
  159. } else {
  160. $this->mapper->expects($this->once())
  161. ->method('findByUserId')
  162. ->with($userId)
  163. ->willThrowException(new DoesNotExistException(''));
  164. }
  165. if ($expectTimeFactory) {
  166. $this->timeFactory
  167. ->method('getTime')
  168. ->willReturn(40);
  169. }
  170. if ($expectException) {
  171. $this->expectException($expectedExceptionClass);
  172. $this->expectExceptionMessage($expectedExceptionMessage);
  173. $this->service->setStatus($userId, $status, $statusTimestamp, $isUserDefined);
  174. }
  175. if ($expectSuccess) {
  176. if ($expectExisting) {
  177. $this->mapper->expects($this->once())
  178. ->method('update')
  179. ->willReturnArgument(0);
  180. } else {
  181. $this->mapper->expects($this->once())
  182. ->method('insert')
  183. ->willReturnArgument(0);
  184. }
  185. $actual = $this->service->setStatus($userId, $status, $statusTimestamp, $isUserDefined);
  186. $this->assertEquals('john.doe', $actual->getUserId());
  187. $this->assertEquals($status, $actual->getStatus());
  188. $this->assertEquals($statusTimestamp ?? 40, $actual->getStatusTimestamp());
  189. $this->assertEquals($isUserDefined, $actual->getIsUserDefined());
  190. }
  191. }
  192. public function setStatusDataProvider(): array {
  193. return [
  194. ['john.doe', 'online', 50, true, true, true, false, false, null, null],
  195. ['john.doe', 'online', 50, true, false, true, false, false, null, null],
  196. ['john.doe', 'online', 50, false, true, true, false, false, null, null],
  197. ['john.doe', 'online', 50, false, false, true, false, false, null, null],
  198. ['john.doe', 'online', null, true, true, true, true, false, null, null],
  199. ['john.doe', 'online', null, true, false, true, true, false, null, null],
  200. ['john.doe', 'online', null, false, true, true, true, false, null, null],
  201. ['john.doe', 'online', null, false, false, true, true, false, null, null],
  202. ['john.doe', 'away', 50, true, true, true, false, false, null, null],
  203. ['john.doe', 'away', 50, true, false, true, false, false, null, null],
  204. ['john.doe', 'away', 50, false, true, true, false, false, null, null],
  205. ['john.doe', 'away', 50, false, false, true, false, false, null, null],
  206. ['john.doe', 'away', null, true, true, true, true, false, null, null],
  207. ['john.doe', 'away', null, true, false, true, true, false, null, null],
  208. ['john.doe', 'away', null, false, true, true, true, false, null, null],
  209. ['john.doe', 'away', null, false, false, true, true, false, null, null],
  210. ['john.doe', 'dnd', 50, true, true, true, false, false, null, null],
  211. ['john.doe', 'dnd', 50, true, false, true, false, false, null, null],
  212. ['john.doe', 'dnd', 50, false, true, true, false, false, null, null],
  213. ['john.doe', 'dnd', 50, false, false, true, false, false, null, null],
  214. ['john.doe', 'dnd', null, true, true, true, true, false, null, null],
  215. ['john.doe', 'dnd', null, true, false, true, true, false, null, null],
  216. ['john.doe', 'dnd', null, false, true, true, true, false, null, null],
  217. ['john.doe', 'dnd', null, false, false, true, true, false, null, null],
  218. ['john.doe', 'invisible', 50, true, true, true, false, false, null, null],
  219. ['john.doe', 'invisible', 50, true, false, true, false, false, null, null],
  220. ['john.doe', 'invisible', 50, false, true, true, false, false, null, null],
  221. ['john.doe', 'invisible', 50, false, false, true, false, false, null, null],
  222. ['john.doe', 'invisible', null, true, true, true, true, false, null, null],
  223. ['john.doe', 'invisible', null, true, false, true, true, false, null, null],
  224. ['john.doe', 'invisible', null, false, true, true, true, false, null, null],
  225. ['john.doe', 'invisible', null, false, false, true, true, false, null, null],
  226. ['john.doe', 'offline', 50, true, true, true, false, false, null, null],
  227. ['john.doe', 'offline', 50, true, false, true, false, false, null, null],
  228. ['john.doe', 'offline', 50, false, true, true, false, false, null, null],
  229. ['john.doe', 'offline', 50, false, false, true, false, false, null, null],
  230. ['john.doe', 'offline', null, true, true, true, true, false, null, null],
  231. ['john.doe', 'offline', null, true, false, true, true, false, null, null],
  232. ['john.doe', 'offline', null, false, true, true, true, false, null, null],
  233. ['john.doe', 'offline', null, false, false, true, true, false, null, null],
  234. ['john.doe', 'illegal-status', 50, true, true, false, false, true, InvalidStatusTypeException::class, 'Status-type "illegal-status" is not supported'],
  235. ['john.doe', 'illegal-status', 50, true, false, false, false, true, InvalidStatusTypeException::class, 'Status-type "illegal-status" is not supported'],
  236. ['john.doe', 'illegal-status', 50, false, true, false, false, true, InvalidStatusTypeException::class, 'Status-type "illegal-status" is not supported'],
  237. ['john.doe', 'illegal-status', 50, false, false, false, false, true, InvalidStatusTypeException::class, 'Status-type "illegal-status" is not supported'],
  238. ['john.doe', 'illegal-status', null, true, true, false, true, true, InvalidStatusTypeException::class, 'Status-type "illegal-status" is not supported'],
  239. ['john.doe', 'illegal-status', null, true, false, false, true, true, InvalidStatusTypeException::class, 'Status-type "illegal-status" is not supported'],
  240. ['john.doe', 'illegal-status', null, false, true, false, true, true, InvalidStatusTypeException::class, 'Status-type "illegal-status" is not supported'],
  241. ['john.doe', 'illegal-status', null, false, false, false, true, true, InvalidStatusTypeException::class, 'Status-type "illegal-status" is not supported'],
  242. ];
  243. }
  244. /**
  245. * @param string $userId
  246. * @param string $messageId
  247. * @param bool $isValidMessageId
  248. * @param int|null $clearAt
  249. * @param bool $expectExisting
  250. * @param bool $expectSuccess
  251. * @param bool $expectException
  252. * @param string|null $expectedExceptionClass
  253. * @param string|null $expectedExceptionMessage
  254. *
  255. * @dataProvider setPredefinedMessageDataProvider
  256. */
  257. public function testSetPredefinedMessage(string $userId,
  258. string $messageId,
  259. bool $isValidMessageId,
  260. ?int $clearAt,
  261. bool $expectExisting,
  262. bool $expectSuccess,
  263. bool $expectException,
  264. ?string $expectedExceptionClass,
  265. ?string $expectedExceptionMessage): void {
  266. $userStatus = new UserStatus();
  267. if ($expectExisting) {
  268. $userStatus->setId(42);
  269. $userStatus->setUserId($userId);
  270. $userStatus->setStatus('offline');
  271. $userStatus->setStatusTimestamp(0);
  272. $userStatus->setIsUserDefined(false);
  273. $userStatus->setCustomIcon('😀');
  274. $userStatus->setCustomMessage('Foo');
  275. $this->mapper->expects($this->once())
  276. ->method('findByUserId')
  277. ->with($userId)
  278. ->willReturn($userStatus);
  279. } else {
  280. $this->mapper->expects($this->once())
  281. ->method('findByUserId')
  282. ->with($userId)
  283. ->willThrowException(new DoesNotExistException(''));
  284. }
  285. $this->predefinedStatusService->expects($this->once())
  286. ->method('isValidId')
  287. ->with($messageId)
  288. ->willReturn($isValidMessageId);
  289. $this->timeFactory
  290. ->method('getTime')
  291. ->willReturn(40);
  292. if ($expectException) {
  293. $this->expectException($expectedExceptionClass);
  294. $this->expectExceptionMessage($expectedExceptionMessage);
  295. $this->service->setPredefinedMessage($userId, $messageId, $clearAt);
  296. }
  297. if ($expectSuccess) {
  298. if ($expectExisting) {
  299. $this->mapper->expects($this->once())
  300. ->method('update')
  301. ->willReturnArgument(0);
  302. } else {
  303. $this->mapper->expects($this->once())
  304. ->method('insert')
  305. ->willReturnArgument(0);
  306. }
  307. $actual = $this->service->setPredefinedMessage($userId, $messageId, $clearAt);
  308. $this->assertEquals('john.doe', $actual->getUserId());
  309. $this->assertEquals('offline', $actual->getStatus());
  310. $this->assertEquals(0, $actual->getStatusTimestamp());
  311. $this->assertEquals(false, $actual->getIsUserDefined());
  312. $this->assertEquals($messageId, $actual->getMessageId());
  313. $this->assertNull($actual->getCustomIcon());
  314. $this->assertNull($actual->getCustomMessage());
  315. $this->assertEquals($clearAt, $actual->getClearAt());
  316. }
  317. }
  318. public function setPredefinedMessageDataProvider(): array {
  319. return [
  320. ['john.doe', 'sick-leave', true, null, true, true, false, null, null],
  321. ['john.doe', 'sick-leave', true, null, false, true, false, null, null],
  322. ['john.doe', 'sick-leave', true, 20, true, false, true, InvalidClearAtException::class, 'ClearAt is in the past'],
  323. ['john.doe', 'sick-leave', true, 20, false, false, true, InvalidClearAtException::class, 'ClearAt is in the past'],
  324. ['john.doe', 'sick-leave', true, 60, true, true, false, null, null],
  325. ['john.doe', 'sick-leave', true, 60, false, true, false, null, null],
  326. ['john.doe', 'illegal-message-id', false, null, true, false, true, InvalidMessageIdException::class, 'Message-Id "illegal-message-id" is not supported'],
  327. ['john.doe', 'illegal-message-id', false, null, false, false, true, InvalidMessageIdException::class, 'Message-Id "illegal-message-id" is not supported'],
  328. ];
  329. }
  330. /**
  331. * @param string $userId
  332. * @param string|null $statusIcon
  333. * @param bool $supportsEmoji
  334. * @param string $message
  335. * @param int|null $clearAt
  336. * @param bool $expectExisting
  337. * @param bool $expectSuccess
  338. * @param bool $expectException
  339. * @param string|null $expectedExceptionClass
  340. * @param string|null $expectedExceptionMessage
  341. *
  342. * @dataProvider setCustomMessageDataProvider
  343. */
  344. public function testSetCustomMessage(string $userId,
  345. ?string $statusIcon,
  346. bool $supportsEmoji,
  347. string $message,
  348. ?int $clearAt,
  349. bool $expectExisting,
  350. bool $expectSuccess,
  351. bool $expectException,
  352. ?string $expectedExceptionClass,
  353. ?string $expectedExceptionMessage): void {
  354. $userStatus = new UserStatus();
  355. if ($expectExisting) {
  356. $userStatus->setId(42);
  357. $userStatus->setUserId($userId);
  358. $userStatus->setStatus('offline');
  359. $userStatus->setStatusTimestamp(0);
  360. $userStatus->setIsUserDefined(false);
  361. $userStatus->setMessageId('messageId-42');
  362. $this->mapper->expects($this->once())
  363. ->method('findByUserId')
  364. ->with($userId)
  365. ->willReturn($userStatus);
  366. } else {
  367. $this->mapper->expects($this->once())
  368. ->method('findByUserId')
  369. ->with($userId)
  370. ->willThrowException(new DoesNotExistException(''));
  371. }
  372. $this->emojiService->method('isValidEmoji')
  373. ->with($statusIcon)
  374. ->willReturn($supportsEmoji);
  375. $this->timeFactory
  376. ->method('getTime')
  377. ->willReturn(40);
  378. if ($expectException) {
  379. $this->expectException($expectedExceptionClass);
  380. $this->expectExceptionMessage($expectedExceptionMessage);
  381. $this->service->setCustomMessage($userId, $statusIcon, $message, $clearAt);
  382. }
  383. if ($expectSuccess) {
  384. if ($expectExisting) {
  385. $this->mapper->expects($this->once())
  386. ->method('update')
  387. ->willReturnArgument(0);
  388. } else {
  389. $this->mapper->expects($this->once())
  390. ->method('insert')
  391. ->willReturnArgument(0);
  392. }
  393. $actual = $this->service->setCustomMessage($userId, $statusIcon, $message, $clearAt);
  394. $this->assertEquals('john.doe', $actual->getUserId());
  395. $this->assertEquals('offline', $actual->getStatus());
  396. $this->assertEquals(0, $actual->getStatusTimestamp());
  397. $this->assertEquals(false, $actual->getIsUserDefined());
  398. $this->assertNull($actual->getMessageId());
  399. $this->assertEquals($statusIcon, $actual->getCustomIcon());
  400. $this->assertEquals($message, $actual->getCustomMessage());
  401. $this->assertEquals($clearAt, $actual->getClearAt());
  402. }
  403. }
  404. public function setCustomMessageDataProvider(): array {
  405. return [
  406. ['john.doe', '😁', true, 'Custom message', null, true, true, false, null, null],
  407. ['john.doe', '😁', true, 'Custom message', null, false, true, false, null, null],
  408. ['john.doe', null, false, 'Custom message', null, true, true, false, null, null],
  409. ['john.doe', null, false, 'Custom message', null, false, true, false, null, null],
  410. ['john.doe', '😁', false, 'Custom message', null, true, false, true, InvalidStatusIconException::class, 'Status-Icon is longer than one character'],
  411. ['john.doe', '😁', false, 'Custom message', null, false, false, true, InvalidStatusIconException::class, 'Status-Icon is longer than one character'],
  412. ['john.doe', null, false, 'Custom message that is way too long and violates the maximum length and hence should be rejected', null, true, false, true, StatusMessageTooLongException::class, 'Message is longer than supported length of 80 characters'],
  413. ['john.doe', null, false, 'Custom message that is way too long and violates the maximum length and hence should be rejected', null, false, false, true, StatusMessageTooLongException::class, 'Message is longer than supported length of 80 characters'],
  414. ['john.doe', '😁', true, 'Custom message', 80, true, true, false, null, null],
  415. ['john.doe', '😁', true, 'Custom message', 80, false, true, false, null, null],
  416. ['john.doe', '😁', true, 'Custom message', 20, true, false, true, InvalidClearAtException::class, 'ClearAt is in the past'],
  417. ['john.doe', '😁', true, 'Custom message', 20, false, false, true, InvalidClearAtException::class, 'ClearAt is in the past'],
  418. ];
  419. }
  420. public function testClearStatus(): void {
  421. $status = new UserStatus();
  422. $status->setId(1);
  423. $status->setUserId('john.doe');
  424. $status->setStatus('dnd');
  425. $status->setStatusTimestamp(1337);
  426. $status->setIsUserDefined(true);
  427. $status->setMessageId('messageId-42');
  428. $status->setCustomIcon('🙊');
  429. $status->setCustomMessage('My custom status message');
  430. $status->setClearAt(42);
  431. $this->mapper->expects($this->once())
  432. ->method('findByUserId')
  433. ->with('john.doe')
  434. ->willReturn($status);
  435. $this->mapper->expects($this->once())
  436. ->method('update')
  437. ->with($status);
  438. $actual = $this->service->clearStatus('john.doe');
  439. $this->assertTrue($actual);
  440. $this->assertEquals('offline', $status->getStatus());
  441. $this->assertEquals(0, $status->getStatusTimestamp());
  442. $this->assertFalse($status->getIsUserDefined());
  443. }
  444. public function testClearStatusDoesNotExist(): void {
  445. $this->mapper->expects($this->once())
  446. ->method('findByUserId')
  447. ->with('john.doe')
  448. ->willThrowException(new DoesNotExistException(''));
  449. $this->mapper->expects($this->never())
  450. ->method('update');
  451. $actual = $this->service->clearStatus('john.doe');
  452. $this->assertFalse($actual);
  453. }
  454. public function testClearMessage(): void {
  455. $status = new UserStatus();
  456. $status->setId(1);
  457. $status->setUserId('john.doe');
  458. $status->setStatus('dnd');
  459. $status->setStatusTimestamp(1337);
  460. $status->setIsUserDefined(true);
  461. $status->setMessageId('messageId-42');
  462. $status->setCustomIcon('🙊');
  463. $status->setCustomMessage('My custom status message');
  464. $status->setClearAt(42);
  465. $this->mapper->expects($this->once())
  466. ->method('findByUserId')
  467. ->with('john.doe')
  468. ->willReturn($status);
  469. $this->mapper->expects($this->once())
  470. ->method('update')
  471. ->with($status);
  472. $actual = $this->service->clearMessage('john.doe');
  473. $this->assertTrue($actual);
  474. $this->assertNull($status->getMessageId());
  475. $this->assertNull($status->getCustomMessage());
  476. $this->assertNull($status->getCustomIcon());
  477. $this->assertNull($status->getClearAt());
  478. }
  479. public function testClearMessageDoesNotExist(): void {
  480. $this->mapper->expects($this->once())
  481. ->method('findByUserId')
  482. ->with('john.doe')
  483. ->willThrowException(new DoesNotExistException(''));
  484. $this->mapper->expects($this->never())
  485. ->method('update');
  486. $actual = $this->service->clearMessage('john.doe');
  487. $this->assertFalse($actual);
  488. }
  489. public function testRemoveUserStatus(): void {
  490. $status = $this->createMock(UserStatus::class);
  491. $this->mapper->expects($this->once())
  492. ->method('findByUserId')
  493. ->with('john.doe')
  494. ->willReturn($status);
  495. $this->mapper->expects($this->once())
  496. ->method('delete')
  497. ->with($status);
  498. $actual = $this->service->removeUserStatus('john.doe');
  499. $this->assertTrue($actual);
  500. }
  501. public function testRemoveUserStatusDoesNotExist(): void {
  502. $this->mapper->expects($this->once())
  503. ->method('findByUserId')
  504. ->with('john.doe')
  505. ->willThrowException(new DoesNotExistException(''));
  506. $this->mapper->expects($this->never())
  507. ->method('delete');
  508. $actual = $this->service->removeUserStatus('john.doe');
  509. $this->assertFalse($actual);
  510. }
  511. }