From 42d69a95f3276a2d6089ca68f635c4e2f6aa7a23 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 21 Oct 2014 16:45:36 +0200 Subject: convert tabs indention to indention with 4 spaces because of mixing of both variants in code and better readability on github and websites because you cant set the indention width there and 8 spaces will be used for a tab --- tests/classloader.php | 26 +- tests/unit/articleenhancer/EnhancerTest.php | 150 +-- .../articleenhancer/GlobalArticleEnhancerTest.php | 72 +- .../articleenhancer/RegexArticleEnhancerTest.php | 22 +- .../articleenhancer/XPathArticleEnhancerTest.php | 610 ++++----- tests/unit/config/AppConfigTest.php | 340 ++--- tests/unit/config/ConfigTest.php | 350 ++--- tests/unit/controller/ExportControllerTest.php | 200 +-- tests/unit/controller/FeedApiControllerTest.php | 576 ++++---- tests/unit/controller/FeedControllerTest.php | 778 +++++------ tests/unit/controller/FolderApiControllerTest.php | 332 ++--- tests/unit/controller/FolderControllerTest.php | 422 +++--- tests/unit/controller/ItemApiControllerTest.php | 674 +++++----- tests/unit/controller/ItemControllerTest.php | 620 ++++----- tests/unit/controller/PageControllerTest.php | 234 ++-- tests/unit/controller/UtilityApiControllerTest.php | 84 +- tests/unit/db/FeedMapperTest.php | 614 ++++----- tests/unit/db/FeedTest.php | 142 +- tests/unit/db/FolderMapperTest.php | 238 ++-- tests/unit/db/FolderTest.php | 60 +- tests/unit/db/ItemMapperTest.php | 768 +++++------ tests/unit/db/ItemTest.php | 514 ++++---- tests/unit/db/MapperFactoryTest.php | 38 +- tests/unit/db/postgres/ItemMapperTest.php | 146 +-- tests/unit/fetcher/FeedFetcherTest.php | 874 ++++++------ tests/unit/fetcher/FetcherTest.php | 194 +-- tests/unit/http/TextDownloadResponseTest.php | 12 +- tests/unit/http/TextResponseTest.php | 30 +- tests/unit/service/FeedServiceTest.php | 1386 ++++++++++---------- tests/unit/service/FolderServiceTest.php | 444 +++---- tests/unit/service/ItemServiceTest.php | 696 +++++----- tests/unit/service/ServiceTest.php | 98 +- tests/unit/service/StatusFlagTest.php | 48 +- tests/unit/utility/FaviconFetcherTest.php | 256 ++-- tests/unit/utility/OPMLExporterTest.php | 172 +-- tests/unit/utility/SimplePieAPIFactoryTest.php | 24 +- tests/unit/utility/UpdaterTest.php | 86 +- 37 files changed, 6165 insertions(+), 6165 deletions(-) (limited to 'tests') diff --git a/tests/classloader.php b/tests/classloader.php index c7a8b9f4d..c660057df 100644 --- a/tests/classloader.php +++ b/tests/classloader.php @@ -18,20 +18,20 @@ require_once __DIR__ . '/../../../tests/lib/appframework/db/mappertestutility.ph // to execute without owncloud, we need to create our own classloader spl_autoload_register(function ($className){ - if (strpos($className, 'OCA\\') === 0) { + if (strpos($className, 'OCA\\') === 0) { - $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); - $relPath = __DIR__ . '/../..' . $path; + $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); + $relPath = __DIR__ . '/../..' . $path; - if(file_exists($relPath)){ - require_once $relPath; - } - } else if(strpos($className, 'OCP\\') === 0) { - $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); - $relPath = __DIR__ . '/../../../lib/public' . $path; + if(file_exists($relPath)){ + require_once $relPath; + } + } else if(strpos($className, 'OCP\\') === 0) { + $path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php'); + $relPath = __DIR__ . '/../../../lib/public' . $path; - if(file_exists($relPath)){ - require_once $relPath; - } - } + if(file_exists($relPath)){ + require_once $relPath; + } + } }); \ No newline at end of file diff --git a/tests/unit/articleenhancer/EnhancerTest.php b/tests/unit/articleenhancer/EnhancerTest.php index 49222a34d..d25b20dc7 100644 --- a/tests/unit/articleenhancer/EnhancerTest.php +++ b/tests/unit/articleenhancer/EnhancerTest.php @@ -17,85 +17,85 @@ use \OCA\News\Db\Item; class AddEnhancer implements ArticleEnhancer { - public function enhance(Item $item) { - $body = $item->getBody(); - $item->setBody($body += 1); - return $item; - } + public function enhance(Item $item) { + $body = $item->getBody(); + $item->setBody($body += 1); + return $item; + } } class EnhancerTest extends \PHPUnit_Framework_TestCase { - private $enhancer; - private $articleEnhancer; - private $articleEnhancer2; - - protected function setUp(){ - $this->enhancer = new Enhancer(); - $this->articleEnhancer = $this->getMockBuilder( - '\OCA\News\ArticleEnhancer\ArticleEnhancer') - ->disableOriginalConstructor() - ->getMock(); - $this->enhancer->registerEnhancer('test.com', $this->articleEnhancer); - } - - - public function testEnhanceSetsCorrectHash(){ - $item = new Item(); - $item->setUrl('hi'); - $urls = [ - 'https://test.com', - 'https://www.test.com', - 'https://test.com/', - 'http://test.com', - 'http://test.com/', - 'http://www.test.com' - ]; - for ($i=0; $i < count($urls); $i++) { - $this->articleEnhancer->expects($this->at($i)) - ->method('enhance') - ->with($this->equalTo($item)) - ->will($this->returnValue($item)); - } - - for ($i=0; $i < count($urls); $i++) { - $url = $urls[$i]; - $result = $this->enhancer->enhance($item, $url); - $this->assertEquals($item, $result); - } - - } - - - 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 testGlobalEnhancer() { - $this->enhancer->registerGlobalEnhancer( - new AddEnhancer() - ); - - $this->enhancer->registerGlobalEnhancer( - new AddEnhancer() - ); - - $item = new Item(); - $item->setBody(1); - - $result = $this->enhancer->enhance($item, 'test'); - - $this->assertEquals(3, $result->getBody()); - } + private $enhancer; + private $articleEnhancer; + private $articleEnhancer2; + + protected function setUp(){ + $this->enhancer = new Enhancer(); + $this->articleEnhancer = $this->getMockBuilder( + '\OCA\News\ArticleEnhancer\ArticleEnhancer') + ->disableOriginalConstructor() + ->getMock(); + $this->enhancer->registerEnhancer('test.com', $this->articleEnhancer); + } + + + public function testEnhanceSetsCorrectHash(){ + $item = new Item(); + $item->setUrl('hi'); + $urls = [ + 'https://test.com', + 'https://www.test.com', + 'https://test.com/', + 'http://test.com', + 'http://test.com/', + 'http://www.test.com' + ]; + for ($i=0; $i < count($urls); $i++) { + $this->articleEnhancer->expects($this->at($i)) + ->method('enhance') + ->with($this->equalTo($item)) + ->will($this->returnValue($item)); + } + + for ($i=0; $i < count($urls); $i++) { + $url = $urls[$i]; + $result = $this->enhancer->enhance($item, $url); + $this->assertEquals($item, $result); + } + + } + + + 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 testGlobalEnhancer() { + $this->enhancer->registerGlobalEnhancer( + new AddEnhancer() + ); + + $this->enhancer->registerGlobalEnhancer( + new AddEnhancer() + ); + + $item = new Item(); + $item->setBody(1); + + $result = $this->enhancer->enhance($item, 'test'); + + $this->assertEquals(3, $result->getBody()); + } } \ No newline at end of file diff --git a/tests/unit/articleenhancer/GlobalArticleEnhancerTest.php b/tests/unit/articleenhancer/GlobalArticleEnhancerTest.php index 84c55ad9d..3add03eb5 100644 --- a/tests/unit/articleenhancer/GlobalArticleEnhancerTest.php +++ b/tests/unit/articleenhancer/GlobalArticleEnhancerTest.php @@ -18,54 +18,54 @@ use \OCA\News\Db\Item; class GlobalArticleEnhancerTest extends \PHPUnit_Framework_TestCase { - private $enhancer; + private $enhancer; - protected function setUp() { - $this->enhancer = new GlobalArticleEnhancer(); - } + protected function setUp() { + $this->enhancer = new GlobalArticleEnhancer(); + } - public function testNoReplaceYoutubeAutoplay() { - $body = ''; - $expected = '
'; - $item = new Item(); - $item->setBody($body); + public function testNoReplaceYoutubeAutoplay() { + $body = ''; + $expected = '
'; + $item = new Item(); + $item->setBody($body); - $result = $this->enhancer->enhance($item); - $this->assertEquals($expected, $result->getBody()); - } + $result = $this->enhancer->enhance($item); + $this->assertEquals($expected, $result->getBody()); + } - public function testReplaceYoutubeAutoplay() { - $body = 'test '; - $expected = '
test
'; - $item = new Item(); - $item->setBody($body); + public function testReplaceYoutubeAutoplay() { + $body = 'test '; + $expected = '
test
'; + $item = new Item(); + $item->setBody($body); - $result = $this->enhancer->enhance($item); - $this->assertEquals($expected, $result->getBody()); - } + $result = $this->enhancer->enhance($item); + $this->assertEquals($expected, $result->getBody()); + } - public function testMultipleParagraphs() { - $body = '

paragraph 1

paragraph 2

'; - $expected = '
' . $body . '
'; - $item = new Item(); - $item->setBody($body); + public function testMultipleParagraphs() { + $body = '

paragraph 1

paragraph 2

'; + $expected = '
' . $body . '
'; + $item = new Item(); + $item->setBody($body); - $result = $this->enhancer->enhance($item); - $this->assertEquals($expected, $result->getBody()); - } + $result = $this->enhancer->enhance($item); + $this->assertEquals($expected, $result->getBody()); + } - public function testMultipleParagraphsInDiv() { - $body = '

paragraph 1

paragraph 2

'; - $expected = '
' . $body . '
'; - $item = new Item(); - $item->setBody($body); + public function testMultipleParagraphsInDiv() { + $body = '

paragraph 1

paragraph 2

'; + $expected = '
' . $body . '
'; + $item = new Item(); + $item->setBody($body); - $result = $this->enhancer->enhance($item); - $this->assertEquals($expected, $result->getBody()); - } + $result = $this->enhancer->enhance($item); + $this->assertEquals($expected, $result->getBody()); + } } diff --git a/tests/unit/articleenhancer/RegexArticleEnhancerTest.php b/tests/unit/articleenhancer/RegexArticleEnhancerTest.php index a08371f47..018a596fa 100644 --- a/tests/unit/articleenhancer/RegexArticleEnhancerTest.php +++ b/tests/unit/articleenhancer/RegexArticleEnhancerTest.php @@ -19,17 +19,17 @@ use \OCA\News\Db\Item; class RegexArticleEnhancerTest extends \PHPUnit_Framework_TestCase { - 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()); - } + 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()); + } } \ No newline at end of file diff --git a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php index 082a2030c..0d4130e9e 100644 --- a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php +++ b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php @@ -18,310 +18,310 @@ use \OCA\News\Db\Item; class XPathArticleEnhancerTest extends \PHPUnit_Framework_TestCase { - private $testEnhancer; - private $fileFactory; - private $timeout; - private $redirects; - private $headers; - private $userAgent; - private $proxyHost; - private $proxyPort; - private $proxyAuth; - - protected function setUp() { - $this->timeout = 30; - $this->fileFactory = $this->getMockBuilder('\OCA\News\Utility\SimplePieAPIFactory') - ->disableOriginalConstructor() - ->getMock(); - $this->proxyHost = 'test'; - $this->proxyPort = 3; - $this->proxyAuth = 'hi'; - $this->config = $this->getMockBuilder( - '\OCA\News\Config\Config') - ->disableOriginalConstructor() - ->getMock(); - $this->config->expects($this->any()) - ->method('getProxyHost') - ->will($this->returnValue('')); - $this->config->expects($this->any()) - ->method('getProxyAuth') - ->will($this->returnValue($this->proxyAuth)); - $this->config->expects($this->any()) - ->method('getProxyPort') - ->will($this->returnValue($this->proxyPort)); - $this->config->expects($this->any()) - ->method('getFeedFetcherTimeout') - ->will($this->returnValue($this->timeout)); - - $this->testEnhancer = new XPathArticleEnhancer( - $this->fileFactory, - [ - '/explosm.net\/comics/' => '//*[@id=\'maincontent\']/div[2]/div/span', - '/explosm.net\/shorts/' => '//*[@id=\'maincontent\']/div/div', - '/explosm.net\/all/' => '//body/*', - '/themerepublic.net/' => '//*[@class=\'post hentry\']' - ], - $this->config - ); - $this->redirects = 5; - $this->headers = null; - $this->userAgent = 'Mozilla/5.0 AppleWebKit'; - } - - - public function testXPathUsesNoProxy() { - $file = new \stdClass; - $file->headers = ["content-type"=>"text/html; charset=utf-8"]; - $file->body = ''; - $item = new Item(); - $item->setUrl('https://www.explosm.net/comics/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), - $this->equalTo(false)) - ->will($this->returnValue($file)); - - $result = $this->testEnhancer->enhance($item); - $this->assertEquals('Hello thar', $result->getBody()); - } - - - public function testDoesNotModifiyNotMatchingResults() { - $item = new Item(); - $item->setUrl('http://explosm.net'); - $this->assertEquals($item, $this->testEnhancer->enhance($item)); - } - - - public function testDoesModifiyArticlesThatMatch() { - $file = new \stdClass; - $file->headers = ["content-type"=>"text/html; charset=utf-8"]; - $file->body = ' - -
-
nooo
-
hiho
-
- - '; - $item = new Item(); - $item->setUrl('https://www.explosm.net/comics/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('
hiho
', $result->getBody()); - } - - - public function testDoesModifiyAllArticlesThatMatch() { - $file = new \stdClass; - $file->headers = ["content-type"=>"text/html; charset=utf-8"]; - $file->body = ' - -
-
nooo
hiho
-
rawr
-
- - '; - $item = new Item(); - $item->setUrl('https://www.explosm.net/shorts/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('
hiho
rawr
', - $result->getBody()); - } - - - public function testModificationHandlesEmptyResults() { - $file = new \stdClass; - $file->headers = ["content-type"=>"text/html; charset=utf-8"]; - $file->body = ' - -
-
- - '; - $item = new Item(); - $item->setUrl('https://www.explosm.net/comics/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('Hello thar', $result->getBody()); - } - - - public function testModificationDoesNotBreakOnEmptyDom() { - $file = new \stdClass; - $file->headers = ["content-type"=>"text/html; charset=utf-8"]; - $file->body = ''; - $item = new Item(); - $item->setUrl('https://www.explosm.net/comics/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('Hello thar', $result->getBody()); - } - - - public function testModificationDoesNotBreakOnBrokenDom() { - $file = new \stdClass; - $file->headers = ["content-type"=>"text/html; charset=utf-8"]; - $file->body = '

- -

-
- - '; - $item = new Item(); - $item->setUrl('https://www.explosm.net/comics/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('Hello thar', $result->getBody()); - } - - - public function testTransformRelativeUrls() { - $file = new \stdClass; - $file->headers = ["content-type"=>"text/html; charset=utf-8"]; - $file->body = ' - - link - link2 - - - '; - $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('
' . - 'link' . - 'link2' . - '' . - '
', $result->getBody()); - } - - public function testTransformRelativeUrlSpecials() { - $file = new \stdClass; - $file->headers = ["content-type"=>"text/html; charset=utf-8"]; - $file->body = ' - - - - '; - $item = new Item(); - $item->setUrl('https://username:secret@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( - '
', - $result->getBody()); - } - - public function testDontTransformAbsoluteUrlsAndMails() { - $file = new \stdClass; - $file->headers = ["content-type"=>"text/html; charset=utf-8"]; - $file->body = ' - - - mail - - '; - $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( - '
' . - '' . - 'mail' . - '
', - $result->getBody() - ); - } + private $testEnhancer; + private $fileFactory; + private $timeout; + private $redirects; + private $headers; + private $userAgent; + private $proxyHost; + private $proxyPort; + private $proxyAuth; + + protected function setUp() { + $this->timeout = 30; + $this->fileFactory = $this->getMockBuilder('\OCA\News\Utility\SimplePieAPIFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->proxyHost = 'test'; + $this->proxyPort = 3; + $this->proxyAuth = 'hi'; + $this->config = $this->getMockBuilder( + '\OCA\News\Config\Config') + ->disableOriginalConstructor() + ->getMock(); + $this->config->expects($this->any()) + ->method('getProxyHost') + ->will($this->returnValue('')); + $this->config->expects($this->any()) + ->method('getProxyAuth') + ->will($this->returnValue($this->proxyAuth)); + $this->config->expects($this->any()) + ->method('getProxyPort') + ->will($this->returnValue($this->proxyPort)); + $this->config->expects($this->any()) + ->method('getFeedFetcherTimeout') + ->will($this->returnValue($this->timeout)); + + $this->testEnhancer = new XPathArticleEnhancer( + $this->fileFactory, + [ + '/explosm.net\/comics/' => '//*[@id=\'maincontent\']/div[2]/div/span', + '/explosm.net\/shorts/' => '//*[@id=\'maincontent\']/div/div', + '/explosm.net\/all/' => '//body/*', + '/themerepublic.net/' => '//*[@class=\'post hentry\']' + ], + $this->config + ); + $this->redirects = 5; + $this->headers = null; + $this->userAgent = 'Mozilla/5.0 AppleWebKit'; + } + + + public function testXPathUsesNoProxy() { + $file = new \stdClass; + $file->headers = ["content-type"=>"text/html; charset=utf-8"]; + $file->body = ''; + $item = new Item(); + $item->setUrl('https://www.explosm.net/comics/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), + $this->equalTo(false)) + ->will($this->returnValue($file)); + + $result = $this->testEnhancer->enhance($item); + $this->assertEquals('Hello thar', $result->getBody()); + } + + + public function testDoesNotModifiyNotMatchingResults() { + $item = new Item(); + $item->setUrl('http://explosm.net'); + $this->assertEquals($item, $this->testEnhancer->enhance($item)); + } + + + public function testDoesModifiyArticlesThatMatch() { + $file = new \stdClass; + $file->headers = ["content-type"=>"text/html; charset=utf-8"]; + $file->body = ' + +
+
nooo
+
hiho
+
+ + '; + $item = new Item(); + $item->setUrl('https://www.explosm.net/comics/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('
hiho
', $result->getBody()); + } + + + public function testDoesModifiyAllArticlesThatMatch() { + $file = new \stdClass; + $file->headers = ["content-type"=>"text/html; charset=utf-8"]; + $file->body = ' + +
+
nooo
hiho
+
rawr
+
+ + '; + $item = new Item(); + $item->setUrl('https://www.explosm.net/shorts/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('
hiho
rawr
', + $result->getBody()); + } + + + public function testModificationHandlesEmptyResults() { + $file = new \stdClass; + $file->headers = ["content-type"=>"text/html; charset=utf-8"]; + $file->body = ' + +
+
+ + '; + $item = new Item(); + $item->setUrl('https://www.explosm.net/comics/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('Hello thar', $result->getBody()); + } + + + public function testModificationDoesNotBreakOnEmptyDom() { + $file = new \stdClass; + $file->headers = ["content-type"=>"text/html; charset=utf-8"]; + $file->body = ''; + $item = new Item(); + $item->setUrl('https://www.explosm.net/comics/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('Hello thar', $result->getBody()); + } + + + public function testModificationDoesNotBreakOnBrokenDom() { + $file = new \stdClass; + $file->headers = ["content-type"=>"text/html; charset=utf-8"]; + $file->body = '

+ +

+
+ + '; + $item = new Item(); + $item->setUrl('https://www.explosm.net/comics/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('Hello thar', $result->getBody()); + } + + + public function testTransformRelativeUrls() { + $file = new \stdClass; + $file->headers = ["content-type"=>"text/html; charset=utf-8"]; + $file->body = ' + + link + link2 + + + '; + $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('
' . + 'link' . + 'link2' . + '' . + '
', $result->getBody()); + } + + public function testTransformRelativeUrlSpecials() { + $file = new \stdClass; + $file->headers = ["content-type"=>"text/html; charset=utf-8"]; + $file->body = ' + + + + '; + $item = new Item(); + $item->setUrl('https://username:secret@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( + '
', + $result->getBody()); + } + + public function testDontTransformAbsoluteUrlsAndMails() { + $file = new \stdClass; + $file->headers = ["content-type"=>"text/html; charset=utf-8"]; + $file->body = ' + + + mail + + '; + $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( + '
' . + '' . + 'mail' . + '
', + $result->getBody() + ); + } } diff --git a/tests/unit/config/AppConfigTest.php b/tests/unit/config/AppConfigTest.php index 34ab2738a..01bacbf5c 100644 --- a/tests/unit/config/AppConfigTest.php +++ b/tests/unit/config/AppConfigTest.php @@ -16,174 +16,174 @@ namespace OCA\News\Config; class AppConfigTest extends \PHPUnit_Framework_TestCase { - private $nav; - private $config; - private $url; - - public function setUp() { - $this->nav = $this->getMockBuilder('\OCP\INavigationManager') - ->disableOriginalConstructor() - ->getMock(); - $this->url = $this->getMockBuilder('\OCP\IURLGenerator') - ->disableOriginalConstructor() - ->getMock(); - $phpVersion = '5.3'; - $ownCloudVersion = '6.0.3'; - $installedExtensions = ['curl' => '4.3']; - $databaseType = 'oracle'; - - $this->config = new AppConfig($this->nav, $this->url, $phpVersion, - $ownCloudVersion, $installedExtensions, $databaseType); - } - - public function testGetId() { - $this->config->loadConfig(__DIR__ . '/../../../appinfo/app.json'); - $this->assertEquals('news', $this->config->getConfig('id')); - } - - - public function testGetConfig() { - $config = file_get_contents(__DIR__ . '/../../../appinfo/app.json'); - $config = json_decode($config, true); - $this->config->loadConfig($config); - $config['navigation'] = [ - 'id' => 'news', - 'order' => 10, - 'route' => 'news.page.index', - 'icon' => 'app.svg', - 'name' => 'News', - ]; - $this->assertEquals($config, $this->config->getConfig()); - } - - - public function testNoNavigation() { - $this->config->loadConfig([]); - - $this->nav->expects($this->never()) - ->method('add'); - } - - - public function testDefaultNavigation() { - $expected = [ - 'id' => 'news', - 'href' => 'news.page.index', - 'order' => 10, - 'icon' => 'app.svg', - 'name' => 'News' - ]; - - $this->url->expects($this->once()) - ->method('linkToRoute') - ->with($this->equalTo('news.page.index')) - ->will($this->returnValue('news.page.index')); - - $this->url->expects($this->once()) - ->method('imagePath') - ->with($this->equalTo('news'), - $this->equalTo('app.svg')) - ->will($this->returnValue('app.svg')); - - $this->nav->expects($this->once()) - ->method('add') - ->with($this->equalTo($expected)); - - $this->config->loadConfig([ - 'id' => 'news', - 'name' => 'News', - 'navigation' => [] - ]); - $this->config->registerNavigation(); - } - - - public function testCustomNavigation() { - $expected = [ - 'id' => 'abc', - 'href' => 'abc.page.index', - 'order' => 1, - 'icon' => 'test.svg', - 'name' => 'haha' - ]; - - $this->url->expects($this->once()) - ->method('linkToRoute') - ->with($this->equalTo('abc.page.index')) - ->will($this->returnValue('abc.page.index')); - - $this->url->expects($this->once()) - ->method('imagePath') - ->with($this->equalTo('abc'), - $this->equalTo('test.svg')) - ->will($this->returnValue('test.svg')); - - $this->nav->expects($this->once()) - ->method('add') - ->with($this->equalTo($expected)); - - $this->config->loadConfig([ - 'id' => 'abc', - 'name' => 'News', - 'navigation' => $expected - ]); - $this->config->registerNavigation(); - } - - - /** - * @expectedException \OCA\News\Config\DependencyException - */ - public function testPHPVersion() { - $this->config->loadConfig([ - 'dependencies' => [ - 'php' => '5.7' - ] - ]); - $this->config->testDependencies(); - } - - - /** - * @expectedException \OCA\News\Config\DependencyException - */ - public function testLibsVersion() { - $this->config->loadConfig([ - 'dependencies' => [ - 'libs' => [ - 'curl' => '>=4.3,<=4.3' - ] - ] - ]); - $this->config->testDependencies(); - } - - - /** - * @expectedException \OCA\News\Config\DependencyException - */ - public function testLibsExistence() { - $this->config->loadConfig([ - 'dependencies' => [ - 'libs' => [ - 'dope' => '>=4.3,<=4.3' - ] - ] - ]); - $this->config->testDependencies(); - } - - - - /** - * @expectedException \OCA\News\Config\DependencyException - */ - public function testSupportedDb() { - $this->config->loadConfig([ - 'dependencies' => [ - "databases" => ['pgsql', 'sqlite'] - ] - ]); - $this->config->testDependencies(); - } + private $nav; + private $config; + private $url; + + public function setUp() { + $this->nav = $this->getMockBuilder('\OCP\INavigationManager') + ->disableOriginalConstructor() + ->getMock(); + $this->url = $this->getMockBuilder('\OCP\IURLGenerator') + ->disableOriginalConstructor() + ->getMock(); + $phpVersion = '5.3'; + $ownCloudVersion = '6.0.3'; + $installedExtensions = ['curl' => '4.3']; + $databaseType = 'oracle'; + + $this->config = new AppConfig($this->nav, $this->url, $phpVersion, + $ownCloudVersion, $installedExtensions, $databaseType); + } + + public function testGetId() { + $this->config->loadConfig(__DIR__ . '/../../../appinfo/app.json'); + $this->assertEquals('news', $this->config->getConfig('id')); + } + + + public function testGetConfig() { + $config = file_get_contents(__DIR__ . '/../../../appinfo/app.json'); + $config = json_decode($config, true); + $this->config->loadConfig($config); + $config['navigation'] = [ + 'id' => 'news', + 'order' => 10, + 'route' => 'news.page.index', + 'icon' => 'app.svg', + 'name' => 'News', + ]; + $this->assertEquals($config, $this->config->getConfig()); + } + + + public function testNoNavigation() { + $this->config->loadConfig([]); + + $this->nav->expects($this->never()) + ->method('add'); + } + + + public function testDefaultNavigation() { + $expected = [ + 'id' => 'news', + 'href' => 'news.page.index', + 'order' => 10, + 'icon' => 'app.svg', + 'name' => 'News' + ]; + + $this->url->expects($this->once()) + ->method('linkToRoute') + ->with($this->equalTo('news.page.index')) + ->will($this->returnValue('news.page.index')); + + $this->url->expects($this->once()) + ->method('imagePath') + ->with($this->equalTo('news'), + $this->equalTo('app.svg')) + ->will($this->returnValue('app.svg')); + + $this->nav->expects($this->once()) + ->method('add') + ->with($this->equalTo($expected)); + + $this->config->loadConfig([ + 'id' => 'news', + 'name' => 'News', + 'navigation' => [] + ]); + $this->config->registerNavigation(); + } + + + public function testCustomNavigation() { + $expected = [ + 'id' => 'abc', + 'href' => 'abc.page.index', + 'order' => 1, + 'icon' => 'test.svg', + 'name' => 'haha' + ]; + + $this->url->expects($this->once()) + ->method('linkToRoute') + ->with($this->equalTo('abc.page.index')) + ->will($this->returnValue('abc.page.index')); + + $this->url->expects($this->once()) + ->method('imagePath') + ->with($this->equalTo('abc'), + $this->equalTo('test.svg')) + ->will($this->returnValue('test.svg')); + + $this->nav->expects($this->once()) + ->method('add') + ->with($this->equalTo($expected)); + + $this->config->loadConfig([ + 'id' => 'abc', + 'name' => 'News', + 'navigation' => $expected + ]); + $this->config->registerNavigation(); + } + + + /** + * @expectedException \OCA\News\Config\DependencyException + */ + public function testPHPVersion() { + $this->config->loadConfig([ + 'dependencies' => [ + 'php' => '5.7' + ] + ]); + $this->config->testDependencies(); + } + + + /** + * @expectedException \OCA\News\Config\DependencyException + */ + public function testLibsVersion() { + $this->config->loadConfig([ + 'dependencies' => [ + 'libs' => [ + 'curl' => '>=4.3,<=4.3' + ] + ] + ]); + $this->config->testDependencies(); + } + + + /** + * @expectedException \OCA\News\Config\DependencyException + */ + public function testLibsExistence() { + $this->config->loadConfig([ + 'dependencies' => [ + 'libs' => [ + 'dope' => '>=4.3,<=4.3' + ] + ] + ]); + $this->config->testDependencies(); + } + + + + /** + * @expectedException \OCA\News\Config\DependencyException + */ + public function testSupportedDb() { + $this->config->loadConfig([ + 'dependencies' => [ + "databases" => ['pgsql', 'sqlite'] + ] + ]); + $this->config->testDependencies(); + } } \ No newline at end of file diff --git a/tests/unit/config/ConfigTest.php b/tests/unit/config/ConfigTest.php index b03eeb325..6a2b07c71 100644 --- a/tests/unit/config/ConfigTest.php +++ b/tests/unit/config/ConfigTest.php @@ -16,200 +16,200 @@ namespace OCA\News\Config; class ConfigTest extends \PHPUnit_Framework_TestCase { - private $fileSystem; - private $config; - private $configPath; - private $loggerParams; - - public function setUp() { - $this->logger = $this->getMockBuilder( - '\OCP\ILogger') - ->disableOriginalConstructor() - ->getMock(); - $this->fileSystem = $this->getMock('FileSystem', [ - 'file_get_contents', - 'file_put_contents', - 'file_exists' - ]); - $this->loggerParams = ['hi']; - $this->config = new Config($this->fileSystem, $this->logger, $this->loggerParams); - $this->configPath = 'config.json'; - } - - - public function testDefaults() { - $this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval()); - $this->assertEquals(200, $this->config->getAutoPurgeCount()); - $this->assertEquals(30*60, $this->config->getSimplePieCacheDuration()); - $this->assertEquals(60, $this->config->getFeedFetcherTimeout()); - $this->assertEquals(true, $this->config->getUseCronUpdates()); - $this->assertEquals(8080, $this->config->getProxyPort()); - $this->assertEquals('', $this->config->getProxyHost()); - $this->assertEquals(null, $this->config->getProxyAuth()); - $this->assertEquals('', $this->config->getProxyUser()); - $this->assertEquals('', $this->config->getProxyPassword()); - } - - - public function testRead () { - $this->fileSystem->expects($this->once()) - ->method('file_get_contents') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue("autoPurgeCount = 3\nuseCronUpdates = true")); - - $this->config->read($this->configPath); - - $this->assertSame(3, $this->config->getAutoPurgeCount()); - $this->assertSame(true, $this->config->getUseCronUpdates()); - } - - - public function testReadIgnoresVeryLowPurgeInterval () { - $this->fileSystem->expects($this->once()) - ->method('file_get_contents') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue("autoPurgeMinimumInterval = 59")); - - $this->config->read($this->configPath); - - $this->assertSame(60, $this->config->getAutoPurgeMinimumInterval()); - } - - - - public function testReadBool () { - $this->fileSystem->expects($this->once()) - ->method('file_get_contents') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue("autoPurgeCount = 3\nuseCronUpdates = false")); - - $this->config->read($this->configPath); - - $this->assertSame(3, $this->config->getAutoPurgeCount()); - $this->assertSame(false, $this->config->getUseCronUpdates()); - } - - - public function testReadLogsInvalidValue() { - $this->fileSystem->expects($this->once()) - ->method('file_get_contents') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue('autoPurgeCounts = 3')); - $this->logger->expects($this->once()) - ->method('warning') - ->with($this->equalTo('Configuration value "autoPurgeCounts" ' . - 'does not exist. Ignored value.'), - $this->equalTo($this->loggerParams)); - - $this->config->read($this->configPath); - } - - - public function testReadLogsInvalidINI() { - $this->fileSystem->expects($this->once()) - ->method('file_get_contents') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue('')); - $this->logger->expects($this->once()) - ->method('warning') - ->with($this->equalTo('Configuration invalid. Ignoring values.'), - $this->equalTo($this->loggerParams)); - - $this->config->read($this->configPath); - } - - - public function testWrite () { - $json = "autoPurgeMinimumInterval = 60\n" . - "autoPurgeCount = 3\n" . - "simplePieCacheDuration = 1800\n" . - "feedFetcherTimeout = 60\n" . - "useCronUpdates = true\n" . - "proxyHost = yo man\n" . - "proxyPort = 12\n" . - "proxyUser = this is a test\n". - "proxyPassword = se"; - $this->config->setAutoPurgeCount(3); - $this->config->setProxyHost("yo man"); - $this->config->setProxyPort(12); - $this->config->setProxyUser("this is a test"); - $this->config->setProxyPassword("se"); + private $fileSystem; + private $config; + private $configPath; + private $loggerParams; + + public function setUp() { + $this->logger = $this->getMockBuilder( + '\OCP\ILogger') + ->disableOriginalConstructor() + ->getMock(); + $this->fileSystem = $this->getMock('FileSystem', [ + 'file_get_contents', + 'file_put_contents', + 'file_exists' + ]); + $this->loggerParams = ['hi']; + $this->config = new Config($this->fileSystem, $this->logger, $this->loggerParams); + $this->configPath = 'config.json'; + } + + + public function testDefaults() { + $this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval()); + $this->assertEquals(200, $this->config->getAutoPurgeCount()); + $this->assertEquals(30*60, $this->config->getSimplePieCacheDuration()); + $this->assertEquals(60, $this->config->getFeedFetcherTimeout()); + $this->assertEquals(true, $this->config->getUseCronUpdates()); + $this->assertEquals(8080, $this->config->getProxyPort()); + $this->assertEquals('', $this->config->getProxyHost()); + $this->assertEquals(null, $this->config->getProxyAuth()); + $this->assertEquals('', $this->config->getProxyUser()); + $this->assertEquals('', $this->config->getProxyPassword()); + } + + + public function testRead () { + $this->fileSystem->expects($this->once()) + ->method('file_get_contents') + ->with($this->equalTo($this->configPath)) + ->will($this->returnValue("autoPurgeCount = 3\nuseCronUpdates = true")); + + $this->config->read($this->configPath); + + $this->assertSame(3, $this->config->getAutoPurgeCount()); + $this->assertSame(true, $this->config->getUseCronUpdates()); + } + + + public function testReadIgnoresVeryLowPurgeInterval () { + $this->fileSystem->expects($this->once()) + ->method('file_get_contents') + ->with($this->equalTo($this->configPath)) + ->will($this->returnValue("autoPurgeMinimumInterval = 59")); + + $this->config->read($this->configPath); + + $this->assertSame(60, $this->config->getAutoPurgeMinimumInterval()); + } + + + + public function testReadBool () { + $this->fileSystem->expects($this->once()) + ->method('file_get_contents') + ->with($this->equalTo($this->configPath)) + ->will($this->returnValue("autoPurgeCount = 3\nuseCronUpdates = false")); + + $this->config->read($this->configPath); + + $this->assertSame(3, $this->config->getAutoPurgeCount()); + $this->assertSame(false, $this->config->getUseCronUpdates()); + } + + + public function testReadLogsInvalidValue() { + $this->fileSystem->expects($this->once()) + ->method('file_get_contents') + ->with($this->equalTo($this->configPath)) + ->will($this->returnValue('autoPurgeCounts = 3')); + $this->logger->expects($this->once()) + ->method('warning') + ->with($this->equalTo('Configuration value "autoPurgeCounts" ' . + 'does not exist. Ignored value.'), + $this->equalTo($this->loggerParams)); + + $this->config->read($this->configPath); + } + + + public function testReadLogsInvalidINI() { + $this->fileSystem->expects($this->once()) + ->method('file_get_contents') + ->with($this->equalTo($this->configPath)) + ->will($this->returnValue('')); + $this->logger->expects($this->once()) + ->method('warning') + ->with($this->equalTo('Configuration invalid. Ignoring values.'), + $this->equalTo($this->loggerParams)); + + $this->config->read($this->configPath); + } + + + public function testWrite () { + $json = "autoPurgeMinimumInterval = 60\n" . + "autoPurgeCount = 3\n" . + "simplePieCacheDuration = 1800\n" . + "feedFetcherTimeout = 60\n" . + "useCronUpdates = true\n" . + "proxyHost = yo man\n" . + "proxyPort = 12\n" . + "proxyUser = this is a test\n". + "proxyPassword = se"; + $this->config->setAutoPurgeCount(3); + $this->config->setProxyHost("yo man"); + $this->config->setProxyPort(12); + $this->config->setProxyUser("this is a test"); + $this->config->setProxyPassword("se"); - $this->fileSystem->expects($this->once()) - ->method('file_put_contents') - ->with($this->equalTo($this->configPath), - $this->equalTo($json)); + $this->fileSystem->expects($this->once()) + ->method('file_put_contents') + ->with($this->equalTo($this->configPath), + $this->equalTo($json)); - $this->config->write($this->configPath); - } + $this->config->write($this->configPath); + } - public function testNoProxyAuthReturnsNull() { - $this->assertNull($this->config->getProxyAuth()); - } + public function testNoProxyAuthReturnsNull() { + $this->assertNull($this->config->getProxyAuth()); + } - public function testReadingNonExistentConfigWillWriteDefaults() { - $this->fileSystem->expects($this->once()) - ->method('file_exists') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue(false)); + public function testReadingNonExistentConfigWillWriteDefaults() { + $this->fileSystem->expects($this->once()) + ->method('file_exists') + ->with($this->equalTo($this->configPath)) + ->will($this->returnValue(false)); - $this->config->setUseCronUpdates(false); + $this->config->setUseCronUpdates(false); - $json = "autoPurgeMinimumInterval = 60\n" . - "autoPurgeCount = 200\n" . - "simplePieCacheDuration = 1800\n" . - "feedFetcherTimeout = 60\n" . - "useCronUpdates = false\n" . - "proxyHost = \n" . - "proxyPort = 8080\n" . - "proxyUser = \n" . - "proxyPassword = "; + $json = "autoPurgeMinimumInterval = 60\n" . + "autoPurgeCount = 200\n" . + "simplePieCacheDuration = 1800\n" . + "feedFetcherTimeout = 60\n" . + "useCronUpdates = false\n" . + "proxyHost = \n" . + "proxyPort = 8080\n" . + "proxyUser = \n" . + "proxyPassword = "; - $this->fileSystem->expects($this->once()) - ->method('file_put_contents') - ->with($this->equalTo($this->configPath), - $this->equalTo($json)); + $this->fileSystem->expects($this->once()) + ->method('file_put_contents') + ->with($this->equalTo($this->configPath), + $this->equalTo($json)); - $this->config->read($this->configPath, true); - } + $this->config->read($this->configPath, true); + } - public function testEncodesUserAndPasswordInHTTPBasicAuth() { - $this->config->setProxyUser("this is a test"); - $this->config->setProxyPassword("se"); + public function testEncodesUserAndPasswordInHTTPBasicAuth() { + $this->config->setProxyUser("this is a test"); + $this->config->setProxyPassword("se"); - $this->assertEquals('this is a test:se', $this->config->getProxyAuth()); - } + $this->assertEquals('this is a test:se', $this->config->getProxyAuth()); + } - public function testNoLowMinimumAutoPurgeInterval() { - $this->config->setAutoPurgeMinimumInterval(59); - $interval = $this->config->getAutoPurgeMinimumInterval(); + public function testNoLowMinimumAutoPurgeInterval() { + $this->config->setAutoPurgeMinimumInterval(59); + $interval = $this->config->getAutoPurgeMinimumInterval(); - $this->assertSame(60, $interval); - } - - - public function testMinimumAutoPurgeInterval() { - $this->config->setAutoPurgeMinimumInterval(61); - $interval = $this->config->getAutoPurgeMinimumInterval(); + $this->assertSame(60, $interval); + } + + + public function testMinimumAutoPurgeInterval() { + $this->config->setAutoPurgeMinimumInterval(61); + $interval = $this->config->getAutoPurgeMinimumInterval(); - $this->assertSame(61, $interval); - } + $this->assertSame(61, $interval); + } - public function testCacheDuration() { - $this->config->setSimplePieCacheDuration(21); - $duration = $this->config->getSimplePieCacheDuration(); + public function testCacheDuration() { + $this->config->setSimplePieCacheDuration(21); + $duration = $this->config->getSimplePieCacheDuration(); - $this->assertSame(21, $duration); - } + $this->assertSame(21, $duration); + } - public function testFeedFetcherTimeout() { - $this->config->setFeedFetcherTimeout(2); - $timout = $this->config->getFeedFetcherTimeout(); + public function testFeedFetcherTimeout() { + $this->config->setFeedFetcherTimeout(2); + $timout = $this->config->getFeedFetcherTimeout(); - $this->assertSame(2, $timout); - } + $this->assertSame(2, $timout); + } } \ No newline at end of file diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php index 28d69c6f3..29760e6f4 100644 --- a/tests/unit/controller/ExportControllerTest.php +++ b/tests/unit/controller/ExportControllerTest.php @@ -23,105 +23,105 @@ use \OCA\News\Db\Feed; class ExportControllerTest extends \PHPUnit_Framework_TestCase { - private $appName; - private $request; - private $controller; - private $user; - private $feedService; - private $folderService; - private $itemService; - private $opmlExporter; - - /** - * Gets run before each test - */ - public function setUp(){ - $this->appName = 'news'; - $this->user = 'john'; - $this->itemService = $this->getMockBuilder( - '\OCA\News\Service\ItemService') - ->disableOriginalConstructor() - ->getMock(); - $this->feedService = $this->getMockBuilder( - '\OCA\News\Service\FeedService') - ->disableOriginalConstructor() - ->getMock(); - $this->folderService = $this->getMockBuilder( - '\OCA\News\Service\FolderService') - ->disableOriginalConstructor() - ->getMock(); - $this->request = $this->getMockBuilder('\OCP\IRequest') - ->disableOriginalConstructor() - ->getMock(); - $this->opmlExporter = new OPMLExporter(); - $this->controller = new ExportController($this->appName, $this->request, - $this->folderService, $this->feedService, - $this->itemService, $this->opmlExporter, $this->user); - } - - - public function testOpmlExportNoFeeds(){ - $opml = - "\n" . - "\n" . - " \n" . - " Subscriptions\n" . - " \n" . - " \n" . - "\n"; - - $this->feedService->expects($this->once()) - ->method('findAll') - ->with($this->equalTo($this->user)) - ->will($this->returnValue([])); - $this->folderService->expects($this->once()) - ->method('findAll') - ->with($this->equalTo($this->user)) - ->will($this->returnValue([])); - - $return = $this->controller->opml(); - $this->assertTrue($return instanceof TextDownloadResponse); - $this->assertEquals($opml, $return->render()); - } - - - 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 = [$feed1, $feed2]; - - $articles = [$item1, $item2]; - - $this->feedService->expects($this->once()) - ->method('findAll') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($feeds)); - $this->itemService->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()); - } + private $appName; + private $request; + private $controller; + private $user; + private $feedService; + private $folderService; + private $itemService; + private $opmlExporter; + + /** + * Gets run before each test + */ + public function setUp(){ + $this->appName = 'news'; + $this->user = 'john'; + $this->itemService = $this->getMockBuilder( + '\OCA\News\Service\ItemService') + ->disableOriginalConstructor() + ->getMock(); + $this->feedService = $this->getMockBuilder( + '\OCA\News\Service\FeedService') + ->disableOriginalConstructor() + ->getMock(); + $this->folderService = $this->getMockBuilder( + '\OCA\News\Service\FolderService') + ->disableOriginalConstructor() + ->getMock(); + $this->request = $this->getMockBuilder('\OCP\IRequest') + ->disableOriginalConstructor() + ->getMock(); + $this->opmlExporter = new OPMLExporter(); + $this->controller = new ExportController($this->appName, $this->request, + $this->folderService, $this->feedService, + $this->itemService, $this->opmlExporter, $this->user); + } + + + public function testOpmlExportNoFeeds(){ + $opml = + "\n" . + "\n" . + " \n" . + " Subscriptions\n" . + " \n" . + " \n" . + "\n"; + + $this->feedService->expects($this->once()) + ->method('findAll') + ->with($this->equalTo($this->user)) + ->will($this->returnValue([])); + $this->folderService->expects($this->once()) + ->method('findAll') + ->with($this->equalTo($this->user)) + ->will($this->returnValue([])); + + $return = $this->controller->opml(); + $this->assertTrue($return instanceof TextDownloadResponse); + $this->assertEquals($opml, $return->render()); + } + + + 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 = [$feed1, $feed2]; + + $articles = [$item1, $item2]; + + $this->feedService->expects($this->once()) + ->method('findAll') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($feeds)); + $this->itemService->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,'