From 53679811da855acf9bd944a389a48399ca5d5a15 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 10 Aug 2015 20:20:30 +0200 Subject: serverside full text remove enhancers add full text client side implementation fix bugs and tests for full text feed --- .../articleenhancer/XPathArticleEnhancerTest.php | 239 --------------------- 1 file changed, 239 deletions(-) delete mode 100644 tests/unit/articleenhancer/XPathArticleEnhancerTest.php (limited to 'tests/unit/articleenhancer/XPathArticleEnhancerTest.php') diff --git a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php deleted file mode 100644 index 77c5ef2e7..000000000 --- a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php +++ /dev/null @@ -1,239 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\ArticleEnhancer; - -use \OCA\News\Db\Item; - - -class XPathArticleEnhancerTest extends \PHPUnit_Framework_TestCase { - - private $testEnhancer; - private $client; - private $clientFactory; - - protected function setUp() { - $this->timeout = 30; - $this->clientFactory = $this - ->getMockBuilder('\OCA\News\Utility\PicoFeedClientFactory') - ->disableOriginalConstructor() - ->getMock(); - $this->client = $this - ->getMockBuilder('\PicoFeed\Client\Client') - ->disableOriginalConstructor() - ->getMock(); - - $this->testEnhancer = new XPathArticleEnhancer( - $this->clientFactory, - [ - '/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->userAgent = 'Mozilla/5.0 AppleWebKit'; - } - - private function setUpFile($body, $encoding, $url) { - $this->clientFactory->expects($this->once()) - ->method('build') - ->will($this->returnValue($this->client)); - $this->client->expects($this->once()) - ->method('execute') - ->with($this->equalTo($url)); - $this->client->expects($this->once()) - ->method('setUserAgent') - ->with($this->equalTo($this->userAgent)); - $this->client->expects($this->once()) - ->method('getContent') - ->will($this->returnValue($body)); - } - - - public function testDoesNotModifiyNotMatchingResults() { - $item = new Item(); - $item->setUrl('http://explosm.net'); - $this->assertEquals($item, $this->testEnhancer->enhance($item)); - } - - - public function testDoesModifiyArticlesThatMatch() { - $encoding = 'utf-8'; - $body = ' - -
-
nooo
-
hiho
-
- - '; - $item = new Item(); - $item->setUrl('https://www.explosm.net/comics/312'); - $item->setBody('Hello thar'); - - $this->setUpFile($body, $encoding, $item->getUrl()); - - $result = $this->testEnhancer->enhance($item); - $this->assertEquals('
hiho
', $result->getBody()); - } - - - public function testDoesModifiyAllArticlesThatMatch() { - $encoding = 'utf-8'; - $body = ' - -
-
nooo
hiho
-
rawr
-
- - '; - $item = new Item(); - $item->setUrl('https://www.explosm.net/shorts/312'); - $item->setBody('Hello thar'); - - $this->setUpFile($body, $encoding, $item->getUrl()); - - $result = $this->testEnhancer->enhance($item); - $this->assertEquals('
hiho
rawr
', - $result->getBody()); - } - - - public function testModificationHandlesEmptyResults() { - $encoding = 'utf-8'; - $body = ' - -
-
- - '; - $item = new Item(); - $item->setUrl('https://www.explosm.net/comics/312'); - $item->setBody('Hello thar'); - - $this->setUpFile($body, $encoding, $item->getUrl()); - - $result = $this->testEnhancer->enhance($item); - $this->assertEquals('Hello thar', $result->getBody()); - } - - - public function testModificationDoesNotBreakOnEmptyDom() { - $encoding = 'utf-8'; - $body = ''; - $item = new Item(); - $item->setUrl('https://www.explosm.net/comics/312'); - $item->setBody('Hello thar'); - - $this->setUpFile($body, $encoding, $item->getUrl()); - - $result = $this->testEnhancer->enhance($item); - $this->assertEquals('Hello thar', $result->getBody()); - } - - - public function testModificationDoesNotBreakOnBrokenDom() { - $encoding = 'utf-8'; - $body = '

- -

-
- - '; - $item = new Item(); - $item->setUrl('https://www.explosm.net/comics/312'); - $item->setBody('Hello thar'); - - $this->setUpFile($body, $encoding, $item->getUrl()); - - $result = $this->testEnhancer->enhance($item); - $this->assertEquals('Hello thar', $result->getBody()); - } - - - public function testTransformRelativeUrls() { - $encoding = 'utf-8'; - $body = ' - - link - link2 - - - '; - $item = new Item(); - $item->setUrl('https://www.explosm.net/all/312'); - $item->setBody('Hello thar'); - - $this->setUpFile($body, $encoding, $item->getUrl()); - - $result = $this->testEnhancer->enhance($item); - $this->assertEquals('
' . - '' . - 'link' . - '' . - 'link2' . - '' . - '
', $result->getBody()); - } - - public function testTransformRelativeUrlSpecials() { - $encoding = 'utf-8'; - $body = ' - - - - '; - $item = new Item(); - $item->setUrl('https://username:secret@www.explosm.net/all/312'); - $item->setBody('Hello thar'); - - $this->setUpFile($body, $encoding, $item->getUrl()); - - $result = $this->testEnhancer->enhance($item); - $this->assertEquals( - '
', - $result->getBody()); - } - - public function testDontTransformAbsoluteUrlsAndMails() { - $encoding = 'utf-8'; - $body = ' - - - mail - - '; - $item = new Item(); - $item->setUrl('https://www.explosm.net/all/312'); - $item->setBody('Hello thar'); - - $this->setUpFile($body, $encoding, $item->getUrl()); - - $result = $this->testEnhancer->enhance($item); - $this->assertEquals( - '
' . - '' . - 'mail' . - '
', - $result->getBody() - ); - } - -} -- cgit v1.2.3