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 = '
-
-
-
- ';
- $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 = '
-
-
-
- ';
- $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('',
- $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('', $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 = '
+
+
+
+ ';
+ $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 = '
+
+
+
+ ';
+ $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('',
+ $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 = '
+
+
+
+