|
| 1 | +<?php |
| 2 | +/*========================================================================= |
| 3 | + MIDAS Server |
| 4 | + Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE |
| 5 | + All rights reserved. |
| 6 | + More information http://www.kitware.com |
| 7 | +
|
| 8 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | + you may not use this file except in compliance with the License. |
| 10 | + You may obtain a copy of the License at |
| 11 | +
|
| 12 | + http://www.apache.org/licenses/LICENSE-2.0.txt |
| 13 | +
|
| 14 | + Unless required by applicable law or agreed to in writing, software |
| 15 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + See the License for the specific language governing permissions and |
| 18 | + limitations under the License. |
| 19 | +=========================================================================*/ |
| 20 | +/** Test for admin controllers */ |
| 21 | +class AdminControllerTest extends ControllerTestCase |
| 22 | + { |
| 23 | + /** init tests*/ |
| 24 | + public function setUp() |
| 25 | + { |
| 26 | + $this->setupDatabase(array('default')); |
| 27 | + $this->_models = array('User'); |
| 28 | + $this->_daos = array('User'); |
| 29 | + parent::setUp(); |
| 30 | + } |
| 31 | + |
| 32 | + /** STUB: test index action */ |
| 33 | + public function testIndexAction() |
| 34 | + { |
| 35 | + // Need this line to render admin index page |
| 36 | + Zend_Registry::set('configCore', array()); |
| 37 | + |
| 38 | + $usersFile = $this->loadData('User', 'default'); |
| 39 | + $user1 = $this->User->load($usersFile[0]->getKey()); |
| 40 | + $adminUser = $this->User->load($usersFile[2]->getKey()); |
| 41 | + |
| 42 | + // Should get empty body if we try to access admin controller unlogged |
| 43 | + $this->dispatchUrI('/admin', null); |
| 44 | + $this->assertController('admin'); |
| 45 | + $this->assertAction('index'); |
| 46 | + $body = $this->getBody(); |
| 47 | + $this->assertTrue(empty($body)); |
| 48 | + |
| 49 | + // If a non admin tries to access admin page, should throw exception |
| 50 | + $this->resetAll(); |
| 51 | + $this->dispatchUrI('/admin', $user1, true); |
| 52 | + |
| 53 | + $this->resetAll(); |
| 54 | + $this->dispatchUrI('/admin', $adminUser); |
| 55 | + $this->assertController('admin'); |
| 56 | + $this->assertAction('index'); |
| 57 | + } |
| 58 | + |
| 59 | + /** STUB: test show log action */ |
| 60 | + public function testShowLogAction() |
| 61 | + { |
| 62 | + $usersFile = $this->loadData('User', 'default'); |
| 63 | + $user1 = $this->User->load($usersFile[0]->getKey()); |
| 64 | + $adminUser = $this->User->load($usersFile[2]->getKey()); |
| 65 | + |
| 66 | + // Should get exception if we try to access logs while not logged in |
| 67 | + $this->dispatchUrI('/admin/showlog', null, true); |
| 68 | + |
| 69 | + // Should get exception if we try to access logs as non admin |
| 70 | + $this->resetAll(); |
| 71 | + $this->dispatchUrI('/admin/showlog', $user1, true); |
| 72 | + |
| 73 | + // Should be able to see log page as admin user |
| 74 | + $this->resetAll(); |
| 75 | + $this->dispatchUrI('/admin/showlog', $adminUser); |
| 76 | + $this->assertController('admin'); |
| 77 | + $this->assertAction('showlog'); |
| 78 | + } |
| 79 | + |
| 80 | + /** STUB: test dashboard action */ |
| 81 | + public function testDashboardAction() |
| 82 | + { |
| 83 | + $usersFile = $this->loadData('User', 'default'); |
| 84 | + $user1 = $this->User->load($usersFile[0]->getKey()); |
| 85 | + $adminUser = $this->User->load($usersFile[2]->getKey()); |
| 86 | + |
| 87 | + // Should get exception if we try to access logs while not logged in |
| 88 | + $this->dispatchUrI('/admin/dashboard', null, true); |
| 89 | + |
| 90 | + // Should get exception if we try to access logs as non admin |
| 91 | + $this->resetAll(); |
| 92 | + $this->dispatchUrI('/admin/dashboard', $user1, true); |
| 93 | + |
| 94 | + // Should be able to see log page as admin user |
| 95 | + $this->resetAll(); |
| 96 | + $this->dispatchUrI('/admin/dashboard', $adminUser); |
| 97 | + $this->assertController('admin'); |
| 98 | + $this->assertAction('dashboard'); |
| 99 | + } |
| 100 | + } |
0 commit comments