diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-22 13:20:24 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-22 13:20:24 +0100 |
commit | 196177a0ca3fc0103d359eec44f46173be685413 (patch) | |
tree | f721b656d64e240050980420202873e94f6e9edc /tests | |
parent | 7a579b42fa731b65db26bd0c026bc68f2339c451 (diff) |
removed mapper parent class and use the new mapper methods from the framework
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bl/BlTest.php | 25 | ||||
-rw-r--r-- | tests/db/ItemMapperTest.php | 15 | ||||
-rw-r--r-- | tests/db/NewsMapperTest.php | 86 |
3 files changed, 29 insertions, 97 deletions
diff --git a/tests/bl/BlTest.php b/tests/bl/BlTest.php index 5dc16d5a2..0878ddccf 100644 --- a/tests/bl/BlTest.php +++ b/tests/bl/BlTest.php @@ -28,6 +28,8 @@ namespace OCA\News\Bl; require_once(__DIR__ . "/../classloader.php"); +use \OCA\AppFramework\Db\DoesNotExistException; +use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Folder; @@ -40,14 +42,15 @@ class TestBl extends BL { class BlTest extends \OCA\AppFramework\Utility\TestUtility { protected $api; - protected $newsMapper; + protected $mapper; protected $newsBl; protected function setUp(){ $this->api = $this->getAPIMock(); - $this->newsMapper = $this->getMock('\OCA\News\Db\NewsMapper', - array('update', 'delete', 'find'), array($this->api, 'test')); - $this->newsBl = new TestBl($this->newsMapper); + $this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') + ->disableOriginalConstructor() + ->getMock(); + $this->newsBl = new TestBl($this->mapper); } @@ -57,10 +60,10 @@ class BlTest extends \OCA\AppFramework\Utility\TestUtility { $folder = new Folder(); $folder->setId($id); - $this->newsMapper->expects($this->once()) + $this->mapper->expects($this->once()) ->method('delete') ->with($this->equalTo($folder)); - $this->newsMapper->expects($this->once()) + $this->mapper->expects($this->once()) ->method('find') ->with($this->equalTo($id), $this->equalTo($user)) ->will($this->returnValue($folder)); @@ -73,7 +76,7 @@ class BlTest extends \OCA\AppFramework\Utility\TestUtility { $id = 3; $user = 'ken'; - $this->newsMapper->expects($this->once()) + $this->mapper->expects($this->once()) ->method('find') ->with($this->equalTo($id), $this->equalTo($user)); @@ -82,9 +85,9 @@ class BlTest extends \OCA\AppFramework\Utility\TestUtility { public function testFindDoesNotExist(){ - $ex = new \OCA\AppFramework\Db\DoesNotExistException('hi'); + $ex = new DoesNotExistException('hi'); - $this->newsMapper->expects($this->once()) + $this->mapper->expects($this->once()) ->method('find') ->will($this->throwException($ex)); @@ -94,9 +97,9 @@ class BlTest extends \OCA\AppFramework\Utility\TestUtility { public function testFindMultiple(){ - $ex = new \OCA\AppFramework\Db\MultipleObjectsReturnedException('hi'); + $ex = new MultipleObjectsReturnedException('hi'); - $this->newsMapper->expects($this->once()) + $this->mapper->expects($this->once()) ->method('find') ->will($this->throwException($ex)); diff --git a/tests/db/ItemMapperTest.php b/tests/db/ItemMapperTest.php index 82b5b2faf..fb37f9bc0 100644 --- a/tests/db/ItemMapperTest.php +++ b/tests/db/ItemMapperTest.php @@ -76,6 +76,21 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { $this->assertEquals($this->items[0], $result); } + + + public function testFindByUrlHash(){ + $urlHash = md5('hihi'); + $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`.`url_hash` = ? ' . + 'AND `*dbprefix*news_feeds`.`user_id` = ? '; + $this->setMapperResult($sql, array($urlHash, $this->userId), $this->row); + + $result = $this->itemMapper->findByUrlHash($urlHash, $this->userId); + $this->assertEquals($this->items[0], $result); + } + // // public function testFindNotFound(){ // $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . diff --git a/tests/db/NewsMapperTest.php b/tests/db/NewsMapperTest.php deleted file mode 100644 index 77459ff27..000000000 --- a/tests/db/NewsMapperTest.php +++ /dev/null @@ -1,86 +0,0 @@ -<?php - -/** -* ownCloud - News -* -* @author Alessandro Cosentino -* @author Bernhard Posselt -* @copyright 2012 Alessandro Cosentino cosenal@gmail.com -* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -namespace OCA\News\Db; -use \OCA\AppFramework\Core\API; - -require_once(__DIR__ . "/../classloader.php"); - -class MapperNews extends NewsMapper { - public function __construct(API $api, $tableName){ - parent::__construct($api, $tableName); - } - - public function publicFindRow($sql, $id, $userId){ - return $this->findRow($sql, $id, $userId); - } -} - -class NewsMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { - - private $newsMapper; - - public function setUp() { - $this->beforeEach(); - $this->newsMapper = new MapperNews($this->api, 'news_table'); - - $this->userId = 'john'; - $this->id = 2; - - $this->rows = array( - array('testRow') - ); - } - - public function testFindRow() { - $sql = 'test'; - - $this->setMapperResult($sql, array($this->id, $this->userId), $this->rows); - - $result = $this->newsMapper->publicFindRow($sql, $this->id, $this->userId); - $this->assertEquals($this->rows[0], $result); - - } - - public function testFindRowNoFound() { - $sql = 'test'; - - $this->setMapperResult($sql, array($this->id, $this->userId), array()); - - $this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException'); - $this->newsMapper->publicFindRow($sql, $this->id, $this->userId); - - } - - public function testFindRowMultipleRows() { - $sql = 'test'; - array_push($this->rows, array('testRow2')); - $this->setMapperResult($sql, array($this->id, $this->userId), $this->rows); - - $this->setExpectedException('\OCA\AppFramework\Db\MultipleObjectsReturnedException'); - $this->newsMapper->publicFindRow($sql, $this->id, $this->userId); - - } -}
\ No newline at end of file |