public function testPlaylistUrl() { $url = 'http://youtube.com/something/weird?a=b&list=sobo3&c=1'; $transformedUrl = 'http://gdata.youtube.com/feeds/api/playlists/sobo3'; $favicon = true; $modified = 3; $etag = 5; $feed = new Feed(); $feed->setUrl('http://google.de'); $result = [$feed, []]; $this->feedFetcher->expects($this->once())->method('fetch')->with($this->equalTo($transformedUrl), $this->equalTo($favicon), $this->equalTo($modified), $this->equalTo($etag))->will($this->returnValue($result)); $feed = $this->fetcher->fetch($url, $favicon, $modified, $etag); $this->assertEquals($url, $result[0]->getUrl()); }
public function testImportArticlesCreatesOwnFeedWhenNotFound() { $url = 'http://owncloud/args'; $feed = new Feed(); $feed->setId(3); $feed->setUserId($this->user); $feed->setUrl($url); $feed->setLink($url); $feed->setTitle('Articles without feed'); $feed->setAdded($this->time); $feed->setFolderId(0); $feed->setPreventUpdate(true); $feeds = [$feed]; $item = new Item(); $item->setFeedId(3); $item->setAuthor('john'); $item->setGuid('s'); $item->setGuidHash('s'); $item->setTitle('hey'); $item->setPubDate(333); $item->setBody('come over'); $item->setEnclosureMime('mime'); $item->setEnclosureLink('lin'); $item->setUnread(); $item->setUnstarred(); $item->setLastModified($this->time); $json = $item->toExport(['feed3' => $feed]); $json2 = $json; // believe it or not this copies stuff :D $json2['feedLink'] = 'http://test.com'; $items = [$json, $json2]; $insertFeed = new Feed(); $insertFeed->setLink('http://owncloud/nofeed'); $insertFeed->setUrl('http://owncloud/nofeed'); $insertFeed->setUserId($this->user); $insertFeed->setTitle('Articles without feed'); $insertFeed->setAdded($this->time); $insertFeed->setPreventUpdate(true); $insertFeed->setFolderId(0); $this->l10n->expects($this->once())->method('t')->will($this->returnValue('Articles without feed')); $this->feedMapper->expects($this->once())->method('findAllFromUser')->with($this->equalTo($this->user))->will($this->returnValue($feeds)); $this->feedMapper->expects($this->once())->method('insert')->with($this->equalTo($insertFeed))->will($this->returnValue($insertFeed)); $this->itemMapper->expects($this->at(0))->method('findByGuidHash')->will($this->throwException(new DoesNotExistException('yo'))); $this->purifier->expects($this->once())->method('purify')->with($this->equalTo($item->getBody()))->will($this->returnValue($item->getBody())); $this->itemMapper->expects($this->at(1))->method('insert')->with($this->equalTo($item)); $this->itemMapper->expects($this->at(2))->method('findByGuidHash')->will($this->returnValue($item)); $this->itemMapper->expects($this->at(3))->method('update')->with($this->equalTo($item)); $this->feedMapper->expects($this->once())->method('findByUrlHash')->will($this->returnValue($feed)); $result = $this->feedService->importArticles($items, $this->user); $this->assertEquals($feed, $result); }
protected function buildFeed($parsedFeed, $url, $getFavicon, $modified, $etag, $location) { $feed = new Feed(); $link = $parsedFeed->getSiteUrl(); if (!$link) { $link = $location; } // unescape content because angularjs helps against XSS $title = strip_tags($this->decodeTwice($parsedFeed->getTitle())); $feed->setTitle($title); $feed->setUrl($url); // the url used to add the feed $feed->setLocation($location); // the url where the feed was found $feed->setLink($link); // <link> attribute in the feed $feed->setLastModified($modified); $feed->setEtag($etag); $feed->setAdded($this->time->getTime()); if ($getFavicon) { $faviconFetcher = $this->faviconFactory->build(); $favicon = $faviconFetcher->find($feed->getLink()); $feed->setFaviconLink($favicon); } return $feed; }
private function createFeed($hasFavicon = false) { $this->expectFeed('getTitle', $this->feedTitle); $this->expectFeed('getSiteUrl', $this->feedLink); $feed = new Feed(); $feed->setTitle('&its a title'); $feed->setUrl($this->url); $feed->setLink($this->feedLink); $feed->setAdded($this->time); $feed->setLastModified($this->modified); $feed->setEtag($this->etag); $feed->setLocation($this->location); if ($hasFavicon) { $this->faviconFactory->expects($this->once())->method('build')->will($this->returnValue($this->faviconFetcher)); $this->faviconFetcher->expects($this->once())->method('find')->with($this->equalTo($this->feedLink))->will($this->returnValue($this->webFavicon)); $feed->setFaviconLink($this->webFavicon); } return $feed; }
public function testfromAllUsers() { $feed = new Feed(); $feed->setUrl(3); $feed->setId(1); $feed->setUserId('john'); $feeds = [$feed]; $this->feedService->expects($this->once())->method('findAllFromAllUsers')->will($this->returnValue($feeds)); $response = json_encode($this->feedAPI->fromAllUsers()); $this->assertEquals('{"feeds":[{"id":1,"userId":"john"}]}', $response); }
public function testFetchMapItemsNoGetFavicon() { $this->expectCore('get_title', $this->feedTitle); $this->expectCore('get_permalink', $this->feedLink, 2); $feed = new Feed(); $feed->setTitle('&its a title'); $feed->setUrl($this->url); $feed->setLink($this->feedLink); $feed->setAdded($this->time); $this->core->expects($this->once())->method('init')->will($this->returnValue(true)); $this->faviconFetcher->expects($this->never())->method('fetch'); $item = $this->createItem(false, true); $this->expectCore('get_items', array($this->item)); $result = $this->fetcher->fetch($this->url, false); $this->assertEquals(array($feed, array($item)), $result); }
/** * Import articles * @param array $json the array with json * @param string $userId the username * @return Feed if one had to be created for nonexistent feeds */ public function importArticles($json, $userId) { $url = 'http://owncloud/nofeed'; $urlHash = md5($url); // build assoc array for fast access $feeds = $this->findAll($userId); $feedsDict = []; foreach($feeds as $feed) { $feedsDict[$feed->getLink()] = $feed; } $createdFeed = false; // loop over all items and get the corresponding feed // if the feed does not exist, create a separate feed for them foreach ($json as $entry) { $item = Item::fromImport($entry); $item->setLastModified($this->timeFactory->getTime()); $feedLink = $entry['feedLink']; // this is not set on the item yet if(array_key_exists($feedLink, $feedsDict)) { $feed = $feedsDict[$feedLink]; $item->setFeedId($feed->getId()); } elseif(array_key_exists($url, $feedsDict)) { $feed = $feedsDict[$url]; $item->setFeedId($feed->getId()); } else { $createdFeed = true; $feed = new Feed(); $feed->setUserId($userId); $feed->setLink($url); $feed->setUrl($url); $feed->setTitle($this->l10n->t('Articles without feed')); $feed->setAdded($this->timeFactory->getTime()); $feed->setFolderId(0); $feed->setPreventUpdate(true); $feed = $this->feedMapper->insert($feed); $item->setFeedId($feed->getId()); $feedsDict[$feed->getLink()] = $feed; } try { // if item exists, copy the status $existingItem = $this->itemMapper->findByGuidHash( $item->getGuidHash(), $feed->getId(), $userId); $existingItem->setStatus($item->getStatus()); $this->itemMapper->update($existingItem); } catch(DoesNotExistException $ex){ $item->setBody($this->purifier->purify($item->getBody())); $this->itemMapper->insert($item); } } if($createdFeed) { return $this->feedMapper->findByUrlHash($urlHash, $userId); } return null; }
private function createFeed($feed) { $newFeed = new Feed(); $newFeed->setUserId($this->userId); $newFeed->setFolderId($feed['folderId']); $newFeed->setTitle($feed['title']); $newFeed->setUrl($feed['url']); $newFeed->setLocation($feed['location']); $newFeed->setFaviconLink($feed['faviconLink']); $newFeed->setAdded($feed['added']); $newFeed->setLink($feed['link']); $newFeed->setPreventUpdate($feed['preventUpdate']); $newFeed->setDeletedAt($feed['deletedAt']); $newFeed->setArticlesPerUpdate($feed['articlesPerUpdate']); $newFeed->setLastModified($feed['lastModified']); $newFeed->setEtag($feed['etag']); return $this->feedMapper->insert($newFeed); }
public function testfromAllUsers() { $feed = new Feed(); $feed->setUrl(3); $feed->setId(1); $feed->setUserId('john'); $feeds = array($feed); $this->feedBusinessLayer->expects($this->once())->method('findAllFromAllUsers')->will($this->returnValue($feeds)); $response = $this->feedAPI->fromAllUsers(); $this->assertEquals('{"feeds":[{"id":1,"userId":"john"}]}', $response->render()); }
protected function buildFeed($simplePieFeed, $url, $getFavicon) { $feed = new Feed(); // unescape content because angularjs helps against XSS $title = strip_tags($this->decodeTwice($simplePieFeed->get_title())); // if there is no title use the url if (!$title) { $title = $url; } $feed->setTitle($title); $feed->setUrl($url); $link = $simplePieFeed->get_permalink(); if (!$link) { $link = $url; } $feed->setLink($link); $feed->setAdded($this->time->getTime()); if ($getFavicon) { // use the favicon from the page first since most feeds use a weird image $favicon = $this->faviconFetcher->fetch($feed->getLink()); if (!$favicon) { $favicon = $simplePieFeed->get_image_url(); } $feed->setFaviconLink($favicon); } return $feed; }