Merged in develop (pull request #7127)

Update with develop

Approved-by: Paula Quispe <paula.quispe@processmaker.com>
This commit is contained in:
Paula Quispe
2019-11-18 16:17:32 +00:00
57 changed files with 13015 additions and 258 deletions

View 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']);
}
}

View File

@@ -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()
{
}

View File

@@ -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);
}
}

View 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));
}
}

View File

@@ -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);
}
}

View File

@@ -27,7 +27,9 @@ class DesignerTest extends TestCase
);
//Start the session for the user logged
session_start();
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
$_SESSION['CASE'] = $application->APP_NUMBER;
$_SESSION['PIN'] = "LJ5W";

View File

@@ -205,4 +205,53 @@ class ActionsByEmailTest extends TestCase
//Assert the email was not sent
$this->assertContains('**ID_UNEXPECTED_ERROR_OCCURRED_PLEASE**', $res);
}
/**
* Test the forwardMail method with ssl
*
* @covers \ProcessMaker\BusinessModel\ActionsByEmail::forwardMail()
* @test
*/
public function it_should_test_the_forward_mail_method_with_ssl()
{
//Create the Task factory
factory(Task::class)->create();
//Create the Process factory
factory(Process::class)->create();
//Create the Dynaform factory
factory(Dynaform::class)->create();
//Create the EmailServerModel factory with smtp secure
factory(EmailServerModel::class)->create(
['SMTPSECURE' => 'ssl']
);
//Create the Application factory
factory(Application::class)->create();
//Create the Delegation factory
$delegation = factory(Delegation::class)->create();
//Create the AbeConfiguration factory
$abeConfiguration = factory(AbeConfiguration::class)->create();
//Create the AbeConfiguration factory
$abeRequest = factory(AbeRequest::class)->create([
'ABE_UID' => $abeConfiguration->ABE_UID,
'APP_UID' => $delegation->APP_UID,
'DEL_INDEX' => $delegation->DEL_INDEX,
'ABE_REQ_UID' => $abeConfiguration->ABE_UID,
]);
//Prepare the array send to the method
$arrayData = [
'action' => 'forwardMail',
'REQ_UID' => $abeRequest->ABE_REQ_UID,
'limit' => '',
'start' => ''
];
//Create the ActionsByEmail object
$abe = new ActionsByEmail();
//Call the forwardMail method
$res = $abe->forwardMail($arrayData);
//Assert the email was sent successfully
$this->assertContains('**ID_EMAIL_RESENT_TO**: ' . $abeRequest->ABE_REQ_SENT_TO, $res);
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel;
use ProcessMaker\BusinessModel\Migrator\GranularImporter;
use Tests\TestCase;
class GranularImporterTest extends TestCase
{
/**
* This returns a set of data that is read from a json file.
*/
public function importDataObject()
{
$filename = PATH_TRUNK . "/tests/resources/GranularImporterTest.json";
$json = file_get_contents($filename);
$data = json_decode($json, true);
return $data;
}
/**
* It should return data from addObjectData() method.
* @test
* @covers \ProcessMaker\BusinessModel\Migrator\GranularImporter::addObjectData()
* @dataProvider importDataObject
*/
public function it_should_return_data_from_add_object_data_method($name, $data)
{
$granularImporter = new GranularImporter();
$result = $granularImporter->addObjectData($name, $data);
$this->assertArrayHasKey($name, $result);
}
}

View File

@@ -62,13 +62,16 @@ class SkinsTest extends TestCase
*/
public function testGetSkinsCurrentWorkspace()
{
$this->object->createSkin('test2', 'test2', 'description skin', config("system.workspace"));
$skins = $this->object->getSkins();
$this->assertCount(3, $skins);
$this->assertEquals('test2', $skins[2]['SKIN_FOLDER_ID']);
$this->object->createSkin('test', 'test', 'description skin', config("system.workspace"));
$this->object->createSkin('test', 'test');
$this->object->createSkin('test2', 'test2', 'Second skin', 'ProcessMaker Team', 'current', 'neoclassic');
$skins = $this->object->getSkins();
$skins = collect($skins)
->sortBy('SKIN_FOLDER_ID')
->values()
->toArray();
$this->assertCount(4, $skins);
$this->assertEquals('test2', $skins[3]['SKIN_FOLDER_ID']);
$this->assertEquals($skins[2]['SKIN_FOLDER_ID'], 'test');
$this->assertEquals($skins[3]['SKIN_FOLDER_ID'], 'test2');
$this->assertEquals($skins[3]['SKIN_WORKSPACE'], config("system.workspace"));
}
}

View File

@@ -2,24 +2,47 @@
namespace Tests\unit\workflow\engine\src\ProcessMaker\Importer;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Carbon\Carbon;
use ProcessMaker\Importer\Importer;
use ProcessMaker\Model\BpmnProject;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\User;
use ReflectionClass;
use Tests\TestCase;
class ImporterTest extends TestCase
{
use DatabaseTransactions;
/**
* Declared to avoid the incompatibility exception
*/
public function setUp()
{
$this->markTestIncomplete();//@todo: Please correct this unit test
parent::setUp();
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
config(["system.workspace" => "test"]);
$workspace = config("system.workspace");
if (!file_exists(PATH_DB . $workspace)) {
mkdir(PATH_DB . $workspace);
}
if (!file_exists(PATH_DB . $workspace . PATH_SEP . "db.php")) {
$myfile = fopen(PATH_DB . $workspace . PATH_SEP . "db.php", "w");
fwrite($myfile, "<?php
define ('DB_ADAPTER', 'mysql' );
define ('DB_HOST', '" . env('DB_HOST') . "' );
define ('DB_NAME', '" . env('DB_DATABASE') . "' );
define ('DB_USER', '" . env('DB_USERNAME') . "' );
define ('DB_PASS', '" . env('DB_PASSWORD') . "' );
define ('DB_RBAC_HOST', '" . env('DB_HOST') . "' );
define ('DB_RBAC_NAME', '" . env('DB_DATABASE') . "' );
define ('DB_RBAC_USER', '" . env('DB_USERNAME') . "' );
define ('DB_RBAC_PASS', '" . env('DB_PASSWORD') . "' );
define ('DB_REPORT_HOST', '" . env('DB_HOST') . "' );
define ('DB_REPORT_NAME', '" . env('DB_DATABASE') . "' );
define ('DB_REPORT_USER', '" . env('DB_USERNAME') . "' );
define ('DB_REPORT_PASS', '" . env('DB_PASSWORD') . "' );");
}
}
/**
@@ -271,6 +294,7 @@ class ImporterTest extends TestCase
// Mock the load method
$importer->method("load")
->willReturn($array);
$importer->setData("usr_uid", factory(User::class)->create()->USR_UID);
// Call the import method
$res = $importer->import(Importer::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW,
@@ -282,7 +306,9 @@ class ImporterTest extends TestCase
$result = $query->get()->values()->toArray();
// Assert the created date is the same as the updated date
$this->assertEquals($result[0]['PRO_CREATE_DATE'], $result[0]['PRO_UPDATE_DATE']);
$createDate = Carbon::createFromTimeString($result[0]['PRO_CREATE_DATE'])->format("Y-m-d");
$updateDate = Carbon::createFromTimeString($result[0]['PRO_UPDATE_DATE'])->format("Y-m-d");
$this->assertEquals($createDate, $updateDate);
}
/**
@@ -520,6 +546,7 @@ class ImporterTest extends TestCase
// Mock the load method
$importer->method("load")
->willReturn($array);
$importer->setData("usr_uid", factory(User::class)->create()->USR_UID);
// Call the setProtectedProperty method
$this->setProtectedProperty($importer, 'metadata', ['uid' => $process['PRO_UID']]);

View File

@@ -0,0 +1,312 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Importer;
use G;
use Exception;
use ProcessMaker\Model\Groupwf;
use ProcessMaker\Model\User;
use ProcessMaker\Importer\XmlImporter;
use Tests\TestCase;
class XmlImporterTest extends TestCase
{
private $user;
public function setUp()
{
/**
* 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();
* }
*
*
* In the file "workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularImporter.php",
* these lines need a valid license.
*
* public function import($objectList)
* {
* try {
* if (\PMLicensedFeatures::getSingleton()->verifyfeature
* ("jXsSi94bkRUcVZyRStNVExlTXhEclVadGRRcG9xbjNvTWVFQUF3cklKQVBiVT0=")
* ) {
* $objectList = $this->reorderImportOrder($objectList);
* foreach ($objectList as $data) {
* $objClass = $this->factory->create($data['name']);
* if (is_object($objClass)) {
* $dataImport = $data['data'][$data['name']];
* $replace = ($data['value'] == 'replace') ? true : false;
* $objClass->beforeImport($dataImport);
* $migratorData = $objClass->import($dataImport, $replace);
* $objClass->afterImport($dataImport);
* }
* }
* } else {
* $exception = new ImportException();
* $exception->setNameException(\G::LoadTranslation('ID_NO_LICENSE_SELECTIVEIMPORTEXPORT_ENABLED'));
* throw($exception);
* }
*
* } catch (\Exception $e) {
* if (get_class($e) === 'ProcessMaker\BusinessModel\Migrator\ImportException') {
* throw $e;
* } else {
* $exception = new ImportException('Please review your current process definition
* for missing elements, it\'s recommended that a new process should be exported
* with all the elements.');
* throw $exception;
* }
* }
* }
*/
$this->markTestIncomplete("To perform the test this requires a valid installation and its respective license.");
parent::setUp();
$this->user = factory(User::class)->create();
Groupwf::truncate();
}
/**
* Test the import new option and the import new group option.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
* @covers \ProcessMaker\Importer\XmlImporter::importBpmnTables()
*/
public function it_should_matter_with_import_option_create_new_and_group_import_option_create_new()
{
$filename = PATH_TRUNK . "/tests/resources/p1normal-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false);
$this->assertNotNull($result);
}
/**
* Test the import new without changing and the import merge group option.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_keep_without_changing_and_create_new_and_group_import_option_merge_preexistent()
{
factory(\ProcessMaker\Model\Groupwf::class)->create([
'GRP_TITLE' => 'group1'
]);
factory(\ProcessMaker\Model\Groupwf::class)->create([
'GRP_TITLE' => 'group2'
]);
$regenerateUids = false;
$filename = PATH_TRUNK . "/tests/resources/p1normal-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT, true);
$this->assertNotNull($result);
}
/**
* Test the import overwrite option and the import rename group option.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_overwrite_and_group_import_option_rename()
{
factory(\ProcessMaker\Model\Groupwf::class)->create([
'GRP_TITLE' => 'group1'
]);
factory(\ProcessMaker\Model\Groupwf::class)->create([
'GRP_TITLE' => 'group2'
]);
$filename = PATH_TRUNK . "/tests/resources/p1normal-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_OVERWRITE, XmlImporter::GROUP_IMPORT_OPTION_RENAME, false);
$this->assertNotNull($result);
}
/**
* Test the import new option and the import new group option with objects imports.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
* @covers \ProcessMaker\BusinessModel\Migrator\GranularImporter::structureBpmnData()
*/
public function it_should_matter_with_import_option_create_new_and_group_import_option_create_new_and_objects_import()
{
$filename = PATH_TRUNK . "/tests/resources/p2custom-1.pmx2";
$objectsToImportFilename = PATH_TRUNK . "/tests/resources/p2custom-1-ObjectsToImport.json";
$json = file_get_contents($objectsToImportFilename);
$objectsToImport = json_decode($json);
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false, $objectsToImport);
$this->assertNotNull($result);
}
/**
* Test the import without changing option and the import new group option with objects import.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_keep_without_changing_and_create_new_and_group_import_option_create_new()
{
$regenerateUids = false;
$filename = PATH_TRUNK . "/tests/resources/p2custom-1.pmx2";
$objectsToImportFilename = PATH_TRUNK . "/tests/resources/p2custom-1-ObjectsToImport.json";
$json = file_get_contents($objectsToImportFilename);
$objectsToImport = json_decode($json);
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, true, $objectsToImport);
$this->assertNotNull($result);
}
/**
* Test the import overwrite option and the import new group option with objects import.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_overwrite_and_group_import_option_create_new()
{
$filename = PATH_TRUNK . "/tests/resources/p2custom-1.pmx2";
$objectsToImportFilename = PATH_TRUNK . "/tests/resources/p2custom-1-ObjectsToImport.json";
$json = file_get_contents($objectsToImportFilename);
$objectsToImport = json_decode($json);
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_OVERWRITE, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false, $objectsToImport);
$this->assertNotNull($result);
}
/**
* Test the import disable option and the import new group option with objects import.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_disable_and_create_new_and_group_import_option_create_new()
{
$regenerateUids = false;
$filename = PATH_TRUNK . "/tests/resources/p2custom-1.pmx2";
$objectsToImportFilename = PATH_TRUNK . "/tests/resources/p2custom-1-ObjectsToImport.json";
$json = file_get_contents($objectsToImportFilename);
$objectsToImport = json_decode($json);
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_DISABLE_AND_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, true, $objectsToImport);
$this->assertNotNull($result);
}
/**
* Test the import new option and the import new group option with exception.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_create_new_and_group_import_option_create_new_with_exception()
{
$filename = PATH_TRUNK . "/tests/resources/p1normal-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$this->expectException(Exception::class);
$result = $importer->import(XmlImporter::IMPORT_OPTION_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false);
$this->assertNotNull($result);
}
/**
* Test the import overwrite option and the import new group option with exist groups.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_overwrite_and_group_import_option_create_new_with_groups()
{
factory(\ProcessMaker\Model\Groupwf::class)->create([
'GRP_TITLE' => 'group1'
]);
factory(\ProcessMaker\Model\Groupwf::class)->create([
'GRP_TITLE' => 'group2'
]);
$filename = PATH_TRUNK . "/tests/resources/p1normal-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$this->expectException(Exception::class);
$result = $importer->import(XmlImporter::IMPORT_OPTION_OVERWRITE, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false);
$this->assertNotNull($result);
}
/**
* Test the import new option and the import new group option with generated uid from js such as null.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
*/
public function it_should_matter_with_import_option_create_new_and_group_import_option_create_new_try_exception()
{
$filename = PATH_TRUNK . "/tests/resources/p1normalWithException-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$this->expectException(Exception::class);
$result = $importer->import(XmlImporter::IMPORT_OPTION_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW);
$this->assertNotNull($result);
}
/**
* Test the import new option and the import new group option with repeated title.
* @test
* @covers \ProcessMaker\Importer\XmlImporter::import()
* @covers \ProcessMaker\Importer\XmlImporter::updateTheProcessOwner()
*/
public function it_should_matter_with_import_option_create_new_and_group_import_option_create_new_try_rename_title()
{
factory(\ProcessMaker\Model\Process::class)->create([
'PRO_TITLE' => 'p1normalWithoutTitle'
]);
$filename = PATH_TRUNK . "/tests/resources/p1normalWithoutTitle-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false);
$this->assertNotNull($result);
factory(\ProcessMaker\Model\Process::class)->create([
'PRO_TITLE' => 'p1normalWithoutTitle2'
]);
$filename = PATH_TRUNK . "/tests/resources/p1normalWithoutTitle2-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$result = $importer->import(XmlImporter::IMPORT_OPTION_OVERWRITE, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false);
$this->assertNotNull($result);
}
}

View File

@@ -81,16 +81,16 @@ class DelegationTest extends TestCase
$process = factory(Process::class)->create();
factory(Delegation::class, 51)->states('foreign_keys')->create([
'PRO_ID' => $process->id
'PRO_ID' => $process->PRO_ID
]);
// Get first page, which is 25
$results = Delegation::search(null, 0, 25, null, $process->id);
$results = Delegation::search(null, 0, 25, null, $process->PRO_ID);
$this->assertCount(25, $results['data']);
// Get second page, which is 25 results
$results = Delegation::search(null, 25, 25, null, $process->id);
$results = Delegation::search(null, 25, 25, null, $process->PRO_ID);
$this->assertCount(25, $results['data']);
// Get third page, which is only 1 result
$results = Delegation::search(null, 50, 25, null, $process->id);
$results = Delegation::search(null, 50, 25, null, $process->PRO_ID);
$this->assertCount(1, $results['data']);
}
@@ -373,7 +373,7 @@ class DelegationTest extends TestCase
{
factory(Delegation::class, 3)->states('foreign_keys')->create([
'PRO_ID' => function () {
return factory(Process::class)->create()->id;
return factory(Process::class)->create()->PRO_ID;
}
]);
// Get first page, all process ordering ASC
@@ -541,7 +541,7 @@ class DelegationTest extends TestCase
]);
// Delegations to found
factory(Delegation::class, 51)->states('foreign_keys')->create([
'PRO_ID' => $processSearch->id
'PRO_ID' => $processSearch->PRO_ID
]);
// Get first page, which is 25
$results = Delegation::search(null, 0, 25, null, null, null, null, null, $category->CATEGORY_UID);
@@ -639,7 +639,7 @@ class DelegationTest extends TestCase
$application = factory(Application::class)->create();
// Create the threads for a parallel process
factory(Delegation::class, 5)->states('foreign_keys')->create([
'PRO_ID' => $process->id,
'PRO_ID' => $process->PRO_ID,
'TAS_ID' => $parallelTask->TAS_ID,
'APP_NUMBER' => $application->APP_NUMBER,
'DEL_THREAD_STATUS' => 'CLOSED'
@@ -666,7 +666,7 @@ class DelegationTest extends TestCase
$application = factory(Application::class)->create();
// Create the threads for a parallel process
factory(Delegation::class, 5)->states('foreign_keys')->create([
'PRO_ID' => $process->id,
'PRO_ID' => $process->PRO_ID,
'TAS_ID' => $parallelTask->TAS_ID,
'APP_NUMBER' => $application->APP_NUMBER,
'DEL_THREAD_STATUS' => 'OPEN'
@@ -693,7 +693,7 @@ class DelegationTest extends TestCase
$application = factory(Application::class)->create(['APP_STATUS_ID' => 2]);
// Create the threads for a parallel process closed
factory(Delegation::class)->states('closed')->create([
'PRO_ID' => $process->id,
'PRO_ID' => $process->PRO_ID,
'PRO_UID' => $process->PRO_UID,
'TAS_ID' => $parallelTask->TAS_ID,
'APP_NUMBER' => $application->APP_NUMBER,
@@ -701,7 +701,7 @@ class DelegationTest extends TestCase
]);
// Create the threads for a parallel process closed
factory(Delegation::class)->states('open')->create([
'PRO_ID' => $process->id,
'PRO_ID' => $process->PRO_ID,
'PRO_UID' => $process->PRO_UID,
'TAS_ID' => $parallelTask->TAS_ID,
'APP_NUMBER' => $application->APP_NUMBER,
@@ -745,27 +745,27 @@ class DelegationTest extends TestCase
//Create a process with category
$processWithCat = factory(Process::class)->create(['PRO_CATEGORY' => $category[0]->CATEGORY_UID]);
factory(Delegation::class)->states('foreign_keys')->create([
'PRO_ID' => $processWithCat->id
'PRO_ID' => $processWithCat->PRO_ID
]);
// Create a process without category
$processWithoutCat = factory(Process::class)->create(['PRO_CATEGORY' => '']);
factory(Delegation::class, 5)->states('foreign_keys')->create([
'PRO_ID' => $processWithoutCat->id
'PRO_ID' => $processWithoutCat->PRO_ID
]);
// Search the cases when the process has related to the category and search by another category
$results = Delegation::search(null, 0, 25, null, $processWithCat->id, null, null, null,
$results = Delegation::search(null, 0, 25, null, $processWithCat->PRO_ID, null, null, null,
$category[1]->CATEGORY_UID);
$this->assertCount(0, $results['data']);
// Search the cases when the process has related to the category and search by this relation
$results = Delegation::search(null, 0, 25, null, $processWithCat->id, null, null, null,
$results = Delegation::search(null, 0, 25, null, $processWithCat->PRO_ID, null, null, null,
$category[0]->CATEGORY_UID);
$this->assertCount(1, $results['data']);
// Search the cases when the process does not have relation with category and search by a category
$results = Delegation::search(null, 0, 25, null, $processWithoutCat->id, null, null, null,
$results = Delegation::search(null, 0, 25, null, $processWithoutCat->PRO_ID, null, null, null,
$category[1]->CATEGORY_UID);
$this->assertCount(0, $results['data']);
// Search the cases when the process does not have relation with category empty
$results = Delegation::search(null, 0, 25, null, $processWithoutCat->id, null, null, null,
$results = Delegation::search(null, 0, 25, null, $processWithoutCat->PRO_ID, null, null, null,
'');
$this->assertCount(5, $results['data']);
}
@@ -786,7 +786,7 @@ class DelegationTest extends TestCase
]);
//Create a delegation related to this process
factory(Delegation::class)->create([
'PRO_ID' => $processWithCat->id
'PRO_ID' => $processWithCat->PRO_ID
]);
//Define a process related with he previous category
$process = factory(Process::class)->create([
@@ -794,7 +794,7 @@ class DelegationTest extends TestCase
]);
//Create a delegation related to other process
factory(Delegation::class, 5)->create([
'PRO_ID' => $process->id,
'PRO_ID' => $process->PRO_ID,
]);
}

View File

@@ -5,53 +5,92 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use G;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\ProcessCategory;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
use Tests\TestCase;
/**
* @coversDefaultClass ProcessMaker\BusinessModel\Model\Process
*/
class ProcessTest extends TestCase
{
use DatabaseTransactions;
/**
* Test belongs to PRO_ID
*
* @covers \ProcessMaker\Model\Process::tasks()
* @test
*/
public function it_has_tasks()
{
$process = factory(Process::class)->create([
'PRO_ID' => function () {
return factory(Task::class)->create()->PRO_ID;
}
]);
$this->assertInstanceOf(Task::class, $process->tasks);
}
/**
* Test belongs to PRO_CREATE_USER
*
* @covers \ProcessMaker\Model\Process::creator()
* @test
*/
public function it_has_a_creator()
{
$process = factory(Process::class)->create([
'PRO_CREATE_USER' => function () {
return factory(User::class)->create()->USR_UID;
}
]);
$this->assertInstanceOf(User::class, $process->creator);
}
/**
* Test belongs to PRO_CREATE_USER
*
* @covers \ProcessMaker\Model\Process::category()
* @test
*/
public function it_has_an_category()
{
$process = factory(Process::class)->create([
'PRO_CATEGORY' => function () {
return factory(ProcessCategory::class)->create()->CATEGORY_UID;
}
]);
$this->assertInstanceOf(ProcessCategory::class, $process->category);
}
/**
* Test it returns all the processes for an specific user
* @covers \ProcessMaker\Model\Process::getProcessList
*
* @covers \ProcessMaker\Model\Process::getProcessList()
* @test
*/
public function it_should_return_all_the_processes_for_an_specific_user()
{
//Create user
$user1 = factory(User::class)->create();
$user2 = factory(User::class)->create();
//Create process
$process1 = factory(Process::class)->create(
['PRO_CREATE_USER' => $user1['USR_UID']]
);
$process2 = factory(Process::class)->create(
['PRO_CREATE_USER' => $user2['USR_UID']]
);
$process = factory(Process::class, 2)->states('foreign_keys')->create([]);
//Create a Process object
$process = new Process();
$pro = new Process();
//Call the getProcessList() method
$res = $process->getProcessList('', $user2['USR_UID']);
$res = $pro->getProcessList('', $process[0]->PRO_CREATE_USER);
//Assert the result is not empty
$this->assertNotEmpty($res);
//Assert there's one result
$this->assertCount(1, $res);
//Assert that the process returned is the one looked for
$this->assertEquals($process2['PRO_UID'], $res[0]['PRO_UID']);
//Assert the process that was not searched is not in the result
$this->assertNotEquals($process1['PRO_UID'], $res[0]['PRO_UID']);
$this->assertEquals($process[0]->PRO_UID, $res[0]['PRO_UID']);
}
/**
* Tests that it returns the processes in an specific category
* @covers \ProcessMaker\Model\Process::getProcessList
*
* @covers \ProcessMaker\Model\Process::getProcessList()
* @test
*/
public function it_should_return_the_processes_in_an_specific_category()
@@ -62,23 +101,19 @@ class ProcessTest extends TestCase
//Create user
$user = factory(User::class)->create();
//Create process
$process1 = factory(Process::class)->create(
[
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_CATEGORY' => $catUid1
]
);
$process2 = factory(Process::class)->create(
[
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_CATEGORY' => $catUid2
]
);
$process1 = factory(Process::class)->create([
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_CATEGORY' => $catUid1
]);
$process2 = factory(Process::class)->create([
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_CATEGORY' => $catUid2
]);
//Create a Process object
$process = new Process();
$pro = new Process();
//Call the getProcessList() method
$res = $process->getProcessList($process1['PRO_CATEGORY'], $user['USR_UID']);
$res = $pro->getProcessList($process1['PRO_CATEGORY'], $user['USR_UID']);
//Assert the result is not empty
$this->assertNotEmpty($res);
@@ -92,7 +127,8 @@ class ProcessTest extends TestCase
/**
* Tests that it returns an empty array if no processes where found
* @covers \ProcessMaker\Model\Process::getProcessList
*
* @covers \ProcessMaker\Model\Process::getProcessList()
* @test
*/
public function it_should_return_empty_if_no_processes_where_found()
@@ -110,7 +146,8 @@ class ProcessTest extends TestCase
/**
* Test it returns all the processes in status active
* @covers \ProcessMaker\Model\Process::getProcessList
*
* @covers \ProcessMaker\Model\Process::getProcessList()
* @test
*/
public function it_should_return_all_the_processes_in_status_active()
@@ -118,24 +155,18 @@ class ProcessTest extends TestCase
//Create user
$user = factory(User::class)->create();
//Create process
$process1 = factory(Process::class)->create(
[
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_STATUS' => 'ACTIVE'
]
);
$process2 = factory(Process::class)->create(
[
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_STATUS' => 'INACTIVE'
]
);
$process3 = factory(Process::class)->create(
[
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_STATUS' => 'DISABLED'
]
);
$process1 = factory(Process::class)->create([
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_STATUS' => 'ACTIVE'
]);
$process2 = factory(Process::class)->create([
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_STATUS' => 'INACTIVE'
]);
$process3 = factory(Process::class)->create([
'PRO_CREATE_USER' => $user['USR_UID'],
'PRO_STATUS' => 'DISABLED'
]);
//Create a Process object
$process = new Process();

View File

@@ -0,0 +1,236 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Project\Adapter;
use Exception;
use Faker\Factory;
use G;
use ProcessMaker\Model\BpmnProject;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\User;
use ProcessMaker\Project\Adapter\BpmnWorkflow;
use ProcessMaker\Importer\XmlImporter;
use Tests\TestCase;
class BpmnWorkflowTest extends TestCase
{
private $user;
public function setUp()
{
parent::setUp();
$this->user = factory(User::class)->create();
}
/**
* Creation of a bpmn project.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::create()
*/
public function it_should_create_bpmn_project()
{
$faker = Factory::create();
$data = [
'PRJ_UID' => G::generateUniqueID(),
'PRJ_AUTHOR' => G::generateUniqueID(),
'PRJ_NAME' => $faker->title,
'PRJ_DESCRIPTION' => $faker->text,
'PRJ_TYPE' => $faker->name,
'PRJ_CATEGORY' => $faker->word,
'PRO_ID' => $faker->randomDigit,
'PRO_STATUS' => 'ACTIVE'
];
$bpmnWorkflow = new BpmnWorkflow();
$bpmnWorkflow->create($data);
$bpmnProject = BpmnProject::where('PRJ_UID', '=', $data['PRJ_UID'])
->get();
$this->assertNotNull($bpmnProject);
}
/**
* We get an exception when the data is incorrect.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::create()
*/
public function it_should_create_bpmn_project_with_incorrect_data()
{
$faker = Factory::create();
$data = [
'PRJ_UID' => []
];
$bpmnWorkflow = new BpmnWorkflow();
$this->expectException(Exception::class);
$bpmnWorkflow->create($data);
}
/**
* An exception is obtained if we try to enter an existing title.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::create()
*/
public function it_should_create_bpmn_project_with_duplicate_title()
{
$faker = Factory::create();
$title = $faker->title;
factory(\ProcessMaker\Model\Process::class)->create([
'PRO_TITLE' => $title
]);
$data = [
'PRJ_UID' => G::generateUniqueID(),
'PRJ_AUTHOR' => G::generateUniqueID(),
'PRJ_NAME' => $title,
'PRJ_DESCRIPTION' => $faker->text,
'PRJ_TYPE' => $faker->name,
'PRJ_CATEGORY' => $faker->word,
'PRO_ID' => $faker->randomDigit,
'PRO_STATUS' => 'ACTIVE'
];
$bpmnWorkflow = new BpmnWorkflow();
$this->expectException(Exception::class);
$bpmnWorkflow->create($data);
}
/**
* Create a project from a data structure.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct()
*/
public function it_should_create_from_structure()
{
$faker = Factory::create();
$projectDataFilename = PATH_TRUNK . "/tests/resources/projectData.json";
$json = file_get_contents($projectDataFilename);
$projectData = json_decode($json, JSON_OBJECT_AS_ARRAY);
$projectData['prj_uid'] = G::generateUniqueID();
$projectData["process"]["pro_id"] = $faker->randomDigit;
$bpmnWorkflow = new BpmnWorkflow();
$bpmnWorkflow->createFromStruct($projectData, true, null);
}
/**
* Get an exception if there is an invalid name in the data structure.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct()
*/
public function it_should_create_from_structure_invalid_name()
{
$faker = Factory::create();
$projectDataFilename = PATH_TRUNK . "/tests/resources/projectData.json";
$json = file_get_contents($projectDataFilename);
$projectData = json_decode($json, JSON_OBJECT_AS_ARRAY);
$projectData['prj_uid'] = G::generateUniqueID();
$projectData["process"]["pro_id"] = $faker->randomDigit;
$bpmnWorkflow = new BpmnWorkflow();
$projectData['prj_name'] = '';
$this->expectException(Exception::class);
$bpmnWorkflow->createFromStruct($projectData, true, null);
}
/**
* Get an exception if there is a duplicate name.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct()
*/
public function it_should_create_from_structure_with_duplicate_name()
{
$faker = Factory::create();
$projectDataFilename = PATH_TRUNK . "/tests/resources/projectData.json";
$json = file_get_contents($projectDataFilename);
$projectData = json_decode($json, JSON_OBJECT_AS_ARRAY);
$projectData['prj_uid'] = G::generateUniqueID();
$projectData["process"]["pro_id"] = $faker->randomDigit;
$bpmnWorkflow = new BpmnWorkflow();
factory(\ProcessMaker\Model\BpmnProject::class)->create([
'PRJ_NAME' => $projectData['prj_name']
]);
$this->expectException(Exception::class);
$bpmnWorkflow->createFromStruct($projectData, true, null);
}
/**
* We get an exception if the type field does not exist in the activity.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct()
*/
public function it_should_create_from_structure_invalid_activity_type()
{
$faker = Factory::create();
$projectDataFilename = PATH_TRUNK . "/tests/resources/projectData.json";
$json = file_get_contents($projectDataFilename);
$projectData = json_decode($json, JSON_OBJECT_AS_ARRAY);
$projectData['prj_uid'] = G::generateUniqueID();
$projectData["process"]["pro_id"] = $faker->randomDigit;
$bpmnWorkflow = new BpmnWorkflow();
$projectData['prj_name'] = $faker->name;
unset($projectData['diagrams']['0']['activities']['0']['act_type']);
$this->expectException(Exception::class);
$bpmnWorkflow->createFromStruct($projectData, true, null);
}
/**
* We get an exception if the type field does not exist in the event.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct()
*/
public function it_should_create_from_structure_invalid_event_type()
{
$faker = Factory::create();
$projectDataFilename = PATH_TRUNK . "/tests/resources/projectData.json";
$json = file_get_contents($projectDataFilename);
$projectData = json_decode($json, JSON_OBJECT_AS_ARRAY);
$projectData['prj_uid'] = G::generateUniqueID();
$projectData["process"]["pro_id"] = $faker->randomDigit;
$bpmnWorkflow = new BpmnWorkflow();
$projectData['prj_name'] = $faker->name;
unset($projectData['diagrams']['0']['events']['0']['evn_type']);
$this->expectException(Exception::class);
$bpmnWorkflow->createFromStruct($projectData, true, null);
}
/**
* We get an exception if the marker field does not exist in the event.
* @test
* @covers \ProcessMaker\Project\Adapter\BpmnWorkflow::createFromStruct()
*/
public function it_should_create_from_structure_invalid_event_marker()
{
$faker = Factory::create();
$projectDataFilename = PATH_TRUNK . "/tests/resources/projectData.json";
$json = file_get_contents($projectDataFilename);
$projectData = json_decode($json, JSON_OBJECT_AS_ARRAY);
$projectData['prj_uid'] = G::generateUniqueID();
$projectData["process"]["pro_id"] = $faker->randomDigit;
$bpmnWorkflow = new BpmnWorkflow();
$projectData['prj_name'] = $faker->name;
unset($projectData['diagrams']['0']['events']['0']['evn_marker']);
$this->expectException(Exception::class);
$bpmnWorkflow->createFromStruct($projectData, true, null);
}
}

View File

@@ -34,6 +34,8 @@ class LightTest extends TestCase
*/
protected function setUp()
{
$this->markTestIncomplete();//@todo: we need to correct this before the epic PMC-857 because this test use Unassigned cases
parent::setUp();
$this->workspace = env("DB_DATABASE", "test");
$this->clientId = config("oauthClients.pm.clientId");

View File

@@ -0,0 +1,61 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Services\Api;
use Faker\Factory;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\User;
use ProcessMaker\Importer\XmlImporter;
use ProcessMaker\Services\Api\Project;
use Tests\TestCase;
class ProjectTest extends TestCase
{
private $user;
public function setUp()
{
/**
* 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.");
parent::setUp();
$this->user = factory(User::class)->create();
}
/**
* Set the process owner with invalid value, the import test covers most of the code.
* @test
* @covers \ProcessMaker\Services\Api\Project::doSaveAs()
* @covers \ProcessMaker\Importer\XmlImporter::saveAs()
*/
public function it_should_set_the_process_owner_with_invalid_value()
{
$filename = PATH_TRUNK . "/tests/resources/p1normal-1.pmx";
$importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID);
$importer->setSourceFile($filename);
$proUid = $importer->import(XmlImporter::IMPORT_OPTION_CREATE_NEW, XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW, false);
$faker = $faker = Factory::create();
$project = new Project();
$project->setUserId($this->user->USR_ID);
$result = $project->doSaveAs($proUid, $faker->title);
$this->assertNotEmpty($result);
}
}