diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-03-20 20:00:29 +0100 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-03-21 13:36:50 +0100 |
commit | 4dfafc5910baec90c9bc58aa61c1103dd41f13fe (patch) | |
tree | 34f9ffbcf2a8a8cbd792d5cb38ef4bb4ded39bbc /tests/unit/db | |
parent | c0dda27f2078de4c3adcf345383ba423c233fe9f (diff) |
add a search parameter to the find all queries
Diffstat (limited to 'tests/unit/db')
-rw-r--r-- | tests/unit/db/ItemMapperTest.php | 55 |
1 files changed, 50 insertions, 5 deletions
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); |