From 9e9bd24c5f865c5fc0275e39316b90a82231fca5 Mon Sep 17 00:00:00 2001 From: Marco Nassabain Date: Fri, 19 Mar 2021 20:12:53 +0100 Subject: =?UTF-8?q?=E2=9C=85=20Add=20+=20update=20sharer=20display=20name?= =?UTF-8?q?=20tests=20-=20added=20testMapSharedByDisplayNames=20-=20update?= =?UTF-8?q?d=20ItemController=20tests=20to=20expect=20call=20to=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Nassabain --- tests/Unit/Controller/ItemControllerTest.php | 42 +++++++++++++++++++++++++- tests/Unit/Service/ShareServiceTest.php | 45 ++++++++++++++++++++++++++-- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php index 0eae52a39..33488a338 100644 --- a/tests/Unit/Controller/ItemControllerTest.php +++ b/tests/Unit/Controller/ItemControllerTest.php @@ -293,6 +293,11 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, 0, false, false, []) ->will($this->returnValue($result['items'])); + $this->shareService->expects($this->once()) + ->method('mapSharedByDisplayNames') + ->with($result['items']) + ->will($this->returnValue($result['items'])); + $response = $this->controller->index(ListType::FEED, 2, 3); $this->assertEquals($result, $response); } @@ -330,6 +335,11 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, 0, false, false, []) ->will($this->returnValue($result['items'])); + $this->shareService->expects($this->once()) + ->method('mapSharedByDisplayNames') + ->with($result['items']) + ->will($this->returnValue($result['items'])); + $response = $this->controller->index(ListType::FOLDER, 2, 3); $this->assertEquals($result, $response); } @@ -367,6 +377,11 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, 0, false, []) ->will($this->returnValue($result['items'])); + $this->shareService->expects($this->once()) + ->method('mapSharedByDisplayNames') + ->with($result['items']) + ->will($this->returnValue($result['items'])); + $response = $this->controller->index(ListType::STARRED, 2, 3); $this->assertEquals($result, $response); } @@ -404,6 +419,11 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, 0, false, false, ['test', 'search']) ->will($this->returnValue($result['items'])); + $this->shareService->expects($this->once()) + ->method('mapSharedByDisplayNames') + ->with($result['items']) + ->will($this->returnValue($result['items'])); + $response = $this->controller->index(ListType::FEED, 2, 3, 0, null, null, 'test%20%20search%20'); $this->assertEquals($result, $response); } @@ -420,6 +440,11 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, 10, false, true) ->will($this->returnValue($result['items'])); + $this->shareService->expects($this->once()) + ->method('mapSharedByDisplayNames') + ->with($result['items']) + ->will($this->returnValue($result['items'])); + $this->feedService->expects($this->never()) ->method('findAllForUser'); @@ -477,6 +502,11 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, false) ->will($this->returnValue($result['items'])); + $this->shareService->expects($this->once()) + ->method('mapSharedByDisplayNames') + ->with($result['items']) + ->will($this->returnValue($result['items'])); + $response = $this->controller->newItems(ListType::FEED, 2, 3); $this->assertEquals($result, $response); } @@ -517,6 +547,11 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, false) ->will($this->returnValue($result['items'])); + $this->shareService->expects($this->once()) + ->method('mapSharedByDisplayNames') + ->with($result['items']) + ->will($this->returnValue($result['items'])); + $response = $this->controller->newItems(ListType::FOLDER, 2, 3); $this->assertEquals($result, $response); } @@ -557,6 +592,11 @@ class ItemControllerTest extends TestCase ->with('user', 6, 3) ->will($this->returnValue($result['items'])); + $this->shareService->expects($this->once()) + ->method('mapSharedByDisplayNames') + ->with($result['items']) + ->will($this->returnValue($result['items'])); + $response = $this->controller->newItems(ListType::UNREAD, 2, 3); $this->assertEquals($result, $response); } @@ -579,4 +619,4 @@ class ItemControllerTest extends TestCase } -} \ No newline at end of file +} diff --git a/tests/Unit/Service/ShareServiceTest.php b/tests/Unit/Service/ShareServiceTest.php index 9dd49484d..a3c9d81d2 100644 --- a/tests/Unit/Service/ShareServiceTest.php +++ b/tests/Unit/Service/ShareServiceTest.php @@ -27,8 +27,10 @@ use OCA\News\Db\Feed; use OCA\News\Db\Item; use OCP\IURLGenerator; +use OCP\IUserManager; use OCP\IConfig; use OCP\IL10N; +use OCP\IUser; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -51,7 +53,12 @@ class ShareServiceTest extends TestCase * @var MockObject|IURLGenerator */ private $urlGenerator; - + + /** + * @var MockObject|IUserManager + */ + private $userManager; + /** * @var MockObject|IL10N */ @@ -92,6 +99,10 @@ class ShareServiceTest extends TestCase ->getMockBuilder(IURLGenerator::class) ->disableOriginalConstructor() ->getMock(); + $this->userManager = $this + ->getMockBuilder(IUserManager::class) + ->disableOriginalConstructor() + ->getMock(); $this->l = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor() ->getMock(); @@ -102,6 +113,7 @@ class ShareServiceTest extends TestCase $this->feedService, $this->itemService, $this->urlGenerator, + $this->userManager, $this->l, $this->logger ); @@ -153,7 +165,7 @@ class ShareServiceTest extends TestCase $this->urlGenerator->expects($this->once()) ->method('getBaseUrl') ->will($this->returnValue('http://serverurl')); - + $this->feedService->expects($this->once()) ->method('findByUrl') ->with($this->recipient, $feedUrl) @@ -247,4 +259,33 @@ class ShareServiceTest extends TestCase $this->class->shareItemWithUser('sender', 1, 'recipient'); } + + + public function testMapSharedByDisplayNames() + { + $item1 = new Item(); + $item1->setTitle('Item 1') + ->setSharedBy('sender'); + $item2 = new Item(); + $item2->setTitle('Item 2') + ->setSharedBy(null); + + $items = [$item1, $item2]; + $user = $this->getMockBuilder(IUser::class) + ->getMock(); + + $this->userManager->expects($this->once()) + ->method('get') + ->with('sender') + ->will($this->returnValue($user)); + + $user->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('Mr. Sender')); + + $result = $this->class->mapSharedByDisplayNames($items); + + $this->assertEquals('Mr. Sender', $result[0]->getSharedByDisplayName()); + $this->assertEquals(null, $result[1]->getSharedByDisplayName()); + } } -- cgit v1.2.3