diff options
Diffstat (limited to 'tests/unit/utility/FaviconFetcherTest.php')
-rw-r--r-- | tests/unit/utility/FaviconFetcherTest.php | 102 |
1 files changed, 101 insertions, 1 deletions
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); |