summaryrefslogtreecommitdiffstats
path: root/tests/unit/db/ItemMapperTest.php
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-06-22 15:11:34 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-06-22 15:11:34 +0200
commit20597eb1af744e6a7bf88d5b03204fd942a96d17 (patch)
treedaa4163a39f8c6051110358450bfc7af2a1b4c4a /tests/unit/db/ItemMapperTest.php
parent7d1c2b2c2cab883c63b074cec87dcc8729b52d1b (diff)
also set last modified when marking feeds, folders, or all read, fix #256
Diffstat (limited to 'tests/unit/db/ItemMapperTest.php')
-rw-r--r--tests/unit/db/ItemMapperTest.php140
1 files changed, 72 insertions, 68 deletions
diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php
index 8b427923c..c88f27403 100644
--- a/tests/unit/db/ItemMapperTest.php
+++ b/tests/unit/db/ItemMapperTest.php
@@ -39,13 +39,13 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
private $updatedSince;
private $status;
-
+
public function setUp()
{
$this->beforeEach();
-
+
$this->mapper = new ItemMapper($this->api);
-
+
// create mock items
$item1 = new Item();
$item2 = new Item();
@@ -54,42 +54,42 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$item1,
$item2
);
-
+
$this->userId = 'john';
$this->id = 3;
$this->folderId = 2;
-
+
$this->row = array(
array('id' => $this->items[0]->getId()),
- );
-
- $this->rows = array(
- array('id' => $this->items[0]->getId()),
- array('id' => $this->items[1]->getId())
- );
-
- $this->user = 'john';
- $this->limit = 10;
- $this->offset = 3;
- $this->id = 11;
- $this->status = 333;
- $this->updatedSince = 323;
- $this->newestItemId = 2;
+ );
+
+ $this->rows = array(
+ array('id' => $this->items[0]->getId()),
+ array('id' => $this->items[1]->getId())
+ );
+
+ $this->user = 'john';
+ $this->limit = 10;
+ $this->offset = 3;
+ $this->id = 11;
+ $this->status = 333;
+ $this->updatedSince = 323;
+ $this->newestItemId = 2;
}
-
+
private function makeSelectQuery($prependTo){
return 'SELECT `items`.* FROM `*PREFIX*news_items` `items` '.
'JOIN `*PREFIX*news_feeds` `feeds` ' .
'ON `feeds`.`id` = `items`.`feed_id` '.
'AND `feeds`.`deleted_at` = 0 ' .
- 'AND `feeds`.`user_id` = ? ' .
+ 'AND `feeds`.`user_id` = ? ' .
$prependTo .
'LEFT OUTER JOIN `*PREFIX*news_folders` `folders` ' .
'ON `folders`.`id` = `feeds`.`folder_id` ' .
'WHERE `feeds`.`folder_id` = 0 ' .
- 'OR `folders`.`deleted_at` = 0 ' .
+ 'OR `folders`.`deleted_at` = 0 ' .
'ORDER BY `items`.`id` DESC';
}
@@ -105,14 +105,14 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testFind(){
$sql = $this->makeSelectQuery('AND `items`.`id` = ? ');
-
+
$this->setMapperResult($sql, array($this->userId, $this->id), $this->row);
-
+
$result = $this->mapper->find($this->id, $this->userId);
$this->assertEquals($this->items[0], $result);
}
-
+
public function testGetStarredCount(){
$userId = 'john';
$row = array(
@@ -124,55 +124,59 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'AND `feeds`.`user_id` = ? ' .
'WHERE ((`items`.`status` & ' . StatusFlag::STARRED . ') = '
. StatusFlag::STARRED . ')';
-
+
$this->setMapperResult($sql, array($userId), $row);
-
+
$result = $this->mapper->starredCount($userId);
$this->assertEquals($row[0]['size'], $result);
}
public function testReadAll(){
- $sql = 'UPDATE `*PREFIX*news_items` ' .
+ $sql = 'UPDATE `*PREFIX*news_items` ' .
'SET `status` = `status` & ? ' .
- 'WHERE `feed_id` IN (' .
- 'SELECT `id` FROM `*PREFIX*news_feeds` ' .
- 'WHERE `user_id` = ? ' .
- ') '.
- 'AND `id` <= ?';
- $params = array(~StatusFlag::UNREAD, $this->user, 3);
+ 'AND `last_modified` = ? ' .
+ 'WHERE `feed_id` IN (' .
+ 'SELECT `id` FROM `*PREFIX*news_feeds` ' .
+ 'WHERE `user_id` = ? ' .
+ ') '.
+ 'AND `id` <= ?';
+ $params = array(~StatusFlag::UNREAD, $this->updatedSince, $this->user, 3);
$this->setMapperResult($sql, $params);
- $this->mapper->readAll(3, $this->user);
- }
+ $this->mapper->readAll(3, $this->updatedSince, $this->user);
+ }
public function testReadFolder(){
- $sql = 'UPDATE `*PREFIX*news_items` ' .
+ $sql = 'UPDATE `*PREFIX*news_items` ' .
'SET `status` = `status` & ? ' .
- 'WHERE `feed_id` IN (' .
- 'SELECT `id` FROM `*PREFIX*news_feeds` ' .
- 'WHERE `folder_id` = ? ' .
- 'AND `user_id` = ? ' .
- ') '.
- 'AND `id` <= ?';
- $params = array(~StatusFlag::UNREAD, 3, $this->user, 6);
+ 'AND `last_modified` = ? ' .
+ 'WHERE `feed_id` IN (' .
+ 'SELECT `id` FROM `*PREFIX*news_feeds` ' .
+ 'WHERE `folder_id` = ? ' .
+ 'AND `user_id` = ? ' .
+ ') '.
+ 'AND `id` <= ?';
+ $params = array(~StatusFlag::UNREAD, $this->updatedSince, 3, $this->user, 6);
$this->setMapperResult($sql, $params);
- $this->mapper->readFolder(3, 6, $this->user);
+ $this->mapper->readFolder(3, 6, $this->updatedSince, $this->user);
}
public function testReadFeed(){
- $sql = 'UPDATE `*PREFIX*news_items` ' .
+ $sql = 'UPDATE `*PREFIX*news_items` ' .
'SET `status` = `status` & ? ' .
+ 'AND `last_modified` = ? ' .
'WHERE `feed_id` = ? ' .
'AND `id` <= ? ' .
'AND EXISTS (' .
'SELECT * FROM `*PREFIX*news_feeds` ' .
'WHERE `user_id` = ? ' .
'AND `id` = ? ) ';
- $params = array(~StatusFlag::UNREAD, 3, 6, $this->user, 3);
+ $params = array(~StatusFlag::UNREAD, $this->updatedSince, 3, 6,
+ $this->user, 3);
$this->setMapperResult($sql, $params);
- $this->mapper->readFeed(3, 6, $this->user);
+ $this->mapper->readFeed(3, 6, $this->updatedSince, $this->user);
}
@@ -182,7 +186,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$params = array($this->user, $this->updatedSince);
$this->setMapperResult($sql, $params, $this->rows);
- $result = $this->mapper->findAllNew($this->updatedSince,
+ $result = $this->mapper->findAllNew($this->updatedSince,
$this->status, $this->user);
$this->assertEquals($this->items, $result);
@@ -196,7 +200,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$params = array($this->user, $this->id, $this->updatedSince);
$this->setMapperResult($sql, $params, $this->rows);
- $result = $this->mapper->findAllNewFolder($this->id, $this->updatedSince,
+ $result = $this->mapper->findAllNewFolder($this->id, $this->updatedSince,
$this->status, $this->user);
$this->assertEquals($this->items, $result);
@@ -210,7 +214,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$params = array($this->user, $this->id, $this->updatedSince);
$this->setMapperResult($sql, $params, $this->rows);
- $result = $this->mapper->findAllNewFeed($this->id, $this->updatedSince,
+ $result = $this->mapper->findAllNewFeed($this->id, $this->updatedSince,
$this->status, $this->user);
$this->assertEquals($this->items, $result);
@@ -223,7 +227,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = $this->makeSelectQueryStatus($sql, $this->status);
$params = array($this->user, $this->id, $this->offset);
$this->setMapperResult($sql, $params, $this->rows);
- $result = $this->mapper->findAllFeed($this->id, $this->limit,
+ $result = $this->mapper->findAllFeed($this->id, $this->limit,
$this->offset, $this->status, $this->user);
$this->assertEquals($this->items, $result);
@@ -235,7 +239,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = $this->makeSelectQueryStatus($sql, $this->status);
$params = array($this->user, $this->id);
$this->setMapperResult($sql, $params, $this->rows);
- $result = $this->mapper->findAllFeed($this->id, $this->limit,
+ $result = $this->mapper->findAllFeed($this->id, $this->limit,
0, $this->status, $this->user);
$this->assertEquals($this->items, $result);
@@ -246,10 +250,10 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = 'AND `feeds`.`folder_id` = ? ' .
'AND `items`.`id` < ? ';
$sql = $this->makeSelectQueryStatus($sql, $this->status);
- $params = array($this->user, $this->id,
+ $params = array($this->user, $this->id,
$this->offset);
$this->setMapperResult($sql, $params, $this->rows);
- $result = $this->mapper->findAllFolder($this->id, $this->limit,
+ $result = $this->mapper->findAllFolder($this->id, $this->limit,
$this->offset, $this->status, $this->user);
$this->assertEquals($this->items, $result);
@@ -261,7 +265,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = $this->makeSelectQueryStatus($sql, $this->status);
$params = array($this->user, $this->id);
$this->setMapperResult($sql, $params, $this->rows);
- $result = $this->mapper->findAllFolder($this->id, $this->limit,
+ $result = $this->mapper->findAllFolder($this->id, $this->limit,
0, $this->status, $this->user);
$this->assertEquals($this->items, $result);
@@ -273,7 +277,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = $this->makeSelectQueryStatus($sql, $this->status);
$params = array($this->user, $this->offset);
$this->setMapperResult($sql, $params, $this->rows);
- $result = $this->mapper->findAll($this->limit,
+ $result = $this->mapper->findAll($this->limit,
$this->offset, $this->status, $this->user);
$this->assertEquals($this->items, $result);
@@ -284,7 +288,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = $this->makeSelectQueryStatus('', $this->status);
$params = array($this->user);
$this->setMapperResult($sql, $params, $this->rows);
- $result = $this->mapper->findAll($this->limit,
+ $result = $this->mapper->findAll($this->limit,
0, $this->status, $this->user);
$this->assertEquals($this->items, $result);
@@ -299,9 +303,9 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = $this->makeSelectQuery(
'AND `items`.`guid_hash` = ? ' .
'AND `feeds`.`id` = ? ');
-
+
$this->setMapperResult($sql, array($this->userId, $hash, $feedId), $this->row);
-
+
$result = $this->mapper->findByGuidHash($hash, $feedId, $this->userId);
$this->assertEquals($this->items[0], $result);
}
@@ -335,7 +339,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'HAVING COUNT(*) > ?';
$params1 = array($status, $threshold);
-
+
$row = array('feed_id' => 30, 'size' => 9);
$sql2 = 'DELETE FROM `*PREFIX*news_items` `items` ' .
@@ -344,8 +348,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'ORDER BY `items`.`id` ASC';
$params2 = array($status, 30);
-
- $pdoResult = $this->getMock('Result',
+
+ $pdoResult = $this->getMock('Result',
array('fetchRow'));
$pdoResult->expects($this->at(0))
@@ -354,8 +358,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$pdoResult->expects($this->at(1))
->method('fetchRow')
->will($this->returnValue(false));
-
- $query = $this->getMock('Query',
+
+ $query = $this->getMock('Query',
array('execute'));
$query->expects($this->at(0))
->method('execute')
@@ -367,7 +371,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
->with($this->equalTo($sql1))
->will(($this->returnValue($query)));
- $query2 = $this->getMock('Query',
+ $query2 = $this->getMock('Query',
array('execute'));
$query2->expects($this->at(0))
->method('execute')
@@ -391,7 +395,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$rows = array(array('max_id' => 3));
$this->setMapperResult($sql, $params, $rows);
-
+
$result = $this->mapper->getNewestItemId($this->user);
$this->assertEquals(3, $result);
}
@@ -411,4 +415,4 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$result = $this->mapper->getNewestItemId($this->user);
}
-} \ No newline at end of file
+}