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/unit/db/ItemTest.php | 514 ++++++++++++++++++++++----------------------- 1 file changed, 257 insertions(+), 257 deletions(-) (limited to 'tests/unit/db/ItemTest.php') diff --git a/tests/unit/db/ItemTest.php b/tests/unit/db/ItemTest.php index 6c1a16c20..2739baabd 100644 --- a/tests/unit/db/ItemTest.php +++ b/tests/unit/db/ItemTest.php @@ -16,263 +16,263 @@ namespace OCA\News\Db; class ItemTest extends \PHPUnit_Framework_TestCase { - private $item; - - protected function setUp(){ - $this->item = new Item(); - $this->item->setStatus(0); - } - - - public function testSetRead(){ - $this->item->setRead(); - - $this->assertTrue($this->item->isRead()); - } - - - public function testSetUnread(){ - $this->item->setUnread(); - - $this->assertTrue($this->item->isUnread()); - } - - - public function testSetStarred(){ - $this->item->setStarred(); - - $this->assertTrue($this->item->isStarred()); - } - - - public function testSetUnstarred(){ - $this->item->setUnstarred(); - - $this->assertTrue($this->item->isUnstarred()); - } - - - public function testToAPI() { - $item = new Item(); - $item->setId(3); - $item->setGuid('guid'); - $item->setGuidHash('hash'); - $item->setUrl('https://google'); - $item->setTitle('title'); - $item->setAuthor('author'); - $item->setPubDate(123); - $item->setBody('body'); - $item->setEnclosureMime('audio/ogg'); - $item->setEnclosureLink('enclink'); - $item->setFeedId(1); - $item->setStatus(0); - $item->setUnread(); - $item->setStarred(); - $item->setLastModified(321); - - $this->assertEquals([ - 'id' => 3, - 'guid' => 'guid', - 'guidHash' => 'hash', - 'url' => 'https://google', - 'title' => 'title', - 'author' => 'author', - 'pubDate' => 123, - 'body' => 'body', - 'enclosureMime' => 'audio/ogg', - 'enclosureLink' => 'enclink', - 'feedId' => 1, - 'unread' => true, - 'starred' => true, - 'lastModified' => 321 - ], $item->toAPI()); - } - - - public function testJSONSerialize() { - $item = new Item(); - $item->setId(3); - $item->setGuid('guid'); - $item->setGuidHash('hash'); - $item->setUrl('https://google'); - $item->setTitle('title'); - $item->setAuthor('author'); - $item->setPubDate(123); - $item->setBody('body'); - $item->setEnclosureMime('audio/ogg'); - $item->setEnclosureLink('enclink'); - $item->setFeedId(1); - $item->setStatus(0); - $item->setUnread(); - $item->setStarred(); - $item->setLastModified(321); - - $this->assertEquals([ - 'id' => 3, - 'guid' => 'guid', - 'guidHash' => 'hash', - 'url' => 'https://google', - 'title' => 'title', - 'author' => 'author', - 'pubDate' => 123, - 'body' => 'body', - 'enclosureMime' => 'audio/ogg', - 'enclosureLink' => 'enclink', - 'feedId' => 1, - 'unread' => true, - 'starred' => true, - 'lastModified' => 321 - ], $item->jsonSerialize()); - } - - public function testToExport() { - $item = new Item(); - $item->setId(3); - $item->setGuid('guid'); - $item->setGuidHash('hash'); - $item->setUrl('https://google'); - $item->setTitle('title'); - $item->setAuthor('author'); - $item->setPubDate(123); - $item->setBody('body'); - $item->setEnclosureMime('audio/ogg'); - $item->setEnclosureLink('enclink'); - $item->setFeedId(1); - $item->setStatus(0); - $item->setRead(); - $item->setStarred(); - $item->setLastModified(321); - - $feed = new Feed(); - $feed->setLink('http://test'); - $feeds = ["feed1" => $feed]; - - $this->assertEquals([ - 'guid' => 'guid', - 'url' => 'https://google', - 'title' => 'title', - 'author' => 'author', - 'pubDate' => 123, - 'body' => 'body', - 'enclosureMime' => 'audio/ogg', - 'enclosureLink' => 'enclink', - 'unread' => false, - 'starred' => true, - 'feedLink' => 'http://test' - ], $item->toExport($feeds)); - } - - - private function createImportItem($isRead) { - $item = new Item(); - $item->setGuid('guid'); - $item->setUrl('https://google'); - $item->setTitle('title'); - $item->setAuthor('author'); - $item->setPubDate(123); - $item->setBody('body'); - $item->setEnclosureMime('audio/ogg'); - $item->setEnclosureLink('enclink'); - $item->setStarred(); - - if ($isRead) { - $item->setUnread(); - } else { - $item->setRead(); - } - - return $item; - } - - - public function testFromImport() { - $item = $this->createImportItem(false); - - $import = [ - 'guid' => $item->getGuid(), - 'url' => $item->getUrl(), - 'title' => $item->getTitle(), - 'author' => $item->getAuthor(), - 'pubDate' => $item->getPubDate(), - 'body' => $item->getBody(), - 'enclosureMime' => $item->getEnclosureMime(), - 'enclosureLink' => $item->getEnclosureLink(), - 'unread' => $item->isUnread(), - 'starred' => $item->isStarred(), - ]; - - $compareWith = Item::fromImport($import); - - $this->assertEquals($item, $compareWith); - } - - - public function testFromImportRead() { - $item = $this->createImportItem(true); - - $import = [ - 'guid' => $item->getGuid(), - 'url' => $item->getUrl(), - 'title' => $item->getTitle(), - 'author' => $item->getAuthor(), - 'pubDate' => $item->getPubDate(), - 'body' => $item->getBody(), - 'enclosureMime' => $item->getEnclosureMime(), - 'enclosureLink' => $item->getEnclosureLink(), - 'unread' => $item->isUnread(), - 'starred' => $item->isStarred(), - ]; - - $compareWith = Item::fromImport($import); - - $this->assertEquals($item, $compareWith); - } - - - - public function testSetAuthor(){ - $item = new Item(); - $item->setAuthor('my link'); - $this->assertEquals('my link', $item->getAuthor()); - $this->assertContains('author', $item->getUpdatedFields()); - } - - - public function testSetTitle(){ - $item = new Item(); - $item->setTitle('my link'); - $this->assertEquals('my link', $item->getTitle()); - $this->assertContains('title', $item->getUpdatedFields()); - } - - - public function testSetXSSUrl() { - $item = new Item(); - $item->setUrl('javascript:alert()'); - $this->assertEquals('', $item->getUrl()); - } - - - public function testSetMagnetUrl() { - $item = new Item(); - $item->setUrl('magnet://link.com'); - $this->assertEquals('magnet://link.com', $item->getUrl()); - } - - - public function testSetGuidUpdatesHash() { - $item = new Item(); - $item->setGuid('http://test'); - $this->assertEquals(md5('http://test'), $item->getGuidHash()); - } - - - public function testMakeLinksInBodyOpenNewTab() { - $item = new Item(); - $item->setBody("ha"); - $this->assertEquals("ha", - $item->getBody()); - } + private $item; + + protected function setUp(){ + $this->item = new Item(); + $this->item->setStatus(0); + } + + + public function testSetRead(){ + $this->item->setRead(); + + $this->assertTrue($this->item->isRead()); + } + + + public function testSetUnread(){ + $this->item->setUnread(); + + $this->assertTrue($this->item->isUnread()); + } + + + public function testSetStarred(){ + $this->item->setStarred(); + + $this->assertTrue($this->item->isStarred()); + } + + + public function testSetUnstarred(){ + $this->item->setUnstarred(); + + $this->assertTrue($this->item->isUnstarred()); + } + + + public function testToAPI() { + $item = new Item(); + $item->setId(3); + $item->setGuid('guid'); + $item->setGuidHash('hash'); + $item->setUrl('https://google'); + $item->setTitle('title'); + $item->setAuthor('author'); + $item->setPubDate(123); + $item->setBody('body'); + $item->setEnclosureMime('audio/ogg'); + $item->setEnclosureLink('enclink'); + $item->setFeedId(1); + $item->setStatus(0); + $item->setUnread(); + $item->setStarred(); + $item->setLastModified(321); + + $this->assertEquals([ + 'id' => 3, + 'guid' => 'guid', + 'guidHash' => 'hash', + 'url' => 'https://google', + 'title' => 'title', + 'author' => 'author', + 'pubDate' => 123, + 'body' => 'body', + 'enclosureMime' => 'audio/ogg', + 'enclosureLink' => 'enclink', + 'feedId' => 1, + 'unread' => true, + 'starred' => true, + 'lastModified' => 321 + ], $item->toAPI()); + } + + + public function testJSONSerialize() { + $item = new Item(); + $item->setId(3); + $item->setGuid('guid'); + $item->setGuidHash('hash'); + $item->setUrl('https://google'); + $item->setTitle('title'); + $item->setAuthor('author'); + $item->setPubDate(123); + $item->setBody('body'); + $item->setEnclosureMime('audio/ogg'); + $item->setEnclosureLink('enclink'); + $item->setFeedId(1); + $item->setStatus(0); + $item->setUnread(); + $item->setStarred(); + $item->setLastModified(321); + + $this->assertEquals([ + 'id' => 3, + 'guid' => 'guid', + 'guidHash' => 'hash', + 'url' => 'https://google', + 'title' => 'title', + 'author' => 'author', + 'pubDate' => 123, + 'body' => 'body', + 'enclosureMime' => 'audio/ogg', + 'enclosureLink' => 'enclink', + 'feedId' => 1, + 'unread' => true, + 'starred' => true, + 'lastModified' => 321 + ], $item->jsonSerialize()); + } + + public function testToExport() { + $item = new Item(); + $item->setId(3); + $item->setGuid('guid'); + $item->setGuidHash('hash'); + $item->setUrl('https://google'); + $item->setTitle('title'); + $item->setAuthor('author'); + $item->setPubDate(123); + $item->setBody('body'); + $item->setEnclosureMime('audio/ogg'); + $item->setEnclosureLink('enclink'); + $item->setFeedId(1); + $item->setStatus(0); + $item->setRead(); + $item->setStarred(); + $item->setLastModified(321); + + $feed = new Feed(); + $feed->setLink('http://test'); + $feeds = ["feed1" => $feed]; + + $this->assertEquals([ + 'guid' => 'guid', + 'url' => 'https://google', + 'title' => 'title', + 'author' => 'author', + 'pubDate' => 123, + 'body' => 'body', + 'enclosureMime' => 'audio/ogg', + 'enclosureLink' => 'enclink', + 'unread' => false, + 'starred' => true, + 'feedLink' => 'http://test' + ], $item->toExport($feeds)); + } + + + private function createImportItem($isRead) { + $item = new Item(); + $item->setGuid('guid'); + $item->setUrl('https://google'); + $item->setTitle('title'); + $item->setAuthor('author'); + $item->setPubDate(123); + $item->setBody('body'); + $item->setEnclosureMime('audio/ogg'); + $item->setEnclosureLink('enclink'); + $item->setStarred(); + + if ($isRead) { + $item->setUnread(); + } else { + $item->setRead(); + } + + return $item; + } + + + public function testFromImport() { + $item = $this->createImportItem(false); + + $import = [ + 'guid' => $item->getGuid(), + 'url' => $item->getUrl(), + 'title' => $item->getTitle(), + 'author' => $item->getAuthor(), + 'pubDate' => $item->getPubDate(), + 'body' => $item->getBody(), + 'enclosureMime' => $item->getEnclosureMime(), + 'enclosureLink' => $item->getEnclosureLink(), + 'unread' => $item->isUnread(), + 'starred' => $item->isStarred(), + ]; + + $compareWith = Item::fromImport($import); + + $this->assertEquals($item, $compareWith); + } + + + public function testFromImportRead() { + $item = $this->createImportItem(true); + + $import = [ + 'guid' => $item->getGuid(), + 'url' => $item->getUrl(), + 'title' => $item->getTitle(), + 'author' => $item->getAuthor(), + 'pubDate' => $item->getPubDate(), + 'body' => $item->getBody(), + 'enclosureMime' => $item->getEnclosureMime(), + 'enclosureLink' => $item->getEnclosureLink(), + 'unread' => $item->isUnread(), + 'starred' => $item->isStarred(), + ]; + + $compareWith = Item::fromImport($import); + + $this->assertEquals($item, $compareWith); + } + + + + public function testSetAuthor(){ + $item = new Item(); + $item->setAuthor('my link'); + $this->assertEquals('my link', $item->getAuthor()); + $this->assertContains('author', $item->getUpdatedFields()); + } + + + public function testSetTitle(){ + $item = new Item(); + $item->setTitle('my link'); + $this->assertEquals('my link', $item->getTitle()); + $this->assertContains('title', $item->getUpdatedFields()); + } + + + public function testSetXSSUrl() { + $item = new Item(); + $item->setUrl('javascript:alert()'); + $this->assertEquals('', $item->getUrl()); + } + + + public function testSetMagnetUrl() { + $item = new Item(); + $item->setUrl('magnet://link.com'); + $this->assertEquals('magnet://link.com', $item->getUrl()); + } + + + public function testSetGuidUpdatesHash() { + $item = new Item(); + $item->setGuid('http://test'); + $this->assertEquals(md5('http://test'), $item->getGuidHash()); + } + + + public function testMakeLinksInBodyOpenNewTab() { + $item = new Item(); + $item->setBody("ha"); + $this->assertEquals("ha", + $item->getBody()); + } } \ No newline at end of file -- cgit v1.2.3