test.php 2.69 KB
<?php
error_reporting(E_ALL & ~E_NOTICE);

//Path to AMDA_Integration base dir
define('INTEGRATION_BASE_PATH', __DIR__.'/../');

require(__DIR__.'/../config/AMDAIntegrationConfig.php');

//Used to skip checkUser in AMDAAction.php
define("NEWKERNEL_DEBUG",true);
define("NEWKERNEL_DEBUG_USER","test-integration");

define('BASE_PATH', IHM_SRC_DIR);
define('DATAPATH', BASE_PATH.'generic_data/');

//define test suite
/*require_once(__DIR__."/US42/test_us42.php");
require_once(__DIR__."/US44/test_us44.php");
require_once(__DIR__."/US43/test_us43.php");
require_once(__DIR__."/US78/test_us78.php");
require_once(__DIR__."/LocalParam/test_localparam.php");*/
require_once(__DIR__."/debug_request.php");

$testSuite = array($debug)/*$us42,$us44,$us43,$us78,$localparam)*/;

//include required IHM source
require_once(IHM_SRC_DIR."php/classes/AmdaAction.php");
require_once(IHM_SRC_DIR."php/classes/UserMgr.php");
require_once(IHM_SRC_DIR."php/classes/AmdaClient.php");

//create test WS
chdir(IHM_SRC_DIR."data");
if (!is_dir(NEWKERNEL_DEBUG_USER))
	mkdir(NEWKERNEL_DEBUG_USER);
chdir(NEWKERNEL_DEBUG_USER);
if (!is_dir("WS"))
	mkdir("WS");
chdir("WS");
//copy some user parameters for test
copy(__DIR__."/../install/testParams/UserParams/WsParams.xml","WsParams.xml");
copy(__DIR__."/../install/testParams/UserParams/ws_0.xml","ws_0.xml");
copy(__DIR__."/../install/testParams/UserParams/wsd_0.xml","wsd_0.xml");
copy(__DIR__."/../install/testParams/UserParams/wsd_1.xml","wsd_1.xml");
//copy some uploaded files for test
chdir(IHM_SRC_DIR."data");
chdir(NEWKERNEL_DEBUG_USER);
if (!is_dir("DATA"))
	mkdir("DATA");
chdir("DATA");
copy(__DIR__."/../install/testParams/UserData/base.xml","base.xml");
copy(__DIR__."/../install/testParams/UserData/2007001.skr-v3.xml","2007001.skr-v3.xml");

//assure DDServer connection
chdir(NEWKERNEL_BASE_PATH."app-debug/");
exec(NEWKERNEL_BASE_PATH."script/loginDD_Server.sh");
chdir(__DIR__);

//create an instance of AmdaAction
$amdaAction = new AmdaAction();

//run test suite
foreach ($testSuite as $us)
	foreach ($us as $key=>$value)
	{
		echo '-------------------------------------------------------'.PHP_EOL;
		echo $key.PHP_EOL;
		try {
			$obj = json_decode($value);
			$nodeType = "";
			if (isset($obj->nodeType))
				$nodeType = $obj->nodeType;
			$result = $amdaAction->execute($obj->nodeType, $obj);
			if ($result['success'])
			{
				if ($result['status'] == 'error')
				{
					echo 'Error during execution !'.PHP_EOL;
				}
				else 
					echo 'Success !'.PHP_EOL;
			}
			else
				echo 'Error ! '.$result['message'].PHP_EOL;	
		} catch (Exception $e) {
			echo 'Exception detected : '.$e->getMessage().PHP_EOL;
		}
	}

?>