From 7f3c63a2a4acea929e70a4136fea5c51e832ec16 Mon Sep 17 00:00:00 2001 From: Marco Nassabain Date: Sat, 6 Mar 2021 22:22:20 +0100 Subject: =?UTF-8?q?=F0=9F=8E=A8=20ShareService:=20update=20dummy=20feed=20?= =?UTF-8?q?URL=20-=20add=20IURLGenerator=20DI=20-=20update=20url=20to=20"h?= =?UTF-8?q?ttp://serverurl/news/sharedwithme"=20-=20updated=20tests:=20add?= =?UTF-8?q?ed=20DI=20+=20adapted=20expected=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Nassabain --- lib/Service/ShareService.php | 13 +++++++++++-- tests/Unit/Service/ShareServiceTest.php | 24 ++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index ab1183d55..e95fe673b 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -14,6 +14,7 @@ use \OCA\News\Db\Item; use \OCA\News\Db\Feed; use \Psr\Log\LoggerInterface; +use OCP\IURLGenerator; use \OCP\IL10N; use OCA\News\Service\Exceptions\ServiceNotFoundException; @@ -45,6 +46,11 @@ class ShareService */ protected $logger; + /** + * @var IURLGenerator + */ + private $url; + /** * @var IL10N */ @@ -55,17 +61,20 @@ class ShareService * * @param FeedServiceV2 $feedService Service for feeds * @param ItemServiceV2 $itemService Service to manage items - * @param IL10N $l Localization interface + * @param IURLGenerator $url URL Generator + * @param IL10N $l Localization interface * @param LoggerInterface $logger Logger */ public function __construct( FeedServiceV2 $feedService, ItemServiceV2 $itemService, + IURLGenerator $url, IL10N $l, LoggerInterface $logger ) { $this->itemService = $itemService; $this->feedService = $feedService; + $this->url = $url; $this->l = $l; $this->logger = $logger; } @@ -98,7 +107,7 @@ class ShareService $sharedItem->setSharedBy($userId); // Get 'shared with me' dummy feed - $feedUrl = 'http://nextcloud/sharedwithme'; + $feedUrl = $this->url->getBaseUrl() . '/news/sharedwithme'; $feed = $this->feedService->findByUrl($shareRecipientId, $feedUrl); if (is_null($feed)) { $feed = new Feed(); diff --git a/tests/Unit/Service/ShareServiceTest.php b/tests/Unit/Service/ShareServiceTest.php index e6fb34716..7c6e068f5 100644 --- a/tests/Unit/Service/ShareServiceTest.php +++ b/tests/Unit/Service/ShareServiceTest.php @@ -25,6 +25,8 @@ use OCA\News\Utility\Time; use OCA\News\Db\Feed; use OCA\News\Db\Item; + +use OCP\IURLGenerator; use OCP\IConfig; use OCP\IL10N; @@ -45,6 +47,11 @@ class ShareServiceTest extends TestCase */ private $feedService; + /** + * @var MockObject|IURLGenerator + */ + private $url; + /** * @var MockObject|IL10N */ @@ -81,6 +88,10 @@ class ShareServiceTest extends TestCase ->getMockBuilder(FeedServiceV2::class) ->disableOriginalConstructor() ->getMock(); + $this->url = $this + ->getMockBuilder(IURLGenerator::class) + ->disableOriginalConstructor() + ->getMock(); $this->l = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor() ->getMock(); @@ -90,6 +101,7 @@ class ShareServiceTest extends TestCase $this->class = new ShareService( $this->feedService, $this->itemService, + $this->url, $this->l, $this->logger ); @@ -100,7 +112,7 @@ class ShareServiceTest extends TestCase public function testShareItemWithUser() { - $feedUrl = 'http://nextcloud/sharedwithme'; + $feedUrl = 'http://serverurl/news/sharedwithme'; $itemId = 3; // Item to be shared @@ -138,6 +150,10 @@ class ShareServiceTest extends TestCase ->with($this->uid, $itemId) ->will($this->returnValue($item)); + $this->url->expects($this->once()) + ->method('getBaseUrl') + ->will($this->returnValue('http://serverurl')); + $this->feedService->expects($this->once()) ->method('findByUrl') ->with($this->recipient, $feedUrl) @@ -155,7 +171,7 @@ class ShareServiceTest extends TestCase public function testShareItemWithUserCreatesOwnFeedWhenNotFound() { - $feedUrl = 'http://nextcloud/sharedwithme'; + $feedUrl = 'http://serverurl/news/sharedwithme'; $itemId = 3; // Item to be shared @@ -193,6 +209,10 @@ class ShareServiceTest extends TestCase ->with($this->uid, $itemId) ->will($this->returnValue($item)); + $this->url->expects($this->once()) + ->method('getBaseUrl') + ->will($this->returnValue('http://serverurl')); + $this->feedService->expects($this->once()) ->method('findByUrl') ->with($this->recipient, $feedUrl) -- cgit v1.2.3