diff options
author | Alessandro Cosentino <cosenal@gmail.com> | 2013-03-21 18:00:07 +0100 |
---|---|---|
committer | Alessandro Cosentino <cosenal@gmail.com> | 2013-03-21 18:00:07 +0100 |
commit | 25177ab4935fea917e6b1ec9dedb2b0258f2ed02 (patch) | |
tree | ef299ee2a4a8f528280eeae55d4b45772cb94b3f /tests/db | |
parent | 3e1225f30a53d1fa217d01f8594514e6832c9464 (diff) |
not working itemmapper with tests
Diffstat (limited to 'tests/db')
-rw-r--r-- | tests/db/ItemMapperTest.php | 254 |
1 files changed, 137 insertions, 117 deletions
diff --git a/tests/db/ItemMapperTest.php b/tests/db/ItemMapperTest.php index 983bfc933..f8db1da70 100644 --- a/tests/db/ItemMapperTest.php +++ b/tests/db/ItemMapperTest.php @@ -33,11 +33,12 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { private $itemMapper; private $items; - protected function setUp(){ + public function setUp() + { $this->beforeEach(); - + $this->itemMapper = new ItemMapper($this->api); - + // create mock items $item1 = new Item(); $item2 = new Item(); @@ -46,150 +47,169 @@ 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()) + ); + } - + public function testFind(){ - $userId = 'john'; - $id = 3; - $rows = array( - array('id' => $this->items[0]->getId()), - ); $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . 'JOIN `*dbprefix*news_feeds` ' . 'ON `*dbprefix*news_feeds`.`id` = `*dbprefix*news_items`.`feed_id` ' . 'WHERE `*dbprefix*news_items`.`id` = ? ' . 'AND `*dbprefix*news_feeds`.`user_id` = ? '; - $this->setMapperResult($sql, array($id, $userId), $rows); + $this->setMapperResult($sql, array($this->id, $this->userId), $this->row); - $result = $this->itemMapper->find($id, $userId); - $this->assertEquals($this->items[0], $result); + $result = $this->itemMapper->find($this->id, $this->userId); + $this->assertEquals($this->items, $result); } - - public function testFindNotFound(){ - $userId = 'john'; - $id = 3; - $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . +// +// public function testFindNotFound(){ +// $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . +// 'JOIN `*dbprefix*news_feeds` ' . +// 'ON `*dbprefix*news_feeds`.`id` = `*dbprefix*news_items`.`feed_id` ' . +// 'WHERE `*dbprefix*news_items`.`id` = ? ' . +// 'AND `*dbprefix*news_feeds`.`user_id` = ? '; +// +// $this->setMapperResult($sql, array($id, $userId)); +// +// $this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException'); +// $result = $this->itemMapper->find($id, $userId); +// } +// +// public function testFindMoreThanOneResultFound(){ +// $rows = array( +// array('id' => $this->items[0]->getId()), +// array('id' => $this->items[1]->getId()) +// ); +// $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . +// 'JOIN `*dbprefix*news_feeds` ' . +// 'ON `*dbprefix*news_feeds`.`id` = `*dbprefix*news_items`.`feed_id` ' . +// 'WHERE `*dbprefix*news_items`.`id` = ? ' . +// 'AND `*dbprefix*news_feeds`.`user_id` = ? '; +// +// +// $this->setMapperResult($sql, array($id, $userId), $rows); +// +// $this->setExpectedException('\OCA\AppFramework\Db\MultipleObjectsReturnedException'); +// $result = $this->itemMapper->find($id, $userId); +// } +// +// public function testFindAllFromFeed(){ +// $userId = 'john'; +// $feedId = 3; +// $rows = array( +// array('id' => $this->items[0]->getId()), +// array('id' => $this->items[1]->getId()) +// ); +// $sql = 'SELECT * FROM `*PREFIX*news_items` ' . +// 'WHERE user_id = ? ' . +// 'AND feed_id = ?'; +// +// $this->setMapperResult($sql, array($feedId, $userId), $rows); +// $result = $this->itemMapper->findAllFromFeed($feedId, $userId); +// $this->assertEquals($this->items, $result); +// +// } +// +// public function testFindAllFromFeedByStatus(){ +// $userId = 'john'; +// $feedId = 3; +// $status = 2; +// $rows = array( +// array('id' => $this->items[0]->getId()), +// array('id' => $this->items[1]->getId()) +// ); +// $sql = 'SELECT * FROM `*PREFIX*news_items` ' . +// 'WHERE user_id = ? ' . +// 'AND feed_id = ? ' . +// 'AND ((`*dbprefix*news_items`.`status` & ?) > 0)'; +// +// $this->setMapperResult($sql, array($feedId, $userId, $status), $rows); +// $result = $this->itemMapper->findAllFromFeedByStatus($feedId, $userId, $status); +// $this->assertEquals($this->items, $result); +// +// } + + private function makeFindAllFromFolderQuery($custom) { + return 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . 'JOIN `*dbprefix*news_feeds` ' . 'ON `*dbprefix*news_feeds`.`id` = `*dbprefix*news_items`.`feed_id` ' . - 'WHERE `*dbprefix*news_items`.`id` = ? ' . - 'AND `*dbprefix*news_feeds`.`user_id` = ? '; - - $this->setMapperResult($sql, array($id, $userId)); - - $this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException'); - $result = $this->itemMapper->find($id, $userId); + 'WHERE `*dbprefix*news_feeds`.`user_id` = ? ' . + 'AND `*dbprefix*news_feeds`.`folder_id` = ? ' . + 'AND ((`*dbprefix*news_items`.`status` & ?) > 0) ' . + $custom; } - public function testFindMoreThanOneResultFound(){ - $userId = 'john'; - $id = 3; - $rows = array( - array('id' => $this->items[0]->getId()), - array('id' => $this->items[1]->getId()) - ); - $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . - 'JOIN `*dbprefix*news_feeds` ' . - 'ON `*dbprefix*news_feeds`.`id` = `*dbprefix*news_items`.`feed_id` ' . - 'WHERE `*dbprefix*news_items`.`id` = ? ' . - 'AND `*dbprefix*news_feeds`.`user_id` = ? '; - + public function testFindAllFromFolder() { + $sql = $this->makeFindAllFromFolderQuery(''); - $this->setMapperResult($sql, array($id, $userId), $rows); + $status = 2; - $this->setExpectedException('\OCA\AppFramework\Db\MultipleObjectsReturnedException'); - $result = $this->itemMapper->find($id, $userId); - } - - public function testFindAllFromFeed(){ - $userId = 'john'; - $feedId = 3; - $rows = array( - array('id' => $this->items[0]->getId()), - array('id' => $this->items[1]->getId()) - ); - $sql = 'SELECT * FROM `*PREFIX*news_items` ' . - 'WHERE user_id = ? ' . - 'AND feed_id = ?'; - - $this->setMapperResult($sql, array($feedId, $userId), $rows); - $result = $this->itemMapper->findAllFromFeed($feedId, $userId); + $params = array($this->userId, $this->folderId, $status); + $this->setMapperResult($sql, $params, $this->rows); + $result = $this->itemMapper->findAllFromFolderByOffset($this->userId, $this->folderId, $status); $this->assertEquals($this->items, $result); - + } - public function testFindAllFromFeedByStatus(){ - $userId = 'john'; - $feedId = 3; + public function testFindAllFromFolderByOffset() { + $sql = $this->makeFindAllFromFolderQuery(''); + $status = 2; - $rows = array( - array('id' => $this->items[0]->getId()), - array('id' => $this->items[1]->getId()) - ); - $sql = 'SELECT * FROM `*PREFIX*news_items` ' . - 'WHERE user_id = ? ' . - 'AND feed_id = ? ' . - 'AND ((`*dbprefix*news_items`.`status` & ?) > 0)'; - - $this->setMapperResult($sql, array($feedId, $userId, $status), $rows); - $result = $this->itemMapper->findAllFromFeedByStatus($feedId, $userId, $status); + $limit = 10; + $offset = 10; + + $params = array($this->userId, $this->folderId, $status); + $this->setMapperResult($sql, $params, $this->rows); + $result = $this->itemMapper->findAllFromFolderByOffset($this->userId, $this->folderId, $status, $limit, $offset); $this->assertEquals($this->items, $result); - + } - public function testFindAllFromFolder() { - $userId = 'john'; - $folderId = 3; + public function testFindAllFromFolderByLastModified() { + $sql = $this->makeFindAllFromFolderQuery(' AND (`*dbprefix*news_items`.`last_modified` >= ?)'); - $rows = array( - array('id' => $this->items[0]->getId()), - array('id' => $this->items[1]->getId()) - ); + $status = 2; + $lastModified = 100; - $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . - 'JOIN `*dbprefix*news_feeds` ' . - 'ON `*dbprefix*news_feeds`.`id` = `*dbprefix*news_items`.`feed_id` ' . - 'WHERE `*dbprefix*news_feeds`.`user_id` = ? ' . - 'AND `*dbprefix*news_feeds`.`folder_id` = ? '; - - $this->setMapperResult($sql, array($userId, $folderId), $rows); - $result = $this->itemMapper->findAllFromFolder($userId, $folderId); + $params = array($this->userId, $this->folderId, $status, $lastModified); + $this->setMapperResult($sql, $params, $this->rows); + $result = $this->itemMapper->findAllFromFolderByLastMofified($this->userId, $this->folderId, $status, $lastModified); $this->assertEquals($this->items, $result); } - public function testFindAllFromFolderByStatus() { - $userId = 'john'; - $folderId = 3; - $status = 2; - $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . - 'JOIN `*dbprefix*news_feeds` ' . - 'ON `*dbprefix*news_feeds`.`id` = `*dbprefix*news_items`.`feed_id` ' . - 'WHERE `*dbprefix*news_feeds`.`user_id` = ? ' . - 'AND `*dbprefix*news_feeds`.`folder_id` = ? ' . - 'AND ((`*dbprefix*news_items`.`status` & ?) > 0)'; - - $this->setMapperResult($sql, array($userId, $folderId, $status)); - $result = $this->itemMapper->findAllFromFolderByStatus($userId, $folderId, $status); - - } - - public function testFindAllFromFolderByLastModified() { - $userId = 'john'; - $folderId = 3; - $lastModified = 123; - - $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . - 'JOIN `*dbprefix*news_feeds` ' . - 'ON `*dbprefix*news_feeds`.`id` = `*dbprefix*news_items`.`feed_id` ' . - 'WHERE `*dbprefix*news_feeds`.`user_id` = ? ' . - 'AND `*dbprefix*news_feeds`.`folder_id` = ? ' . - 'AND `*dbprefix*news_items`.last_modified >= ? '; - - $this->setMapperResult($sql, array($userId, $folderId, $lastModified)); - $result = $this->itemMapper->findAllFromFolderByLastMofified($userId, $folderId, $lastModified); - } +// } +// +// public function testFindAllFromFolderByLastModified() { +// $userId = 'john'; +// $folderId = 3; +// $lastModified = 123; +// +// $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . +// 'JOIN `*dbprefix*news_feeds` ' . +// 'ON `*dbprefix*news_feeds`.`id` = `*dbprefix*news_items`.`feed_id` ' . +// 'WHERE `*dbprefix*news_feeds`.`user_id` = ? ' . +// 'AND `*dbprefix*news_feeds`.`folder_id` = ? ' . +// 'AND `*dbprefix*news_items`.last_modified >= ? '; +// +// $this->setMapperResult($sql, array($userId, $folderId, $lastModified)); +// $result = $this->itemMapper->findAllFromFolderByLastMofified($userId, $folderId, $lastModified); +// } }
\ No newline at end of file |