diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-19 19:20:42 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-19 19:20:42 +0100 |
commit | 4e077697a1fd0cf15a6eac22cb6e3d6ec4b10ff2 (patch) | |
tree | fa6ad4cab5d6c9a3ac2686171d00341d57729a89 /tests | |
parent | 3cacc9c90d40f385786482faa51c308afdf54cec (diff) |
added itemmapper test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/db/ItemMapperTest.php | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/db/ItemMapperTest.php b/tests/db/ItemMapperTest.php new file mode 100644 index 000000000..d5068d1f8 --- /dev/null +++ b/tests/db/ItemMapperTest.php @@ -0,0 +1,92 @@ +<?php + +/** +* ownCloud - News +* +* @author Alessandro Cosentino +* @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; + +require_once(__DIR__ . "/../classloader.php"); + + +class Test extends \PHPUnit_Framework_TestCase { + + private $itemMapper; + private $api; + private $items; + + protected function setUp(){ + $this->api = $this->getMock('\OCA\AppFramework\Core\API', + array('prepareQuery'), + array('a')); + $this->itemMapper = new ItemMapper($this->api); + + // create mock items + $item1 = new Item(); + $item1->test = 1; + + $item2 = new Item(); + $item2->test = 2; + + $this->items = array( + $item1, + $item2 + ); + } + + + public function testFindAllFromFeed(){ + $userId = 'john'; + $feedId = 3; + $rows = array( + array('test' => 1), + array('test' => 2) + ); + $sql = 'SELECT * FROM `*PREFIX*news_items` + WHERE user_id = ? + AND feed_id = ?'; + + $pdoResult = $this->getMock('Result', + array('fetchRow')); + $pdoResult->expects($this->once()) + ->method('fetchRow') + ->will($this->returnValue($rows)); + + $query = $this->getMock('Query', + array('execute')); + $query->expects($this->once()) + ->method('execute') + ->with($this->equalTo(array($feedId, $userId))) + ->will($this->returnValue($pdoResult)); + + $this->api->expects($this->once()) + ->method('prepareQuery') + ->with($this->equalTo($sql)) + ->will(($this->returnValue($query))); + + $result = $this->itemMapper->findAllFromFeed($feedId, $userId); + + $this->assertEquals($this->items, $result); + + } + +}
\ No newline at end of file |