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

Commit

Permalink
ENH: fixed bug #174 Add module testing
Browse files Browse the repository at this point in the history
Add module testing
Move core test
Move MIDAS library
Add helloworld test
  • Loading branch information
Charles Ma committed Jul 7, 2011
1 parent 94b5ab8 commit 9abaf36
Show file tree
Hide file tree
Showing 90 changed files with 1,406 additions and 1,130 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/library/CMake/CTestCustom.cmake.in
include(CTest)
set( SERVER_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR} )
add_subdirectory(tests)

add_subdirectory(core/tests)
add_subdirectory(modules)
21 changes: 0 additions & 21 deletions core/AppFilters.php

This file was deleted.

2 changes: 1 addition & 1 deletion core/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function _initConfig()
'driver_options' => $pdoParams);
if($configGlobal->environment == "production")
{
Zend_Loader::loadClass("ProductionDbProfiler", BASE_PATH . '/library/MIDAS/models/profiler');
Zend_Loader::loadClass("ProductionDbProfiler", BASE_PATH . '/core/models/profiler');
$params['profiler'] = new ProductionDbProfiler();
}
$db = Zend_Db::factory($configDatabase->database->adapter, $params);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,16 @@ public function preDispatch()
{
foreach($configs as $key => $config)
{
if($config->system == 1)
if(file_exists(BASE_PATH.'/modules/'.$key.'/controllers/'. ucfirst($request->getControllerName()).'CoreController.php'))
{
if(file_exists(BASE_PATH.'/modules/'.$key.'/controllers/'. ucfirst($request->getControllerName()).'CoreController.php'))
include_once BASE_PATH.'/modules/'.$key.'/controllers/'. ucfirst($request->getControllerName()).'CoreController.php';
$name = ucfirst($key).'_'.ucfirst($request->getControllerName()).'CoreController';
$controller = new $name($request, $response);
if(method_exists($controller, $request->getActionName().'Action'))
{
include_once BASE_PATH.'/modules/'.$key.'/controllers/'. ucfirst($request->getControllerName()).'CoreController.php';
$name = ucfirst($key).'_'.ucfirst($request->getControllerName()).'CoreController';
$controller = new $name($request, $response);
if(method_exists($controller, $request->getActionName().'Action'))
{
$this->_forward($request->getActionName(), $request->getControllerName().'Core', $key, array('forwardModule' => true));
}
$this->_forward($request->getActionName(), $request->getControllerName().'Core', $key, array('forwardModule' => true));
}
}
}
}
}
parent::preDispatch();
Expand Down
10 changes: 10 additions & 0 deletions core/constant/datatype.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@
define("MIDAS_ASSETSTORE_LOCAL", 0);
define("MIDAS_ASSETSTORE_REMOTE", 1);
define("MIDAS_ASSETSTORE_AMAZON", 2);

/*
* Define Model Data type
*/
define("MIDAS_DATA", 1001);
define("MIDAS_ONE_TO_MANY", 1002);
define("MIDAS_MANY_TO_ONE", 1003);
define("MIDAS_ONE_TO_ONE", 1004);
define("MIDAS_MANY_TO_MANY", 1005);

?>
28 changes: 1 addition & 27 deletions core/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,33 +110,7 @@ function indexAction()
if(!file_exists($moduleConfigLocalFile))
{
copy($moduleConfigFile, $moduleConfigLocalFile);
switch(Zend_Registry::get('configDatabase')->database->adapter)
{
case 'PDO_MYSQL':
if(file_exists(BASE_PATH.'/modules/'.$moduleName.'/database/mysql/'.$allModules[$moduleName]->version.'.sql'))
{
$this->Component->Utility->run_mysql_from_file(BASE_PATH.'/modules/'.$moduleName.'/database/mysql/'.$allModules[$moduleName]->version.'.sql',
Zend_Registry::get('configDatabase')->database->params->host,
Zend_Registry::get('configDatabase')->database->params->username,
Zend_Registry::get('configDatabase')->database->params->password,
Zend_Registry::get('configDatabase')->database->params->dbname,
Zend_Registry::get('configDatabase')->database->params->port);
}
break;
case 'PDO_PGSQL':
if(file_exists(BASE_PATH.'/modules/'.$key.'/database/pgsql/'.$allModules[$moduleName]->version.'.sql'))
{
$this->Component->Utility->run_pgsql_from_file(BASE_PATH.'/modules/'.$key.'/database/pgsql/'.$allModules[$moduleName]->version.'.sql',
Zend_Registry::get('configDatabase')->database->params->host,
Zend_Registry::get('configDatabase')->database->params->username,
Zend_Registry::get('configDatabase')->database->params->password,
Zend_Registry::get('configDatabase')->database->params->dbname,
Zend_Registry::get('configDatabase')->database->params->port);
}
break;
default:
break;
}
$this->Component->Utility->installModule($moduleName);
}
rename(BASE_PATH.'/core/configs/application.local.ini', BASE_PATH.'/core/configs/application.local.ini.old');
$applicationConfig['module'][$moduleName] = $modulevalue;
Expand Down
4 changes: 2 additions & 2 deletions core/controllers/components/UpgradeComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function getClassName($filename)
/** execute de upgrade*/
protected function _processFile($migration)
{
require_once BASE_PATH.'/library/MIDAS/models/MIDASUpgrade.php';
require_once BASE_PATH.'/core/MIDASUpgrade.php';
$version = $migration['version'];
$filename = $migration['filename'];
$classname = $this->getClassName($filename);
Expand All @@ -248,7 +248,7 @@ protected function _processFile($migration)
throw new Zend_Exception("Could not find class '".$classname."' in file '".$filename."'");
}

$class = new $classname($this->db, $this->module);
$class = new $classname($this->db, $this->module, $this->dbtype);
$class->preUpgrade();
$dbtypeShort = $this->dbtypeShort;
$class->$dbtypeShort();
Expand Down
49 changes: 49 additions & 0 deletions core/controllers/components/UtilityComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,53 @@ static function run_pgsql_from_file($sqlfile, $host, $username, $password, $dbna
return true;
}


/** install a module */
public function installModule($moduleName)
{
// TODO, The module installation process needs some improvment.
$allModules = $this->getAllModules();
$version = $allModules[$moduleName]->version;
try
{
switch(Zend_Registry::get('configDatabase')->database->adapter)
{
case 'PDO_MYSQL':
if(file_exists(BASE_PATH.'/modules/'.$moduleName.'/database/mysql/'.$version.'.sql'))
{
$this->run_mysql_from_file(BASE_PATH.'/modules/'.$moduleName.'/database/mysql/'.$version.'.sql',
Zend_Registry::get('configDatabase')->database->params->host,
Zend_Registry::get('configDatabase')->database->params->username,
Zend_Registry::get('configDatabase')->database->params->password,
Zend_Registry::get('configDatabase')->database->params->dbname,
Zend_Registry::get('configDatabase')->database->params->port);
}
break;
case 'PDO_PGSQL':
if(file_exists(BASE_PATH.'/modules/'.$moduleName.'/database/pgsql/'.$version.'.sql'))
{
$this->run_pgsql_from_file(BASE_PATH.'/modules/'.$moduleName.'/database/pgsql/'.$version.'.sql',
Zend_Registry::get('configDatabase')->database->params->host,
Zend_Registry::get('configDatabase')->database->params->username,
Zend_Registry::get('configDatabase')->database->params->password,
Zend_Registry::get('configDatabase')->database->params->dbname,
Zend_Registry::get('configDatabase')->database->params->port);
}
break;
default:
break;
}
}
catch(Zend_Exception $exc)
{
$this->getLogger()->warn($exc->getMessage());
}

require_once dirname(__FILE__).'/UpgradeComponent.php';
$upgrade = new UpgradeComponent();
$db = Zend_Registry::get('dbAdapter');
$dbtype = Zend_Registry::get('configDatabase')->database->adapter;
$upgrade->initUpgrade($moduleName, $db, $dbtype);
$upgrade->upgrade($version);
}
} // end class
Loading

0 comments on commit 9abaf36

Please sign in to comment.