Пример #1
0
 public function testGetAllArticles()
 {
     $item1 = new Item();
     $item1->setFeedId(3);
     $item2 = new Item();
     $item2->setFeedId(5);
     $feed1 = new Feed();
     $feed1->setId(3);
     $feed1->setLink('http://goo');
     $feed2 = new Feed();
     $feed2->setId(5);
     $feed2->setLink('http://gee');
     $feeds = array($feed1, $feed2);
     $articles = array($item1, $item2);
     $this->feedBusinessLayer->expects($this->once())->method('findAll')->with($this->equalTo($this->user))->will($this->returnValue($feeds));
     $this->itemBusinessLayer->expects($this->once())->method('getUnreadOrStarred')->with($this->equalTo($this->user))->will($this->returnValue($articles));
     $return = $this->controller->articles();
     $headers = $return->getHeaders();
     $this->assertEquals('attachment; filename="articles.json"', $headers['Content-Disposition']);
     $this->assertEquals('[{"guid":null,"url":null,"title":null,' . '"author":null,"pubDate":null,"body":null,"enclosureMime":null,' . '"enclosureLink":null,"unread":false,"starred":false,' . '"feedLink":"http:\\/\\/goo"},{"guid":null,"url":null,"title":null,' . '"author":null,"pubDate":null,"body":null,"enclosureMime":null,' . '"enclosureLink":null,"unread":false,"starred":false,' . '"feedLink":"http:\\/\\/gee"}]', $return->render());
 }
Пример #2
0
 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);
 }
Пример #3
0
 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;
 }
Пример #4
0
 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;
 }
Пример #5
0
 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);
 }
Пример #6
0
    /**
     * 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;
    }
Пример #7
0
 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);
 }
Пример #8
0
 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;
 }