summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-14 18:08:52 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-14 18:08:52 +0200
commitd9acb9ed876d9814e468081d799f06ffd631580f (patch)
tree887653ca34a9b67adeb60435b3dd37f7329619c3 /tests
parentf52cdaa750f1efa8cb76f6d88c9b1dc291f7b328 (diff)
add serverside possibility to order by oldest first
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/businesslayer/ItemBusinessLayerTest.php8
-rw-r--r--tests/unit/controller/ItemControllerTest.php22
-rw-r--r--tests/unit/controller/PageControllerTest.php32
-rw-r--r--tests/unit/db/ItemMapperTest.php51
4 files changed, 96 insertions, 17 deletions
diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php
index 1b31963c1..48c077460 100644
--- a/tests/unit/businesslayer/ItemBusinessLayerTest.php
+++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php
@@ -127,7 +127,8 @@ class ItemBusinessLayerTest extends \PHPUnit_Framework_TestCase {
$this->equalTo($this->limit),
$this->equalTo($this->offset),
$this->equalTo($this->status),
- $this->equalTo($this->user))
+ $this->equalTo($this->user),
+ $this->equalTo(false))
->will($this->returnValue($this->response));
$result = $this->itemBusinessLayer->findAll(
@@ -164,13 +165,14 @@ class ItemBusinessLayerTest extends \PHPUnit_Framework_TestCase {
->with( $this->equalTo($this->limit),
$this->equalTo($this->offset),
$this->equalTo($this->status),
- $this->equalTo($this->user))
+ $this->equalTo($this->user),
+ $this->equalTo(true))
->will($this->returnValue($this->response));
$result = $this->itemBusinessLayer->findAll(
$this->id, $type, $this->limit,
$this->offset, $this->showAll,
- $this->user);
+ $this->user, true);
$this->assertEquals($this->response, $result);
}
diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php
index b4f87a0e9..1ebcdce55 100644
--- a/tests/unit/controller/ItemControllerTest.php
+++ b/tests/unit/controller/ItemControllerTest.php
@@ -188,20 +188,26 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase {
}
- private function itemsApiExpects($id, $type){
- $this->settings->expects($this->once())
+ private function itemsApiExpects($id, $type, $oldestFirst='1'){
+ $this->settings->expects($this->at(0))
->method('getUserValue')
->with($this->equalTo($this->user),
$this->equalTo($this->appName),
$this->equalTo('showAll'))
->will($this->returnValue('1'));
$this->settings->expects($this->at(1))
+ ->method('getUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo($this->appName),
+ $this->equalTo('oldestFirst'))
+ ->will($this->returnValue($oldestFirst));
+ $this->settings->expects($this->at(2))
->method('setUserValue')
->with($this->equalTo($this->user),
$this->equalTo($this->appName),
$this->equalTo('lastViewedFeedId'),
$this->equalTo($id));
- $this->settings->expects($this->at(2))
+ $this->settings->expects($this->at(3))
->method('setUserValue')
->with($this->equalTo($this->user),
$this->equalTo($this->appName),
@@ -219,7 +225,7 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase {
'starred' => 3111
];
- $this->itemsApiExpects(2, FeedType::FEED);
+ $this->itemsApiExpects(2, FeedType::FEED, '0');
$this->feedBusinessLayer->expects($this->once())
->method('findAll')
@@ -244,7 +250,8 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase {
$this->equalTo(3),
$this->equalTo(0),
$this->equalTo(true),
- $this->equalTo($this->user))
+ $this->equalTo($this->user),
+ $this->equalTo(false))
->will($this->returnValue($result['items']));
$response = $this->controller->index(FeedType::FEED, 2, 3);
@@ -264,13 +271,14 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase {
$this->equalTo(3),
$this->equalTo(10),
$this->equalTo(true),
- $this->equalTo($this->user))
+ $this->equalTo($this->user),
+ $this->equalTo(true))
->will($this->returnValue($result['items']));
$this->feedBusinessLayer->expects($this->never())
->method('findAll');
- $response = $this->controller->index(FeedType::FEED, 2, 3, 10);
+ $response = $this->controller->index(FeedType::FEED, 2, 3, 10, true);
$this->assertEquals($result, $response);
}
diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php
index d4c53e468..1e898c146 100644
--- a/tests/unit/controller/PageControllerTest.php
+++ b/tests/unit/controller/PageControllerTest.php
@@ -60,7 +60,9 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase {
$result = [
'showAll' => true,
'compact' => true,
- 'language' => 'de'
+ 'readOnScroll' => true,
+ 'oldestFirst' => true,
+ 'language' => 'de',
];
$this->l10n->expects($this->once())
@@ -78,6 +80,18 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase {
$this->equalTo($this->appName),
$this->equalTo('compact'))
->will($this->returnValue('1'));
+ $this->settings->expects($this->at(2))
+ ->method('getUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo($this->appName),
+ $this->equalTo('readOnScroll'))
+ ->will($this->returnValue('1'));
+ $this->settings->expects($this->at(3))
+ ->method('getUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo($this->appName),
+ $this->equalTo('oldestFirst'))
+ ->will($this->returnValue('1'));
$response = $this->controller->settings();
$this->assertEquals($result, $response);
@@ -97,7 +111,19 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase {
$this->equalTo($this->appName),
$this->equalTo('compact'),
$this->equalTo(true));
- $this->controller->updateSettings(true, true);
+ $this->settings->expects($this->at(2))
+ ->method('setUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo($this->appName),
+ $this->equalTo('readOnScroll'),
+ $this->equalTo(true));
+ $this->settings->expects($this->at(3))
+ ->method('setUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo($this->appName),
+ $this->equalTo('oldestFirst'),
+ $this->equalTo(true));
+ $this->controller->updateSettings(true, true, true, true);
}
@@ -113,7 +139,7 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase {
$this->equalTo('showAll'),
$this->equalTo(true));
- $this->controller->updateSettings(true, null);
+ $this->controller->updateSettings(true, null, null, null);
}
} \ No newline at end of file
diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php
index 15379f485..7a855b7bb 100644
--- a/tests/unit/db/ItemMapperTest.php
+++ b/tests/unit/db/ItemMapperTest.php
@@ -63,7 +63,12 @@ class ItemMapperTest extends \OCP\AppFramework\Db\MapperTestUtility {
}
- private function makeSelectQuery($prependTo){
+ private function makeSelectQuery($prependTo, $oldestFirst=false){
+ if($oldestFirst) {
+ $ordering = 'ASC';
+ } else {
+ $ordering = 'DESC';
+ }
return 'SELECT `items`.* FROM `*PREFIX*news_items` `items` '.
'JOIN `*PREFIX*news_feeds` `feeds` ' .
'ON `feeds`.`id` = `items`.`feed_id` '.
@@ -74,15 +79,15 @@ class ItemMapperTest extends \OCP\AppFramework\Db\MapperTestUtility {
'ON `folders`.`id` = `feeds`.`folder_id` ' .
'WHERE `feeds`.`folder_id` = 0 ' .
'OR `folders`.`deleted_at` = 0 ' .
- 'ORDER BY `items`.`id` DESC';
+ 'ORDER BY `items`.`id` ' . $ordering;
}
- private function makeSelectQueryStatus($prependTo, $status) {
+ private function makeSelectQueryStatus($prependTo, $status, $oldestFirst=false) {
$status = (int) $status;
return $this->makeSelectQuery(
'AND ((`items`.`status` & ' . $status . ') = ' . $status . ') ' .
- $prependTo
+ $prependTo, $oldestFirst
);
}
@@ -227,6 +232,19 @@ class ItemMapperTest extends \OCP\AppFramework\Db\MapperTestUtility {
}
+ public function testFindAllFeedOldestFirst(){
+ $sql = 'AND `items`.`feed_id` = ? ' .
+ 'AND `items`.`id` < ? ';
+ $sql = $this->makeSelectQueryStatus($sql, $this->status, true);
+ $params = [$this->user, $this->id, $this->offset];
+ $this->setMapperResult($sql, $params, $this->rows);
+ $result = $this->mapper->findAllFeed($this->id, $this->limit,
+ $this->offset, $this->status, $this->user, true);
+
+ $this->assertEquals($this->items, $result);
+ }
+
+
public function testFindAllFeedOffsetZero(){
$sql = 'AND `items`.`feed_id` = ? ';
$sql = $this->makeSelectQueryStatus($sql, $this->status);
@@ -252,6 +270,19 @@ class ItemMapperTest extends \OCP\AppFramework\Db\MapperTestUtility {
}
+ public function testFindAllFolderOldestFirst(){
+ $sql = 'AND `feeds`.`folder_id` = ? ' .
+ 'AND `items`.`id` < ? ';
+ $sql = $this->makeSelectQueryStatus($sql, $this->status, true);
+ $params = [$this->user, $this->id, $this->offset];
+ $this->setMapperResult($sql, $params, $this->rows);
+ $result = $this->mapper->findAllFolder($this->id, $this->limit,
+ $this->offset, $this->status, $this->user, true);
+
+ $this->assertEquals($this->items, $result);
+ }
+
+
public function testFindAllFolderOffsetZero(){
$sql = 'AND `feeds`.`folder_id` = ? ';
$sql = $this->makeSelectQueryStatus($sql, $this->status);
@@ -276,6 +307,18 @@ class ItemMapperTest extends \OCP\AppFramework\Db\MapperTestUtility {
}
+ public function testFindAllOldestFirst(){
+ $sql = 'AND `items`.`id` < ? ';
+ $sql = $this->makeSelectQueryStatus($sql, $this->status, true);
+ $params = [$this->user, $this->offset];
+ $this->setMapperResult($sql, $params, $this->rows);
+ $result = $this->mapper->findAll($this->limit,
+ $this->offset, $this->status, $this->user, true);
+
+ $this->assertEquals($this->items, $result);
+ }
+
+
public function testFindAllOffsetZero(){
$sql = $this->makeSelectQueryStatus('', $this->status);
$params = [$this->user];