summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-10-21 23:45:06 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-10-21 23:45:06 +0200
commitfb28fadcf6e71b4b797aa4241436ec3add543ba0 (patch)
tree01b2e19338badfa89be45c8a90c4b391b8cd6119 /tests
parent976cd93e3c9aef7734792ba6b53f15621c5b6c91 (diff)
get rid of faviconfetcher and use picofeed
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/config/ConfigTest.php10
-rw-r--r--tests/unit/controller/AdminControllerTest.php6
-rw-r--r--tests/unit/fetcher/FeedFetcherTest.php8
-rw-r--r--tests/unit/utility/FaviconFetcherTest.php201
4 files changed, 12 insertions, 213 deletions
diff --git a/tests/unit/config/ConfigTest.php b/tests/unit/config/ConfigTest.php
index 2032c2169..9aaac57c5 100644
--- a/tests/unit/config/ConfigTest.php
+++ b/tests/unit/config/ConfigTest.php
@@ -42,7 +42,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
public function testDefaults() {
$this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval());
$this->assertEquals(200, $this->config->getAutoPurgeCount());
- $this->assertEquals(30*60, $this->config->getSimplePieCacheDuration());
+ $this->assertEquals(30*60, $this->config->getCacheDuration());
$this->assertEquals(60, $this->config->getFeedFetcherTimeout());
$this->assertEquals(true, $this->config->getUseCronUpdates());
$this->assertEquals(8080, $this->config->getProxyPort());
@@ -128,7 +128,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
public function testWrite () {
$json = 'autoPurgeMinimumInterval = 60' . "\n" .
'autoPurgeCount = 3' . "\n" .
- 'simplePieCacheDuration = 1800' . "\n" .
+ 'cacheDuration = 1800' . "\n" .
'feedFetcherTimeout = 60' . "\n" .
'useCronUpdates = true' . "\n" .
'proxyHost = yo man' . "\n" .
@@ -165,7 +165,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
$json = 'autoPurgeMinimumInterval = 60' . "\n" .
'autoPurgeCount = 200' . "\n" .
- 'simplePieCacheDuration = 1800' . "\n" .
+ 'cacheDuration = 1800' . "\n" .
'feedFetcherTimeout = 60' . "\n" .
'useCronUpdates = false' . "\n" .
'proxyHost = ' . "\n" .
@@ -206,8 +206,8 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
}
public function testCacheDuration() {
- $this->config->setSimplePieCacheDuration(21);
- $duration = $this->config->getSimplePieCacheDuration();
+ $this->config->setCacheDuration(21);
+ $duration = $this->config->getCacheDuration();
$this->assertSame(21, $duration);
}
diff --git a/tests/unit/controller/AdminControllerTest.php b/tests/unit/controller/AdminControllerTest.php
index 61e510c24..b468823da 100644
--- a/tests/unit/controller/AdminControllerTest.php
+++ b/tests/unit/controller/AdminControllerTest.php
@@ -56,7 +56,7 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase {
->method('getAutoPurgeCount')
->will($this->returnValue($expected['autoPurgeCount']));
$this->config->expects($this->once())
- ->method('getSimplePieCacheDuration')
+ ->method('getCacheDuration')
->will($this->returnValue($expected['cacheDuration']));
$this->config->expects($this->once())
->method('getFeedFetcherTimeout')
@@ -92,7 +92,7 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase {
->method('setAutoPurgeCount')
->with($this->equalTo($expected['autoPurgeCount']));
$this->config->expects($this->once())
- ->method('setSimplePieCacheDuration')
+ ->method('setCacheDuration')
->with($this->equalTo($expected['cacheDuration']));
$this->config->expects($this->once())
->method('setFeedFetcherTimeout')
@@ -111,7 +111,7 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase {
->method('getAutoPurgeCount')
->will($this->returnValue($expected['autoPurgeCount']));
$this->config->expects($this->once())
- ->method('getSimplePieCacheDuration')
+ ->method('getCacheDuration')
->will($this->returnValue($expected['cacheDuration']));
$this->config->expects($this->once())
->method('getFeedFetcherTimeout')
diff --git a/tests/unit/fetcher/FeedFetcherTest.php b/tests/unit/fetcher/FeedFetcherTest.php
index 2d31fb18a..ff1581082 100644
--- a/tests/unit/fetcher/FeedFetcherTest.php
+++ b/tests/unit/fetcher/FeedFetcherTest.php
@@ -83,7 +83,7 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
->disableOriginalConstructor()
->getMock();
$this->faviconFetcher = $this->getMockBuilder(
- '\OCA\News\Utility\FaviconFetcher')
+ '\PicoFeed\Favicon')
->disableOriginalConstructor()
->getMock();
$this->appconfig = $this->getMockBuilder(
@@ -106,7 +106,7 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
->disableOriginalConstructor()
->getMock();
$this->config->expects($this->any())
- ->method('getSimplePieCacheDuration')
+ ->method('getCacheDuration')
->will($this->returnValue($this->cacheDuration));
$this->config->expects($this->any())
->method('getProxyHost')
@@ -317,7 +317,7 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
if($hasWebFavicon) {
$this->faviconFetcher->expects($this->once())
- ->method('fetch')
+ ->method('find')
->with($this->equalTo($this->feedLink))
->will($this->returnValue($this->webFavicon));
$feed->setFaviconLink($this->webFavicon);
@@ -425,7 +425,7 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
->will($this->returnValue(true));
$this->faviconFetcher->expects($this->once())
- ->method('fetch')
+ ->method('find')
->will($this->returnValue($this->webFavicon));
$item = $this->createItem(false, 'video/ogg');
diff --git a/tests/unit/utility/FaviconFetcherTest.php b/tests/unit/utility/FaviconFetcherTest.php
deleted file mode 100644
index 4ee823636..000000000
--- a/tests/unit/utility/FaviconFetcherTest.php
+++ /dev/null
@@ -1,201 +0,0 @@
-<?php
-/**
- * ownCloud - News
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
- */
-
-
-namespace OCA\News\Utility;
-
-
-class FaviconFetcherTest extends \PHPUnit_Framework_TestCase {
-
- private $fetcher;
- private $fileFactory;
- private $png;
-
- protected function setUp(){
- $this->png = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
- $this->fileFactory = $this->getMockBuilder(
- '\OCA\News\Utility\SimplePieAPIFactory')
- ->disableOriginalConstructor()
- ->getMock();
- $this->config = $this->getMockBuilder(
- '\OCA\News\Utility\Config')
- ->disableOriginalConstructor()
- ->getMock();
- $this->fetcher = new FaviconFetcher($this->fileFactory);
- }
-
-
- protected function getFileMock($body='') {
- $mock = $this->getMockBuilder('\SimplePie_File')
- ->disableOriginalConstructor()
- ->getMock();
- $mock->body = $body;
- return $mock;
- }
-
-
- protected function getFileMockCallback($onEqual, $returnMock) {
- $defaultMock = $this->getFileMock();
-
- return function($url) use ($onEqual, $returnMock, $defaultMock) {
- if($url === $onEqual){
- return $returnMock;
- } else {
- return $defaultMock;
- }
- };
- }
-
-
- public function testFetchNoResponseReturnsNull() {
- $mock = $this->getFileMock();
-
- $this->fileFactory->expects($this->any())
- ->method('getFile')
- ->will($this->returnValue($mock));
-
- $favicon = $this->fetcher->fetch('dfdf');
- $this->assertNull($favicon);
- }
-
-
- public function testNoProxySettingsAreUsed() {
- $faviconPath = "/owncloud/core/img/favicon.png";
- $html = $this->getFaviconHTML($faviconPath);
-
- $url = 'http://google.com';
- $pageMock = $this->getFileMock($html);
- $pngMock = $this->getFileMock($this->png);
-
- $this->fileFactory->expects($this->at(0))
- ->method('getFile')
- ->with($this->equalTo('http://google.com'))
- ->will($this->returnValue($pageMock));
-
- $this->fileFactory->expects($this->at(1))
- ->method('getFile')
- ->with($this->equalTo(
- 'http://google.com/owncloud/core/img/favicon.png'),
- $this->equalTo(10),
- $this->equalTo(5),
- $this->equalTo(null),
- $this->equalTo('Mozilla/5.0 AppleWebKit'))
- ->will($this->returnValue($pngMock));
-
- $favicon = $this->fetcher->fetch($url);
-
- $this->assertEquals('http://google.com/owncloud/core/img/favicon.png',
- $favicon);
- }
-
-
- public function testFetchFaviconFaviconDotIcoHttp(){
- $url = ' sub.google.com ';
- $mock = $this->getFileMock($this->png);
-
- $callback = $this->getFileMockCallback(
- 'http://sub.google.com/favicon.ico', $mock);
-
- $this->fileFactory->expects($this->any())
- ->method('getFile')
- ->will($this->returnCallback($callback));
-
- $favicon = $this->fetcher->fetch($url);
-
- $this->assertEquals('http://sub.google.com/favicon.ico', $favicon);
- }
-
-
- public function testFetchFaviconFaviconDotIcoHttpBaseUrl(){
- $url = 'https://google.com/sometetst/dfladsf';
- $mock = $this->getFileMock($this->png);
-
- $callback = $this->getFileMockCallback(
- 'https://google.com/favicon.ico', $mock);
-
- $this->fileFactory->expects($this->any())
- ->method('getFile')
- ->will($this->returnCallback($callback));
-
- $favicon = $this->fetcher->fetch($url);
-
- $this->assertEquals('https://google.com/favicon.ico', $favicon);
- }
-
-
- private function getFaviconHTML($faviconPath) {
- return "<html>
- <head>
- <link rel=\"shortcut icon\" href=\"$faviconPath\" />
- </head>
- <body></body>
- </html>";
- }
-
-
- public function testIconAbspathHTTP() {
- $faviconPath = "/owncloud/core/img/favicon.png";
- $html = $this->getFaviconHTML($faviconPath);
-
- $url = 'http://google.com';
- $pageMock = $this->getFileMock($html);
- $pngMock = $this->getFileMock($this->png);
-
- $this->fileFactory->expects($this->at(0))
- ->method('getFile')
- ->with($this->equalTo('http://google.com'))
- ->will($this->returnValue($pageMock));
-
- $this->fileFactory->expects($this->at(1))
- ->method('getFile')
- ->with($this->equalTo(
- 'http://google.com/owncloud/core/img/favicon.png'))
- ->will($this->returnValue($pngMock));
-
- $favicon = $this->fetcher->fetch($url);
-
- $this->assertEquals('http://google.com/owncloud/core/img/favicon.png',
- $favicon);
- }
-
-
- public function testEmptyFilePathDoesNotOpenFile() {
- $url = '';
-
- $this->fileFactory->expects($this->never())
- ->method('getFile');
-
- $this->fetcher->fetch($url);
- }
-
- public function testInvalidHostnameDoesNotOpenFile() {
- $url = "a.b_c.de";
-
- $this->fileFactory->expects($this->never())
- ->method('getFile');
-
- $this->fetcher->fetch($url);
- }
-
-
- public function testInvalidHostnameDoesNotOpenFileHttp() {
- $url = "http://a.b_c.de";
-
- $this->fileFactory->expects($this->never())
- ->method('getFile');
-
- $this->fetcher->fetch($url);
- }
-
-
-}