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

Commit

Permalink
ENH: refs #0322. Allow batchmake tests to pass test configs.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Michael Grauer committed Oct 29, 2011
1 parent be25fcd commit af25e71
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 25 deletions.
36 changes: 32 additions & 4 deletions modules/batchmake/controllers/components/KWBatchmakeComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,37 @@ public function filterBatchmakeConfigProperties($fullConfig)
*/
public function loadConfigProperties($alternateConfig = null, $batchmakeOnly = true)
{
// load the full config
$rawConfig = $this->loadConfig(true);
// get the global namespace props
$globalProps = $rawConfig['global'];
try
{
// load the full config
$rawConfig = $this->loadConfig(true);
// get the global namespace props
$globalProps = $rawConfig['global'];
}
catch(Zend_Exception $ze)
{
// if there is an alternateConfig, it is acceptable not to be able to
// load a config, so just create an empty raw config and global
if(isset($alternateConfig))
{
$rawConfig = array();
$globalProps = array();
}
else if(Zend_Registry::get('configGlobal')->environment == 'testing')
{
// it is acceptable not to be able to load a config if we are in
// testing mode, can get the config from the Zend_Registry set
// by the tests
$rawConfig = array();
$globalProps = array();
$alternateConfig = Zend_Registry::get('batchmake_test_config');
}
else
{
throw $ze;
}
}

// now set all the batchmake properties if we have any alternatives
$configPropertiesParamVals = array();
if(isset($alternateConfig))
Expand All @@ -158,6 +185,7 @@ public function loadConfigProperties($alternateConfig = null, $batchmakeOnly = t
}
$rawConfig['global'] = $globalProps;
}

// get out the batchmake props
$batchmakeProps = $this->filterBatchmakeConfigProperties($rawConfig);
foreach($batchmakeProps as $configProperty => $configPropertyVal)
Expand Down
11 changes: 11 additions & 0 deletions modules/batchmake/tests/controllers/BatchmakeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
class BatchmakeControllerTest extends ControllerTestCase
{

/**
* setup function will set test config properties in the Zend_Registry
*/
public function setup()
{
parent::setup();
$testConfigProps = $this->setupAndGetConfig();
Zend_Registry::set('batchmake_test_config', $testConfigProps);
}


/**
* helper function to return Midas configured temp directory
* @return midas temp dir
Expand Down
56 changes: 35 additions & 21 deletions modules/batchmake/tests/controllers/ConfigControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,57 @@
class ConfigControllerTest extends BatchmakeControllerTest
{

protected $kwBatchmakeComponent;


/** set up tests*/
public function setUp()
{
$this->setupDatabase(array('default'));
$this->_daos = array('User');
$this->_models = array('User');
$this->enabledModules = array('batchmake');
parent::setUp();
if(!isset($this->kwBatchmakeComponent))
{
require_once BASE_PATH.'/modules/batchmake/controllers/components/KWBatchmakeComponent.php';
$this->kwBatchmakeComponent = new Batchmake_KWBatchmakeComponent($this->setupAndGetConfig());
}
}




/** test index action*/
public function testIndexAction()
{
$this->dispatchUrI("/batchmake/config/index");
// first try to bring up the page without logging in, should get an exception
$usersFile = $this->loadData('User', 'default');
$nullUserDao = null;
foreach($usersFile as $userDao)
{
if($userDao->getFirstname() === 'Admin')
{
$adminUserDao = $userDao;
}
else if($userDao->getFirstname() === 'FirstName1')
{
$nonAdminUserDao = $userDao;
}
}

$withException = true;
$page = '/batchmake/config/index';
$this->params = array();
$this->getRequest()->setMethod('GET');
$this->dispatchUrI($page, $nullUserDao, $withException);

// now login with a non-admin account, should get an exception
$this->resetAll();
$this->params = array();
$this->getRequest()->setMethod('GET');
$this->dispatchUrI($page, $nonAdminUserDao, $withException);

// now login with an admin account
$this->resetAll();
$this->params = array();
$this->getRequest()->setMethod('GET');
$this->dispatchUrI($page, $adminUserDao);

$body = $this->getBody();

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

$this->assertQuery("form#configForm");
$applicationConfig = $this->setupAndGetConfig();
$this->params = array();
$this->params[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY];
$this->params[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY];
$this->params[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY];
$this->params[MIDAS_BATCHMAKE_APP_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY];
$this->params[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY];
$this->params[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY];
// @TODO get these tests to a better state, testing more
// luckily, almost all of the functionality goes through KWBatchmakeComponent
// which is reasonably well tested
$this->params['submit'] = 'submitConfig';
$this->request->setMethod('POST');
$this->dispatchUrI("/batchmake/config", null, true);
}


Expand Down

0 comments on commit af25e71

Please sign in to comment.