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

Commit 014853f

Browse files
committed
ENH: refs #0340. Add stub admin ctrlr test for better coverage reporting
1 parent fb39c40 commit 014853f

File tree

3 files changed

+104
-7
lines changed

3 files changed

+104
-7
lines changed

core/controllers/AdminController.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,7 @@ function indexAction()
310310
function showlogAction()
311311
{
312312
$this->requireAdminPrivileges();
313-
$this->requireAjaxRequest();
314-
$this->_helper->layout->disableLayout();
313+
$this->disableLayout();
315314

316315
$start = $this->_getParam('startlog');
317316
$end = $this->_getParam('endlog');
@@ -388,8 +387,7 @@ function showlogAction()
388387
function deletelogAction()
389388
{
390389
$this->requireAdminPrivileges();
391-
$this->requireAjaxRequest();
392-
$this->_helper->layout->disableLayout();
390+
$this->disableLayout();
393391
$this->_helper->viewRenderer->setNoRender();
394392
$ids = $this->_getParam('idList');
395393
$count = 0;
@@ -414,9 +412,7 @@ function deletelogAction()
414412
function dashboardAction()
415413
{
416414
$this->requireAdminPrivileges();
417-
$this->requireAjaxRequest();
418-
419-
$this->_helper->layout->disableLayout();
415+
$this->disableLayout();
420416

421417
$this->view->dashboard = Zend_Registry::get('notifier')->callback("CALLBACK_CORE_GET_DASHBOARD");
422418

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
}

core/tests/controllers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
add_midas_test( AdminController AdminControllerTest.php )
12
add_midas_test( BrowseController BrowseControllerTest.php )
23
add_midas_test( FeedController FeedControllerTest.php )
34
add_midas_test( ItemController ItemControllerTest.php )

0 commit comments

Comments
 (0)