diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-23 13:24:35 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-23 13:24:35 +0100 |
commit | 3455fe9cb792e584671f465ff6d51732fc1802ff (patch) | |
tree | 817a26f6d03bed8939c0842a63ca5349e28ed099 /tests | |
parent | f4f27ab927f16d7ff8900e92ecf7aee75f355f34 (diff) |
finished findall methods in itembl
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bl/ItemBlTest.php | 127 | ||||
-rw-r--r-- | tests/bl/StatusFlagTest.php | 74 |
2 files changed, 191 insertions, 10 deletions
diff --git a/tests/bl/ItemBlTest.php b/tests/bl/ItemBlTest.php index 4b4c71219..e8c4cc9d7 100644 --- a/tests/bl/ItemBlTest.php +++ b/tests/bl/ItemBlTest.php @@ -29,41 +29,148 @@ require_once(__DIR__ . "/../classloader.php"); use \OCA\News\Db\Item; +use \OCA\News\Db\StatusFlag; +use \OCA\News\Db\FeedType; class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { - protected $api; - protected $mapper; - protected $bl; - protected $user; - protected $response; + private $api; + private $mapper; + private $bl; + private $user; + private $response; + private $status; + protected function setUp(){ $this->api = $this->getAPIMock(); $this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') ->disableOriginalConstructor() ->getMock(); - $this->bl = new ItemBl($this->mapper); + $statusFlag = $this->getMockBuilder('\OCA\News\Db\StatusFlag') + ->disableOriginalConstructor() + ->getMock(); + $this->status = StatusFlag::STARRED; + $statusFlag->expects($this->any()) + ->method('typeToStatus') + ->will($this->returnValue($this->status)); + $this->bl = new ItemBl($this->mapper, $statusFlag); $this->user = 'jack'; $response = 'hi'; + $this->id = 3; + $this->updatedSince = 20333; + $this->showAll = true; + $this->offset = 5; + $this->limit = 20; + } + + + public function testFindAllNewFeed(){ + $type = FeedType::FEED; + $this->mapper->expects($this->once()) + ->method('findAllNewFeed') + ->with($this->equalTo($this->id), + $this->equalTo($this->updatedSince), + $this->equalTo($this->status), + $this->equalTo($this->user)) + ->will($this->returnValue($this->response)); + + $result = $this->bl->findAllNew( + $this->id, $type, $this->updatedSince, $this->showAll, + $this->user); + $this->assertEquals($this->response, $result); + } + + + public function testFindAllNewFolder(){ + $type = FeedType::FOLDER; + $this->mapper->expects($this->once()) + ->method('findAllNewFolder') + ->with($this->equalTo($this->id), + $this->equalTo($this->updatedSince), + $this->equalTo($this->status), + $this->equalTo($this->user)) + ->will($this->returnValue($this->response)); + + $result = $this->bl->findAllNew( + $this->id, $type, $this->updatedSince, $this->showAll, + $this->user); + $this->assertEquals($this->response, $result); + } + + + public function testFindAllNew(){ + $type = FeedType::STARRED; + $this->mapper->expects($this->once()) + ->method('findAllNew') + ->with( $this->equalTo($this->updatedSince), + $this->equalTo($this->status), + $this->equalTo($this->user)) + ->will($this->returnValue($this->response)); + + $result = $this->bl->findAllNew( + $this->id, $type, $this->updatedSince, $this->showAll, + $this->user); + $this->assertEquals($this->response, $result); + } + + + public function testFindAllFeed(){ + $type = FeedType::FEED; + $this->mapper->expects($this->once()) + ->method('findAllFeed') + ->with($this->equalTo($this->id), + $this->equalTo($this->limit), + $this->equalTo($this->offset), + $this->equalTo($this->status), + $this->equalTo($this->user)) + ->will($this->returnValue($this->response)); + + $result = $this->bl->findAll( + $this->id, $type, $this->limit, + $this->offset, $this->showAll, + $this->user); + $this->assertEquals($this->response, $result); } + public function testFindAllFolder(){ + $type = FeedType::FOLDER; + $this->mapper->expects($this->once()) + ->method('findAllFolder') + ->with($this->equalTo($this->id), + $this->equalTo($this->limit), + $this->equalTo($this->offset), + $this->equalTo($this->status), + $this->equalTo($this->user)) + ->will($this->returnValue($this->response)); + + $result = $this->bl->findAll( + $this->id, $type, $this->limit, + $this->offset, $this->showAll, + $this->user); + $this->assertEquals($this->response, $result); + } - /* public function testFindAll(){ + $type = FeedType::STARRED; $this->mapper->expects($this->once()) ->method('findAll') - ->with($this->equalTo($this->user)) + ->with( $this->equalTo($this->limit), + $this->equalTo($this->offset), + $this->equalTo($this->status), + $this->equalTo($this->user)) ->will($this->returnValue($this->response)); - $result = $this->bl->findAllFromUser($this->user); + $result = $this->bl->findAll( + $this->id, $type, $this->limit, + $this->offset, $this->showAll, + $this->user); $this->assertEquals($this->response, $result); } - */ public function testStarredCount(){ $star = 18; diff --git a/tests/bl/StatusFlagTest.php b/tests/bl/StatusFlagTest.php new file mode 100644 index 000000000..9e9be9fca --- /dev/null +++ b/tests/bl/StatusFlagTest.php @@ -0,0 +1,74 @@ +<?php + +/** +* ownCloud - News +* +* @author Alessandro Copyright +* @author Bernhard Posselt +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +namespace OCA\News\Db; + +use \OCA\AppFramework\Utility\TestUtility; + + +require_once(__DIR__ . "/../classloader.php"); + + +class StatusFlagTest extends TestUtility { + + private $statusFlag; + + protected function setUp(){ + $this->statusFlag = new StatusFlag(); + } + + + public function testTypeToStatusUnreadStarred(){ + $expected = StatusFlag::UNREAD | StatusFlag::STARRED; + $status = $this->statusFlag->typeToStatus(FeedType::STARRED, true); + + $this->assertEquals($expected, $status); + } + + + public function testTypeToStatusUnread(){ + $expected = StatusFlag::UNREAD; + $status = $this->statusFlag->typeToStatus(FeedType::FEED, true); + + $this->assertEquals($expected, $status); + } + + + public function testTypeToStatusReadStarred(){ + $expected = (~StatusFlag::UNREAD) & StatusFlag::STARRED; + $status = $this->statusFlag->typeToStatus(FeedType::STARRED, false); + + $this->assertEquals($expected, $status); + } + + + public function testTypeToStatusRead(){ + $expected = (~StatusFlag::UNREAD) & 0; + $status = $this->statusFlag->typeToStatus(FeedType::FEED, false); + + $this->assertEquals($expected, $status); + } + +}
\ No newline at end of file |