Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 47807bb

Browse files
committed
ENH: refs #0355. Add a test to make sure item delete doesn't break again
1 parent e82bb22 commit 47807bb

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed

core/controllers/ItemController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,21 @@ function editAction()
292292
$this->view->form = $formArray;
293293
}
294294

295-
/** Delete an item*/
295+
/** Delete an item */
296296
function deleteAction()
297297
{
298-
$this->_helper->layout->disableLayout();
298+
$this->disableLayout();
299299
$this->_helper->viewRenderer->setNoRender();
300300

301-
$itemId = $this->_getParam("itemId");
301+
$itemId = $this->_getParam('itemId');
302302
if(!isset($itemId) || (!is_numeric($itemId) && strlen($itemId) != 32)) // This is tricky! and for Cassandra for now
303303
{
304304
throw new Zend_Exception("itemId should be a number");
305305
}
306306
$itemDao = $this->Item->load($itemId);
307307
if($itemDao === false || !$this->Item->policyCheck($itemDao, $this->userSession->Dao, MIDAS_POLICY_ADMIN))
308308
{
309-
throw new Zend_Exception("This community doesn't exist or you don't have the permissions.");
309+
throw new Zend_Exception("This item doesn't exist or you don't have the permissions.");
310310
}
311311

312312
$this->Item->delete($itemDao);

core/tests/controllers/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
add_midas_test( IndexController IndexControllerTest.php )
21
add_midas_test( FeedController FeedControllerTest.php )
3-
add_midas_test( UserController UserControllerTest.php )
2+
add_midas_test( ItemController ItemControllerTest.php )
3+
add_midas_test( IndexController IndexControllerTest.php )
44
add_midas_test( UploadDownloadController UploadDownloadControllerTest.php )
5+
add_midas_test( UserController UserControllerTest.php )
56

67
add_subdirectory( components )
78

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
/** test item controller*/
13+
class ItemControllerTest extends ControllerTestCase
14+
{
15+
16+
/** init test*/
17+
public function setUp()
18+
{
19+
$this->setupDatabase(array('default'));
20+
$this->_models = array('Item', 'ItemRevision', 'User');
21+
parent::setUp();
22+
}
23+
24+
/** Test explicit deletion of an item */
25+
public function testDeleteAction()
26+
{
27+
$itemsFile = $this->loadData('Item', 'default');
28+
$usersFile = $this->loadData('User', 'default');
29+
$userWithPermission = $this->User->load($usersFile[0]->getKey());
30+
$userWithoutPermission = $this->User->load($usersFile[1]->getKey());
31+
32+
$itemDao = $this->Item->load($itemsFile[1]->getKey());
33+
$this->assertEquals(count($itemDao->getRevisions()), 1);
34+
$revisions = $itemDao->getRevisions();
35+
$revisionId = $revisions[0]->getItemrevisionId();
36+
37+
$url = '/item/delete?itemId='.$itemDao->getItemId();
38+
39+
// Should throw an exception for anonymous user
40+
$this->dispatchUrI($url, null, true);
41+
$this->assertController('error');
42+
43+
// Should throw an exception for normal user
44+
$this->resetAll();
45+
$this->dispatchUrI($url, $userWithoutPermission, true);
46+
$this->assertController('error');
47+
48+
// User with proper privileges should be able to delete the item
49+
$this->resetAll();
50+
$this->dispatchUrI($url, $userWithPermission);
51+
$this->assertController('item');
52+
$this->assertAction('delete');
53+
54+
$this->assertFalse($this->Item->load($itemsFile[1]->getKey()));
55+
$this->assertFalse($this->ItemRevision->load($revisionId));
56+
}
57+
58+
}

0 commit comments

Comments
 (0)