ManagerTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <?php
  2. namespace Test\Comments;
  3. use OCP\Comments\ICommentsManager;
  4. use OCP\IUser;
  5. use Test\TestCase;
  6. /**
  7. * Class ManagerTest
  8. *
  9. * @group DB
  10. */
  11. class ManagerTest extends TestCase {
  12. public function setUp() {
  13. parent::setUp();
  14. $sql = \OC::$server->getDatabaseConnection()->getDatabasePlatform()->getTruncateTableSQL('`*PREFIX*comments`');
  15. \OC::$server->getDatabaseConnection()->prepare($sql)->execute();
  16. }
  17. protected function addDatabaseEntry($parentId, $topmostParentId, $creationDT = null, $latestChildDT = null) {
  18. if(is_null($creationDT)) {
  19. $creationDT = new \DateTime();
  20. }
  21. if(is_null($latestChildDT)) {
  22. $latestChildDT = new \DateTime('yesterday');
  23. }
  24. $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
  25. $qb
  26. ->insert('comments')
  27. ->values([
  28. 'parent_id' => $qb->createNamedParameter($parentId),
  29. 'topmost_parent_id' => $qb->createNamedParameter($topmostParentId),
  30. 'children_count' => $qb->createNamedParameter(2),
  31. 'actor_type' => $qb->createNamedParameter('users'),
  32. 'actor_id' => $qb->createNamedParameter('alice'),
  33. 'message' => $qb->createNamedParameter('nice one'),
  34. 'verb' => $qb->createNamedParameter('comment'),
  35. 'creation_timestamp' => $qb->createNamedParameter($creationDT, 'datetime'),
  36. 'latest_child_timestamp' => $qb->createNamedParameter($latestChildDT, 'datetime'),
  37. 'object_type' => $qb->createNamedParameter('files'),
  38. 'object_id' => $qb->createNamedParameter('file64'),
  39. ])
  40. ->execute();
  41. return $qb->getLastInsertId();
  42. }
  43. protected function getManager() {
  44. $factory = new \OC\Comments\ManagerFactory(\OC::$server);
  45. return $factory->getManager();
  46. }
  47. /**
  48. * @expectedException \OCP\Comments\NotFoundException
  49. */
  50. public function testGetCommentNotFound() {
  51. $manager = $this->getManager();
  52. $manager->get('22');
  53. }
  54. /**
  55. * @expectedException \InvalidArgumentException
  56. */
  57. public function testGetCommentNotFoundInvalidInput() {
  58. $manager = $this->getManager();
  59. $manager->get('unexisting22');
  60. }
  61. public function testGetComment() {
  62. $manager = $this->getManager();
  63. $creationDT = new \DateTime();
  64. $latestChildDT = new \DateTime('yesterday');
  65. $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
  66. $qb
  67. ->insert('comments')
  68. ->values([
  69. 'parent_id' => $qb->createNamedParameter('2'),
  70. 'topmost_parent_id' => $qb->createNamedParameter('1'),
  71. 'children_count' => $qb->createNamedParameter(2),
  72. 'actor_type' => $qb->createNamedParameter('users'),
  73. 'actor_id' => $qb->createNamedParameter('alice'),
  74. 'message' => $qb->createNamedParameter('nice one'),
  75. 'verb' => $qb->createNamedParameter('comment'),
  76. 'creation_timestamp' => $qb->createNamedParameter($creationDT, 'datetime'),
  77. 'latest_child_timestamp' => $qb->createNamedParameter($latestChildDT, 'datetime'),
  78. 'object_type' => $qb->createNamedParameter('files'),
  79. 'object_id' => $qb->createNamedParameter('file64'),
  80. ])
  81. ->execute();
  82. $id = strval($qb->getLastInsertId());
  83. $comment = $manager->get($id);
  84. $this->assertTrue($comment instanceof \OCP\Comments\IComment);
  85. $this->assertSame($comment->getId(), $id);
  86. $this->assertSame($comment->getParentId(), '2');
  87. $this->assertSame($comment->getTopmostParentId(), '1');
  88. $this->assertSame($comment->getChildrenCount(), 2);
  89. $this->assertSame($comment->getActorType(), 'users');
  90. $this->assertSame($comment->getActorId(), 'alice');
  91. $this->assertSame($comment->getMessage(), 'nice one');
  92. $this->assertSame($comment->getVerb(), 'comment');
  93. $this->assertSame($comment->getObjectType(), 'files');
  94. $this->assertSame($comment->getObjectId(), 'file64');
  95. $this->assertEquals($comment->getCreationDateTime(), $creationDT);
  96. $this->assertEquals($comment->getLatestChildDateTime(), $latestChildDT);
  97. }
  98. /**
  99. * @expectedException \OCP\Comments\NotFoundException
  100. */
  101. public function testGetTreeNotFound() {
  102. $manager = $this->getManager();
  103. $manager->getTree('22');
  104. }
  105. /**
  106. * @expectedException \InvalidArgumentException
  107. */
  108. public function testGetTreeNotFoundInvalidIpnut() {
  109. $manager = $this->getManager();
  110. $manager->getTree('unexisting22');
  111. }
  112. public function testGetTree() {
  113. $headId = $this->addDatabaseEntry(0, 0);
  114. $this->addDatabaseEntry($headId, $headId, new \DateTime('-3 hours'));
  115. $this->addDatabaseEntry($headId, $headId, new \DateTime('-2 hours'));
  116. $id = $this->addDatabaseEntry($headId, $headId, new \DateTime('-1 hour'));
  117. $manager = $this->getManager();
  118. $tree = $manager->getTree($headId);
  119. // Verifying the root comment
  120. $this->assertTrue(isset($tree['comment']));
  121. $this->assertTrue($tree['comment'] instanceof \OCP\Comments\IComment);
  122. $this->assertSame($tree['comment']->getId(), strval($headId));
  123. $this->assertTrue(isset($tree['replies']));
  124. $this->assertSame(count($tree['replies']), 3);
  125. // one level deep
  126. foreach($tree['replies'] as $reply) {
  127. $this->assertTrue($reply['comment'] instanceof \OCP\Comments\IComment);
  128. $this->assertSame($reply['comment']->getId(), strval($id));
  129. $this->assertSame(count($reply['replies']), 0);
  130. $id--;
  131. }
  132. }
  133. public function testGetTreeNoReplies() {
  134. $id = $this->addDatabaseEntry(0, 0);
  135. $manager = $this->getManager();
  136. $tree = $manager->getTree($id);
  137. // Verifying the root comment
  138. $this->assertTrue(isset($tree['comment']));
  139. $this->assertTrue($tree['comment'] instanceof \OCP\Comments\IComment);
  140. $this->assertSame($tree['comment']->getId(), strval($id));
  141. $this->assertTrue(isset($tree['replies']));
  142. $this->assertSame(count($tree['replies']), 0);
  143. // one level deep
  144. foreach($tree['replies'] as $reply) {
  145. throw new \Exception('This ain`t happen');
  146. }
  147. }
  148. public function testGetTreeWithLimitAndOffset() {
  149. $headId = $this->addDatabaseEntry(0, 0);
  150. $this->addDatabaseEntry($headId, $headId, new \DateTime('-3 hours'));
  151. $this->addDatabaseEntry($headId, $headId, new \DateTime('-2 hours'));
  152. $this->addDatabaseEntry($headId, $headId, new \DateTime('-1 hour'));
  153. $idToVerify = $this->addDatabaseEntry($headId, $headId, new \DateTime());
  154. $manager = $this->getManager();
  155. for ($offset = 0; $offset < 3; $offset += 2) {
  156. $tree = $manager->getTree(strval($headId), 2, $offset);
  157. // Verifying the root comment
  158. $this->assertTrue(isset($tree['comment']));
  159. $this->assertTrue($tree['comment'] instanceof \OCP\Comments\IComment);
  160. $this->assertSame($tree['comment']->getId(), strval($headId));
  161. $this->assertTrue(isset($tree['replies']));
  162. $this->assertSame(count($tree['replies']), 2);
  163. // one level deep
  164. foreach ($tree['replies'] as $reply) {
  165. $this->assertTrue($reply['comment'] instanceof \OCP\Comments\IComment);
  166. $this->assertSame($reply['comment']->getId(), strval($idToVerify));
  167. $this->assertSame(count($reply['replies']), 0);
  168. $idToVerify--;
  169. }
  170. }
  171. }
  172. public function testGetForObject() {
  173. $this->addDatabaseEntry(0, 0);
  174. $manager = $this->getManager();
  175. $comments = $manager->getForObject('files', 'file64');
  176. $this->assertTrue(is_array($comments));
  177. $this->assertSame(count($comments), 1);
  178. $this->assertTrue($comments[0] instanceof \OCP\Comments\IComment);
  179. $this->assertSame($comments[0]->getMessage(), 'nice one');
  180. }
  181. public function testGetForObjectWithLimitAndOffset() {
  182. $this->addDatabaseEntry(0, 0, new \DateTime('-6 hours'));
  183. $this->addDatabaseEntry(0, 0, new \DateTime('-5 hours'));
  184. $this->addDatabaseEntry(1, 1, new \DateTime('-4 hours'));
  185. $this->addDatabaseEntry(0, 0, new \DateTime('-3 hours'));
  186. $this->addDatabaseEntry(2, 2, new \DateTime('-2 hours'));
  187. $this->addDatabaseEntry(2, 2, new \DateTime('-1 hours'));
  188. $idToVerify = $this->addDatabaseEntry(3, 1, new \DateTime());
  189. $manager = $this->getManager();
  190. $offset = 0;
  191. do {
  192. $comments = $manager->getForObject('files', 'file64', 3, $offset);
  193. $this->assertTrue(is_array($comments));
  194. foreach($comments as $comment) {
  195. $this->assertTrue($comment instanceof \OCP\Comments\IComment);
  196. $this->assertSame($comment->getMessage(), 'nice one');
  197. $this->assertSame($comment->getId(), strval($idToVerify));
  198. $idToVerify--;
  199. }
  200. $offset += 3;
  201. } while(count($comments) > 0);
  202. }
  203. public function testGetForObjectWithDateTimeConstraint() {
  204. $this->addDatabaseEntry(0, 0, new \DateTime('-6 hours'));
  205. $this->addDatabaseEntry(0, 0, new \DateTime('-5 hours'));
  206. $id1 = $this->addDatabaseEntry(0, 0, new \DateTime('-3 hours'));
  207. $id2 = $this->addDatabaseEntry(2, 2, new \DateTime('-2 hours'));
  208. $manager = $this->getManager();
  209. $comments = $manager->getForObject('files', 'file64', 0, 0, new \DateTime('-4 hours'));
  210. $this->assertSame(count($comments), 2);
  211. $this->assertSame($comments[0]->getId(), strval($id2));
  212. $this->assertSame($comments[1]->getId(), strval($id1));
  213. }
  214. public function testGetForObjectWithLimitAndOffsetAndDateTimeConstraint() {
  215. $this->addDatabaseEntry(0, 0, new \DateTime('-7 hours'));
  216. $this->addDatabaseEntry(0, 0, new \DateTime('-6 hours'));
  217. $this->addDatabaseEntry(1, 1, new \DateTime('-5 hours'));
  218. $this->addDatabaseEntry(0, 0, new \DateTime('-3 hours'));
  219. $this->addDatabaseEntry(2, 2, new \DateTime('-2 hours'));
  220. $this->addDatabaseEntry(2, 2, new \DateTime('-1 hours'));
  221. $idToVerify = $this->addDatabaseEntry(3, 1, new \DateTime());
  222. $manager = $this->getManager();
  223. $offset = 0;
  224. do {
  225. $comments = $manager->getForObject('files', 'file64', 3, $offset, new \DateTime('-4 hours'));
  226. $this->assertTrue(is_array($comments));
  227. foreach($comments as $comment) {
  228. $this->assertTrue($comment instanceof \OCP\Comments\IComment);
  229. $this->assertSame($comment->getMessage(), 'nice one');
  230. $this->assertSame($comment->getId(), strval($idToVerify));
  231. $this->assertTrue(intval($comment->getId()) >= 4);
  232. $idToVerify--;
  233. }
  234. $offset += 3;
  235. } while(count($comments) > 0);
  236. }
  237. public function testGetNumberOfCommentsForObject() {
  238. for($i = 1; $i < 5; $i++) {
  239. $this->addDatabaseEntry(0, 0);
  240. }
  241. $manager = $this->getManager();
  242. $amount = $manager->getNumberOfCommentsForObject('untype', '00');
  243. $this->assertSame($amount, 0);
  244. $amount = $manager->getNumberOfCommentsForObject('files', 'file64');
  245. $this->assertSame($amount, 4);
  246. }
  247. public function invalidCreateArgsProvider() {
  248. return [
  249. ['', 'aId-1', 'oType-1', 'oId-1'],
  250. ['aType-1', '', 'oType-1', 'oId-1'],
  251. ['aType-1', 'aId-1', '', 'oId-1'],
  252. ['aType-1', 'aId-1', 'oType-1', ''],
  253. [1, 'aId-1', 'oType-1', 'oId-1'],
  254. ['aType-1', 1, 'oType-1', 'oId-1'],
  255. ['aType-1', 'aId-1', 1, 'oId-1'],
  256. ['aType-1', 'aId-1', 'oType-1', 1],
  257. ];
  258. }
  259. /**
  260. * @dataProvider invalidCreateArgsProvider
  261. * @expectedException \InvalidArgumentException
  262. */
  263. public function testCreateCommentInvalidArguments($aType, $aId, $oType, $oId) {
  264. $manager = $this->getManager();
  265. $manager->create($aType, $aId, $oType, $oId);
  266. }
  267. public function testCreateComment() {
  268. $actorType = 'bot';
  269. $actorId = 'bob';
  270. $objectType = 'weather';
  271. $objectId = 'bielefeld';
  272. $comment = $this->getManager()->create($actorType, $actorId, $objectType, $objectId);
  273. $this->assertTrue($comment instanceof \OCP\Comments\IComment);
  274. $this->assertSame($comment->getActorType(), $actorType);
  275. $this->assertSame($comment->getActorId(), $actorId);
  276. $this->assertSame($comment->getObjectType(), $objectType);
  277. $this->assertSame($comment->getObjectId(), $objectId);
  278. }
  279. /**
  280. * @expectedException \OCP\Comments\NotFoundException
  281. */
  282. public function testDelete() {
  283. $manager = $this->getManager();
  284. $done = $manager->delete('404');
  285. $this->assertFalse($done);
  286. $done = $manager->delete('%');
  287. $this->assertFalse($done);
  288. $done = $manager->delete('');
  289. $this->assertFalse($done);
  290. $id = strval($this->addDatabaseEntry(0, 0));
  291. $comment = $manager->get($id);
  292. $this->assertTrue($comment instanceof \OCP\Comments\IComment);
  293. $done = $manager->delete($id);
  294. $this->assertTrue($done);
  295. $manager->get($id);
  296. }
  297. public function testSaveNew() {
  298. $manager = $this->getManager();
  299. $comment = new \OC\Comments\Comment();
  300. $comment
  301. ->setActor('users', 'alice')
  302. ->setObject('files', 'file64')
  303. ->setMessage('very beautiful, I am impressed!')
  304. ->setVerb('comment');
  305. $saveSuccessful = $manager->save($comment);
  306. $this->assertTrue($saveSuccessful);
  307. $this->assertTrue($comment->getId() !== '');
  308. $this->assertTrue($comment->getId() !== '0');
  309. $this->assertTrue(!is_null($comment->getCreationDateTime()));
  310. $loadedComment = $manager->get($comment->getId());
  311. $this->assertSame($comment->getMessage(), $loadedComment->getMessage());
  312. $this->assertEquals($comment->getCreationDateTime(), $loadedComment->getCreationDateTime());
  313. }
  314. public function testSaveUpdate() {
  315. $manager = $this->getManager();
  316. $comment = new \OC\Comments\Comment();
  317. $comment
  318. ->setActor('users', 'alice')
  319. ->setObject('files', 'file64')
  320. ->setMessage('very beautiful, I am impressed!')
  321. ->setVerb('comment');
  322. $manager->save($comment);
  323. $comment->setMessage('very beautiful, I am really so much impressed!');
  324. $manager->save($comment);
  325. $loadedComment = $manager->get($comment->getId());
  326. $this->assertSame($comment->getMessage(), $loadedComment->getMessage());
  327. }
  328. /**
  329. * @expectedException \OCP\Comments\NotFoundException
  330. */
  331. public function testSaveUpdateException() {
  332. $manager = $this->getManager();
  333. $comment = new \OC\Comments\Comment();
  334. $comment
  335. ->setActor('users', 'alice')
  336. ->setObject('files', 'file64')
  337. ->setMessage('very beautiful, I am impressed!')
  338. ->setVerb('comment');
  339. $manager->save($comment);
  340. $manager->delete($comment->getId());
  341. $comment->setMessage('very beautiful, I am really so much impressed!');
  342. $manager->save($comment);
  343. }
  344. /**
  345. * @expectedException \UnexpectedValueException
  346. */
  347. public function testSaveIncomplete() {
  348. $manager = $this->getManager();
  349. $comment = new \OC\Comments\Comment();
  350. $comment->setMessage('from no one to nothing');
  351. $manager->save($comment);
  352. }
  353. public function testSaveAsChild() {
  354. $id = $this->addDatabaseEntry(0, 0);
  355. $manager = $this->getManager();
  356. for($i = 0; $i < 3; $i++) {
  357. $comment = new \OC\Comments\Comment();
  358. $comment
  359. ->setActor('users', 'alice')
  360. ->setObject('files', 'file64')
  361. ->setParentId(strval($id))
  362. ->setMessage('full ack')
  363. ->setVerb('comment')
  364. // setting the creation time avoids using sleep() while making sure to test with different timestamps
  365. ->setCreationDateTime(new \DateTime('+' . $i . ' minutes'));
  366. $manager->save($comment);
  367. $this->assertSame($comment->getTopmostParentId(), strval($id));
  368. $parentComment = $manager->get(strval($id));
  369. $this->assertSame($parentComment->getChildrenCount(), $i + 1);
  370. $this->assertEquals($parentComment->getLatestChildDateTime(), $comment->getCreationDateTime());
  371. }
  372. }
  373. public function invalidActorArgsProvider() {
  374. return
  375. [
  376. ['', ''],
  377. [1, 'alice'],
  378. ['users', 1],
  379. ];
  380. }
  381. /**
  382. * @dataProvider invalidActorArgsProvider
  383. * @expectedException \InvalidArgumentException
  384. */
  385. public function testDeleteReferencesOfActorInvalidInput($type, $id) {
  386. $manager = $this->getManager();
  387. $manager->deleteReferencesOfActor($type, $id);
  388. }
  389. public function testDeleteReferencesOfActor() {
  390. $ids = [];
  391. $ids[] = $this->addDatabaseEntry(0, 0);
  392. $ids[] = $this->addDatabaseEntry(0, 0);
  393. $ids[] = $this->addDatabaseEntry(0, 0);
  394. $manager = $this->getManager();
  395. // just to make sure they are really set, with correct actor data
  396. $comment = $manager->get(strval($ids[1]));
  397. $this->assertSame($comment->getActorType(), 'users');
  398. $this->assertSame($comment->getActorId(), 'alice');
  399. $wasSuccessful = $manager->deleteReferencesOfActor('users', 'alice');
  400. $this->assertTrue($wasSuccessful);
  401. foreach($ids as $id) {
  402. $comment = $manager->get(strval($id));
  403. $this->assertSame($comment->getActorType(), ICommentsManager::DELETED_USER);
  404. $this->assertSame($comment->getActorId(), ICommentsManager::DELETED_USER);
  405. }
  406. // actor info is gone from DB, but when database interaction is alright,
  407. // we still expect to get true back
  408. $wasSuccessful = $manager->deleteReferencesOfActor('users', 'alice');
  409. $this->assertTrue($wasSuccessful);
  410. }
  411. public function testDeleteReferencesOfActorWithUserManagement() {
  412. $user = \OC::$server->getUserManager()->createUser('xenia', '123456');
  413. $this->assertTrue($user instanceof \OCP\IUser);
  414. $manager = \OC::$server->getCommentsManager();
  415. $comment = $manager->create('users', $user->getUID(), 'files', 'file64');
  416. $comment
  417. ->setMessage('Most important comment I ever left on the Internet.')
  418. ->setVerb('comment');
  419. $status = $manager->save($comment);
  420. $this->assertTrue($status);
  421. $commentID = $comment->getId();
  422. $user->delete();
  423. $comment = $manager->get($commentID);
  424. $this->assertSame($comment->getActorType(), \OCP\Comments\ICommentsManager::DELETED_USER);
  425. $this->assertSame($comment->getActorId(), \OCP\Comments\ICommentsManager::DELETED_USER);
  426. }
  427. public function invalidObjectArgsProvider() {
  428. return
  429. [
  430. ['', ''],
  431. [1, 'file64'],
  432. ['files', 1],
  433. ];
  434. }
  435. /**
  436. * @dataProvider invalidObjectArgsProvider
  437. * @expectedException \InvalidArgumentException
  438. */
  439. public function testDeleteCommentsAtObjectInvalidInput($type, $id) {
  440. $manager = $this->getManager();
  441. $manager->deleteCommentsAtObject($type, $id);
  442. }
  443. public function testDeleteCommentsAtObject() {
  444. $ids = [];
  445. $ids[] = $this->addDatabaseEntry(0, 0);
  446. $ids[] = $this->addDatabaseEntry(0, 0);
  447. $ids[] = $this->addDatabaseEntry(0, 0);
  448. $manager = $this->getManager();
  449. // just to make sure they are really set, with correct actor data
  450. $comment = $manager->get(strval($ids[1]));
  451. $this->assertSame($comment->getObjectType(), 'files');
  452. $this->assertSame($comment->getObjectId(), 'file64');
  453. $wasSuccessful = $manager->deleteCommentsAtObject('files', 'file64');
  454. $this->assertTrue($wasSuccessful);
  455. $verified = 0;
  456. foreach($ids as $id) {
  457. try {
  458. $manager->get(strval($id));
  459. } catch (\OCP\Comments\NotFoundException $e) {
  460. $verified++;
  461. }
  462. }
  463. $this->assertSame($verified, 3);
  464. // actor info is gone from DB, but when database interaction is alright,
  465. // we still expect to get true back
  466. $wasSuccessful = $manager->deleteCommentsAtObject('files', 'file64');
  467. $this->assertTrue($wasSuccessful);
  468. }
  469. public function testSetMarkRead() {
  470. $user = $this->createMock(IUser::class);
  471. $user->expects($this->any())
  472. ->method('getUID')
  473. ->will($this->returnValue('alice'));
  474. $dateTimeSet = new \DateTime();
  475. $manager = $this->getManager();
  476. $manager->setReadMark('robot', '36', $dateTimeSet, $user);
  477. $dateTimeGet = $manager->getReadMark('robot', '36', $user);
  478. $this->assertEquals($dateTimeGet, $dateTimeSet);
  479. }
  480. public function testSetMarkReadUpdate() {
  481. $user = $this->createMock(IUser::class);
  482. $user->expects($this->any())
  483. ->method('getUID')
  484. ->will($this->returnValue('alice'));
  485. $dateTimeSet = new \DateTime('yesterday');
  486. $manager = $this->getManager();
  487. $manager->setReadMark('robot', '36', $dateTimeSet, $user);
  488. $dateTimeSet = new \DateTime('today');
  489. $manager->setReadMark('robot', '36', $dateTimeSet, $user);
  490. $dateTimeGet = $manager->getReadMark('robot', '36', $user);
  491. $this->assertEquals($dateTimeGet, $dateTimeSet);
  492. }
  493. public function testReadMarkDeleteUser() {
  494. $user = $this->createMock(IUser::class);
  495. $user->expects($this->any())
  496. ->method('getUID')
  497. ->will($this->returnValue('alice'));
  498. $dateTimeSet = new \DateTime();
  499. $manager = $this->getManager();
  500. $manager->setReadMark('robot', '36', $dateTimeSet, $user);
  501. $manager->deleteReadMarksFromUser($user);
  502. $dateTimeGet = $manager->getReadMark('robot', '36', $user);
  503. $this->assertNull($dateTimeGet);
  504. }
  505. public function testReadMarkDeleteObject() {
  506. $user = $this->createMock(IUser::class);
  507. $user->expects($this->any())
  508. ->method('getUID')
  509. ->will($this->returnValue('alice'));
  510. $dateTimeSet = new \DateTime();
  511. $manager = $this->getManager();
  512. $manager->setReadMark('robot', '36', $dateTimeSet, $user);
  513. $manager->deleteReadMarksOnObject('robot', '36');
  514. $dateTimeGet = $manager->getReadMark('robot', '36', $user);
  515. $this->assertNull($dateTimeGet);
  516. }
  517. }