diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-21 23:29:54 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-21 23:29:54 +0100 |
commit | e674fe47e6a44d693314af4149022d51597b42ab (patch) | |
tree | ea3bf0764b5f9d7af6127ce102487e1714d567aa /tests | |
parent | b6adabf245fb2e32763dda43a54270eef11d3411 (diff) |
disallow creating and renaming of folders that already exist
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bl/FolderBlTest.php | 36 | ||||
-rw-r--r-- | tests/db/FolderMapperTest.php | 17 |
2 files changed, 51 insertions, 2 deletions
diff --git a/tests/bl/FolderBlTest.php b/tests/bl/FolderBlTest.php index 6b771e02b..c9fe50802 100644 --- a/tests/bl/FolderBlTest.php +++ b/tests/bl/FolderBlTest.php @@ -65,18 +65,35 @@ class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility { $folder = new Folder(); $folder->setName('hey'); $folder->setParentId(5); + $folder->setUserId('john'); $this->folderMapper->expects($this->once()) ->method('insert') ->with($this->equalTo($folder)) ->will($this->returnValue($folder)); - $result = $this->folderBl->create('hey', 5); + $result = $this->folderBl->create('hey', 'john', 5); $this->assertEquals($folder, $result); } + public function testCreateThrowsExWhenFolderNameExists(){ + $folderName = 'hihi'; + $rows = array( + array('id' => 1) + ); + + $this->folderMapper->expects($this->once()) + ->method('findByName') + ->with($this->equalTo($folderName)) + ->will($this->returnValue($rows)); + + $this->setExpectedException('\OCA\News\Bl\BLException'); + $result = $this->folderBl->create($folderName, 'john', 3); + } + + public function testOpen(){ $folder = new Folder(); @@ -114,4 +131,21 @@ class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility { $this->assertEquals('bogus', $folder->getName()); } + + public function testRenameThrowsExWhenFolderNameExists(){ + $folderName = 'hihi'; + $rows = array( + array('id' => 1) + ); + + $this->folderMapper->expects($this->once()) + ->method('findByName') + ->with($this->equalTo($folderName)) + ->will($this->returnValue($rows)); + + $this->setExpectedException('\OCA\News\Bl\BLException'); + $result = $this->folderBl->rename(3, $folderName, 'john'); + } + + } diff --git a/tests/db/FolderMapperTest.php b/tests/db/FolderMapperTest.php index 469ea2701..924bd7068 100644 --- a/tests/db/FolderMapperTest.php +++ b/tests/db/FolderMapperTest.php @@ -107,7 +107,7 @@ class FolderMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { array('id' => $this->folders[1]->getId()) ); $sql = 'SELECT * FROM `*dbprefix*news_folders` ' . - 'AND `user_id` = ?'; + 'WHERE `user_id` = ?'; $this->setMapperResult($sql, array($userId), $rows); @@ -116,4 +116,19 @@ class FolderMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { } + public function testFindByName(){ + $userId = 'john'; + $rows = array( + array('id' => $this->folders[0]->getId()), + array('id' => $this->folders[1]->getId()) + ); + $sql = 'SELECT * FROM `*dbprefix*news_folders` ' . + 'WHERE `user_id` = ?'; + + $this->setMapperResult($sql, array($userId), $rows); + + $result = $this->folderMapper->findAllFromUser($userId); + $this->assertEquals($this->folders, $result); + } + }
\ No newline at end of file |