From 01cdc70f9c8fd98d2ea49bcfba9005f2797c815d Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 28 Jan 2016 22:59:48 +0100 Subject: introduce comments read marke tables, comes with user cleanup after deletion --- tests/lib/comments/fakemanager.php | 4 +++ tests/lib/comments/manager.php | 57 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/lib/comments/fakemanager.php b/tests/lib/comments/fakemanager.php index 8e513cb301a..7186529e718 100644 --- a/tests/lib/comments/fakemanager.php +++ b/tests/lib/comments/fakemanager.php @@ -34,4 +34,8 @@ class FakeManager implements \OCP\Comments\ICommentsManager { public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user) {} public function getReadMark($objectType, $objectId, \OCP\IUser $user) {} + + public function deleteReadMarksFromUser(\OCP\IUser $user) {} + + public function deleteReadMarksOnObject($objectType, $objectId) {} } diff --git a/tests/lib/comments/manager.php b/tests/lib/comments/manager.php index 2578fcc5189..a71f78f2818 100644 --- a/tests/lib/comments/manager.php +++ b/tests/lib/comments/manager.php @@ -570,11 +570,64 @@ class Test_Comments_Manager extends TestCase $dateTimeSet = new \DateTime(); $manager = $this->getManager(); - $manager->setReadMark('files', '36', $dateTimeSet, $user); + $manager->setReadMark('robot', '36', $dateTimeSet, $user); - $dateTimeGet = $manager->getReadMark('files', '36', $user); + $dateTimeGet = $manager->getReadMark('robot', '36', $user); $this->assertEquals($dateTimeGet, $dateTimeSet); } + public function testSetMarkReadUpdate() { + $user = $this->getMock('\OCP\IUser'); + $user->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('alice')); + + $dateTimeSet = new \DateTime('yesterday'); + + $manager = $this->getManager(); + $manager->setReadMark('robot', '36', $dateTimeSet, $user); + + $dateTimeSet = new \DateTime('today'); + $manager->setReadMark('robot', '36', $dateTimeSet, $user); + + $dateTimeGet = $manager->getReadMark('robot', '36', $user); + + $this->assertEquals($dateTimeGet, $dateTimeSet); + } + + public function testReadMarkDeleteUser() { + $user = $this->getMock('\OCP\IUser'); + $user->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('alice')); + + $dateTimeSet = new \DateTime(); + + $manager = $this->getManager(); + $manager->setReadMark('robot', '36', $dateTimeSet, $user); + + $manager->deleteReadMarksFromUser($user); + $dateTimeGet = $manager->getReadMark('robot', '36', $user); + + $this->assertNull($dateTimeGet); + } + + public function testReadMarkDeleteObject() { + $user = $this->getMock('\OCP\IUser'); + $user->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('alice')); + + $dateTimeSet = new \DateTime(); + + $manager = $this->getManager(); + $manager->setReadMark('robot', '36', $dateTimeSet, $user); + + $manager->deleteReadMarksOnObject('robot', '36'); + $dateTimeGet = $manager->getReadMark('robot', '36', $user); + + $this->assertNull($dateTimeGet); + } + } -- cgit v1.2.3