summaryrefslogtreecommitdiffstats
path: root/tests/unit/utility
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-04-10 19:15:31 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-04-10 19:15:31 +0200
commit5befce51ef9f38609b713cfbc6095a3b60b1d574 (patch)
tree0bbe540c109afa83086ed7ad43adb8a215e54633 /tests/unit/utility
parentdb545b430a513e7fda3fba5859972b6c550958b5 (diff)
add proxy support based on simplepie pr, fix #491
Diffstat (limited to 'tests/unit/utility')
-rw-r--r--tests/unit/utility/ConfigTest.php8
-rw-r--r--tests/unit/utility/FaviconFetcherTest.php102
2 files changed, 105 insertions, 5 deletions
diff --git a/tests/unit/utility/ConfigTest.php b/tests/unit/utility/ConfigTest.php
index d3f91b975..9cea0acf0 100644
--- a/tests/unit/utility/ConfigTest.php
+++ b/tests/unit/utility/ConfigTest.php
@@ -57,7 +57,7 @@ class ConfigFetcherTest extends \OCA\News\Utility\TestUtility {
$this->assertEquals(true, $this->config->getUseCronUpdates());
$this->assertEquals(8080, $this->config->getProxyPort());
$this->assertEquals('', $this->config->getProxyHost());
- $this->assertEquals('', $this->config->getProxyPassword());
+ $this->assertEquals('', $this->config->getProxyAuth());
}
@@ -124,11 +124,11 @@ class ConfigFetcherTest extends \OCA\News\Utility\TestUtility {
"useCronUpdates = true\n" .
"proxyHost = yo man\n" .
"proxyPort = 12\n" .
- "proxyPassword = this is a test";
+ "proxyAuth = this is a test";
$this->config->setAutoPurgeCount(3);
$this->config->setProxyHost("yo man");
$this->config->setProxyPort(12);
- $this->config->setProxyPassword("this is a test");
+ $this->config->setProxyAuth("this is a test");
$this->fileSystem->expects($this->once())
->method('file_put_contents')
@@ -154,7 +154,7 @@ class ConfigFetcherTest extends \OCA\News\Utility\TestUtility {
"useCronUpdates = false\n" .
"proxyHost = \n" .
"proxyPort = 8080\n" .
- "proxyPassword = ";
+ "proxyAuth = ";
$this->fileSystem->expects($this->once())
->method('file_put_contents')
diff --git a/tests/unit/utility/FaviconFetcherTest.php b/tests/unit/utility/FaviconFetcherTest.php
index 4f11c49e1..875fcf11d 100644
--- a/tests/unit/utility/FaviconFetcherTest.php
+++ b/tests/unit/utility/FaviconFetcherTest.php
@@ -33,14 +33,33 @@ class FaviconFetcherTest extends \PHPUnit_Framework_TestCase {
private $fetcher;
private $fileFactory;
private $png;
+ private $proxyHost;
+ private $proxyPort;
+ private $proxyAuth;
protected function setUp(){
$this->png = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
+ $this->proxyHost = 'test';
+ $this->proxyPort = 3;
+ $this->proxyAuth = 'hi';
$this->fileFactory = $this->getMockBuilder(
'\OCA\News\Utility\SimplePieAPIFactory')
->disableOriginalConstructor()
->getMock();
- $this->fetcher = new FaviconFetcher($this->fileFactory);
+ $this->config = $this->getMockBuilder(
+ '\OCA\News\Utility\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->fetcher = new FaviconFetcher($this->fileFactory, $this->config);
}
@@ -78,6 +97,87 @@ class FaviconFetcherTest extends \PHPUnit_Framework_TestCase {
}
+ public function testProxySettingsAreUsed() {
+ $this->config = $this->getMockBuilder(
+ '\OCA\News\Utility\Config')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->config->expects($this->any())
+ ->method('getProxyHost')
+ ->will($this->returnValue($this->proxyHost));
+ $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->fetcher = new FaviconFetcher($this->fileFactory, $this->config);
+
+ $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(null),
+ $this->equalTo(false),
+ $this->equalTo($this->proxyHost),
+ $this->equalTo($this->proxyPort),
+ $this->equalTo($this->proxyAuth))
+ ->will($this->returnValue($pngMock));
+
+ $favicon = $this->fetcher->fetch($url);
+
+ $this->assertEquals('http://google.com/owncloud/core/img/favicon.png', $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(null),
+ $this->equalTo(false),
+ $this->equalTo(null),
+ $this->equalTo(null),
+ $this->equalTo(null))
+ ->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);