summaryrefslogtreecommitdiffstats
path: root/tests/unit/articleenhancer/XPathArticleEnhancerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/articleenhancer/XPathArticleEnhancerTest.php')
-rw-r--r--tests/unit/articleenhancer/XPathArticleEnhancerTest.php106
1 files changed, 103 insertions, 3 deletions
diff --git a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php
index a600d6739..dbd752518 100644
--- a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php
+++ b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php
@@ -38,17 +38,32 @@ class XPathArticleEnhancerTest extends \OCA\News\Utility\TestUtility {
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();
- $config = $this->getMockBuilder(
+ $this->proxyHost = 'test';
+ $this->proxyPort = 3;
+ $this->proxyAuth = 'hi';
+ $this->config = $this->getMockBuilder(
'\OCA\News\Utility\Config')
->disableOriginalConstructor()
->getMock();
- $config->expects($this->any())
+ $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));
@@ -60,7 +75,7 @@ class XPathArticleEnhancerTest extends \OCA\News\Utility\TestUtility {
'/explosm.net\/all/' => '//body/*',
'/themerepublic.net/' => '//*[@class=\'post hentry\']'
),
- $config
+ $this->config
);
$this->redirects = 5;
$this->headers = null;
@@ -68,6 +83,91 @@ class XPathArticleEnhancerTest extends \OCA\News\Utility\TestUtility {
}
+ public function testXPathUsesNoProxy() {
+ $file = new \stdClass;
+ $file->headers = array("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),
+ $this->equalTo(null),
+ $this->equalTo(null),
+ $this->equalTo(null))
+ ->will($this->returnValue($file));
+
+ $result = $this->testEnhancer->enhance($item);
+ $this->assertEquals('Hello thar', $result->getBody());
+ }
+
+
+ public function testXPathUsesProxy() {
+ $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->config->expects($this->any())
+ ->method('getFeedFetcherTimeout')
+ ->will($this->returnValue($this->timeout));
+
+ $this->testEnhancer = new XPathArticleEnhancer(
+ $this->fileFactory,
+ array(
+ '/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
+ );
+
+ $file = new \stdClass;
+ $file->headers = array("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->config->expects($this->any())
+ ->method('getProxyHost')
+ ->will($this->returnValue($this->proxyHost));
+
+ $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),
+ $this->equalTo($this->proxyHost),
+ $this->equalTo($this->proxyPort),
+ $this->equalTo($this->proxyAuth))
+ ->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');