diff options
author | Daniel Opitz <danopz@users.noreply.github.com> | 2017-08-14 10:34:53 +0200 |
---|---|---|
committer | Bernhard Posselt <BernhardPosselt@users.noreply.github.com> | 2017-08-14 10:34:53 +0200 |
commit | a97dd58e3b499b60ac8b37786d402d7f2e371a88 (patch) | |
tree | 98bb8a6c750fb33fbef38d22407fa29fbf6c7b1e /tests/Unit/Service | |
parent | 7d8a85c82c4c13a71b70ddb4ecb8c40ede4c9b70 (diff) |
Split binary to booleans (#203)
* replaced old status with 2 flags for unread and starred
* add fields to db, replace int(1,0) with booleans in sql queries, removed StatusFlags class + refactor code relying to it
* add repair step for migration
* again use integer(1,0) instead of bool in sql queries, because of sqlite doesn't support true/false
* add/fix unit tests for new boolean status
* set unread/starred flags as statements in sql
* fixed mysql unknown column items.unread, fixed marking of read items on repair step
* remove unnecessary bool casts
* add empty checks to Items::is* methods
* update migration to use native sql instead of the querybuilder
* don't cast the flags manually, let the api do the work
Diffstat (limited to 'tests/Unit/Service')
-rw-r--r-- | tests/Unit/Service/FeedServiceTest.php | 14 | ||||
-rw-r--r-- | tests/Unit/Service/ItemServiceTest.php | 44 | ||||
-rw-r--r-- | tests/Unit/Service/StatusFlagTest.php | 57 |
3 files changed, 27 insertions, 88 deletions
diff --git a/tests/Unit/Service/FeedServiceTest.php b/tests/Unit/Service/FeedServiceTest.php index 68d25df9e..6df02e51c 100644 --- a/tests/Unit/Service/FeedServiceTest.php +++ b/tests/Unit/Service/FeedServiceTest.php @@ -388,7 +388,7 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $item->setTitle('hey'); $item->setAuthor('aut'); $item->setBody('new'); - $item->setRead(); + $item->setUnread(false); return $item; } @@ -401,7 +401,7 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $item->setTitle('ho'); $item->setAuthor('auto'); $item->setBody('old'); - $item->setRead(); + $item->setUnread(false); return $item; } @@ -448,7 +448,7 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $item = $this->createUpdateItem(); $item2 = $this->createUpdateItem2(); $item3 = $this->createUpdateItem(); - $item3->setUnread(); + $item3->setUnread(true); $items = [$item]; @@ -760,8 +760,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $item->setBody('come over'); $item->setEnclosureMime('mime'); $item->setEnclosureLink('lin'); - $item->setUnread(); - $item->setUnstarred(); + $item->setUnread(true); + $item->setStarred(false); $item->generateSearchIndex(); $json = $item->toExport(['feed3' => $feed]); @@ -816,8 +816,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $item->setBody('come over'); $item->setEnclosureMime('mime'); $item->setEnclosureLink('lin'); - $item->setUnread(); - $item->setUnstarred(); + $item->setUnread(true); + $item->setStarred(false); $item->generateSearchIndex(); $json = $item->toExport(['feed3' => $feed]); diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php index 3b3197136..4beebbb63 100644 --- a/tests/Unit/Service/ItemServiceTest.php +++ b/tests/Unit/Service/ItemServiceTest.php @@ -16,13 +16,13 @@ namespace OCA\News\Service; use \OCP\AppFramework\Db\DoesNotExistException; use \OCA\News\Db\Item; -use \OCA\News\Db\StatusFlag; use \OCA\News\Db\FeedType; class ItemServiceTest extends \PHPUnit_Framework_TestCase { private $mapper; + /** @var ItemService */ private $itemService; private $user; private $response; @@ -46,13 +46,6 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { $this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') ->disableOriginalConstructor() ->getMock(); - $this->statusFlag = $this->getMockBuilder('\OCA\News\Db\StatusFlag') - ->disableOriginalConstructor() - ->getMock(); - $this->status = StatusFlag::STARRED; - $this->statusFlag->expects($this->any()) - ->method('typeToStatus') - ->will($this->returnValue($this->status)); $this->config = $this->getMockBuilder( '\OCA\News\Config\Config') ->disableOriginalConstructor() @@ -62,8 +55,7 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor() ->getMock(); $this->itemService = new ItemService($this->mapper, - $this->statusFlag, $this->timeFactory, $this->config, - $this->systemConfig); + $this->timeFactory, $this->config, $this->systemConfig); $this->user = 'jack'; $this->id = 3; $this->updatedSince = 20333; @@ -80,7 +72,7 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { ->method('findAllNewFeed') ->with($this->equalTo($this->id), $this->equalTo($this->updatedSince), - $this->equalTo($this->status), + $this->equalTo($this->showAll), $this->equalTo($this->user)) ->will($this->returnValue($this->response)); @@ -97,7 +89,7 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { ->method('findAllNewFolder') ->with($this->equalTo($this->id), $this->equalTo($this->updatedSince), - $this->equalTo($this->status), + $this->equalTo($this->showAll), $this->equalTo($this->user)) ->will($this->returnValue($this->response)); @@ -113,7 +105,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { $this->mapper->expects($this->once()) ->method('findAllNew') ->with( $this->equalTo($this->updatedSince), - $this->equalTo($this->status), + $this->equalTo($type), + $this->equalTo($this->showAll), $this->equalTo($this->user)) ->will($this->returnValue($this->response)); @@ -131,7 +124,7 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($this->id), $this->equalTo($this->limit), $this->equalTo($this->offset), - $this->equalTo($this->status), + $this->equalTo($this->showAll), $this->equalTo(false), $this->equalTo($this->user), $this->equalTo([])) @@ -152,7 +145,7 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($this->id), $this->equalTo($this->limit), $this->equalTo($this->offset), - $this->equalTo($this->status), + $this->equalTo($this->showAll), $this->equalTo(true), $this->equalTo($this->user), $this->equalTo([])) @@ -172,7 +165,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { ->method('findAll') ->with( $this->equalTo($this->limit), $this->equalTo($this->offset), - $this->equalTo($this->status), + $this->equalTo($type), + $this->equalTo($this->showAll), $this->equalTo(true), $this->equalTo($this->user), $this->equalTo([])) @@ -193,7 +187,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { ->method('findAll') ->with( $this->equalTo($this->limit), $this->equalTo($this->offset), - $this->equalTo($this->status), + $this->equalTo($type), + $this->equalTo($this->showAll), $this->equalTo(true), $this->equalTo($this->user), $this->equalTo($search)) @@ -216,11 +211,11 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { $item = new Item(); $item->setStatus(128); $item->setId($itemId); - $item->setUnstarred(); + $item->setStarred(false); $expectedItem = new Item(); $expectedItem->setStatus(128); - $expectedItem->setStarred(); + $expectedItem->setStarred(true); $expectedItem->setId($itemId); $this->mapper->expects($this->once()) @@ -249,11 +244,12 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { $item = new Item(); $item->setStatus(128); $item->setId($itemId); - $item->setStarred(); + $item->setStarred(true); $expectedItem = new Item(); $expectedItem->setStatus(128); - $expectedItem->setUnstarred(); + $expectedItem->setStarred(true); //workaround to set starred as updated field + $expectedItem->setStarred(false); $expectedItem->setId($itemId); $this->mapper->expects($this->once()) @@ -270,7 +266,7 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { $this->itemService->star($feedId, $guidHash, false, $this->user); - $this->assertTrue($item->isUnstarred()); + $this->assertFalse($item->isStarred()); } public function testRead(){ @@ -278,11 +274,11 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { $item = new Item(); $item->setStatus(128); $item->setId($itemId); - $item->setUnread(); + $item->setUnread(true); $expectedItem = new Item(); $expectedItem->setStatus(128); - $expectedItem->setRead(); + $expectedItem->setUnread(false); $expectedItem->setId($itemId); $expectedItem->setLastModified($this->time); diff --git a/tests/Unit/Service/StatusFlagTest.php b/tests/Unit/Service/StatusFlagTest.php deleted file mode 100644 index 5d672fc53..000000000 --- a/tests/Unit/Service/StatusFlagTest.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php -/** - * Nextcloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Alessandro Cosentino <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Db; - - -class StatusFlagTest extends \PHPUnit_Framework_TestCase { - - private $statusFlag; - - protected function setUp(){ - $this->statusFlag = new StatusFlag(); - } - - - public function testTypeToStatusUnreadStarred(){ - $expected = StatusFlag::STARRED; - $status = $this->statusFlag->typeToStatus(FeedType::STARRED, false); - - $this->assertEquals($expected, $status); - } - - - public function testTypeToStatusUnread(){ - $expected = StatusFlag::UNREAD; - $status = $this->statusFlag->typeToStatus(FeedType::FEED, false); - - $this->assertEquals($expected, $status); - } - - - public function testTypeToStatusReadStarred(){ - $expected = StatusFlag::STARRED; - $status = $this->statusFlag->typeToStatus(FeedType::STARRED, true); - - $this->assertEquals($expected, $status); - } - - - public function testTypeToStatusRead(){ - $expected = (~StatusFlag::UNREAD) & 0; - $status = $this->statusFlag->typeToStatus(FeedType::FEED, true); - - $this->assertEquals($expected, $status); - } - -}
\ No newline at end of file |