diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/controller/FeedApiControllerTest.php | 8 | ||||
-rw-r--r-- | tests/unit/controller/FolderApiControllerTest.php | 10 | ||||
-rw-r--r-- | tests/unit/controller/ItemApiControllerTest.php | 18 | ||||
-rw-r--r-- | tests/unit/controller/ItemControllerTest.php | 8 | ||||
-rw-r--r-- | tests/unit/db/ItemMapperTest.php | 91 | ||||
-rw-r--r-- | tests/unit/service/ItemServiceTest.php | 27 |
6 files changed, 67 insertions, 95 deletions
diff --git a/tests/unit/controller/FeedApiControllerTest.php b/tests/unit/controller/FeedApiControllerTest.php index b5a167588..a276512f6 100644 --- a/tests/unit/controller/FeedApiControllerTest.php +++ b/tests/unit/controller/FeedApiControllerTest.php @@ -90,7 +90,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->feedAPI->index(); $this->assertEquals([ - 'feeds' => $feeds, + 'feeds' => [$feeds[0]->toAPI()], 'starredCount' => $starredCount, 'newestItemId' => $newestItemId ], $response); @@ -117,7 +117,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->feedAPI->index(); $this->assertEquals([ - 'feeds' => $feeds, + 'feeds' => [$feeds[0]->toAPI()], 'starredCount' => $starredCount, ], $response); } @@ -167,7 +167,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->feedAPI->create('url', 3); $this->assertEquals([ - 'feeds' => $feeds, + 'feeds' => [$feeds[0]->toAPI()], 'newestItemId' => 3 ], $response); } @@ -193,7 +193,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->feedAPI->create('ho', 3); $this->assertEquals([ - 'feeds' => $feeds + 'feeds' => [$feeds[0]->toAPI()] ], $response); } diff --git a/tests/unit/controller/FolderApiControllerTest.php b/tests/unit/controller/FolderApiControllerTest.php index 4a2c922b0..a2e3a4c6f 100644 --- a/tests/unit/controller/FolderApiControllerTest.php +++ b/tests/unit/controller/FolderApiControllerTest.php @@ -73,7 +73,9 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->folderAPI->index(); - $this->assertEquals($folders, $response); + $this->assertEquals([ + 'folders' => [$folders[0]->toAPI()] + ], $response); } @@ -81,7 +83,7 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $folderName = 'test'; $folder = new Folder(); $folder->setName($folderName); - + $this->folderService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); @@ -92,7 +94,9 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->folderAPI->create($folderName); - $this->assertEquals($folder, $response); + $this->assertEquals([ + 'folders' => [$folder->toAPI()] + ], $response); } diff --git a/tests/unit/controller/ItemApiControllerTest.php b/tests/unit/controller/ItemApiControllerTest.php index d95d67594..e1e91b424 100644 --- a/tests/unit/controller/ItemApiControllerTest.php +++ b/tests/unit/controller/ItemApiControllerTest.php @@ -61,14 +61,17 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { $this->equalTo(1), $this->equalTo(30), $this->equalTo(20), - $this->equalTo(false), + $this->equalTo(true), + $this->equalTo(true), $this->equalTo($this->user) ) ->will($this->returnValue($items)); - $response = $this->itemAPI->index(1, 2, false, 30, 20); + $response = $this->itemAPI->index(1, 2, true, 30, 20, true); - $this->assertEquals($items, $response); + $this->assertEquals([ + 'items' => [$items[0]->toApi()] + ], $response); } @@ -83,13 +86,16 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { $this->equalTo(20), $this->equalTo(0), $this->equalTo(false), + $this->equalTo(false), $this->equalTo($this->user) ) ->will($this->returnValue($items)); $response = $this->itemAPI->index(1, 2, false); - $this->assertEquals($items, $response); + $this->assertEquals([ + 'items' => [$items[0]->toApi()] + ], $response); } @@ -109,7 +115,9 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->itemAPI->updated(1, 2, 30); - $this->assertEquals($items, $response); + $this->assertEquals([ + 'items' => [$items[0]->toApi()] + ], $response); } diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php index a09b7d297..4b57068a9 100644 --- a/tests/unit/controller/ItemControllerTest.php +++ b/tests/unit/controller/ItemControllerTest.php @@ -196,8 +196,8 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $this->equalTo(3), $this->equalTo(0), $this->equalTo(true), - $this->equalTo($this->user), - $this->equalTo(false)) + $this->equalTo(false), + $this->equalTo($this->user)) ->will($this->returnValue($result['items'])); $response = $this->controller->index(FeedType::FEED, 2, 3); @@ -217,8 +217,8 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $this->equalTo(3), $this->equalTo(10), $this->equalTo(true), - $this->equalTo($this->user), - $this->equalTo(true)) + $this->equalTo(true), + $this->equalTo($this->user)) ->will($this->returnValue($result['items'])); $this->feedService->expects($this->never()) diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php index 629d7da38..a0ea3bae3 100644 --- a/tests/unit/db/ItemMapperTest.php +++ b/tests/unit/db/ItemMapperTest.php @@ -79,7 +79,7 @@ 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` ' . $ordering; + 'ORDER BY `items`.`pub_date`, `items`.`id` ' . $ordering; } private function makeSelectQueryStatus($prependTo, $status, $oldestFirst=false) { @@ -220,118 +220,77 @@ class ItemMapperTest extends \OCP\AppFramework\Db\MapperTestUtility { public function testFindAllFeed(){ - $sql = 'AND `items`.`feed_id` = ? ' . - 'AND `items`.`id` < ? '; + $sql = 'AND `items`.`feed_id` = ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = [$this->user, $this->id, $this->offset]; - $this->setMapperResult($sql, $params, $this->rows); + $params = [$this->user, $this->id]; + $this->setMapperResult($sql, $params, $this->rows, $this->limit, $this->offset); $result = $this->mapper->findAllFeed($this->id, $this->limit, - $this->offset, $this->status, $this->user); + $this->offset, $this->status, false, $this->user); $this->assertEquals($this->items, $result); } 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); + $sql = $this->makeSelectQueryStatus($sql, $this->status, true); $params = [$this->user, $this->id]; - $this->setMapperResult($sql, $params, $this->rows); + $this->setMapperResult($sql, $params, $this->rows, $this->limit, $this->offset); $result = $this->mapper->findAllFeed($this->id, $this->limit, - 0, $this->status, $this->user); + $this->offset, $this->status, true, $this->user); $this->assertEquals($this->items, $result); } public function testFindAllFolder(){ - $sql = 'AND `feeds`.`folder_id` = ? ' . - 'AND `items`.`id` < ? '; + $sql = 'AND `feeds`.`folder_id` = ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = [$this->user, $this->id, $this->offset]; - $this->setMapperResult($sql, $params, $this->rows); + $params = [$this->user, $this->id]; + $this->setMapperResult($sql, $params, $this->rows, $this->limit, $this->offset); $result = $this->mapper->findAllFolder($this->id, $this->limit, - $this->offset, $this->status, $this->user); + $this->offset, $this->status, false, $this->user); $this->assertEquals($this->items, $result); } 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); + $sql = $this->makeSelectQueryStatus($sql, $this->status, true); $params = [$this->user, $this->id]; - $this->setMapperResult($sql, $params, $this->rows); + $this->setMapperResult($sql, $params, $this->rows, $this->limit, $this->offset); $result = $this->mapper->findAllFolder($this->id, $this->limit, - 0, $this->status, $this->user); + $this->offset, $this->status, true, $this->user); $this->assertEquals($this->items, $result); } public function testFindAll(){ - $sql = 'AND `items`.`id` < ? '; + $sql = ''; $sql = $this->makeSelectQueryStatus($sql, $this->status); - $params = [$this->user, $this->offset]; - $this->setMapperResult($sql, $params, $this->rows); + $params = [$this->user]; + $this->setMapperResult($sql, $params, $this->rows, $this->limit, $this->offset); $result = $this->mapper->findAll($this->limit, - $this->offset, $this->status, $this->user); + $this->offset, $this->status, false, $this->user); $this->assertEquals($this->items, $result); } public function testFindAllOldestFirst(){ - $sql = 'AND `items`.`id` > ? '; + $sql = ''; $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]; - $this->setMapperResult($sql, $params, $this->rows); + $this->setMapperResult($sql, $params, $this->rows, $this->limit, $this->offset); $result = $this->mapper->findAll($this->limit, - 0, $this->status, $this->user); + $this->offset, $this->status, true, $this->user); $this->assertEquals($this->items, $result); } - - public function testFindByGuidHash(){ $hash = md5('test'); $feedId = 3; @@ -349,7 +308,7 @@ class ItemMapperTest extends \OCP\AppFramework\Db\MapperTestUtility { public function testDeleteReadOlderThanThresholdDoesNotDeleteBelowThreshold(){ $status = StatusFlag::STARRED | StatusFlag::UNREAD; $sql = 'SELECT COUNT(*) - `feeds`.`articles_per_update` AS `size`, ' . - '`items`.`feed_id` AS `feed_id` ' . + '`items`.`feed_id` AS `feed_id` ' . 'FROM `*PREFIX*news_items` `items` ' . 'JOIN `*PREFIX*news_feeds` `feeds` ' . 'ON `feeds`.`id` = `items`.`feed_id` ' . @@ -373,7 +332,7 @@ class ItemMapperTest extends \OCP\AppFramework\Db\MapperTestUtility { $status = StatusFlag::STARRED | StatusFlag::UNREAD; $sql1 = 'SELECT COUNT(*) - `feeds`.`articles_per_update` AS `size`, ' . - '`items`.`feed_id` AS `feed_id` ' . + '`items`.`feed_id` AS `feed_id` ' . 'FROM `*PREFIX*news_items` `items` ' . 'JOIN `*PREFIX*news_feeds` `feeds` ' . 'ON `feeds`.`id` = `items`.`feed_id` ' . @@ -430,7 +389,7 @@ class ItemMapperTest extends \OCP\AppFramework\Db\MapperTestUtility { public function testDeleteFromUser(){ $userId = 'john'; - $sql = 'DELETE FROM `*PREFIX*news_items` ' . + $sql = 'DELETE FROM `*PREFIX*news_items` ' . 'WHERE `feed_id` IN (' . 'SELECT `feeds`.`id` FROM `*PREFIX*news_feeds` `feeds` ' . 'WHERE `feeds`.`user_id` = ?' . diff --git a/tests/unit/service/ItemServiceTest.php b/tests/unit/service/ItemServiceTest.php index e9c8e70c4..81cbf1bff 100644 --- a/tests/unit/service/ItemServiceTest.php +++ b/tests/unit/service/ItemServiceTest.php @@ -127,14 +127,14 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { $this->equalTo($this->limit), $this->equalTo($this->offset), $this->equalTo($this->status), - $this->equalTo($this->user), - $this->equalTo(false)) + $this->equalTo(false), + $this->equalTo($this->user)) ->will($this->returnValue($this->response)); $result = $this->itemService->findAll( - $this->id, $type, $this->limit, - $this->offset, $this->showAll, - $this->user); + $this->id, $type, $this->limit, $this->offset, + $this->showAll, false, $this->user + ); $this->assertEquals($this->response, $result); } @@ -147,13 +147,14 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { $this->equalTo($this->limit), $this->equalTo($this->offset), $this->equalTo($this->status), + $this->equalTo(true), $this->equalTo($this->user)) ->will($this->returnValue($this->response)); $result = $this->itemService->findAll( - $this->id, $type, $this->limit, - $this->offset, $this->showAll, - $this->user); + $this->id, $type, $this->limit, $this->offset, + $this->showAll, true, $this->user + ); $this->assertEquals($this->response, $result); } @@ -165,14 +166,14 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo($this->limit), $this->equalTo($this->offset), $this->equalTo($this->status), - $this->equalTo($this->user), - $this->equalTo(true)) + $this->equalTo(true), + $this->equalTo($this->user)) ->will($this->returnValue($this->response)); $result = $this->itemService->findAll( - $this->id, $type, $this->limit, - $this->offset, $this->showAll, - $this->user, true); + $this->id, $type, $this->limit, $this->offset, + $this->showAll, true, $this->user + ); $this->assertEquals($this->response, $result); } |