|
| 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