diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-08-28 19:19:28 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-08-28 19:19:28 +0200 |
commit | 2f67340e551b12dce8824381c3291bb2137857cb (patch) | |
tree | 2342cb35b5b337e083bb2fdc866a3d10d92f99c7 /tests/unit/utility/articleenhancer/EnhancerTest.php | |
parent | a9eb72911b6f022da645dc08cf8c0f4b1702d1e1 (diff) |
Possible backwards incompatible change by using the link provided by simplepie instead of the user for the url hash. This prevents duplication of the feed when adding a slightly different feed url which points to the same feed and allows a speedup from O(n) to O(1) for article enhanchers
Diffstat (limited to 'tests/unit/utility/articleenhancer/EnhancerTest.php')
-rw-r--r-- | tests/unit/utility/articleenhancer/EnhancerTest.php | 78 |
1 files changed, 30 insertions, 48 deletions
diff --git a/tests/unit/utility/articleenhancer/EnhancerTest.php b/tests/unit/utility/articleenhancer/EnhancerTest.php index 559722e60..769538740 100644 --- a/tests/unit/utility/articleenhancer/EnhancerTest.php +++ b/tests/unit/utility/articleenhancer/EnhancerTest.php @@ -42,67 +42,49 @@ class EnhancerTest extends \OCA\AppFramework\Utility\TestUtility { '\OCA\News\Utility\ArticleEnhancer\ArticleEnhancer') ->disableOriginalConstructor() ->getMock(); - $this->articleEnhancer2 = $this->getMockBuilder( - '\OCA\News\Utility\ArticleEnhancer\ArticleEnhancer') - ->disableOriginalConstructor() - ->getMock(); + $this->enhancer->registerEnhancer('test.com', $this->articleEnhancer); } - public function testFetch(){ + public function testEnhanceSetsCorrectHash(){ $item = new Item(); $item->setUrl('hi'); + $urls = array( + '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++) { + $url = $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); + } - $this->articleEnhancer->expects($this->once()) - ->method('canHandle') - ->with($this->equalTo($item)) - ->will($this->returnValue(true)); - $this->enhancer->registerEnhancer($this->articleEnhancer); - - $this->enhancer->enhance($item); } - public function testMultipleFetchers(){ + public function testNotMatchShouldJustReturnItem() { $item = new Item(); $item->setUrl('hi'); - $this->articleEnhancer->expects($this->once()) - ->method('canHandle') - ->with($this->equalTo($item)) - ->will($this->returnValue(false)); - $this->articleEnhancer2->expects($this->once()) - ->method('canHandle') - ->with($this->equalTo($item)) - ->will($this->returnValue(true)); - - $this->enhancer->registerEnhancer($this->articleEnhancer); - $this->enhancer->registerEnhancer($this->articleEnhancer2); - - $this->enhancer->enhance($item); - } + $url = 'https://tests.com'; + $this->articleEnhancer->expects($this->never()) + ->method('enhance'); - public function testMultipleFetchersOnlyOneShouldHandle(){ - $item = new Item(); - $item->setUrl('hi'); - $return = 'zeas'; - $this->articleEnhancer->expects($this->once()) - ->method('canHandle') - ->with($this->equalTo($item)) - ->will($this->returnValue(true)); - $this->articleEnhancer->expects($this->once()) - ->method('enhance') - ->with($this->equalTo($item)) - ->will($this->returnValue($return)); - $this->articleEnhancer2->expects($this->never()) - ->method('canHandle'); - - $this->enhancer->registerEnhancer($this->articleEnhancer); - $this->enhancer->registerEnhancer($this->articleEnhancer2); - - $result = $this->enhancer->enhance($item); - - $this->assertEquals($return, $result); + $result = $this->enhancer->enhance($item, $url); + $this->assertEquals($item, $result); + } |