summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-03-20 20:00:29 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2015-03-21 13:36:50 +0100
commit4dfafc5910baec90c9bc58aa61c1103dd41f13fe (patch)
tree34f9ffbcf2a8a8cbd792d5cb38ef4bb4ded39bbc /tests
parentc0dda27f2078de4c3adcf345383ba423c233fe9f (diff)
add a search parameter to the find all queries
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/controller/ItemControllerTest.php48
-rw-r--r--tests/unit/db/ItemMapperTest.php55
-rw-r--r--tests/unit/service/ItemServiceTest.php31
3 files changed, 125 insertions, 9 deletions
diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php
index 88e49c690..a58a907df 100644
--- a/tests/unit/controller/ItemControllerTest.php
+++ b/tests/unit/controller/ItemControllerTest.php
@@ -226,7 +226,8 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase {
$this->equalTo(0),
$this->equalTo(true),
$this->equalTo(false),
- $this->equalTo($this->user))
+ $this->equalTo($this->user),
+ $this->equalTo([]))
->will($this->returnValue($result['items']));
$response = $this->controller->index(FeedType::FEED, 2, 3);
@@ -234,6 +235,51 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase {
}
+ public function testIndexSearch(){
+ $feeds = [new Feed()];
+ $result = [
+ 'items' => [new Item()],
+ 'feeds' => $feeds,
+ 'newestItemId' => $this->newestItemId,
+ 'starred' => 3111
+ ];
+
+ $this->itemsApiExpects(2, FeedType::FEED, '0');
+
+ $this->feedService->expects($this->once())
+ ->method('findAll')
+ ->with($this->equalTo($this->user))
+ ->will($this->returnValue($feeds));
+
+ $this->itemService->expects($this->once())
+ ->method('getNewestItemId')
+ ->with($this->equalTo($this->user))
+ ->will($this->returnValue($this->newestItemId));
+
+ $this->itemService->expects($this->once())
+ ->method('starredCount')
+ ->with($this->equalTo($this->user))
+ ->will($this->returnValue(3111));
+
+ $this->itemService->expects($this->once())
+ ->method('findAll')
+ ->with(
+ $this->equalTo(2),
+ $this->equalTo(FeedType::FEED),
+ $this->equalTo(3),
+ $this->equalTo(0),
+ $this->equalTo(true),
+ $this->equalTo(false),
+ $this->equalTo($this->user),
+ $this->equalTo(['test', 'search']))
+ ->will($this->returnValue($result['items']));
+
+ $response = $this->controller->index(FeedType::FEED, 2, 3,
+ 0, null, null, 'test%20search');
+ $this->assertEquals($result, $response);
+ }
+
+
public function testItemsOffsetNotZero(){
$result = ['items' => [new Item()]];
diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php
index adb1dfe7a..de8e0226f 100644
--- a/tests/unit/db/ItemMapperTest.php
+++ b/tests/unit/db/ItemMapperTest.php
@@ -85,13 +85,19 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility {
}
private function makeSelectQueryStatus($prependTo, $status,
- $oldestFirst=false) {
+ $oldestFirst=false, $search=[]) {
$status = (int) $status;
- return $this->makeSelectQuery(
- 'AND ((`items`.`status` & ' . $status . ') = ' . $status . ') ' .
- $prependTo, $oldestFirst
- );
+ // WARNING: Potential SQL injection if you change this carelessly
+ $sql = 'AND ((`items`.`status` & ' . $status . ') = ' . $status . ') ';
+
+ foreach ($search as $_) {
+ $sql .= 'AND `items`.`search_index` LIKE ? ';
+ }
+
+ $sql .= $prependTo;
+
+ return $this->makeSelectQuery($sql, $oldestFirst);
}
@@ -244,6 +250,20 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility {
}
+ public function testFindAllFeedSearch(){
+ $sql = 'AND `items`.`feed_id` = ? ' .
+ 'AND `items`.`id` < ? ';
+ $search = ['%test_\\', 'a'];
+ $sql = $this->makeSelectQueryStatus($sql, $this->status, false, $search);
+ $params = [$this->user, '%\%test\\_\\\\%', '%a%', $this->id, $this->offset];
+ $this->setMapperResult($sql, $params, $this->rows, $this->limit);
+ $result = $this->mapper->findAllFeed($this->id, $this->limit,
+ $this->offset, $this->status, false, $this->user, $search);
+
+ $this->assertEquals($this->items, $result);
+ }
+
+
public function testFindAllFeedNegativeLimit(){
$sql = 'AND `items`.`feed_id` = ? ' .
'AND `items`.`id` < ? ';
@@ -294,6 +314,18 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility {
$this->assertEquals($this->items, $result);
}
+ public function testFindAllFolderSearch(){
+ $sql = 'AND `feeds`.`folder_id` = ? ' .
+ 'AND `items`.`id` < ? ';
+ $search = ['%test_\\', 'a'];
+ $sql = $this->makeSelectQueryStatus($sql, $this->status, false, $search);
+ $params = [$this->user, '%\%test\\_\\\\%', '%a%', $this->id, $this->offset];
+ $this->setMapperResult($sql, $params, $this->rows, $this->limit);
+ $result = $this->mapper->findAllFolder($this->id, $this->limit,
+ $this->offset, $this->status, false, $this->user, $search);
+
+ $this->assertEquals($this->items, $result);
+ }
public function testFindAllFolderNegativeLimit(){
$sql = 'AND `feeds`.`folder_id` = ? ' .
@@ -346,6 +378,19 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility {
}
+ public function testFindAllSearch(){
+ $sql = 'AND `items`.`id` < ? ';
+ $search = ['%test_\\', 'a'];
+ $params = [$this->user, '%\%test\\_\\\\%', '%a%', $this->offset];
+ $sql = $this->makeSelectQueryStatus($sql, $this->status, false, $search);
+ $this->setMapperResult($sql, $params, $this->rows, $this->limit);
+ $result = $this->mapper->findAll($this->limit,
+ $this->offset, $this->status, false, $this->user, $search);
+
+ $this->assertEquals($this->items, $result);
+ }
+
+
public function testFindAllNegativeLimit(){
$sql = 'AND `items`.`id` < ? ';
$sql = $this->makeSelectQueryStatus($sql, $this->status);
diff --git a/tests/unit/service/ItemServiceTest.php b/tests/unit/service/ItemServiceTest.php
index d7bf70dc9..be9f49148 100644
--- a/tests/unit/service/ItemServiceTest.php
+++ b/tests/unit/service/ItemServiceTest.php
@@ -125,7 +125,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
$this->equalTo($this->offset),
$this->equalTo($this->status),
$this->equalTo(false),
- $this->equalTo($this->user))
+ $this->equalTo($this->user),
+ $this->equalTo([]))
->will($this->returnValue($this->response));
$result = $this->itemService->findAll(
@@ -145,7 +146,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
$this->equalTo($this->offset),
$this->equalTo($this->status),
$this->equalTo(true),
- $this->equalTo($this->user))
+ $this->equalTo($this->user),
+ $this->equalTo([]))
->will($this->returnValue($this->response));
$result = $this->itemService->findAll(
@@ -164,7 +166,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
$this->equalTo($this->offset),
$this->equalTo($this->status),
$this->equalTo(true),
- $this->equalTo($this->user))
+ $this->equalTo($this->user),
+ $this->equalTo([]))
->will($this->returnValue($this->response));
$result = $this->itemService->findAll(
@@ -175,6 +178,28 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
+ public function testFindAllSearch(){
+ $type = FeedType::STARRED;
+ $search = ['test'];
+ $this->mapper->expects($this->once())
+ ->method('findAll')
+ ->with( $this->equalTo($this->limit),
+ $this->equalTo($this->offset),
+ $this->equalTo($this->status),
+ $this->equalTo(true),
+ $this->equalTo($this->user),
+ $this->equalTo($search))
+ ->will($this->returnValue($this->response));
+
+ $result = $this->itemService->findAll(
+ $this->id, $type, $this->limit, $this->offset,
+ $this->showAll, true, $this->user, $search
+ );
+ $this->assertEquals($this->response, $result);
+ }
+
+
+
public function testStar(){
$itemId = 3;
$feedId = 5;