From 95530f62513a82c385d9378b4a59da57d74092d9 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 5 Nov 2014 11:30:27 +0100 Subject: update picofeed, add max size setting, fix #642 --- .../articleenhancer/XPathArticleEnhancerTest.php | 2 +- tests/unit/config/ConfigTest.php | 4 + tests/unit/controller/AdminControllerTest.php | 13 ++- tests/unit/fetcher/FeedFetcherTest.php | 111 +++++++++++---------- tests/unit/service/FeedServiceTest.php | 2 - 5 files changed, 74 insertions(+), 58 deletions(-) (limited to 'tests') diff --git a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php index 33f0e75ab..e133f6e16 100644 --- a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php +++ b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php @@ -29,7 +29,7 @@ class XPathArticleEnhancerTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor() ->getMock(); $this->client = $this - ->getMockBuilder('\PicoFeed\Client') + ->getMockBuilder('\PicoFeed\Client\Client') ->disableOriginalConstructor() ->getMock(); diff --git a/tests/unit/config/ConfigTest.php b/tests/unit/config/ConfigTest.php index a2739de59..bdffeb0d1 100644 --- a/tests/unit/config/ConfigTest.php +++ b/tests/unit/config/ConfigTest.php @@ -50,6 +50,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { $this->assertEquals(null, $this->config->getProxyAuth()); $this->assertEquals('', $this->config->getProxyUser()); $this->assertEquals('', $this->config->getProxyPassword()); + $this->assertEquals(1024*1024*100, $this->config->getMaxSize()); } @@ -129,6 +130,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { $json = 'autoPurgeMinimumInterval = 60' . "\n" . 'autoPurgeCount = 3' . "\n" . 'maxRedirects = 10' . "\n" . + 'maxSize = 399' . "\n" . 'feedFetcherTimeout = 60' . "\n" . 'useCronUpdates = true'; $this->config->setAutoPurgeCount(3); @@ -136,6 +138,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { $this->config->setProxyPort(12); $this->config->setProxyUser('this is a test'); $this->config->setProxyPassword('se'); + $this->config->setMaxSize(399); $this->fileSystem->expects($this->once()) ->method('file_put_contents') @@ -162,6 +165,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { $json = 'autoPurgeMinimumInterval = 60' . "\n" . 'autoPurgeCount = 200' . "\n" . 'maxRedirects = 10' . "\n" . + 'maxSize = 104857600' . "\n" . 'feedFetcherTimeout = 60' . "\n" . 'useCronUpdates = false'; diff --git a/tests/unit/controller/AdminControllerTest.php b/tests/unit/controller/AdminControllerTest.php index 4a9bf7764..347e0a4a5 100644 --- a/tests/unit/controller/AdminControllerTest.php +++ b/tests/unit/controller/AdminControllerTest.php @@ -47,7 +47,8 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase { 'autoPurgeCount' => 2, 'maxRedirects' => 3, 'feedFetcherTimeout' => 4, - 'useCronUpdates' => 5 + 'useCronUpdates' => 5, + 'maxSize' => 7 ]; $this->config->expects($this->once()) ->method('getAutoPurgeMinimumInterval') @@ -64,6 +65,9 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase { $this->config->expects($this->once()) ->method('getUseCronUpdates') ->will($this->returnValue($expected['useCronUpdates'])); + $this->config->expects($this->once()) + ->method('getMaxSize') + ->will($this->returnValue($expected['maxSize'])); $response = $this->controller->index(); $data = $response->getParams(); @@ -82,7 +86,8 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase { 'autoPurgeCount' => 2, 'maxRedirects' => 3, 'feedFetcherTimeout' => 4, - 'useCronUpdates' => 5 + 'useCronUpdates' => 5, + 'maxSize' => 7, ]; $this->config->expects($this->once()) @@ -119,12 +124,16 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase { $this->config->expects($this->once()) ->method('getUseCronUpdates') ->will($this->returnValue($expected['useCronUpdates'])); + $this->config->expects($this->once()) + ->method('getMaxSize') + ->will($this->returnValue($expected['maxSize'])); $response = $this->controller->update( $expected['autoPurgeMinimumInterval'], $expected['autoPurgeCount'], $expected['maxRedirects'], $expected['feedFetcherTimeout'], + $expected['maxSize'], $expected['useCronUpdates'] ); diff --git a/tests/unit/fetcher/FeedFetcherTest.php b/tests/unit/fetcher/FeedFetcherTest.php index 3f837cdd8..a9e29de0c 100644 --- a/tests/unit/fetcher/FeedFetcherTest.php +++ b/tests/unit/fetcher/FeedFetcherTest.php @@ -26,10 +26,12 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { private $faviconFetcher; private $parsedFeed; private $faviconFactory; - private $readerFactory; + private $l10n; private $url; private $time; private $item; + private $content; + private $encoding; // items private $permalink; @@ -50,32 +52,32 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { private $location; protected function setUp(){ + $this->l10n = $this->getMockBuilder( + '\OCP\IL10N') + ->disableOriginalConstructor() + ->getMock(); $this->reader = $this->getMockBuilder( - '\PicoFeed\Reader') + '\PicoFeed\Reader\Reader') ->disableOriginalConstructor() ->getMock(); $this->parser = $this->getMockBuilder( - '\PicoFeed\Parser') + '\PicoFeed\Parser\Parser') ->disableOriginalConstructor() ->getMock(); $this->client = $this->getMockBuilder( - '\PicoFeed\Client') + '\PicoFeed\Client\Client') ->disableOriginalConstructor() ->getMock(); $this->parsedFeed = $this->getMockBuilder( - '\PicoFeed\Feed') + '\PicoFeed\Parser\Feed') ->disableOriginalConstructor() ->getMock(); $this->item = $this->getMockBuilder( - '\PicoFeed\Item') + '\PicoFeed\Parser\Item') ->disableOriginalConstructor() ->getMock(); $this->faviconFetcher = $this->getMockBuilder( - '\PicoFeed\Favicon') - ->disableOriginalConstructor() - ->getMock(); - $this->readerFactory = $this->getMockBuilder( - '\OCA\News\Utility\PicoFeedReaderFactory') + '\PicoFeed\Client\Favicon') ->disableOriginalConstructor() ->getMock(); $this->faviconFactory = $this->getMockBuilder( @@ -88,9 +90,11 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { $timeFactory->expects($this->any()) ->method('getTime') ->will($this->returnValue($this->time)); - $this->fetcher = new FeedFetcher($this->readerFactory, - $this->faviconFactory, - $timeFactory); + $this->fetcher = new FeedFetcher( + $this->reader, + $this->faviconFactory, + $this->l10n, + $timeFactory); $this->url = 'http://tests'; $this->permalink = 'http://permalink'; @@ -110,6 +114,8 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { $this->authorMail = 'doe@joes.com'; $this->modified = 3; $this->etag = 'yo'; + $this->content = 'some content'; + $this->encoding = 'UTF-8'; } @@ -119,51 +125,57 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->fetcher->canHandle($url)); } - private function setUpReader($url='', $modified=true, $noParser=false, - $noFeed=false) { - $this->readerFactory->expects($this->once()) - ->method('build') - ->will($this->returnValue($this->reader)); + private function setUpReader($url='', $modified=true, $noParser=false) { $this->reader->expects($this->once()) - ->method('download') + ->method('discover') ->with($this->equalTo($url)) ->will($this->returnValue($this->client)); $this->client->expects($this->once()) - ->method('getLastModified') - ->will($this->returnValue($this->modified)); - $this->client->expects($this->once()) - ->method('getEtag') - ->will($this->returnValue($this->etag)); - $this->client->expects($this->once()) - ->method('getUrl') - ->will($this->returnValue($this->location)); + ->method('isModified') + ->will($this->returnValue($modified)); if (!$modified) { $this->reader->expects($this->never()) ->method('getParser'); - } else if ($noParser) { - $this->reader->expects($this->once()) - ->method('getParser') - ->will($this->returnValue(false)); } else { - $this->reader->expects($this->once()) - ->method('getParser') - ->will($this->returnValue($this->parser)); - - if ($noFeed) { - $this->parser->expects($this->once()) - ->method('execute') - ->will($this->returnValue(false)); + $this->client->expects($this->once()) + ->method('getLastModified') + ->will($this->returnValue($this->modified)); + $this->client->expects($this->once()) + ->method('getEtag') + ->will($this->returnValue($this->etag)); + $this->client->expects($this->once()) + ->method('getUrl') + ->will($this->returnValue($this->location)); + $this->client->expects($this->once()) + ->method('getContent') + ->will($this->returnValue($this->content)); + $this->client->expects($this->once()) + ->method('getEncoding') + ->will($this->returnValue($this->encoding)); + + if ($noParser) { + $this->reader->expects($this->once()) + ->method('getParser') + ->will($this->throwException( + new \PicoFeed\Reader\SubscriptionNotFoundException() + )); } else { - $this->parser->expects($this->once()) - ->method('execute') - ->will($this->returnValue($this->parsedFeed)); + $this->reader->expects($this->once()) + ->method('getParser') + ->with( + $this->equalTo($this->location), + $this->equalTo($this->content), + $this->equalTo($this->encoding) + ) + ->will($this->returnValue($this->parser)); } + + $this->parser->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->parsedFeed)); } - $this->client->expects($this->once()) - ->method('isModified') - ->will($this->returnValue($modified)); } @@ -249,13 +261,6 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { } - public function testFetchThrowsExceptionWhenParsingFailed() { - $this->setUpReader($this->url, true, true, false); - - $this->setExpectedException('\OCA\News\Fetcher\FetcherException'); - $this->fetcher->fetch($this->url, false); - } - public function testNoFetchIfNotModified(){ $this->setUpReader($this->url, false);; $result = $this->fetcher->fetch($this->url, false); diff --git a/tests/unit/service/FeedServiceTest.php b/tests/unit/service/FeedServiceTest.php index 2b7205dba..ff00104e9 100644 --- a/tests/unit/service/FeedServiceTest.php +++ b/tests/unit/service/FeedServiceTest.php @@ -102,8 +102,6 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { public function testCreateDoesNotFindFeed(){ $ex = new FetcherException('hi'); $url = 'test'; - $this->l10n->expects($this->once()) - ->method('t'); $this->fetcher->expects($this->once()) ->method('fetch') ->with($this->equalTo($url)) -- cgit v1.2.3