public function testNotMatchShouldJustReturnItem() { $item = new Item(); $item->setUrl('hi'); $url = 'https://tests.com'; $this->articleEnhancer->expects($this->never())->method('enhance'); $result = $this->enhancer->enhance($item, $url); $this->assertEquals($item, $result); }
public function testRegexEnhancer() { $item = new Item(); $item->setBody('atests is a nice thing'); $item->setUrl('http://john.com'); $regex = ["%tes(ts)%" => "heho\$1tests"]; $regexEnhancer = new RegexArticleEnhancer('%john.com%', $regex); $item = $regexEnhancer->enhance($item); $this->assertEquals('ahehotstests is a nice thing', $item->getBody()); }
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; }
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; }
public function testDontTransformAbsoluteUrlsAndMails() { $file = new \stdClass(); $file->headers = array("content-type" => "text/html; charset=utf-8"); $file->body = '<html> <body> <img src="http://www.url.com/absolute/url.png"> <a href="mailto:test@testsite.com">mail</a> </body> </html>'; $item = new Item(); $item->setUrl('https://www.explosm.net/all/312'); $item->setBody('Hello thar'); $this->fileFactory->expects($this->once())->method('getFile')->with($this->equalTo($item->getUrl()), $this->equalTo($this->timeout), $this->equalTo($this->redirects), $this->equalTo($this->headers), $this->equalTo($this->userAgent))->will($this->returnValue($file)); $result = $this->testEnhancer->enhance($item); $this->assertEquals('<img src="http://www.url.com/absolute/url.png"><a target="_blank" href="mailto:test@testsite.com">mail</a>', $result->getBody()); }
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(); $this->expectItem('getDate', $this->pub); $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); $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; }
private function createItem($author = false, $enclosureType = null, $noPubDate = false) { $this->expectItem('get_permalink', $this->permalink); $this->expectItem('get_title', $this->title); $this->expectItem('get_id', $this->guid); $this->expectItem('get_content', $this->body); $item = new Item(); if ($noPubDate) { $this->expectItem('get_date', 0); $item->setPubDate($this->time); } else { $this->expectItem('get_date', $this->pub); $item->setPubDate($this->pub); } $item->setStatus(0); $item->setUnread(); $item->setUrl($this->permalink); $item->setTitle('my<\' title'); $item->setGuid($this->guid); $item->setGuidHash(md5($this->guid)); $item->setBody($this->body); $item->setLastModified($this->time); if ($author) { $mock = $this->getMock('author', array('get_name')); $mock->expects($this->once())->method('get_name')->will($this->returnValue($this->author)); $this->expectItem('get_author', $mock); $item->setAuthor(html_entity_decode($this->author)); } else { $mock = $this->getMock('author', array('get_name', 'get_email')); $mock->expects($this->any())->method('get_name')->will($this->returnValue('')); $mock->expects($this->any())->method('get_email')->will($this->returnValue($this->authorMail)); $this->expectItem('get_author', $mock); $item->setAuthor(html_entity_decode($this->authorMail)); } if ($enclosureType === 'audio/ogg') { $mock = $this->getMock('enclosure', array('get_type', 'get_link')); $mock->expects($this->any())->method('get_type')->will($this->returnValue($enclosureType)); $this->expectItem('get_enclosure', $this->mock); $item->setEnclosureMime($enclosureType); $item->setEnclosureLink($this->enclosureLink); } return $item; }
public function testDontTransformAbsoluteUrlsAndMails() { $encoding = 'utf-8'; $body = '<html> <body> <img src="http://www.url.com/absolute/url.png"> <a href="mailto:test@testsite.com">mail</a> </body> </html>'; $item = new Item(); $item->setUrl('https://www.explosm.net/all/312'); $item->setBody('Hello thar'); $this->setUpFile($body, $encoding, $item->getUrl()); $result = $this->testEnhancer->enhance($item); $this->assertEquals('<div>' . '<img src="http://www.url.com/absolute/url.png">' . '<a target="_blank" rel="noreferrer" href="mailto:test@testsite.com">mail</a>' . '</div>', $result->getBody()); }
private function createItem($item) { $newItem = new Item(); $newItem->setFeedId($item['feedId']); $newItem->setStatus($item['status']); $newItem->setBody($item['body']); $newItem->setTitle($item['title']); $newItem->setAuthor($item['author']); $newItem->setGuid($item['guid']); $newItem->setGuidHash($item['guid']); $newItem->setUrl($item['url']); $newItem->setPubDate($item['pubDate']); $newItem->setLastModified($item['lastModified']); $newItem->setEnclosureMime($item['enclosureMime']); $newItem->setEnclosureLink($item['enclosureLink']); return $this->itemMapper->insert($newItem); }
protected function buildItem($simplePieItem, $feedLink) { $item = new Item(); $item->setStatus(0); $item->setUnread(); $url = $this->decodeTwice($simplePieItem->get_permalink()); if (!$url) { $url = $feedLink; } $item->setUrl($url); // unescape content because angularjs helps against XSS $item->setTitle($this->decodeTwice($simplePieItem->get_title())); $guid = $simplePieItem->get_id(); $item->setGuid($guid); // purification is done in the businesslayer $item->setBody($simplePieItem->get_content()); // pubdate is not required. if not given use the current date $date = $simplePieItem->get_date('U'); if (!$date) { $date = $this->time->getTime(); } $item->setPubDate($date); $item->setLastModified($this->time->getTime()); $author = $simplePieItem->get_author(); if ($author !== null) { $name = $this->decodeTwice($author->get_name()); if ($name) { $item->setAuthor($name); } else { $item->setAuthor($this->decodeTwice($author->get_email())); } } // TODO: make it work for video files also $enclosure = $simplePieItem->get_enclosure(); if ($enclosure !== null) { $enclosureType = $enclosure->get_type(); if (stripos($enclosureType, "audio/") !== false) { $item->setEnclosureMime($enclosureType); $item->setEnclosureLink($enclosure->get_link()); } } return $item; }