summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-20 19:21:47 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-20 19:21:47 +0100
commit9c78fd8295f8e27cdb8fe8c4e10ffae650bc14d0 (patch)
tree5a9bf0d8e6c7044b85c93b95c044b6a1449197ce
parent8f215ec03ba57e51dbbfef004069fb1e63c8fca1 (diff)
added feedmaper
-rw-r--r--.gitignore10
-rw-r--r--db/feedmapper.php35
-rw-r--r--tests/db/FeedMapperTest.php38
3 files changed, 73 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index 5bdb78845..d8fd59476 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,9 @@
#specific to news app
--coffee/build/
--node_modules/
--*.log
--build/
--test-results.xml
+coffee/build/
+node_modules/
+*.log
+build/
+test-results.xml
# just sane ignores
.*.sw[po]
diff --git a/db/feedmapper.php b/db/feedmapper.php
index 9eb85c3fe..2a84574df 100644
--- a/db/feedmapper.php
+++ b/db/feedmapper.php
@@ -25,6 +25,8 @@
namespace OCA\News\Db;
+use \OCA\AppFramework\Core\API;
+
class FeedMapper extends NewsMapper {
@@ -39,10 +41,41 @@ class FeedMapper extends NewsMapper {
'WHERE `id` = ? ' .
'AND `user_id` = ?';
- return $this->findRow($sql, $id, $userId);
+ $row = $this->findRow($sql, $id, $userId);
+ $feed = new Feed();
+ $feed->fromRow($row);
+
+ return $feed;
}
+ private function findAllRows($sql, $params=array()){
+ $result = $this->execute($sql, $params);
+
+ $feeds = array();
+ while($row = $result->fetchRow()){
+ $feed = new Feed();
+ $feed->fromRow($row);
+ array_push($feeds, $feed);
+ }
+
+ return $feeds;
+ }
+ public function findAllFromUser($userId){
+ $sql = 'SELECT * FROM `*dbprefix*news_feeds` ' .
+ 'AND `user_id` = ?';
+ $params = array($userId);
+
+ return $this->findAllRows($sql, $params);
+ }
+
+
+ public function findAll(){
+ $sql = 'SELECT * FROM `*dbprefix*news_feeds`';
+
+ return $this->findAllRows($sql);
+ }
+
} \ No newline at end of file
diff --git a/tests/db/FeedMapperTest.php b/tests/db/FeedMapperTest.php
index 9353365f5..c2dd6eced 100644
--- a/tests/db/FeedMapperTest.php
+++ b/tests/db/FeedMapperTest.php
@@ -77,7 +77,7 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$this->setMapperResult($sql, array($id, $userId));
$this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException');
- $result = $this->itemMapper->find($id, $userId);
+ $result = $this->feedMapper->find($id, $userId);
}
@@ -85,8 +85,8 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$userId = 'john';
$id = 3;
$rows = array(
- array('id' => $this->items[0]->getId()),
- array('id' => $this->items[1]->getId())
+ array('id' => $this->feeds[0]->getId()),
+ array('id' => $this->feeds[1]->getId())
);
$sql = 'SELECT * FROM `*dbprefix*news_feeds` ' .
'WHERE `id` = ? ' .
@@ -95,8 +95,38 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$this->setMapperResult($sql, array($id, $userId), $rows);
$this->setExpectedException('\OCA\AppFramework\Db\MultipleObjectsReturnedException');
- $result = $this->itemMapper->find($id, $userId);
+ $result = $this->feedMapper->find($id, $userId);
+ }
+
+
+ public function testFindAll(){
+ $userId = 'john';
+ $rows = array(
+ array('id' => $this->feeds[0]->getId()),
+ array('id' => $this->feeds[1]->getId())
+ );
+ $sql = 'SELECT * FROM `*dbprefix*news_feeds`';
+
+ $this->setMapperResult($sql, array(), $rows);
+
+ $result = $this->feedMapper->findAll();
+ $this->assertEquals($this->feeds, $result);
}
+ public function testFindAllFromUser(){
+ $userId = 'john';
+ $rows = array(
+ array('id' => $this->feeds[0]->getId()),
+ array('id' => $this->feeds[1]->getId())
+ );
+ $sql = 'SELECT * FROM `*dbprefix*news_feeds` ' .
+ 'AND `user_id` = ?';
+
+ $this->setMapperResult($sql, array($userId), $rows);
+
+ $result = $this->feedMapper->findAllFromUser($userId);
+ $this->assertEquals($this->feeds, $result);
+ }
+
} \ No newline at end of file