summaryrefslogtreecommitdiffstats
path: root/tests/unit/utility
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-10-21 16:45:36 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-10-21 16:45:36 +0200
commit42d69a95f3276a2d6089ca68f635c4e2f6aa7a23 (patch)
tree6a17fd7998f291e6dec1d996c1e7c724b92b8e58 /tests/unit/utility
parent0e6598b0734fb927109f745d9c0f3a8605a30ca5 (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/unit/utility')
-rw-r--r--tests/unit/utility/FaviconFetcherTest.php256
-rw-r--r--tests/unit/utility/OPMLExporterTest.php172
-rw-r--r--tests/unit/utility/SimplePieAPIFactoryTest.php24
-rw-r--r--tests/unit/utility/UpdaterTest.php86
4 files changed, 269 insertions, 269 deletions
diff --git a/tests/unit/utility/FaviconFetcherTest.php b/tests/unit/utility/FaviconFetcherTest.php
index 3ed0d4dc8..e73510a13 100644
--- a/tests/unit/utility/FaviconFetcherTest.php
+++ b/tests/unit/utility/FaviconFetcherTest.php
@@ -17,183 +17,183 @@ namespace OCA\News\Utility;
class FaviconFetcherTest extends \PHPUnit_Framework_TestCase {
- private $fetcher;
- private $fileFactory;
- private $png;
+ private $fetcher;
+ private $fileFactory;
+ private $png;
- protected function setUp(){
- $this->png = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
- $this->fileFactory = $this->getMockBuilder(
- '\OCA\News\Utility\SimplePieAPIFactory')
- ->disableOriginalConstructor()
- ->getMock();
- $this->config = $this->getMockBuilder(
- '\OCA\News\Utility\Config')
- ->disableOriginalConstructor()
- ->getMock();
- $this->fetcher = new FaviconFetcher($this->fileFactory);
- }
+ protected function setUp(){
+ $this->png = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
+ $this->fileFactory = $this->getMockBuilder(
+ '\OCA\News\Utility\SimplePieAPIFactory')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->config = $this->getMockBuilder(
+ '\OCA\News\Utility\Config')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->fetcher = new FaviconFetcher($this->fileFactory);
+ }
- protected function getFileMock($body='') {
- $mock = $this->getMockBuilder('\SimplePie_File')
- ->disableOriginalConstructor()
- ->getMock();
- $mock->body = $body;
- return $mock;
- }
+ protected function getFileMock($body='') {
+ $mock = $this->getMockBuilder('\SimplePie_File')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mock->body = $body;
+ return $mock;
+ }
- protected function getFileMockCallback($onEqual, $returnMock) {
- $defaultMock = $this->getFileMock();
+ protected function getFileMockCallback($onEqual, $returnMock) {
+ $defaultMock = $this->getFileMock();
- return function($url) use ($onEqual, $returnMock, $defaultMock) {
- if($url === $onEqual){
- return $returnMock;
- } else {
- return $defaultMock;
- }
- };
- }
+ return function($url) use ($onEqual, $returnMock, $defaultMock) {
+ if($url === $onEqual){
+ return $returnMock;
+ } else {
+ return $defaultMock;
+ }
+ };
+ }
- public function testFetchNoResponseReturnsNull() {
- $mock = $this->getFileMock();
+ public function testFetchNoResponseReturnsNull() {
+ $mock = $this->getFileMock();
- $this->fileFactory->expects($this->any())
- ->method('getFile')
- ->will($this->returnValue($mock));
+ $this->fileFactory->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue($mock));
- $favicon = $this->fetcher->fetch('dfdf');
- $this->assertNull($favicon);
- }
+ $favicon = $this->fetcher->fetch('dfdf');
+ $this->assertNull($favicon);
+ }
- public function testNoProxySettingsAreUsed() {
- $faviconPath = "/owncloud/core/img/favicon.png";
- $html = $this->getFaviconHTML($faviconPath);
+ public function testNoProxySettingsAreUsed() {
+ $faviconPath = "/owncloud/core/img/favicon.png";
+ $html = $this->getFaviconHTML($faviconPath);
- $url = 'http://google.com';
- $pageMock = $this->getFileMock($html);
- $pngMock = $this->getFileMock($this->png);
+ $url = 'http://google.com';
+ $pageMock = $this->getFileMock($html);
+ $pngMock = $this->getFileMock($this->png);
- $this->fileFactory->expects($this->at(0))
- ->method('getFile')
- ->with($this->equalTo('http://google.com'))
- ->will($this->returnValue($pageMock));
+ $this->fileFactory->expects($this->at(0))
+ ->method('getFile')
+ ->with($this->equalTo('http://google.com'))
+ ->will($this->returnValue($pageMock));
- $this->fileFactory->expects($this->at(1))
- ->method('getFile')
- ->with($this->equalTo(
- 'http://google.com/owncloud/core/img/favicon.png'),
- $this->equalTo(10),
- $this->equalTo(5),
- $this->equalTo(null),
- $this->equalTo('Mozilla/5.0 AppleWebKit'))
- ->will($this->returnValue($pngMock));
+ $this->fileFactory->expects($this->at(1))
+ ->method('getFile')
+ ->with($this->equalTo(
+ 'http://google.com/owncloud/core/img/favicon.png'),
+ $this->equalTo(10),
+ $this->equalTo(5),
+ $this->equalTo(null),
+ $this->equalTo('Mozilla/5.0 AppleWebKit'))
+ ->will($this->returnValue($pngMock));
- $favicon = $this->fetcher->fetch($url);
+ $favicon = $this->fetcher->fetch($url);
- $this->assertEquals('http://google.com/owncloud/core/img/favicon.png', $favicon);
- }
+ $this->assertEquals('http://google.com/owncloud/core/img/favicon.png', $favicon);
+ }
- public function testFetchFaviconFaviconDotIcoHttp(){
- $url = ' sub.google.com ';
- $mock = $this->getFileMock($this->png);
+ public function testFetchFaviconFaviconDotIcoHttp(){
+ $url = ' sub.google.com ';
+ $mock = $this->getFileMock($this->png);
- $callback = $this->getFileMockCallback(
- 'http://sub.google.com/favicon.ico', $mock);
+ $callback = $this->getFileMockCallback(
+ 'http://sub.google.com/favicon.ico', $mock);
- $this->fileFactory->expects($this->any())
- ->method('getFile')
- ->will($this->returnCallback($callback));
+ $this->fileFactory->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnCallback($callback));
- $favicon = $this->fetcher->fetch($url);
+ $favicon = $this->fetcher->fetch($url);
- $this->assertEquals('http://sub.google.com/favicon.ico', $favicon);
- }
+ $this->assertEquals('http://sub.google.com/favicon.ico', $favicon);
+ }
- public function testFetchFaviconFaviconDotIcoHttpBaseUrl(){
- $url = 'https://google.com/sometetst/dfladsf';
- $mock = $this->getFileMock($this->png);
+ public function testFetchFaviconFaviconDotIcoHttpBaseUrl(){
+ $url = 'https://google.com/sometetst/dfladsf';
+ $mock = $this->getFileMock($this->png);
- $callback = $this->getFileMockCallback(
- 'https://google.com/favicon.ico', $mock);
+ $callback = $this->getFileMockCallback(
+ 'https://google.com/favicon.ico', $mock);
- $this->fileFactory->expects($this->any())
- ->method('getFile')
- ->will($this->returnCallback($callback));
+ $this->fileFactory->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnCallback($callback));
- $favicon = $this->fetcher->fetch($url);
+ $favicon = $this->fetcher->fetch($url);
- $this->assertEquals('https://google.com/favicon.ico', $favicon);
- }
+ $this->assertEquals('https://google.com/favicon.ico', $favicon);
+ }
- private function getFaviconHTML($faviconPath) {
- return "<html>
- <head>
- <link rel=\"shortcut icon\" href=\"$faviconPath\" />
- </head>
- <body></body>
- </html>";
- }
+ private function getFaviconHTML($faviconPath) {
+ return "<html>
+ <head>
+ <link rel=\"shortcut icon\" href=\"$faviconPath\" />
+ </head>
+ <body></body>
+ </html>";
+ }
- public function testIconAbspathHTTP() {
- $faviconPath = "/owncloud/core/img/favicon.png";
- $html = $this->getFaviconHTML($faviconPath);
+ public function testIconAbspathHTTP() {
+ $faviconPath = "/owncloud/core/img/favicon.png";
+ $html = $this->getFaviconHTML($faviconPath);
- $url = 'http://google.com';
- $pageMock = $this->getFileMock($html);
- $pngMock = $this->getFileMock($this->png);
+ $url = 'http://google.com';
+ $pageMock = $this->getFileMock($html);
+ $pngMock = $this->getFileMock($this->png);
- $this->fileFactory->expects($this->at(0))
- ->method('getFile')
- ->with($this->equalTo('http://google.com'))
- ->will($this->returnValue($pageMock));
+ $this->fileFactory->expects($this->at(0))
+ ->method('getFile')
+ ->with($this->equalTo('http://google.com'))
+ ->will($this->returnValue($pageMock));
- $this->fileFactory->expects($this->at(1))
- ->method('getFile')
- ->with($this->equalTo(
- 'http://google.com/owncloud/core/img/favicon.png'))
- ->will($this->returnValue($pngMock));
+ $this->fileFactory->expects($this->at(1))
+ ->method('getFile')
+ ->with($this->equalTo(
+ 'http://google.com/owncloud/core/img/favicon.png'))
+ ->will($this->returnValue($pngMock));
- $favicon = $this->fetcher->fetch($url);
+ $favicon = $this->fetcher->fetch($url);
- $this->assertEquals('http://google.com/owncloud/core/img/favicon.png', $favicon);
- }
+ $this->assertEquals('http://google.com/owncloud/core/img/favicon.png', $favicon);
+ }
- public function testEmptyFilePathDoesNotOpenFile() {
- $url = '';
+ public function testEmptyFilePathDoesNotOpenFile() {
+ $url = '';
- $this->fileFactory->expects($this->never())
- ->method('getFile');
+ $this->fileFactory->expects($this->never())
+ ->method('getFile');
- $this->fetcher->fetch($url);
- }
+ $this->fetcher->fetch($url);
+ }
- public function testInvalidHostnameDoesNotOpenFile() {
- $url = "a.b_c.de";
+ public function testInvalidHostnameDoesNotOpenFile() {
+ $url = "a.b_c.de";
- $this->fileFactory->expects($this->never())
- ->method('getFile');
+ $this->fileFactory->expects($this->never())
+ ->method('getFile');
- $this->fetcher->fetch($url);
- }
+ $this->fetcher->fetch($url);
+ }
- public function testInvalidHostnameDoesNotOpenFileHttp() {
- $url = "http://a.b_c.de";
+ public function testInvalidHostnameDoesNotOpenFileHttp() {
+ $url = "http://a.b_c.de";
- $this->fileFactory->expects($this->never())
- ->method('getFile');
+ $this->fileFactory->expects($this->never())
+ ->method('getFile');
- $this->fetcher->fetch($url);
- }
+ $this->fetcher->fetch($url);
+ }
}
diff --git a/tests/unit/utility/OPMLExporterTest.php b/tests/unit/utility/OPMLExporterTest.php
index fe7b142e8..5d6f849fb 100644
--- a/tests/unit/utility/OPMLExporterTest.php
+++ b/tests/unit/utility/OPMLExporterTest.php
@@ -19,92 +19,92 @@ use \OCA\News\Db\Feed;
class OPMLExporterTest extends \PHPUnit_Framework_TestCase {
- private $exporter;
- private $feed1;
- private $feed2;
-
- protected function setUp() {
- $this->exporter = new OPMLExporter();
- $this->folder1 = new Folder();
- $this->folder1->setId(3);
- $this->folder1->setParentId(0);
- $this->folder1->setName('Örgendwas');
- $this->folder2 = new Folder();
- $this->folder2->setId(1);
- $this->folder2->setParentId(3);
- $this->folder2->setName('a ergendwas');
- $this->feed1 = new Feed();
- $this->feed1->setUrl('url 1');
- $this->feed1->setTitle('tötel');
- $this->feed1->setFolderId(0);
- $this->feed2 = new Feed();
- $this->feed2->setUrl('url');
- $this->feed2->setTitle('ttel df');
- $this->feed2->setLink('goooooogel');
- $this->feed2->setFolderId(1);
- }
-
-
- private function getAttribute($item, $name) {
- // used to fix scrutinizer errors
- if ($item instanceof \DOMElement) {
- return $item->getAttribute($name);
- } else {
- return null;
- }
- }
-
-
- public function testBuildEmpty(){
- $result = $this->exporter->build([], []);
- $xpath = new \DOMXpath($result);
-
- $this->assertEquals(0, $xpath->query('//outline')->length);
- }
-
-
- public function testBuildReturnsFolders() {
- $result = $this->exporter->build([$this->folder1, $this->folder2], []);
- $xpath = new \DOMXpath($result);
- $elems = $xpath->query('/opml/body/outline');
-
- $this->assertEquals(2, $elems->length);
- $this->assertEquals($this->folder1->getName(), $this->getAttribute($elems->item(0), 'title'));
- $this->assertEquals($this->folder1->getName(), $this->getAttribute($elems->item(0), 'text'));
- $this->assertEquals($this->folder2->getName(), $this->getAttribute($elems->item(1), 'title'));
- $this->assertEquals($this->folder2->getName(), $this->getAttribute($elems->item(1), 'text'));
- }
-
-
- public function testBuildReturnsOnlyOneFeedIfParentFolderNotThere() {
- $result = $this->exporter->build([], [$this->feed1, $this->feed2]);
- $xpath = new \DOMXpath($result);
- $elems = $xpath->query('//outline');
-
- $this->assertEquals(1, $elems->length);
- $this->assertEquals($this->feed1->getTitle(), $this->getAttribute($elems->item(0), 'title'));
- $this->assertEquals($this->feed1->getTitle(), $this->getAttribute($elems->item(0), 'text'));
- $this->assertEquals($this->feed1->getUrl(), $this->getAttribute($elems->item(0), 'xmlUrl'));
- $this->assertEquals('', $this->getAttribute($elems->item(0), 'htmlUrl'));
- }
-
-
- public function testBuildReturnsFeedsAndFolders() {
- $result = $this->exporter->build(
- [$this->folder1, $this->folder2],
- [$this->feed1, $this->feed2]
- );
- $xpath = new \DOMXpath($result);
- $elems = $xpath->query('/opml/body/outline');
-
- $this->assertEquals(3, $elems->length);
-
-
- $this->assertEquals($this->folder1->getName(), $this->getAttribute($elems->item(0), 'title'));
- $this->assertEquals($this->folder2->getName(), $this->getAttribute($elems->item(1), 'text'));
- $this->assertEquals($this->feed1->getUrl(), $this->getAttribute($elems->item(2), 'xmlUrl'));
- $this->assertEquals($this->feed2->getLink(), $this->getAttribute($elems->item(1)->childNodes->item(0), 'htmlUrl'));
- }
+ private $exporter;
+ private $feed1;
+ private $feed2;
+
+ protected function setUp() {
+ $this->exporter = new OPMLExporter();
+ $this->folder1 = new Folder();
+ $this->folder1->setId(3);
+ $this->folder1->setParentId(0);
+ $this->folder1->setName('Örgendwas');
+ $this->folder2 = new Folder();
+ $this->folder2->setId(1);
+ $this->folder2->setParentId(3);
+ $this->folder2->setName('a ergendwas');
+ $this->feed1 = new Feed();
+ $this->feed1->setUrl('url 1');
+ $this->feed1->setTitle('tötel');
+ $this->feed1->setFolderId(0);
+ $this->feed2 = new Feed();
+ $this->feed2->setUrl('url');
+ $this->feed2->setTitle('ttel df');
+ $this->feed2->setLink('goooooogel');
+ $this->feed2->setFolderId(1);
+ }
+
+
+ private function getAttribute($item, $name) {
+ // used to fix scrutinizer errors
+ if ($item instanceof \DOMElement) {
+ return $item->getAttribute($name);
+ } else {
+ return null;
+ }
+ }
+
+
+ public function testBuildEmpty(){
+ $result = $this->exporter->build([], []);
+ $xpath = new \DOMXpath($result);
+
+ $this->assertEquals(0, $xpath->query('//outline')->length);
+ }
+
+
+ public function testBuildReturnsFolders() {
+ $result = $this->exporter->build([$this->folder1, $this->folder2], []);
+ $xpath = new \DOMXpath($result);
+ $elems = $xpath->query('/opml/body/outline');
+
+ $this->assertEquals(2, $elems->length);
+ $this->assertEquals($this->folder1->getName(), $this->getAttribute($elems->item(0), 'title'));
+ $this->assertEquals($this->folder1->getName(), $this->getAttribute($elems->item(0), 'text'));
+ $this->assertEquals($this->folder2->getName(), $this->getAttribute($elems->item(1), 'title'));
+ $this->assertEquals($this->folder2->getName(), $this->getAttribute($elems->item(1), 'text'));
+ }
+
+
+ public function testBuildReturnsOnlyOneFeedIfParentFolderNotThere() {
+ $result = $this->exporter->build([], [$this->feed1, $this->feed2]);
+ $xpath = new \DOMXpath($result);
+ $elems = $xpath->query('//outline');
+
+ $this->assertEquals(1, $elems->length);
+ $this->assertEquals($this->feed1->getTitle(), $this->getAttribute($elems->item(0), 'title'));
+ $this->assertEquals($this->feed1->getTitle(), $this->getAttribute($elems->item(0), 'text'));
+ $this->assertEquals($this->feed1->getUrl(), $this->getAttribute($elems->item(0), 'xmlUrl'));
+ $this->assertEquals('', $this->getAttribute($elems->item(0), 'htmlUrl'));
+ }
+
+
+ public function testBuildReturnsFeedsAndFolders() {
+ $result = $this->exporter->build(
+ [$this->folder1, $this->folder2],
+ [$this->feed1, $this->feed2]
+ );
+ $xpath = new \DOMXpath($result);
+ $elems = $xpath->query('/opml/body/outline');
+
+ $this->assertEquals(3, $elems->length);
+
+
+ $this->assertEquals($this->folder1->getName(), $this->getAttribute($elems->item(0), 'title'));
+ $this->assertEquals($this->folder2->getName(), $this->getAttribute($elems->item(1), 'text'));
+ $this->assertEquals($this->feed1->getUrl(), $this->getAttribute($elems->item(2), 'xmlUrl'));
+ $this->assertEquals($this->feed2->getLink(), $this->getAttribute($elems->item(1)->childNodes->item(0), 'htmlUrl'));
+ }
} \ No newline at end of file
diff --git a/tests/unit/utility/SimplePieAPIFactoryTest.php b/tests/unit/utility/SimplePieAPIFactoryTest.php
index a7e7472a0..4f401a72e 100644
--- a/tests/unit/utility/SimplePieAPIFactoryTest.php
+++ b/tests/unit/utility/SimplePieAPIFactoryTest.php
@@ -17,18 +17,18 @@ namespace OCA\News\Utility;
class SimplePieAPIFactoryTest extends \PHPUnit_Framework_TestCase {
- public function testGetFile() {
- $factory = new SimplePieAPIFactory();
- $file = $factory->getFile('php://input', 10, 5, $headers='headers',
- $useragent='flashce', $force_fsockopen=true);
- $this->assertTrue($file instanceof \SimplePie_File);
- }
-
-
- public function testGetCore() {
- $factory = new SimplePieAPIFactory();
- $this->assertTrue($factory->getCore() instanceof \SimplePie);
- }
+ public function testGetFile() {
+ $factory = new SimplePieAPIFactory();
+ $file = $factory->getFile('php://input', 10, 5, $headers='headers',
+ $useragent='flashce', $force_fsockopen=true);
+ $this->assertTrue($file instanceof \SimplePie_File);
+ }
+
+
+ public function testGetCore() {
+ $factory = new SimplePieAPIFactory();
+ $this->assertTrue($factory->getCore() instanceof \SimplePie);
+ }
} \ No newline at end of file
diff --git a/tests/unit/utility/UpdaterTest.php b/tests/unit/utility/UpdaterTest.php
index 1d61d65bb..edca29f67 100644
--- a/tests/unit/utility/UpdaterTest.php
+++ b/tests/unit/utility/UpdaterTest.php
@@ -16,47 +16,47 @@ namespace OCA\News\Utility;
class UpdaterTest extends \PHPUnit_Framework_TestCase {
- private $folderService;
- private $feedService;
- private $itemService;
- private $updater;
-
- protected function setUp() {
- $this->folderService = $this->getMockBuilder(
- '\OCA\News\Service\FolderService')
- ->disableOriginalConstructor()
- ->getMock();
- $this->feedService = $this->getMockBuilder(
- '\OCA\News\Service\FeedService')
- ->disableOriginalConstructor()
- ->getMock();
- $this->itemService = $this->getMockBuilder(
- '\OCA\News\Service\ItemService')
- ->disableOriginalConstructor()
- ->getMock();
- $this->updater = new Updater($this->folderService,
- $this->feedService,
- $this->itemService);
- }
-
- public function testBeforeUpdate() {
- $this->folderService->expects($this->once())
- ->method('purgeDeleted');
- $this->feedService->expects($this->once())
- ->method('purgeDeleted');
- $this->updater->beforeUpdate();
- }
-
-
- public function testAfterUpdate() {
- $this->itemService->expects($this->once())
- ->method('autoPurgeOld');
- $this->updater->afterUpdate();
- }
-
- public function testUpdate() {
- $this->feedService->expects($this->once())
- ->method('updateAll');
- $this->updater->update();
- }
+ private $folderService;
+ private $feedService;
+ private $itemService;
+ private $updater;
+
+ protected function setUp() {
+ $this->folderService = $this->getMockBuilder(
+ '\OCA\News\Service\FolderService')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->feedService = $this->getMockBuilder(
+ '\OCA\News\Service\FeedService')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->itemService = $this->getMockBuilder(
+ '\OCA\News\Service\ItemService')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->updater = new Updater($this->folderService,
+ $this->feedService,
+ $this->itemService);
+ }
+
+ public function testBeforeUpdate() {
+ $this->folderService->expects($this->once())
+ ->method('purgeDeleted');
+ $this->feedService->expects($this->once())
+ ->method('purgeDeleted');
+ $this->updater->beforeUpdate();
+ }
+
+
+ public function testAfterUpdate() {
+ $this->itemService->expects($this->once())
+ ->method('autoPurgeOld');
+ $this->updater->afterUpdate();
+ }
+
+ public function testUpdate() {
+ $this->feedService->expects($this->once())
+ ->method('updateAll');
+ $this->updater->update();
+ }
} \ No newline at end of file