Merged in develop (pull request #7127)
Update with develop Approved-by: Paula Quispe <paula.quispe@processmaker.com>
This commit is contained in:
83
tests/unit/workflow/engine/classes/DerivationTest.php
Normal file
83
tests/unit/workflow/engine/classes/DerivationTest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\classes;
|
||||
|
||||
use \Derivation;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DerivationTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Call the setUp parent method
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the getSubProcessVariables method with object variables
|
||||
*
|
||||
* @covers Derivation::getSubProcessVariables()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_get_sub_process_variables_method_with_object_variables()
|
||||
{
|
||||
$fields = ['@&var2' => '@&var3'];
|
||||
$childCaseData = ['var2' => (object)['Street' => 'test', 'name' => 'Something']];
|
||||
$parentCaseData = ['var1' => (object)['Street' => 'test']];
|
||||
|
||||
$der = new Derivation();
|
||||
$res = $der->getSubProcessVariables($fields, $childCaseData, $parentCaseData);
|
||||
|
||||
$this->assertArrayHasKey('var3', $res);
|
||||
$this->assertObjectHasAttribute('Street', $res['var3']);
|
||||
$this->assertObjectHasAttribute('name', $res['var3']);
|
||||
$this->assertEquals($res['var3'], (object)['Street' => 'test', 'name' => 'Something']);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the getSubProcessVariables method with origin labels
|
||||
*
|
||||
* @covers Derivation::getSubProcessVariables()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_get_sub_process_variables_method_with_origin_labels()
|
||||
{
|
||||
$fields = ['@&var2' => '@&var3', '@&var2_label' => '@&var3'];
|
||||
$childCaseData = [
|
||||
'var2' => (object)['Street' => 'test', 'name' => 'Something'],
|
||||
'var2_label' => ['Street' => 'test', 'name' => 'Something']
|
||||
];
|
||||
$parentCaseData = ['var1' => (object)['Street' => 'test']];
|
||||
|
||||
$der = new Derivation();
|
||||
$res = $der->getSubProcessVariables($fields, $childCaseData, $parentCaseData);
|
||||
|
||||
$this->assertArrayHasKey('var3_label', $res);
|
||||
$this->assertEquals($res['var3_label'], ['Street' => 'test', 'name' => 'Something']);
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the getSubProcessVariables method with target labels
|
||||
*
|
||||
* @covers Derivation::getSubProcessVariables()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_test_the_get_sub_process_variables_method_with_target_labels()
|
||||
{
|
||||
$fields = ['@&var2' => '@&var3', '@&var2' => '@&var3_label'];
|
||||
$childCaseData = ['var2' => (object)['Street' => 'test', 'name' => 'Something']];
|
||||
$parentCaseData = ['var1' => (object)['Street' => 'test']];
|
||||
|
||||
$der = new Derivation();
|
||||
$res = $der->getSubProcessVariables($fields, $childCaseData, $parentCaseData);
|
||||
|
||||
$this->assertArrayHasKey('var3_label', $res);
|
||||
$this->assertObjectHasAttribute('Street', $res['var3_label']);
|
||||
$this->assertObjectHasAttribute('name', $res['var3_label']);
|
||||
$this->assertEquals($res['var3_label'], (object)['Street' => 'test', 'name' => 'Something']);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Faker\Factory;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use ProcessMaker\Model\Dynaform;
|
||||
use ProcessMaker\Model\Process;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class PmDynaformTest
|
||||
*
|
||||
* @coversDefaultClass PmDynaform
|
||||
*/
|
||||
class PmDynaformTest extends TestCase
|
||||
{
|
||||
|
||||
@@ -239,7 +245,7 @@ class PmDynaformTest extends TestCase
|
||||
$pmDynaform = new PmDynaform(['CURRENT_DYNAFORM' => G::generateUniqueID()]);
|
||||
$pmDynaform->getDynaform();
|
||||
|
||||
$this->assertEquals(null, $pmDynaform->langs);
|
||||
$this->assertEquals(null, $pmDynaform->translations);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -824,4 +830,136 @@ class PmDynaformTest extends TestCase
|
||||
$this->assertFalse($jsonData->dataSchema[$key][4]['defined']);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Review if the set translations are working correctly
|
||||
* If the translation does not exit needs to return null
|
||||
*
|
||||
* @covers PmDynaform::setTranslations()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_set_the_translations_if_exist()
|
||||
{
|
||||
// Create a form without translations defined
|
||||
$arrayForm = $this->createArrayDynaform();
|
||||
$form = factory(Dynaform::class)->create([
|
||||
'DYN_UID' => $arrayForm['items'][0]['id'],
|
||||
'DYN_CONTENT' => G::json_encode($arrayForm)
|
||||
]);
|
||||
$pmDynaform = new PmDynaform([]);
|
||||
$pmDynaform->setTranslations($form->DYN_UID);
|
||||
$this->assertNull($pmDynaform->translations);
|
||||
|
||||
// Create a form with translations defined
|
||||
$arrayForm = $this->createArrayDynaform();
|
||||
$form = factory(Dynaform::class)->states('translations')->create([
|
||||
'DYN_UID' => $arrayForm['items'][0]['id'],
|
||||
'DYN_CONTENT' => G::json_encode($arrayForm)
|
||||
]);
|
||||
$pmDynaform = new PmDynaform([]);
|
||||
$pmDynaform->setTranslations($form->DYN_UID);
|
||||
$this->assertNotNull($pmDynaform->translations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Review if the get labels from a specific language is working
|
||||
* If the translation defined does not have the specific language will return null
|
||||
*
|
||||
* @covers PmDynaform::getLabelsPo()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_get_label_from_translation()
|
||||
{
|
||||
$arrayForm = $this->createArrayDynaform();
|
||||
// Create a translations related to ["es", "es-Es"]
|
||||
$form = factory(Dynaform::class)->states('translations')->create([
|
||||
'DYN_UID' => $arrayForm['items'][0]['id'],
|
||||
'DYN_CONTENT' => G::json_encode($arrayForm)
|
||||
]);
|
||||
$pmDynaform = new PmDynaform([]);
|
||||
$pmDynaform->setTranslations($form->DYN_UID);
|
||||
$labelsPo = $pmDynaform->getLabelsPo('es');
|
||||
$this->assertNotNull($labelsPo);
|
||||
$labelsPo = $pmDynaform->getLabelsPo('es-Es');
|
||||
$this->assertNotNull($labelsPo);
|
||||
$faker = Factory::create();
|
||||
$labelsPo = $pmDynaform->getLabelsPo($faker->sentence(1));
|
||||
$this->assertNull($labelsPo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Review if the SQL that uses the SELECT statement is parsed correctly
|
||||
*
|
||||
* @covers PmDynaform::sqlParse()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_get_sql_parsed_select_statement()
|
||||
{
|
||||
// Note.- The following queries are used by running tests but none of them are valid
|
||||
$sqlOriginal1 = 'SELECT TOP 10 USERS.USR_UID, USERS.USR_ID, USERS.USR_USERNAME AS USERNAME, MAX(RBAC_USERS_ROLES.ROL_UID),
|
||||
MIN(RBAC_USERS_ROLES.ROL_UID) AS THEMIN, (SELECT USR_FIRSTNAME FROM USERS), (SELECT USR_LASTNAME AS XXX) AS YYY, <>, 1000
|
||||
FROM USERS AS OFFSET INNER JOIN RBAC_USERS ON USERS.USR_UID = RBAC_USERS.USR_UID INNER JOIN RBAC_USERS_ROLES ON
|
||||
USERS.USR_UID = RBAC_USERS_ROLES.USR_UID WHERE USERS.USR_UID <> "" AND 1 AND OFFSET 1 GROUP BY USERS.USR_UID HAVING
|
||||
USERS.USR_UID <> "" ORDER BY USERS.USR_ID DESC LIMIT 1 OFFSET 10 FOR UPDATE';
|
||||
|
||||
$sqlOriginal2 = 'SELECT TOP 10 USERS.USR_UID, USERS.USR_ID, USERS.USR_USERNAME AS USERNAME, MAX(RBAC_USERS_ROLES.ROL_UID),
|
||||
MIN(RBAC_USERS_ROLES.ROL_UID) AS THEMIN, (SELECT USR_FIRSTNAME FROM USERS), (SELECT USR_LASTNAME AS XXX) AS YYY, <>, 1000
|
||||
FROM USERS INNER JOIN RBAC_USERS ON USERS.USR_UID = RBAC_USERS.USR_UID INNER JOIN RBAC_USERS_ROLES ON
|
||||
USERS.USR_UID = RBAC_USERS_ROLES.USR_UID WHERE USERS.USR_UID <> "" AND 1 GROUP BY USERS.USR_UID HAVING
|
||||
USERS.USR_UID <> "" ORDER BY USERS.USR_ID DESC LIMIT 1, 10 FOR UPDATE';
|
||||
|
||||
$sqlOriginal3 = 'DUMMY';
|
||||
|
||||
// Instance the class PmDynaform
|
||||
$pmDynaform = new PmDynaform([]);
|
||||
|
||||
// Test bug PMC-1299
|
||||
$sqlParsed1 = $pmDynaform->sqlParse($sqlOriginal1);
|
||||
$this->assertFalse(strpos($sqlParsed1, 'INNER INNER'));
|
||||
|
||||
// For now is only used for complete the coverture
|
||||
$sqlParsed2 = $pmDynaform->sqlParse($sqlOriginal2, 'dummy_function_for_this_unit_test');
|
||||
// To Do: Currently, there is a coverture of 100%, but is necessary to add more tests to verify
|
||||
// if the SQL string is parsed correctly in more scenarios
|
||||
|
||||
// Test another string, shoul be return the same value
|
||||
$sqlParsed3 = $pmDynaform->sqlParse($sqlOriginal3);
|
||||
$this->assertEquals($sqlOriginal3, $sqlParsed3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Review if the SQL that uses the CALL statement is parsed correctly
|
||||
*
|
||||
* @covers PmDynaform::sqlParse()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_get_sql_parsed_call_statement()
|
||||
{
|
||||
$sqlOriginal = 'CALL dummy_sp_for_this_unit_test()';
|
||||
|
||||
$pmDynaform = new PmDynaform([]);
|
||||
$sqlParsed = $pmDynaform->sqlParse($sqlOriginal);
|
||||
|
||||
$this->assertEquals(strlen($sqlOriginal), strlen($sqlParsed));
|
||||
}
|
||||
|
||||
/**
|
||||
* Review if the SQL that uses the EXECUTE statement is parsed correctly
|
||||
*
|
||||
* @covers PmDynaform::sqlParse()
|
||||
* @test
|
||||
*/
|
||||
public function it_should_get_sql_parsed_execute_statement()
|
||||
{
|
||||
$sqlOriginal = 'EXECUTE dummy_sp_for_this_unit_test()';
|
||||
|
||||
$pmDynaform = new PmDynaform([]);
|
||||
$sqlParsed = $pmDynaform->sqlParse($sqlOriginal);
|
||||
|
||||
$this->assertEquals(strlen($sqlOriginal), strlen($sqlParsed));
|
||||
}
|
||||
}
|
||||
|
||||
// Dummy function used for the coverture
|
||||
function dummy_function_for_this_unit_test()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,346 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\classes\PmFunctions;
|
||||
|
||||
use Faker\Factory;
|
||||
use G;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use ProcessMaker\Model\DbSource;
|
||||
use ProcessMaker\Model\ProcessCategory;
|
||||
use ProcessMaker\Model\User;
|
||||
use SQLException;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Test the executeQuery() function
|
||||
*
|
||||
* @link https://wiki.processmaker.com/3.1/ProcessMaker_Functions#executeQuery.28.29
|
||||
*/
|
||||
class ExecuteQueryTest extends TestCase
|
||||
{
|
||||
// todo: Please do not use "DatabaseTransactions", the executeQuery method opens another connection.
|
||||
use DatabaseTransactions;
|
||||
|
||||
protected $nameSystemTables = "system-tables.ini";
|
||||
protected $contentSystemTables = "tables = 'APPLICATION|APP_SEQUENCE|APP_DELEGATION|APP_DOCUMENT|APP_MESSAGE|APP_OWNER|CONFIGURATION|CONTENT|DEPARTMENT|DYNAFORM|GROUPWF|GROUP_USER|HOLIDAY|INPUT_DOCUMENT|ISO_COUNTRY|ISO_LOCATION|ISO_SUBDIVISION|LANGUAGE|LEXICO|OUTPUT_DOCUMENT|PROCESS|PROCESS_OWNER|REPORT_TABLE|REPORT_VAR|ROUTE|STEP|STEP_TRIGGER|SWIMLANES_ELEMENTS|TASK|TASK_USER|TRANSLATION|TRIGGERS|USERS|APP_THREAD|APP_DELAY|PROCESS_USER|SESSION|DB_SOURCE|STEP_SUPERVISOR|OBJECT_PERMISSION|CASE_TRACKER|CASE_TRACKER_OBJECT|CASE_CONSOLIDATED|STAGE|SUB_PROCESS|SUB_APPLICATION|LOGIN_LOG|USERS_PROPERTIES|ADDITIONAL_TABLES|FIELDS|SHADOW_TABLE|EVENT|GATEWAY|APP_EVENT|APP_CACHE_VIEW|DIM_TIME_DELEGATE|DIM_TIME_COMPLETE|APP_HISTORY|APP_FOLDER|FIELD_CONDITION|LOG_CASES_SCHEDULER|CASE_SCHEDULER|CALENDAR_DEFINITION|CALENDAR_BUSINESS_HOURS|CALENDAR_HOLIDAYS|CALENDAR_ASSIGNMENTS|PROCESS_CATEGORY|APP_NOTES|DASHLET|DASHLET_INSTANCE|APP_SOLR_QUEUE|SEQUENCES|SESSION_STORAGE|PROCESS_FILES|WEB_ENTRY|OAUTH_ACCESS_TOKENS|OAUTH_AUTHORIZATION_CODES|OAUTH_CLIENTS|OAUTH_REFRESH_TOKENS|OAUTH_SCOPES|PMOAUTH_USER_ACCESS_TOKENS|BPMN_PROJECT|BPMN_PROCESS|BPMN_ACTIVITY|BPMN_ARTIFACT|BPMN_DIAGRAM|BPMN_BOUND|BPMN_DATA|BPMN_EVENT|BPMN_FLOW|BPMN_GATEWAY|BPMN_LANESET|BPMN_LANE|BPMN_PARTICIPANT|BPMN_EXTENSION|BPMN_DOCUMENTATION|PROCESS_VARIABLES|APP_TIMEOUT_ACTION_EXECUTED|ADDONS_STORE|ADDONS_MANAGER|LICENSE_MANAGER|APP_ASSIGN_SELF_SERVICE_VALUE|APP_ASSIGN_SELF_SERVICE_VALUE_GROUP|LIST_INBOX|LIST_PARTICIPATED_HISTORY|LIST_PARTICIPATED_LAST|LIST_COMPLETED|LIST_PAUSED|LIST_CANCELED|LIST_MY_INBOX|LIST_UNASSIGNED|LIST_UNASSIGNED_GROUP|MESSAGE_TYPE|MESSAGE_TYPE_VARIABLE|EMAIL_SERVER|WEB_ENTRY_EVENT|MESSAGE_EVENT_DEFINITION|MESSAGE_EVENT_RELATION|MESSAGE_APPLICATION|ELEMENT_TASK_RELATION|ABE_CONFIGURATION|ABE_REQUESTS|ABE_RESPONSES|USR_REPORTING|PRO_REPORTING|DASHBOARD|DASHBOARD_INDICATOR|DASHBOARD_DAS_IND|CATALOG|SCRIPT_TASK|TIMER_EVENT|EMAIL_EVENT|NOTIFICATION_DEVICE|GMAIL_RELABELING|NOTIFICATION_QUEUE|PLUGINS_REGISTRY|APP_DATA_CHANGE_LOG|JOBS_PENDING|JOBS_FAILED|RBAC_PERMISSIONS|RBAC_ROLES|RBAC_ROLES_PERMISSIONS|RBAC_SYSTEMS|RBAC_USERS|RBAC_USERS_ROLES|RBAC_AUTHENTICATION_SOURCE|'";
|
||||
protected $oldContentSystemTables = "";
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
ProcessCategory::truncate();
|
||||
$this->oldContentSystemTables = "";
|
||||
$path = PATH_CONFIG . $this->nameSystemTables;
|
||||
if (file_exists($path)) {
|
||||
$this->oldContentSystemTables = file_get_contents($path);
|
||||
}
|
||||
file_put_contents($path, $this->contentSystemTables);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
$path = PATH_CONFIG . $this->nameSystemTables;
|
||||
file_put_contents($path, $this->oldContentSystemTables);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests if the "executeQuery" method is returning the data of a query.
|
||||
* @test
|
||||
*/
|
||||
public function it_must_return_the_result_of_execute_query_method()
|
||||
{
|
||||
$user = factory(User::class, 5)->create();
|
||||
|
||||
$user = $user->sortByDesc('USR_UID')->values()->map(function($item) {
|
||||
$result = [
|
||||
'USR_UID' => $item['USR_UID'],
|
||||
'USR_USERNAME' => $item['USR_USERNAME'],
|
||||
'USR_PASSWORD' => $item['USR_PASSWORD'],
|
||||
'USR_FIRSTNAME' => $item['USR_FIRSTNAME'],
|
||||
'USR_LASTNAME' => $item['USR_LASTNAME'],
|
||||
'USR_EMAIL' => $item['USR_EMAIL'],
|
||||
];
|
||||
return $result;
|
||||
});
|
||||
$expected = $user->toArray();
|
||||
|
||||
$sql = "SELECT "
|
||||
. "USR_UID ,"
|
||||
. "USR_USERNAME ,"
|
||||
. "USR_PASSWORD ,"
|
||||
. "USR_FIRSTNAME, "
|
||||
. "USR_LASTNAME, "
|
||||
. "USR_EMAIL "
|
||||
. "FROM USERS "
|
||||
. "WHERE "
|
||||
. "USR_UID NOT IN ("
|
||||
. " '00000000000000000000000000000001',"
|
||||
. " '00000000000000000000000000000002'"
|
||||
. ")"
|
||||
. "ORDER BY USR_UID DESC";
|
||||
$actual = executeQuery($sql);
|
||||
$actual = array_values($actual);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a record in the category table using the execute query function.
|
||||
* @test
|
||||
*/
|
||||
public function it_should_insert_a_record_in_the_category_table_using_the_execute_query_method()
|
||||
{
|
||||
$database = env('DB_DATABASE');
|
||||
$faker = Factory::create();
|
||||
$uid = G::generateUniqueID();
|
||||
$id = $faker->unique()->numberBetween(1, 10000000);
|
||||
$name = str_replace("'", " ", $faker->name);
|
||||
$sql = ""
|
||||
. "INSERT INTO {$database}.PROCESS_CATEGORY("
|
||||
. " CATEGORY_UID,"
|
||||
. " CATEGORY_ID,"
|
||||
. " CATEGORY_PARENT,"
|
||||
. " CATEGORY_NAME,"
|
||||
. " CATEGORY_ICON"
|
||||
. ") VALUES"
|
||||
. "("
|
||||
. " '{$uid}',"
|
||||
. " '{$id}',"
|
||||
. " '0',"
|
||||
. " '{$name}',"
|
||||
. " ''"
|
||||
. ")";
|
||||
executeQuery($sql);
|
||||
$expected = [
|
||||
[
|
||||
'CATEGORY_UID' => $uid,
|
||||
'CATEGORY_ID' => $id,
|
||||
'CATEGORY_PARENT' => '0',
|
||||
'CATEGORY_NAME' => $name,
|
||||
'CATEGORY_ICON' => '',
|
||||
]
|
||||
];
|
||||
|
||||
$actual = ProcessCategory::get();
|
||||
|
||||
$this->assertEquals($expected, $actual->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a record in the category table using the execute query function.
|
||||
* @test
|
||||
*/
|
||||
public function it_should_replace_a_record_in_the_category_table_using_the_execute_query_method()
|
||||
{
|
||||
$database = env('DB_DATABASE');
|
||||
$faker = Factory::create();
|
||||
$id = $faker->unique()->numberBetween(1, 10000000);
|
||||
$newName = str_replace("'", " ", $faker->name);
|
||||
|
||||
$category = factory(ProcessCategory::class)->create([
|
||||
'CATEGORY_ID' => $id
|
||||
]);
|
||||
$expected = $category->toArray();
|
||||
$expected['CATEGORY_NAME'] = $newName;
|
||||
unset($expected['id']);
|
||||
|
||||
$sql = "REPLACE INTO {$database}.PROCESS_CATEGORY "
|
||||
. "SET "
|
||||
. "CATEGORY_UID='{$category->CATEGORY_UID}',"
|
||||
. "CATEGORY_PARENT='{$category->CATEGORY_PARENT}', "
|
||||
. "CATEGORY_NAME='{$newName}', "
|
||||
. "CATEGORY_ICON='{$category->CATEGORY_ICON}', "
|
||||
. "CATEGORY_ID='{$category->CATEGORY_ID}'"
|
||||
. "";
|
||||
|
||||
executeQuery($sql);
|
||||
|
||||
$actual = ProcessCategory::where('CATEGORY_UID', '=', $category->CATEGORY_UID)
|
||||
->get()
|
||||
->first();
|
||||
|
||||
$this->assertEquals($expected, $actual->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a record in the category table using the execute query function.
|
||||
* @test
|
||||
*/
|
||||
public function it_should_update_a_record_in_the_category_table_using_the_execute_query_method()
|
||||
{
|
||||
$database = env('DB_DATABASE');
|
||||
$faker = Factory::create();
|
||||
$id = $faker->unique()->numberBetween(1, 10000000);
|
||||
$newName = str_replace("'", " ", $faker->name);
|
||||
|
||||
$category = factory(ProcessCategory::class)->create([
|
||||
'CATEGORY_ID' => $id
|
||||
]);
|
||||
$expected = $category->toArray();
|
||||
$expected['CATEGORY_NAME'] = $newName;
|
||||
unset($expected['id']);
|
||||
|
||||
$sql = ""
|
||||
. "UPDATE {$database}.PROCESS_CATEGORY SET "
|
||||
. "CATEGORY_NAME='{$newName}' "
|
||||
. "WHERE "
|
||||
. "CATEGORY_UID='{$category->CATEGORY_UID}'";
|
||||
executeQuery($sql);
|
||||
|
||||
$actual = ProcessCategory::where('CATEGORY_UID', '=', $category->CATEGORY_UID)
|
||||
->get()
|
||||
->first();
|
||||
|
||||
$this->assertEquals($expected, $actual->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a record in the category table using the execute query function.
|
||||
* @test
|
||||
*/
|
||||
public function it_should_delete_a_record_in_the_category_table_using_the_execute_query_method()
|
||||
{
|
||||
|
||||
$database = env('DB_DATABASE');
|
||||
$category = factory(ProcessCategory::class)->create();
|
||||
|
||||
$sql = ""
|
||||
. "DELETE FROM {$database}.PROCESS_CATEGORY "
|
||||
. "WHERE "
|
||||
. "CATEGORY_UID='{$category->CATEGORY_UID}'";
|
||||
executeQuery($sql);
|
||||
|
||||
$actual = ProcessCategory::where('CATEGORY_UID', '=', $category->CATEGORY_UID)
|
||||
->get()
|
||||
->first();
|
||||
|
||||
$this->assertNull($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* This performs a test of connectivity to an external database using DBS_UID
|
||||
* in the executeQuery() method.
|
||||
* @test
|
||||
*/
|
||||
public function this_connects_to_an_external_database_using_the_execute_query_method()
|
||||
{
|
||||
$dbName = env('DB_DATABASE');
|
||||
$dbSource = factory(DbSource::class)->create([
|
||||
'DBS_TYPE' => 'mysql',
|
||||
'DBS_SERVER' => env('DB_HOST'),
|
||||
'DBS_DATABASE_NAME' => $dbName,
|
||||
'DBS_USERNAME' => env('DB_USERNAME'),
|
||||
'DBS_PASSWORD' => G::encrypt(env('DB_PASSWORD'), $dbName) . "_2NnV3ujj3w",
|
||||
'DBS_PORT' => '3306',
|
||||
]);
|
||||
|
||||
//this is important to get the connection
|
||||
$_SESSION['PROCESS'] = $dbSource->PRO_UID;
|
||||
|
||||
$sql = "show tables";
|
||||
$result = executeQuery($sql, $dbSource->DBS_UID);
|
||||
|
||||
$this->assertTrue(is_array($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* This performs a test of connectivity to an external database using DBS_UID
|
||||
* in the executeQuery() method.
|
||||
* @test
|
||||
*/
|
||||
public function this_connects_to_an_external_oracle_database_using_the_execute_query_method()
|
||||
{
|
||||
$this->markTestIncomplete('This test has not been implemented yet.');
|
||||
|
||||
$dbName = "XE";
|
||||
$dbSource = factory(DbSource::class)->create([
|
||||
'DBS_TYPE' => 'oracle',
|
||||
'DBS_CONNECTION_TYPE' => 'NORMAL',
|
||||
'DBS_SERVER' => 'localhost',
|
||||
'DBS_DATABASE_NAME' => $dbName,
|
||||
'DBS_USERNAME' => env('DB_USERNAME'),
|
||||
'DBS_PASSWORD' => G::encrypt(env('DB_PASSWORD'), $dbName) . "_2NnV3ujj3w",
|
||||
'DBS_PORT' => '1521',
|
||||
]);
|
||||
|
||||
//this is important to get the connection
|
||||
$_SESSION['PROCESS'] = $dbSource->PRO_UID;
|
||||
|
||||
$sql = "select username,account_status from dba_users";
|
||||
$result = executeQuery($sql, $dbSource->DBS_UID);
|
||||
|
||||
$this->assertTrue(is_array($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* This verifies the protection of the system tables.
|
||||
* @test
|
||||
*/
|
||||
public function this_check_the_black_list()
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$uid = G::generateUniqueID();
|
||||
$id = $faker->unique()->numberBetween(1, 10000000);
|
||||
$name = str_replace("'", " ", $faker->name);
|
||||
$sql = ""
|
||||
. "INSERT INTO PROCESS_CATEGORY("
|
||||
. " CATEGORY_UID,"
|
||||
. " CATEGORY_ID,"
|
||||
. " CATEGORY_PARENT,"
|
||||
. " CATEGORY_NAME,"
|
||||
. " CATEGORY_ICON"
|
||||
. ") VALUES"
|
||||
. "("
|
||||
. " '{$uid}',"
|
||||
. " '{$id}',"
|
||||
. " '0',"
|
||||
. " '{$name}',"
|
||||
. " ''"
|
||||
. ")";
|
||||
|
||||
$this->expectException(SQLException::class);
|
||||
|
||||
/**
|
||||
* The executeQuery() function is executing the standard error_log()
|
||||
* output, this test shows error information, but will not stop the
|
||||
* execution of the test.
|
||||
* The error_log() method must stop being used.
|
||||
*/
|
||||
executeQuery($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* This verifies the protection of the system tables.
|
||||
* @test
|
||||
*/
|
||||
public function this_check_the_black_list_for_multiple_tables()
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$id = $faker->unique()->numberBetween(1, 10000000);
|
||||
$newName = str_replace("'", " ", $faker->name);
|
||||
|
||||
$category = factory(ProcessCategory::class)->create([
|
||||
'CATEGORY_ID' => $id
|
||||
]);
|
||||
$expected = $category->toArray();
|
||||
$expected['CATEGORY_NAME'] = $newName;
|
||||
unset($expected['id']);
|
||||
|
||||
$sql = ""
|
||||
. "UPDATE PROCESS_CATEGORY SET "
|
||||
. "CATEGORY_NAME='{$newName}' "
|
||||
. "WHERE "
|
||||
. "CATEGORY_UID='{$category->CATEGORY_UID}'";
|
||||
|
||||
$this->expectException(SQLException::class);
|
||||
|
||||
/**
|
||||
* The executeQuery() function is executing the standard error_log()
|
||||
* output, this test shows error information, but will not stop the
|
||||
* execution of the test.
|
||||
* The error_log() method must stop being used.
|
||||
*/
|
||||
executeQuery($sql);
|
||||
}
|
||||
}
|
||||
28
tests/unit/workflow/engine/classes/PmTableTest.php
Normal file
28
tests/unit/workflow/engine/classes/PmTableTest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class PmTablesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Check if the "removePmtPropelFolder" is working correctly
|
||||
*
|
||||
* @covers PmTable::removePmtPropelFolder()
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function it_should_check_remove_pmt_propel_folder()
|
||||
{
|
||||
// Define the folder path
|
||||
$pmtPropelFolderPath = PATH_DB . config('system.workspace') . PATH_SEP . 'pmt-propel';
|
||||
|
||||
// Create the folder
|
||||
G::mk_dir($pmtPropelFolderPath);
|
||||
|
||||
// Remove the "pmt-propel" folder
|
||||
PmTable::removePmtPropelFolder();
|
||||
|
||||
// Assert that the folder was deleted correctly
|
||||
$this->assertFalse(is_dir($pmtPropelFolderPath));
|
||||
}
|
||||
}
|
||||
@@ -428,4 +428,35 @@ class ProcessesTest extends TestCase
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets the data structure of a project.
|
||||
* @test
|
||||
* @covers Processes::getWorkflowData()
|
||||
*/
|
||||
public function it_should_get_workflow_data()
|
||||
{
|
||||
/**
|
||||
* To perform the test this requires a valid installation and its respective license.
|
||||
*
|
||||
* In the file "workflow/engine/classes/WorkspaceTools.php",
|
||||
* these lines need the db.php file.
|
||||
*
|
||||
* public function __construct($workspaceName)
|
||||
* {
|
||||
* $this->name = $workspaceName;
|
||||
* $this->path = PATH_DB . $this->name;
|
||||
* $this->dbPath = $this->path . '/db.php';
|
||||
* if ($this->workspaceExists()) {
|
||||
* $this->getDBInfo();
|
||||
* }
|
||||
* $this->setListContentMigrateTable();
|
||||
* }
|
||||
*/
|
||||
$this->markTestIncomplete("To perform the test this requires a valid installation and its respective license.");
|
||||
$process = factory(\ProcessMaker\Model\Process::class)->create();
|
||||
$processes = new Processes();
|
||||
$result = $processes->getWorkflowData($process->PRO_UID);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user