Пример #1
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);
     $item->generateSearchIndex();
     $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);
 }
Пример #2
0
 protected function buildItem($parsedItem)
 {
     $item = new Item();
     $item->setUnread();
     $item->setUrl($parsedItem->getUrl());
     $item->setGuid($parsedItem->getId());
     $item->setGuidHash($item->getGuid());
     $item->setPubDate($parsedItem->getDate()->getTimestamp());
     $item->setLastModified($this->time->getTime());
     // unescape content because angularjs helps against XSS
     $item->setTitle($this->decodeTwice($parsedItem->getTitle()));
     $item->setAuthor($this->decodeTwice($parsedItem->getAuthor()));
     // purification is done in the service layer
     $body = $parsedItem->getContent();
     $body = mb_convert_encoding($body, 'HTML-ENTITIES', mb_detect_encoding($body));
     $item->setBody($body);
     $enclosureUrl = $parsedItem->getEnclosureUrl();
     if ($enclosureUrl) {
         $enclosureType = $parsedItem->getEnclosureType();
         if (stripos($enclosureType, 'audio/') !== false || stripos($enclosureType, 'video/') !== false) {
             $item->setEnclosureMime($enclosureType);
             $item->setEnclosureLink($enclosureUrl);
         }
     }
     $item->generateSearchIndex();
     return $item;
 }
Пример #3
0
 private function createItem($enclosureType = null)
 {
     $this->expectItem('getUrl', $this->permalink);
     $this->expectItem('getTitle', $this->title);
     $this->expectItem('getId', $this->guid);
     $this->expectItem('getContent', $this->body);
     $item = new Item();
     date_default_timezone_set('America/Los_Angeles');
     $date = new \DateTime();
     $date->setTimestamp($this->pub);
     $this->expectItem('getDate', $date);
     $item->setPubDate($this->pub);
     $item->setStatus(0);
     $item->setUnread();
     $item->setUrl($this->permalink);
     $item->setTitle('my<\' title');
     $item->setGuid($this->guid);
     $item->setGuidHash($this->guid);
     $item->setBody($this->body);
     $item->setLastModified($this->time);
     $item->generateSearchIndex();
     $this->expectItem('getAuthor', $this->author);
     $item->setAuthor(html_entity_decode($this->author));
     if ($enclosureType === 'audio/ogg' || $enclosureType === 'video/ogg') {
         $this->expectItem('getEnclosureUrl', $this->enclosureLink);
         $this->expectItem('getEnclosureType', $enclosureType);
         $item->setEnclosureMime($enclosureType);
         $item->setEnclosureLink($this->enclosureLink);
     }
     return $item;
 }