diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-10-21 16:45:36 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-10-21 16:45:36 +0200 |
commit | 42d69a95f3276a2d6089ca68f635c4e2f6aa7a23 (patch) | |
tree | 6a17fd7998f291e6dec1d996c1e7c724b92b8e58 /tests | |
parent | 0e6598b0734fb927109f745d9c0f3a8605a30ca5 (diff) |
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
Diffstat (limited to 'tests')
37 files changed, 6165 insertions, 6165 deletions
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 = '<iframe width="728" height="410" src="//www.youtube.com/embed/autoplay=1/AWE6UpXQoGU" frameborder="0" allowfullscreen=""></iframe>'; - $expected = '<div><iframe width="728" height="410" src="//www.youtube.com/embed/autoplay=1/AWE6UpXQoGU" frameborder="0" allowfullscreen=""></iframe></div>'; - $item = new Item(); - $item->setBody($body); + public function testNoReplaceYoutubeAutoplay() { + $body = '<iframe width="728" height="410" src="//www.youtube.com/embed/autoplay=1/AWE6UpXQoGU" frameborder="0" allowfullscreen=""></iframe>'; + $expected = '<div><iframe width="728" height="410" src="//www.youtube.com/embed/autoplay=1/AWE6UpXQoGU" frameborder="0" allowfullscreen=""></iframe></div>'; + $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 <iframe width="728" height="410" src="//www.youtube.com/embed/AWE6UpXQoGU?tst=1&autoplay=1&abc=1" frameborder="0" allowfullscreen=""></iframe>'; - $expected = '<div>test <iframe width="728" height="410" src="//www.youtube.com/embed/AWE6UpXQoGU?tst=1&autoplay=0&abc=1" frameborder="0" allowfullscreen=""></iframe></div>'; - $item = new Item(); - $item->setBody($body); + public function testReplaceYoutubeAutoplay() { + $body = 'test <iframe width="728" height="410" src="//www.youtube.com/embed/AWE6UpXQoGU?tst=1&autoplay=1&abc=1" frameborder="0" allowfullscreen=""></iframe>'; + $expected = '<div>test <iframe width="728" height="410" src="//www.youtube.com/embed/AWE6UpXQoGU?tst=1&autoplay=0&abc=1" frameborder="0" allowfullscreen=""></iframe></div>'; + $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 = '<p>paragraph 1</p><p>paragraph 2</p>'; - $expected = '<div>' . $body . '</div>'; - $item = new Item(); - $item->setBody($body); + public function testMultipleParagraphs() { + $body = '<p>paragraph 1</p><p>paragraph 2</p>'; + $expected = '<div>' . $body . '</div>'; + $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 = '<p>paragraph 1</p><p>paragraph 2</p>'; - $expected = '<div>' . $body . '</div>'; - $item = new Item(); - $item->setBody($body); + public function testMultipleParagraphsInDiv() { + $body = '<p>paragraph 1</p><p>paragraph 2</p>'; + $expected = '<div>' . $body . '</div>'; + $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 = '<html> - <body> - <div id="maincontent"> - <div>nooo</div> - <div><div><span>hiho</span></div></div> - </div> - </body> - </html>'; - $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('<div><span>hiho</span></div>', $result->getBody()); - } - - - public function testDoesModifiyAllArticlesThatMatch() { - $file = new \stdClass; - $file->headers = ["content-type"=>"text/html; charset=utf-8"]; - $file->body = '<html> - <body> - <div id="maincontent"> - <div>nooo<div>hiho</div></div> - <div><div>rawr</div></div> - </div> - </body> - </html>'; - $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('<div><div>hiho</div><div>rawr</div></div>', - $result->getBody()); - } - - - public function testModificationHandlesEmptyResults() { - $file = new \stdClass; - $file->headers = ["content-type"=>"text/html; charset=utf-8"]; - $file->body = '<html> - <body> - <div id="maincontent"> - </div> - </body> - </html>'; - $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 = '<html/><p> - <body> - <div id="maincontent"> - </div> - </body> - </html>'; - $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 = '<html> - <body> - <a href="../a/relative/url.html?a=1#b">link</a> - <a href="b/relative/url.html">link2</a> - <img src="/another/relative/link.jpg"></img> - </body> - </html>'; - $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('<div>' . - '<a target="_blank" href="https://www.explosm.net/a/relative/url.html?a=1#b">link</a>' . - '<a target="_blank" href="https://www.explosm.net/all/b/relative/url.html">link2</a>' . - '<img src="https://www.explosm.net/another/relative/link.jpg">' . - '</div>', $result->getBody()); - } - - public function testTransformRelativeUrlSpecials() { - $file = new \stdClass; - $file->headers = ["content-type"=>"text/html; charset=utf-8"]; - $file->body = '<html> - <body> - <img src="relative/url.png?a=1&b=2"> - </body> - </html>'; - $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->equal |