summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-04 17:21:43 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-04 17:21:43 +0200
commit1ffedced057ad7968629c974574b5f66adf01b48 (patch)
tree3e40d318ac3122f1dee6328094dff6b566b63c2c
parentb723c12e4c3e0039d9785861d4ad204fd899ac52 (diff)
fixes mappers by using the correct status condition
-rw-r--r--db/feedmapper.php12
-rw-r--r--db/itemmapper.php18
-rw-r--r--js/tests/services/bl/feedblSpec.coffee3
-rw-r--r--js/tests/services/bl/folderblSpec.coffee3
-rw-r--r--js/tests/services/bl/itemblSpec.coffee3
-rw-r--r--tests/db/FeedMapperTest.php32
-rw-r--r--tests/db/ItemMapperTest.php30
7 files changed, 54 insertions, 47 deletions
diff --git a/db/feedmapper.php b/db/feedmapper.php
index 7f0466647..f2c3a8ada 100644
--- a/db/feedmapper.php
+++ b/db/feedmapper.php
@@ -43,11 +43,11 @@ class FeedMapper extends Mapper implements IMapper {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) > 0 ' .
+ 'AND (`items`.`status` & ?) = ? ' .
'WHERE `feeds`.`id` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $params = array(StatusFlag::UNREAD, $id, $userId);
+ $params = array(StatusFlag::UNREAD, StatusFlag::UNREAD, $id, $userId);
$row = $this->findOneQuery($sql, $params);
$feed = new Feed();
@@ -76,10 +76,10 @@ class FeedMapper extends Mapper implements IMapper {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) > 0 ' .
+ 'AND (`items`.`status` & ?) = ? ' .
'WHERE `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $params = array(StatusFlag::UNREAD, $userId);
+ $params = array(StatusFlag::UNREAD, StatusFlag::UNREAD, $userId);
return $this->findAllRows($sql, $params);
}
@@ -97,11 +97,11 @@ class FeedMapper extends Mapper implements IMapper {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) > 0 ' .
+ 'AND (`items`.`status` & ?) = ? ' .
'WHERE `feeds`.`url_hash` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $params = array(StatusFlag::UNREAD, $hash, $userId);
+ $params = array(StatusFlag::UNREAD, StatusFlag::UNREAD, $hash, $userId);
$row = $this->findOneQuery($sql, $params);
$feed = new Feed();
diff --git a/db/itemmapper.php b/db/itemmapper.php
index a5c0e8af2..af190cd27 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -60,7 +60,7 @@ class ItemMapper extends Mapper implements IMapper {
private function makeSelectQueryStatus($prependTo) {
return $this->makeSelectQuery(
- 'AND ((`items`.`status` & ?) > 0) ' .
+ 'AND ((`items`.`status` & ?) = ?) ' .
$prependTo
);
}
@@ -82,9 +82,9 @@ class ItemMapper extends Mapper implements IMapper {
'JOIN `*PREFIX*news_items` `items` ' .
'ON `items`.`feed_id` = `feeds`.`id` ' .
'AND `feeds`.`user_id` = ? ' .
- 'WHERE ((`items`.`status` & ?) > 0)';
+ 'WHERE ((`items`.`status` & ?) = ?)';
- $params = array($userId, StatusFlag::STARRED);
+ $params = array($userId, StatusFlag::STARRED, StatusFlag::STARRED);
$result = $this->execute($sql, $params)->fetchRow();
@@ -110,7 +110,7 @@ class ItemMapper extends Mapper implements IMapper {
$sql = 'AND `items`.`feed_id` = ? ' .
'AND `items`.`id` >= ?';
$sql = $this->makeSelectQueryStatus($sql);
- $params = array($userId, $status, $id, $updatedSince);
+ $params = array($userId, $status, $status, $id, $updatedSince);
return $this->findAllRows($sql, $params);
}
@@ -119,20 +119,20 @@ class ItemMapper extends Mapper implements IMapper {
$sql = 'AND `feeds`.`folder_id` = ? ' .
'AND `items`.`id` >= ?';
$sql = $this->makeSelectQueryStatus($sql);
- $params = array($userId, $status, $id, $updatedSince);
+ $params = array($userId, $status, $status, $id, $updatedSince);
return $this->findAllRows($sql, $params);
}
public function findAllNew($updatedSince, $status, $userId){
$sql = $this->makeSelectQueryStatus('AND `items`.`id` >= ?');
- $params = array($userId, $status, $updatedSince);
+ $params = array($userId, $status, $status, $updatedSince);
return $this->findAllRows($sql, $params);
}
public function findAllFeed($id, $limit, $offset, $status, $userId){
- $params = array($userId, $status, $id);
+ $params = array($userId, $status, $status, $id);
$sql = 'AND `items`.`feed_id` = ? ';
if($offset !== 0){
$sql .= 'AND `items`.`id` > ? ';
@@ -145,7 +145,7 @@ class ItemMapper extends Mapper implements IMapper {
public function findAllFolder($id, $limit, $offset, $status, $userId){
- $params = array($userId, $status, $id);
+ $params = array($userId, $status, $status, $id);
$sql = 'AND `feeds`.`folder_id` = ? ';
if($offset !== 0){
$sql .= 'AND `items`.`id` > ? ';
@@ -158,7 +158,7 @@ class ItemMapper extends Mapper implements IMapper {
public function findAll($limit, $offset, $status, $userId){
- $params = array($userId, $status);
+ $params = array($userId, $status, $status);
$sql = '';
if($offset !== 0){
$sql .= 'AND `items`.`id` > ? ';
diff --git a/js/tests/services/bl/feedblSpec.coffee b/js/tests/services/bl/feedblSpec.coffee
index 486c32198..602e93909 100644
--- a/js/tests/services/bl/feedblSpec.coffee
+++ b/js/tests/services/bl/feedblSpec.coffee
@@ -27,8 +27,7 @@ describe 'FeedBl', ->
beforeEach =>
angular.module('News').factory 'Persistence', =>
- @persistence =
- getItems: ->
+ @persistence = {}
beforeEach inject (@FeedBl, @FeedModel, @ItemModel) =>
diff --git a/js/tests/services/bl/folderblSpec.coffee b/js/tests/services/bl/folderblSpec.coffee
index 9ede654ee..299633cf5 100644
--- a/js/tests/services/bl/folderblSpec.coffee
+++ b/js/tests/services/bl/folderblSpec.coffee
@@ -27,8 +27,7 @@ describe 'FolderBl', ->
beforeEach =>
angular.module('News').factory 'Persistence', =>
- @persistence =
- getItems: ->
+ @persistence = {}
beforeEach inject (@FolderBl, @FolderModel, @FeedModel) =>
diff --git a/js/tests/services/bl/itemblSpec.coffee b/js/tests/services/bl/itemblSpec.coffee
index 36a283de2..e2644989e 100644
--- a/js/tests/services/bl/itemblSpec.coffee
+++ b/js/tests/services/bl/itemblSpec.coffee
@@ -28,8 +28,7 @@ describe 'ItemBl', ->
beforeEach =>
angular.module('News').factory 'Persistence', =>
- @persistence =
- getItems: ->
+ @persistence = {}
beforeEach inject (@ItemModel, @ItemBl, @StatusFlag) =>
diff --git a/tests/db/FeedMapperTest.php b/tests/db/FeedMapperTest.php
index d7163be30..ebd8163ca 100644
--- a/tests/db/FeedMapperTest.php
+++ b/tests/db/FeedMapperTest.php
@@ -60,11 +60,11 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) > 0 ' .
+ 'AND (`items`.`status` & ?) = ? ' .
'WHERE `feeds`.`id` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $params = array(StatusFlag::UNREAD, $id, $userId);
+ $params = array(StatusFlag::UNREAD, StatusFlag::UNREAD, $id, $userId);
$this->setMapperResult($sql, $params, $rows);
$result = $this->mapper->find($id, $userId);
@@ -80,11 +80,11 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) > 0 ' .
+ 'AND (`items`.`status` & ?) = ? ' .
'WHERE `feeds`.`id` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $params = array(StatusFlag::UNREAD, $id, $userId);
+ $params = array(StatusFlag::UNREAD, StatusFlag::UNREAD, $id, $userId);
$this->setMapperResult($sql, $params);
$this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException');
@@ -103,11 +103,11 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) > 0 ' .
+ 'AND (`items`.`status` & ?) = ? ' .
'WHERE `feeds`.`id` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $params = array(StatusFlag::UNREAD, $id, $userId);
+ $params = array(StatusFlag::UNREAD, StatusFlag::UNREAD, $id, $userId);
$this->setMapperResult($sql, $params, $rows);
$this->setExpectedException('\OCA\AppFramework\Db\MultipleObjectsReturnedException');
@@ -140,11 +140,12 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) > 0 ' .
+ 'AND (`items`.`status` & ?) = ? ' .
'WHERE `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $this->setMapperResult($sql, array(StatusFlag::UNREAD, $userId), $rows);
+ $this->setMapperResult($sql,
+ array(StatusFlag::UNREAD, StatusFlag::UNREAD, $userId), $rows);
$result = $this->mapper->findAllFromUser($userId);
$this->assertEquals($this->feeds, $result);
@@ -160,11 +161,12 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) > 0 ' .
+ 'AND (`items`.`status` & ?) = ? ' .
'WHERE `feeds`.`url_hash` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $this->setMapperResult($sql, array(StatusFlag::UNREAD, $urlHash, $this->user), $row);
+ $this->setMapperResult($sql,
+ array(StatusFlag::UNREAD, StatusFlag::UNREAD, $urlHash, $this->user), $row);
$result = $this->mapper->findByUrlHash($urlHash, $this->user);
$this->assertEquals($this->feeds[0], $result);
@@ -177,11 +179,12 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) > 0 ' .
+ 'AND (`items`.`status` & ?) = ? ' .
'WHERE `feeds`.`url_hash` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $this->setMapperResult($sql, array(StatusFlag::UNREAD, $urlHash, $this->user));
+ $this->setMapperResult($sql,
+ array(StatusFlag::UNREAD, StatusFlag::UNREAD, $urlHash, $this->user));
$this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException');
$result = $this->mapper->findByUrlHash($urlHash, $this->user);
@@ -198,11 +201,12 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) > 0 ' .
+ 'AND (`items`.`status` & ?) = ? ' .
'WHERE `feeds`.`url_hash` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $this->setMapperResult($sql, array(StatusFlag::UNREAD, $urlHash, $this->user), $rows);
+ $this->setMapperResult($sql,
+ array(StatusFlag::UNREAD, StatusFlag::UNREAD, $urlHash, $this->user), $rows);
$this->setExpectedException('\OCA\AppFramework\Db\MultipleObjectsReturnedException');
$result = $this->mapper->findByUrlHash($urlHash, $this->user);
diff --git a/tests/db/ItemMapperTest.php b/tests/db/ItemMapperTest.php
index de9b2b4ac..470d0c82d 100644
--- a/tests/db/ItemMapperTest.php
+++ b/tests/db/ItemMapperTest.php
@@ -80,7 +80,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
private function makeSelectQueryStatus($prependTo) {
return $this->makeSelectQuery(
- 'AND ((`items`.`status` & ?) > 0) ' .
+ 'AND ((`items`.`status` & ?) = ?) ' .
$prependTo
);
}
@@ -105,9 +105,10 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'JOIN `*PREFIX*news_items` `items` ' .
'ON `items`.`feed_id` = `feeds`.`id` ' .
'AND `feeds`.`user_id` = ? ' .
- 'WHERE ((`items`.`status` & ?) > 0)';
+ 'WHERE ((`items`.`status` & ?) = ?)';
- $this->setMapperResult($sql, array($userId, StatusFlag::STARRED), $row);
+ $this->setMapperResult($sql, array($userId, StatusFlag::STARRED,
+ StatusFlag::STARRED), $row);
$result = $this->mapper->starredCount($userId);
$this->assertEquals($row[0]['size'], $result);
@@ -131,7 +132,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testFindAllNew(){
$sql = 'AND `items`.`id` >= ?';
$sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->updatedSince);
+ $params = array($this->user, $this->status, $this->status,
+ $this->updatedSince);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllNew($this->updatedSince,
@@ -145,7 +147,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = 'AND `items`.`feed_id` = ? ' .
'AND `items`.`id` >= ?';
$sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->id, $this->updatedSince);
+ $params = array($this->user, $this->status, $this->status, $this->id,
+ $this->updatedSince);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllNewFeed($this->id, $this->updatedSince,
@@ -160,7 +163,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'AND `items`.`id` >= ?';
$sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->id,
+ $params = array($this->user, $this->status, $this->status, $this->id,
$this->updatedSince);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllNewFolder($this->id, $this->updatedSince,
@@ -175,7 +178,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'AND `items`.`id` > ? ' .
'ORDER BY `items`.`id` DESC ';
$sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->id, $this->offset);
+ $params = array($this->user, $this->status, $this->status, $this->id,
+ $this->offset);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllFeed($this->id, $this->limit,
$this->offset, $this->status, $this->user);
@@ -188,7 +192,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = 'AND `items`.`feed_id` = ? ' .
'ORDER BY `items`.`id` DESC ';
$sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->id);
+ $params = array($this->user, $this->status, $this->status, $this->id);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllFeed($this->id, $this->limit,
0, $this->status, $this->user);
@@ -202,7 +206,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'AND `items`.`id` > ? ' .
'ORDER BY `items`.`id` DESC ';
$sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->id, $this->offset);
+ $params = array($this->user, $this->status, $this->status, $this->id,
+ $this->offset);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllFolder($this->id, $this->limit,
$this->offset, $this->status, $this->user);
@@ -215,7 +220,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = 'AND `feeds`.`folder_id` = ? ' .
'ORDER BY `items`.`id` DESC ';
$sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->id);
+ $params = array($this->user, $this->status, $this->status, $this->id);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllFolder($this->id, $this->limit,
0, $this->status, $this->user);
@@ -228,7 +233,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = 'AND `items`.`id` > ? ' .
'ORDER BY `items`.`id` DESC ';
$sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->offset);
+ $params = array($this->user, $this->status, $this->status,
+ $this->offset);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAll($this->limit,
$this->offset, $this->status, $this->user);
@@ -240,7 +246,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testFindAllOffsetZero(){
$sql = 'ORDER BY `items`.`id` DESC ';
$sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status);
+ $params = array($this->user, $this->status, $this->status);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAll($this->limit,
0, $this->status, $this->user);