diff options
-rw-r--r-- | lib/Service/ShareService.php | 13 | ||||
-rw-r--r-- | 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; @@ -46,6 +47,11 @@ class ShareService protected $logger; /** + * @var IURLGenerator + */ + private $url; + + /** * @var IL10N */ private $l; @@ -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; @@ -46,6 +48,11 @@ class ShareServiceTest extends TestCase private $feedService; /** + * @var MockObject|IURLGenerator + */ + private $url; + + /** * @var MockObject|IL10N */ private $l; @@ -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) |