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

Commit

Permalink
ENH: refs #0340. Add stub admin ctrlr test for better coverage reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmullen committed Jan 16, 2012
1 parent fb39c40 commit 014853f
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 7 deletions.
10 changes: 3 additions & 7 deletions core/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ function indexAction()
function showlogAction()
{
$this->requireAdminPrivileges();
$this->requireAjaxRequest();
$this->_helper->layout->disableLayout();
$this->disableLayout();

$start = $this->_getParam('startlog');
$end = $this->_getParam('endlog');
Expand Down Expand Up @@ -388,8 +387,7 @@ function showlogAction()
function deletelogAction()
{
$this->requireAdminPrivileges();
$this->requireAjaxRequest();
$this->_helper->layout->disableLayout();
$this->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$ids = $this->_getParam('idList');
$count = 0;
Expand All @@ -414,9 +412,7 @@ function deletelogAction()
function dashboardAction()
{
$this->requireAdminPrivileges();
$this->requireAjaxRequest();

$this->_helper->layout->disableLayout();
$this->disableLayout();

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

Expand Down
100 changes: 100 additions & 0 deletions core/tests/controllers/AdminControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
/** Test for admin controllers */
class AdminControllerTest extends ControllerTestCase
{
/** init tests*/
public function setUp()
{
$this->setupDatabase(array('default'));
$this->_models = array('User');
$this->_daos = array('User');
parent::setUp();
}

/** STUB: test index action */
public function testIndexAction()
{
// Need this line to render admin index page
Zend_Registry::set('configCore', array());

$usersFile = $this->loadData('User', 'default');
$user1 = $this->User->load($usersFile[0]->getKey());
$adminUser = $this->User->load($usersFile[2]->getKey());

// Should get empty body if we try to access admin controller unlogged
$this->dispatchUrI('/admin', null);
$this->assertController('admin');
$this->assertAction('index');
$body = $this->getBody();
$this->assertTrue(empty($body));

// If a non admin tries to access admin page, should throw exception
$this->resetAll();
$this->dispatchUrI('/admin', $user1, true);

$this->resetAll();
$this->dispatchUrI('/admin', $adminUser);
$this->assertController('admin');
$this->assertAction('index');
}

/** STUB: test show log action */
public function testShowLogAction()
{
$usersFile = $this->loadData('User', 'default');
$user1 = $this->User->load($usersFile[0]->getKey());
$adminUser = $this->User->load($usersFile[2]->getKey());

// Should get exception if we try to access logs while not logged in
$this->dispatchUrI('/admin/showlog', null, true);

// Should get exception if we try to access logs as non admin
$this->resetAll();
$this->dispatchUrI('/admin/showlog', $user1, true);

// Should be able to see log page as admin user
$this->resetAll();
$this->dispatchUrI('/admin/showlog', $adminUser);
$this->assertController('admin');
$this->assertAction('showlog');
}

/** STUB: test dashboard action */
public function testDashboardAction()
{
$usersFile = $this->loadData('User', 'default');
$user1 = $this->User->load($usersFile[0]->getKey());
$adminUser = $this->User->load($usersFile[2]->getKey());

// Should get exception if we try to access logs while not logged in
$this->dispatchUrI('/admin/dashboard', null, true);

// Should get exception if we try to access logs as non admin
$this->resetAll();
$this->dispatchUrI('/admin/dashboard', $user1, true);

// Should be able to see log page as admin user
$this->resetAll();
$this->dispatchUrI('/admin/dashboard', $adminUser);
$this->assertController('admin');
$this->assertAction('dashboard');
}
}
1 change: 1 addition & 0 deletions core/tests/controllers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_midas_test( AdminController AdminControllerTest.php )
add_midas_test( BrowseController BrowseControllerTest.php )
add_midas_test( FeedController FeedControllerTest.php )
add_midas_test( ItemController ItemControllerTest.php )
Expand Down

0 comments on commit 014853f

Please sign in to comment.