2017-05-19 13:38:37 -04:00
< ? php
2019-06-28 14:24:59 -04:00
namespace Tests ;
use PDO ;
use PHPUnit\Framework\TestCase as TestCaseFramework ;
2017-05-19 13:38:37 -04:00
use ProcessMaker\Importer\XmlImporter ;
/**
* Test case that could instance a workspace DB
*
*/
2019-06-28 14:24:59 -04:00
class WorkflowTestCase extends TestCaseFramework
2017-05-19 13:38:37 -04:00
{
2019-06-28 14:24:59 -04:00
private $host ;
private $user ;
private $password ;
private $database ;
2017-05-19 13:38:37 -04:00
/**
* Create and install the database .
*/
protected function setupDB ()
{
2019-06-28 14:24:59 -04:00
$this -> host = env ( " DB_HOST " );
$this -> user = env ( " DB_USERNAME " );
$this -> password = env ( " DB_PASSWORD " );
$this -> database = env ( " DB_DATABASE " );
2017-05-19 13:38:37 -04:00
//Install Database
2019-06-28 14:24:59 -04:00
$pdo0 = new PDO ( " mysql:host= " . $this -> host , $this -> user , $this -> password );
$pdo0 -> query ( 'DROP DATABASE IF EXISTS ' . $this -> database );
$pdo0 -> query ( 'CREATE DATABASE ' . $this -> database );
$pdo = new PDO ( " mysql:host= " . $this -> host . " ;dbname= " . $this -> database , $this -> user ,
$this -> password );
2017-05-19 13:38:37 -04:00
$pdo -> setAttribute ( PDO :: ATTR_EMULATE_PREPARES , 0 );
$pdo -> exec ( file_get_contents ( PATH_CORE . 'data/mysql/schema.sql' ));
$pdo -> exec ( file_get_contents ( PATH_RBAC_CORE . 'data/mysql/schema.sql' ));
$pdo -> exec ( file_get_contents ( PATH_CORE . 'data/mysql/insert.sql' ));
$pdo -> exec ( file_get_contents ( PATH_RBAC_CORE . 'data/mysql/insert.sql' ));
2017-07-04 16:51:24 -04:00
$pdo -> exec ( " INSERT INTO `APP_SEQUENCE` (`ID`) VALUES ('1') " );
$pdo -> exec ( " INSERT INTO `OAUTH_CLIENTS` (`CLIENT_ID`, `CLIENT_SECRET`, `CLIENT_NAME`, `CLIENT_DESCRIPTION`, `CLIENT_WEBSITE`, `REDIRECT_URI`, `USR_UID`) VALUES
2025-04-13 15:23:31 +00:00
( 'x-pm-local-client' , '179ad45c6ce2cb97cf1029e212046e81' , 'PM Web Designer' , 'ProcessMaker Web Designer App' , 'www.processmaker.com' , 'http://".$_SERVER["HTTP_HOST"].":".$_SERVER[' SERVER_PORT ']."/sys".config("system.workspace")."/en/lurana/oauth2/grant' , '00000000000000000000000000000001' ); " );
2017-07-04 16:51:24 -04:00
$pdo -> exec ( " INSERT INTO `OAUTH_ACCESS_TOKENS` (`ACCESS_TOKEN`, `CLIENT_ID`, `USER_ID`, `EXPIRES`, `SCOPE`) VALUES
( '39704d17049f5aef45e884e7b769989269502f83' , 'x-pm-local-client' , '00000000000000000000000000000001' , '2017-06-15 17:55:19' , 'view_processes edit_processes *' ); " );
2017-05-19 13:38:37 -04:00
}
/**
* Drop the database .
*/
protected function dropDB ()
{
//Install Database
2019-06-28 14:24:59 -04:00
$pdo0 = new PDO ( " mysql:host= " . $this -> host , $this -> user , $this -> password );
$pdo0 -> query ( 'DROP DATABASE IF EXISTS ' . $this -> database );
2017-05-19 13:38:37 -04:00
}
/**
* Import a process to the database .
2017-06-02 13:07:52 -04:00
*
2017-05-19 13:38:37 -04:00
* @ param type $filename ProcessMaker file to be imported
* @ return string PRO_UID
*/
2017-06-02 09:59:33 -04:00
protected function import ( $filename , $regenerateUids = false )
2017-05-19 13:38:37 -04:00
{
$importer = new XmlImporter ();
$importer -> setSourceFile ( $filename );
return $importer -> import (
2017-06-01 16:54:48 -04:00
$regenerateUids ? XmlImporter :: IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW : XmlImporter :: IMPORT_OPTION_CREATE_NEW ,
XmlImporter :: GROUP_IMPORT_OPTION_CREATE_NEW , $regenerateUids
2017-05-19 13:38:37 -04:00
);
}
/**
* Rebuild workflow ' s schema . sql
*/
protected function rebuildModel ()
{
$pwd = getcwd ();
chdir ( PATH_CORE );
exec ( '../../gulliver/bin/gulliver propel-build-sql mysql' );
exec ( '../../gulliver/bin/gulliver propel-build-model' );
chdir ( $pwd );
}
2017-05-22 11:26:15 -04:00
2017-05-24 14:04:07 -04:00
/**
* Clean the shared folder to only have the sites .
*/
protected function cleanShared ()
{
$this -> rrmdir ( PATH_DATA . 'skins' );
mkdir ( PATH_DATA . 'skins' );
clearstatcache ();
}
2017-05-22 11:26:15 -04:00
/**
* Set the text of and specific translated message .
*
* @ global array $translation
* @ param type $msgId
* @ param type $text
*/
protected function setTranslation ( $msgId , $text )
{
global $translation ;
$translation [ $msgId ] = $text ;
}
/**
* Clear all the translated messages loaded .
2017-06-02 13:07:52 -04:00
*
2017-05-22 11:26:15 -04:00
* @ global array $translation
*/
protected function clearTranslations ()
{
global $translation ;
foreach ( $translation as $msgId => $text ) {
unset ( $translation [ $msgId ]);
}
}
2017-05-24 14:04:07 -04:00
private function rrmdir ( $dir )
{
if ( ! is_dir ( $dir )) {
return ;
}
$files = array_diff ( scandir ( $dir ), array ( '.' , '..' ));
foreach ( $files as $file ) {
( is_dir ( " $dir / $file " ) && ! is_link ( $dir )) ? $this -> rrmdir ( " $dir / $file " )
: unlink ( " $dir / $file " );
}
return rmdir ( $dir );
}
2017-07-04 16:51:24 -04:00
/**
* Set specific env . ini configuration .
*
* @ param type $param
* @ param type $value
*/
protected function setEnvIni ( $param , $value )
{
$config = file_get_contents ( PATH_CONFIG . 'env.ini' );
if ( substr ( $config , - 1 , 1 ) !== " \n " ) {
$config .= " \n " ;
}
$regexp = '/^\s*' . preg_quote ( $param ) . '\s*=\s*.*\n$/m' ;
if ( preg_match ( $regexp , $config . " \n " )) {
if ( $value === null ) {
$config = preg_replace ( $regexp , " " , $config );
} else {
$value1 = is_numeric ( $value ) ? $value : json_encode ( $value , true );
$config = preg_replace ( $regexp , " $param = $value1\n " , $config );
}
} elseif ( $value !== null ) {
$value1 = is_numeric ( $value ) ? $value : json_encode ( $value , true );
$config .= " $param = $value1\n " ;
}
file_put_contents ( PATH_CONFIG . 'env.ini' , $config );
}
/**
* Unset specific env . ini configuration .
*
* @ param type $param
*/
protected function unsetEnvIni ( $param )
{
$this -> setEnvIni ( $param , null );
}
/**
* Add a PM configuration .
*
* @ return \Configurations
*/
protected function config ( $config = []){
$configGetStarted = new \Configuration ;
$data = array_merge ([
'OBJ_UID' => '' ,
'PRO_UID' => '' ,
'USR_UID' => '' ,
'APP_UID' => '' ,
], $config );
$configGetStarted -> create ( $data );
}
protected function getBaseUrl ( $url )
{
return ( \G :: is_https () ? " https:// " : " http:// " ) .
2017-10-10 12:33:25 -04:00
$GLOBALS [ " APP_HOST " ] . ':' . $GLOBALS [ 'SERVER_PORT' ] . " /sys " . config ( " system.workspace " ) . " / " .
2017-07-04 16:51:24 -04:00
SYS_LANG . " / " . SYS_SKIN . " / " . $url ;
}
2017-05-19 13:38:37 -04:00
}