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

Commit af25e71

Browse files
author
Michael Grauer
committed
ENH: refs #0322. Allow batchmake tests to pass test configs.
Batchmake tests and KWBatchmakeComponent had assumed an install was performed, but this isn't the case for a dashboard machine. Now the controller tests will set a test config through the Zend_Registry, and the KWBatchmakeComponent will check if it is in testing mode if it cannot find an installed config.
1 parent be25fcd commit af25e71

File tree

3 files changed

+78
-25
lines changed

3 files changed

+78
-25
lines changed

modules/batchmake/controllers/components/KWBatchmakeComponent.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,37 @@ public function filterBatchmakeConfigProperties($fullConfig)
142142
*/
143143
public function loadConfigProperties($alternateConfig = null, $batchmakeOnly = true)
144144
{
145-
// load the full config
146-
$rawConfig = $this->loadConfig(true);
147-
// get the global namespace props
148-
$globalProps = $rawConfig['global'];
145+
try
146+
{
147+
// load the full config
148+
$rawConfig = $this->loadConfig(true);
149+
// get the global namespace props
150+
$globalProps = $rawConfig['global'];
151+
}
152+
catch(Zend_Exception $ze)
153+
{
154+
// if there is an alternateConfig, it is acceptable not to be able to
155+
// load a config, so just create an empty raw config and global
156+
if(isset($alternateConfig))
157+
{
158+
$rawConfig = array();
159+
$globalProps = array();
160+
}
161+
else if(Zend_Registry::get('configGlobal')->environment == 'testing')
162+
{
163+
// it is acceptable not to be able to load a config if we are in
164+
// testing mode, can get the config from the Zend_Registry set
165+
// by the tests
166+
$rawConfig = array();
167+
$globalProps = array();
168+
$alternateConfig = Zend_Registry::get('batchmake_test_config');
169+
}
170+
else
171+
{
172+
throw $ze;
173+
}
174+
}
175+
149176
// now set all the batchmake properties if we have any alternatives
150177
$configPropertiesParamVals = array();
151178
if(isset($alternateConfig))
@@ -158,6 +185,7 @@ public function loadConfigProperties($alternateConfig = null, $batchmakeOnly = t
158185
}
159186
$rawConfig['global'] = $globalProps;
160187
}
188+
161189
// get out the batchmake props
162190
$batchmakeProps = $this->filterBatchmakeConfigProperties($rawConfig);
163191
foreach($batchmakeProps as $configProperty => $configPropertyVal)

modules/batchmake/tests/controllers/BatchmakeControllerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
class BatchmakeControllerTest extends ControllerTestCase
2020
{
2121

22+
/**
23+
* setup function will set test config properties in the Zend_Registry
24+
*/
25+
public function setup()
26+
{
27+
parent::setup();
28+
$testConfigProps = $this->setupAndGetConfig();
29+
Zend_Registry::set('batchmake_test_config', $testConfigProps);
30+
}
31+
32+
2233
/**
2334
* helper function to return Midas configured temp directory
2435
* @return midas temp dir

modules/batchmake/tests/controllers/ConfigControllerTest.php

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,57 @@
1818
class ConfigControllerTest extends BatchmakeControllerTest
1919
{
2020

21-
protected $kwBatchmakeComponent;
2221

2322

2423
/** set up tests*/
2524
public function setUp()
2625
{
2726
$this->setupDatabase(array('default'));
27+
$this->_daos = array('User');
2828
$this->_models = array('User');
2929
$this->enabledModules = array('batchmake');
3030
parent::setUp();
31-
if(!isset($this->kwBatchmakeComponent))
32-
{
33-
require_once BASE_PATH.'/modules/batchmake/controllers/components/KWBatchmakeComponent.php';
34-
$this->kwBatchmakeComponent = new Batchmake_KWBatchmakeComponent($this->setupAndGetConfig());
35-
}
3631
}
3732

3833

3934

35+
4036
/** test index action*/
4137
public function testIndexAction()
4238
{
43-
$this->dispatchUrI("/batchmake/config/index");
39+
// first try to bring up the page without logging in, should get an exception
40+
$usersFile = $this->loadData('User', 'default');
41+
$nullUserDao = null;
42+
foreach($usersFile as $userDao)
43+
{
44+
if($userDao->getFirstname() === 'Admin')
45+
{
46+
$adminUserDao = $userDao;
47+
}
48+
else if($userDao->getFirstname() === 'FirstName1')
49+
{
50+
$nonAdminUserDao = $userDao;
51+
}
52+
}
53+
54+
$withException = true;
55+
$page = '/batchmake/config/index';
56+
$this->params = array();
57+
$this->getRequest()->setMethod('GET');
58+
$this->dispatchUrI($page, $nullUserDao, $withException);
59+
60+
// now login with a non-admin account, should get an exception
61+
$this->resetAll();
62+
$this->params = array();
63+
$this->getRequest()->setMethod('GET');
64+
$this->dispatchUrI($page, $nonAdminUserDao, $withException);
65+
66+
// now login with an admin account
67+
$this->resetAll();
68+
$this->params = array();
69+
$this->getRequest()->setMethod('GET');
70+
$this->dispatchUrI($page, $adminUserDao);
71+
4472
$body = $this->getBody();
4573

4674
$this->assertModule("batchmake");
@@ -52,20 +80,6 @@ public function testIndexAction()
5280
}
5381

5482
$this->assertQuery("form#configForm");
55-
$applicationConfig = $this->setupAndGetConfig();
56-
$this->params = array();
57-
$this->params[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY];
58-
$this->params[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY];
59-
$this->params[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY];
60-
$this->params[MIDAS_BATCHMAKE_APP_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY];
61-
$this->params[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY];
62-
$this->params[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY];
63-
// @TODO get these tests to a better state, testing more
64-
// luckily, almost all of the functionality goes through KWBatchmakeComponent
65-
// which is reasonably well tested
66-
$this->params['submit'] = 'submitConfig';
67-
$this->request->setMethod('POST');
68-
$this->dispatchUrI("/batchmake/config", null, true);
6983
}
7084

7185

0 commit comments

Comments
 (0)