diff --git a/features/backend/admin_setup/settings/category/basic_sequence_category.feature b/features/backend/admin_setup/settings/category/basic_sequence_category.feature index e69de29bb..9322f1830 100644 --- a/features/backend/admin_setup/settings/category/basic_sequence_category.feature +++ b/features/backend/admin_setup/settings/category/basic_sequence_category.feature @@ -0,0 +1,72 @@ +@ProcessMakerMichelangelo @RestAPI +Feature: Process Category + Requirements: + a workspace with the workspace with one process category + + +Background: + Given that I have a valid access_token + + +Scenario: Get list of Categories + Given I request "categories" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "array" + And the response has 1 records + + +Scenario: Get a Category specific + Given I request "category/4177095085330818c324501061677193" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "array" + + +Scenario: Create a new Categories + Given POST this data: + """ + { + "cat_name": "Test new Category" + } + """ + And I request "category" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "object" + And store "cat_uid" in session array as variable "cat_uid" + + +Scenario: Get list of Categories + Given I request "categories" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "array" + And the response has 2 records + + +Scenario: Update the Category created in this script + Given PUT this data: + """ + { + "cat_name": "Name Updated" + } + """ + And that I want to update a resource with the key "cat_uid" stored in session array + And I request "category" + And the content type is "application/json" + Then the response status code should be 200 + And the response charset is "UTF-8" + + +Scenario: Delete the Category created previously in this script + Given that I want to delete a resource with the key "cat_uid" stored in session array + And I request "category" + And the content type is "application/json" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the type is "object" \ No newline at end of file diff --git a/features/backend/admin_setup/settings/category/main_tests_category.feature b/features/backend/admin_setup/settings/category/main_tests_category.feature index e69de29bb..817e1a5a5 100644 --- a/features/backend/admin_setup/settings/category/main_tests_category.feature +++ b/features/backend/admin_setup/settings/category/main_tests_category.feature @@ -0,0 +1,139 @@ +@ProcessMakerMichelangelo @RestAPI +Feature: Process Category Main Test + Requirements: + a workspace with the workspace with one process category + + +Background: + Given that I have a valid access_token + + +Scenario: Get list of Categories + Given I request "categories" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "array" + And the response has 1 records + + +Scenario: Get a Category specific + Given I request "category/4177095085330818c324501061677193" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "array" + And the "cat_uid" property equals "4177095085330818c324501061677193" + And the "cat_name" property equals "Category Cases Lists" + And the "cat_total_processes" property equals 5 + + +Scenario Outline: Create a new Categories + Given POST this data: + """ + { + "cat_name": "" + } + """ + And I request "category" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "object" + And store "cat_uid" in session array as variable "cat_uid_" + + Examples: + + | test_description | cat_uid_number | cat_name | + | Create new Category with character special | 1 | sample!@#$%^^& | + | Create new Category with only character numeric | 2 | 32425325 | + | Create new Category with only character special | 3 | @$@$#@% | + | Create new Category with normal character | 4 | sample | + + + +Scenario: Get list of Categories + Given I request "categories" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "array" + And the response has 5 records + + +Scenario: Create Category with same name + Given POST this data: + """ + { + "cat_name": "sample" + } + """ + And I request "category" + Then the response status code should be 400 + And the response status message should have the following text "Duplicate" + + +Scenario Outline: Update the Category created in this script + Given PUT this data: + """ + { + "cat_name": "cat_name" + } + """ + And I request "category/cat_uid" with the key "cat_uid" stored in session array as variable "cat_uid_" + And store "cat_uid" in session array as variable "cat_uid_" + + And the content type is "application/json" + Then the response status code should be 200 + And the response charset is "UTF-8" + + + Examples: + + | test_description | cat_uid_number | cat_name | + | Update Category | 1 | UPDATE sample!@#$%^^& | + | Update Category | 2 | UPDATE 32425325 | + + +Scenario Outline: Get a Category specific + Given I request "category/4177095085330818c324501061677193" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "array" + And the "cat_name" property equals "UPDATE sample!@#$%^^&" + And the "cat_total_processes" property equals 0 + + Examples: + + | cat_uid_number | cat_name | cat_total_processes | + | 1 | UPDATE sample!@#$%^^& | 0 | + | 2 | UPDATE 32425325 | 0 | + + +Scenario Outline: Delete the Category created previously in this script + Given that I want to delete a resource with the key "cat_uid" stored in session array as variable "cat_uid_" + And I request "category" + And the content type is "application/json" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the type is "object" + + Examples: + + | cat_uid_number | + | 1 | + | 2 | + | 3 | + | 4 | + + +Scenario: Get a Category specific + Given I request "category/4177095085330818c324501061677193" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "array" + And the "cat_uid" property equals "4177095085330818c324501061677193" + And the "cat_name" property equals "Category Cases Lists" + And the "cat_total_processes" property equals 5 \ No newline at end of file diff --git a/features/backend/admin_setup/settings/category/negative_tests_category.feature b/features/backend/admin_setup/settings/category/negative_tests_category.feature index e69de29bb..716b8228c 100644 --- a/features/backend/admin_setup/settings/category/negative_tests_category.feature +++ b/features/backend/admin_setup/settings/category/negative_tests_category.feature @@ -0,0 +1,23 @@ +@ProcessMakerMichelangelo @RestAPI +Feature: Process Category Negative Tests + + +Background: + Given that I have a valid access_token + + +Scenario Outline: Create a new Categories (Negative Test) + Given POST this data: + """ + { + "cat_name": "" + } + """ + And I request "category" + Then the response status code should be + And the response status message should have the following text "" + + Examples: + + | test_description | cat_name | error_code | error_message | + | without name | | 400 | cat_name | \ No newline at end of file diff --git a/features/backend/application_cases/case_actions/negative_tests_cases_actions.feature b/features/backend/application_cases/case_actions/negative_tests_cases_actions.feature index 9d8578b11..1299e6a99 100644 --- a/features/backend/application_cases/case_actions/negative_tests_cases_actions.feature +++ b/features/backend/application_cases/case_actions/negative_tests_cases_actions.feature @@ -22,9 +22,9 @@ Scenario Outline: Create a new case (Negative Test) Examples: | Description | pro_uid | tas_uid | error_code | error_message | | Create new case with pro_uid wrong | 99209594750ec1111111927000421575 | 68707275350ec281ada1c95068712556 | 400 | pro_uid | - | Create new case with task_uid wrong | 46279907250ec73b9b25a78031279680 | 99371337811111111111116024620271 | 400 | task_uid | + | Create new case with tas_uid wrong | 46279907250ec73b9b25a78031279680 | 99371337811111111111116024620271 | 400 | tas_uid | | Create new case without pro_uid | | 52838134750ec7dd0989fc0015625952 | 400 | pro_uid | - | Create new case without tas_uid | 34579467750ec8d55e8b115057818502 | | 400 | task_uid | + | Create new case without tas_uid | 34579467750ec8d55e8b115057818502 | | 400 | tas_uid | | Create new case whith pro_uid and tas_uid wrong | 8245849601111111181ecc7039804404 | 5690001111111118e4a9243080698854 | 400 | pro_uid | @@ -34,9 +34,9 @@ Scenario Outline: Create a new case Impersonate (Negative Test) Given POST this data: """ { - "pro_uid": "99209594750ec27ea338927000421575", + "pro_uid": "", "usr_uid": "", - "tas_uid": "68707275350ec281ada1c95068712556", + "tas_uid": "", "variables": [{"name": "pruebaQA", "amount":"10400"}] } """ @@ -45,12 +45,12 @@ Scenario Outline: Create a new case Impersonate (Negative Test) And the response status message should have the following text "" Examples: - | Description | case_number | usr_uid | error_code | error_message | - | Create new case with process "Derivation rules - sequential" - Case Start with chris | 26 | 51049032352d56710347233042615067 | 400 | pro_uid | - | Create new case with process "Derivation rules - evaluation" - Case Start with adam | 27 | 44811996752d567110634a1013636964 | 400 | task_uid | - | Create new case with process "Derivation rules - Parallel" - Case Start with aaron | 28 | 24166330352d56730cdd525035621101 | 400 | pro_uid | - | Create new case with process "Derivation rules - parallel evaluation"- Case Start with jeremiah | 29 | 86677227852d5671f40ba25017213081 | 400 | task_uid | - | Create new case with process "Derivation rules - selection" - Case Start with admin | 30 | 62625000752d5672d6661e6072881167 | 400 | | + | Description | pro_uid | usr_uid | tas_uid | error_code | error_message | + | Create new case with process "Derivation rules - sequential" invalid pro_uid | 99201111111111111138927000421575 | 51049032352d56710347233042615067 | 68707275350ec281ada1c95068712556 | 400 | pro_uid | + | Create new case with process "Derivation rules - evaluation" invalid tas_uid | 99209594750ec27ea338927000421575 | 44811996752d567110634a1013636964 | 68707211111111111111111111712556 | 400 | tas_uid | + | Create new case with process "Derivation rules - Parallel" usr_uid | 99209594750ec27ea338927000421575 | 24166331111111111111115035621101 | 68707275350ec281ada1c95068712556 | 400 | usr_uid | + | Create new case with process "Derivation rules - without pro_uid | | 86677227852d5671f40ba25017213081 | 68707275350ec281ada1c95068712556 | 400 | pro_uid | + | Create new case with process "Derivation rules - selection" tas_uid | 99209594750ec27ea338927000421575 | 62625000752d5672d6661e6072881167 | | 400 | tas_uid | Scenario Outline: Create a case, derivate and cancel. then try do pause or route @@ -66,6 +66,7 @@ Scenario Outline: Create a case, derivate and cancel. then try do pause or route And I request "cases" Then the response status code should be 200 And store "app_uid" in session array as variable "app_uid_" + #Send some variables And PUT this data: """ @@ -115,9 +116,22 @@ Scenario Outline: Create a case, derivate and cancel. then try do pause or route And I request "cases/app_uid/pause" with the key "app_uid" stored in session array as variable "app_uid_" Then the response status code should be 400 And the response status message should have the following text "" + + And PUT this data: + """ + { + + } + """ + + And that I want to delete a resource with the key "app_uid" stored in session array as variable "app_uid_" + And I request "cases" + Then the response status code should be 200 + And the content type is "application/json" + And the response charset is "UTF-8" + And the type is "object" Examples: | Description | case_number | pro_uid | tas_uid | error_message_route | error_message_pause | - | Create new case with process "Derivation rules - sequential" | 1 | 99209594750ec27ea338927000421575 | 68707275350ec281ada1c95068712556 | This case delegation is already closed | This case delegation is already closed | - \ No newline at end of file + | Create new case with process "Derivation rules - sequential" | 1 | 99209594750ec27ea338927000421575 | 68707275350ec281ada1c95068712556 | This case delegation is already closed | This case delegation is already closed | \ No newline at end of file diff --git a/features/backend/application_cases/case_note/basic_sequence_case_note.feature b/features/backend/application_cases/case_note/basic_sequence_case_note.feature index 4ca715b26..ad6d98e01 100644 --- a/features/backend/application_cases/case_note/basic_sequence_case_note.feature +++ b/features/backend/application_cases/case_note/basic_sequence_case_note.feature @@ -9,7 +9,6 @@ Background: Scenario: List of case notes for this case Given I request "cases/1185553665335d2e209f723099733152/notes" - the response time should at least be (\d+) milliseconds$/ Then the response status code should be 200 And the response charset is "UTF-8" And the type is "array" @@ -36,4 +35,11 @@ Scenario: Create a new case note for specified case And the content type is "application/json" And the type is "object" +Scenario: List of case notes for this case + Given I request "cases/1185553665335d2e209f723099733152/notes" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the type is "array" + + #case 125 \ No newline at end of file diff --git a/features/backend/application_cases/case_note/main_tests_case_note.feature b/features/backend/application_cases/case_note/main_tests_case_note.feature index 9487a72bc..8a86e9813 100644 --- a/features/backend/application_cases/case_note/main_tests_case_note.feature +++ b/features/backend/application_cases/case_note/main_tests_case_note.feature @@ -12,18 +12,46 @@ Scenario: List of case notes for this case Then the response status code should be 200 And the response charset is "UTF-8" And the type is "array" + And the "note_content" property in row 0 equals "tercer case note creado desde script" - -Scenario: Create a new case note for specified case - Given POST this data: - """ - { - "note_content": "tercer case note creado desde script", - "send_email": 1 - } - """ - And I request "case/1185553665335d2e209f723099733152/case" - Then the response status code should be 201 - And the response charset is "UTF-8" - And the content type is "application/json" - And the type is "object" \ No newline at end of file + +Scenario: Get a List of cases notes of a case with paged + Given I request "cases/1185553665335d2e209f723099733152/notes/paged" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the type is "array" + + +Scenario Outline: Create a new case note for specified case + Given POST this data: + """ + { + "note_content": "", + "send_email": + } + """ + And I request "cases/1185553665335d2e209f723099733152/note" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "object" + + + Examples: + + | test_description | note_content | send_email | + | Create case note with charater special | Test!@#$ %^&*£ | 1 | + | Create case note with 150 chacarters | Este es una prueba con varios caracteres 112334@#$Este es una prueba con varios caracteres 112334@#$Este es una prueba con varios caracteres 112334@#$ | 1 | + | Create case note with character without space | Estaesunapruebasinespaciosentrepalabraslamismadebeseraceptado | 1 | + | Create case note without send mail | Test sin envio de email | 0 | + | Create case normal with character normal | tercer case note creado desde script | 1 | + + + +Scenario: List of case notes for this case + Given I request "cases/1185553665335d2e209f723099733152/notes" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the type is "array" + And the "note_content" property in row 0 equals "tercer case note creado desde script" + And the "note_content" property in row 1 equals "Test sin envio de email" \ No newline at end of file diff --git a/features/backend/application_cases/case_note/negative_tests_case_note.feature b/features/backend/application_cases/case_note/negative_tests_case_note.feature index 9000c45e0..b8655d20a 100644 --- a/features/backend/application_cases/case_note/negative_tests_case_note.feature +++ b/features/backend/application_cases/case_note/negative_tests_case_note.feature @@ -20,8 +20,5 @@ Scenario: create a new case note for specified case (Negative Tests) Then the response status code should be 400 And the response status message should have the following text "You do not have permission to cases notes" - - - - + #case 124 \ No newline at end of file diff --git a/features/backend/application_cases/input_documents_case/basic_sequence_input_document_case.feature b/features/backend/application_cases/input_documents_case/basic_sequence_input_document_case.feature index d002887be..b48aedc6e 100644 --- a/features/backend/application_cases/input_documents_case/basic_sequence_input_document_case.feature +++ b/features/backend/application_cases/input_documents_case/basic_sequence_input_document_case.feature @@ -13,11 +13,11 @@ Scenario: Returns a list of the uploaded documents for a given case Then the response status code should be 200 And the response charset is "UTF-8" And the type is "array" - And the response has 5 records + And the response has 9 records Scenario: Returns an uploaded documents for a given case - Given I request "cases/170220159534214f642abb8058832933/input-document/6075490825331a1c5eebff9015468244" + Given I request "cases/170220159534214f642abb8058832933/input-document/925833635534215b9148a64026212674" Then the response status code should be 200 And the response charset is "UTF-8" And the type is "object" diff --git a/features/backend/application_cases/input_documents_case/main_tests_input_document_case.feature b/features/backend/application_cases/input_documents_case/main_tests_input_document_case.feature index f2638724a..c756a6549 100644 --- a/features/backend/application_cases/input_documents_case/main_tests_input_document_case.feature +++ b/features/backend/application_cases/input_documents_case/main_tests_input_document_case.feature @@ -40,19 +40,11 @@ Scenario Outline: Post metadata and then upload documents for a given case | 4 | /home/wendy/uploadfiles/test.txt | 170220159534214f642abb8058832933 | 68671480353319e5e1dee74089764900 | 19582733053319e304cfa76025663570 | comment 1 | Scenario Outline: Returns an uploaded documents for a given case - Given I request "cases//output-document/app_doc_uid" with the key "app_doc_uid" stored in session array as variable "app_doc_uid_" + Given I request "cases//input-document/app_doc_uid" with the key "app_doc_uid" stored in session array as variable "app_doc_uid_" Then the response status code should be 200 And the response charset is "UTF-8" And the type is "object" - And the "app_doc_uid" property equals "" - And the "app_doc_filename" property equals "" - And the "doc_uid" property equals "" - And the "app_doc_version" property equals "" - And the "app_doc_create_date" property equals "" - And the "app_doc_create_user" property equals "" - And the "app_doc_type" property equals "" - And the "app_doc_index" property equals "" - And the "app_doc_link" property equals "" + Examples: diff --git a/features/backend/application_cases/input_documents_case/negative_tests_input_document_case.feature b/features/backend/application_cases/input_documents_case/negative_tests_input_document_case.feature index 6bbdca397..b96d5db0d 100644 --- a/features/backend/application_cases/input_documents_case/negative_tests_input_document_case.feature +++ b/features/backend/application_cases/input_documents_case/negative_tests_input_document_case.feature @@ -9,7 +9,7 @@ Background: Scenario: Returns a list of the uploaded documents for a given case - Given I request "cases/170220159534214f642abb8058832000/input-documents" + Given I request "cases/170220159534214f642abb8058832900/input-documents" Then the response status code should be 404 Scenario Outline: Post metadata and then upload documents for a given case diff --git a/features/backend/application_cases/output_document_case/basic_sequence_output_document_case.feature b/features/backend/application_cases/output_document_case/basic_sequence_output_document_case.feature index eaf808238..136797aa4 100644 --- a/features/backend/application_cases/output_document_case/basic_sequence_output_document_case.feature +++ b/features/backend/application_cases/output_document_case/basic_sequence_output_document_case.feature @@ -13,14 +13,14 @@ Scenario: Returns a list of the generated documents for a given cases Then the response status code should be 200 And the response charset is "UTF-8" And the type is "array" - And the response has 6 records + And the response has 1 records Scenario: Returns an generated document for a given case - Given I request "cases/33125846153383cecdf64f1079330191/output-document/3000248055333006ab56a01005891659" + Given I request "cases/33125846153383cecdf64f1079330191/output-document/75468909953383d0bc42f96046736849" Then the response status code should be 200 And the response charset is "UTF-8" - And the type is "Object" + And the type is "object" Scenario: Generate or regenerates an output documents for a given case diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Calendar.php b/workflow/engine/src/ProcessMaker/BusinessModel/Calendar.php index 54886cb52..2df0651d4 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Calendar.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Calendar.php @@ -262,13 +262,19 @@ class Calendar public function create($arrayData) { try { + //Verify data + $process = new \ProcessMaker\BusinessModel\Process(); + $validator = new \ProcessMaker\BusinessModel\Validator(); + + $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData"); + $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData"); + + //Set data $arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER); unset($arrayData["CAL_UID"]); //Verify data - $process = new \ProcessMaker\BusinessModel\Process(); - $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true); $this->throwExceptionIfExistsName($arrayData["CAL_NAME"], $this->arrayFieldNameForException["calendarName"]); @@ -321,11 +327,7 @@ class Calendar $arrayDataAux = array(); $arrayDataAux["CALENDAR_UID"] = \G::generateUniqueID(); $arrayDataAux["CALENDAR_NAME"] = $arrayData["CAL_NAME"]; - - if (isset($arrayData["CAL_DESCRIPTION"])) { - $arrayDataAux["CALENDAR_DESCRIPTION"] = $arrayData["CAL_DESCRIPTION"]; - } - + $arrayDataAux["CALENDAR_DESCRIPTION"] = (isset($arrayData["CAL_DESCRIPTION"]))? $arrayData["CAL_DESCRIPTION"] : ""; $arrayDataAux["CALENDAR_WORK_DAYS"] = explode("|", $this->workDaysReplaceData(implode("|", $arrayData["CAL_WORK_DAYS"]))); $arrayDataAux["CALENDAR_STATUS"] = $arrayData["CAL_STATUS"]; @@ -361,11 +363,17 @@ class Calendar public function update($calendarUid, $arrayData) { try { + //Verify data + $process = new \ProcessMaker\BusinessModel\Process(); + $validator = new \ProcessMaker\BusinessModel\Validator(); + + $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData"); + $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData"); + + //Set data $arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER); //Verify data - $process = new \ProcessMaker\BusinessModel\Process(); - $this->throwExceptionIfNotExistsCalendar($calendarUid, $this->arrayFieldNameForException["calendarUid"]); $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index 468123114..0dd798e63 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -61,7 +61,9 @@ class Cases if ($start != 0) { $start--; } - if ((abs((int)$limit)) == 0) { + $limit = (int)$limit; + $limit = abs($limit); + if ($limit == 0) { G::LoadClass("configuration"); $conf = new \Configurations(); $generalConfCasesList = $conf->getConfiguration('ENVIRONMENT_SETTINGS', ''); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Validator.php b/workflow/engine/src/ProcessMaker/BusinessModel/Validator.php index d9de7775c..93be26c74 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Validator.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Validator.php @@ -9,7 +9,8 @@ namespace ProcessMaker\BusinessModel; * * @protected */ -class Validator{ +class Validator +{ /** * Validate dep_uid * @var string $dep_uid. Uid for Departament @@ -330,6 +331,47 @@ class Validator{ throw (new \Exception("The field '$nameField' is empty.")); } } + + /** + * Verify if data is array + * + * @param string $data Data + * @param string $dataNameForException Data name for the exception + * + * return void Throw exception if data is not array + */ + public function throwExceptionIfDataIsNotArray($data, $dataNameForException) + { + try { + if (!is_array($data)) { + $msg = str_replace(array("{0}"), array($dataNameForException), "The data \"{0}\" is not array"); + + throw (new \Exception($msg)); + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Verify if data is empty + * + * @param string $data Data + * @param string $dataNameForException Data name for the exception + * + * return void Throw exception if data is empty + */ + public function throwExceptionIfDataIsEmpty($data, $dataNameForException) + { + try { + if (empty($data)) { + $msg = str_replace(array("{0}"), array($dataNameForException), "The data \"{0}\" is empty"); + + throw (new \Exception($msg)); + } + } catch (\Exception $e) { + throw $e; + } + } } - diff --git a/workflow/engine/src/Tests/BusinessModel/CalendarTest.php b/workflow/engine/src/Tests/BusinessModel/CalendarTest.php index d43b8b8da..994158d2a 100644 --- a/workflow/engine/src/Tests/BusinessModel/CalendarTest.php +++ b/workflow/engine/src/Tests/BusinessModel/CalendarTest.php @@ -12,8 +12,8 @@ if (!class_exists("Propel")) { */ class CalendarTest extends \PHPUnit_Framework_TestCase { - private static $calendar; - private static $numCalendar = 2; + protected static $calendar; + protected static $numCalendar = 2; /** * Set class for test @@ -63,6 +63,22 @@ class CalendarTest extends \PHPUnit_Framework_TestCase $arrayRecord[] = $arrayCalendar; } + //Create - Japanese characters + $arrayData = array( + "CAL_NAME" => "私の名前(PHPUnitの)", + "CAL_WORK_DAYS" => array("MON", "TUE", "WED", "THU", "FRI"), + "CAL_STATUS" => "ACTIVE" + ); + + $arrayCalendar = self::$calendar->create($arrayData); + + $this->assertTrue(is_array($arrayCalendar)); + $this->assertNotEmpty($arrayCalendar); + + $this->assertTrue(isset($arrayCalendar["CAL_UID"])); + + $arrayRecord[] = $arrayCalendar; + //Return return $arrayRecord; } @@ -70,10 +86,10 @@ class CalendarTest extends \PHPUnit_Framework_TestCase /** * Test update calendars * + * @covers \ProcessMaker\BusinessModel\Calendar::update + * * @depends testCreate * @param array $arrayRecord Data of the calendars - * - * @covers \ProcessMaker\BusinessModel\Calendar::update */ public function testUpdate($arrayRecord) { @@ -92,10 +108,10 @@ class CalendarTest extends \PHPUnit_Framework_TestCase /** * Test get calendars * + * @covers \ProcessMaker\BusinessModel\Calendar::getCalendars + * * @depends testCreate * @param array $arrayRecord Data of the calendars - * - * @covers \ProcessMaker\BusinessModel\Calendar::getCalendars */ public function testGetCalendars($arrayRecord) { @@ -121,13 +137,14 @@ class CalendarTest extends \PHPUnit_Framework_TestCase /** * Test get calendar * + * @covers \ProcessMaker\BusinessModel\Calendar::getCalendar + * * @depends testCreate * @param array $arrayRecord Data of the calendars - * - * @covers \ProcessMaker\BusinessModel\Calendar::getCalendar */ public function testGetCalendar($arrayRecord) { + //Get $arrayCalendar = self::$calendar->getCalendar($arrayRecord[0]["CAL_UID"]); $this->assertTrue(is_array($arrayCalendar)); @@ -137,15 +154,249 @@ class CalendarTest extends \PHPUnit_Framework_TestCase $this->assertEquals($arrayCalendar["CAL_NAME"], $arrayRecord[0]["CAL_NAME"]); $this->assertEquals($arrayCalendar["CAL_DESCRIPTION"], $arrayRecord[0]["CAL_DESCRIPTION"]); $this->assertEquals($arrayCalendar["CAL_STATUS"], $arrayRecord[0]["CAL_STATUS"]); + + //Get - Japanese characters + $arrayCalendar = self::$calendar->getCalendar($arrayRecord[self::$numCalendar]["CAL_UID"]); + + $this->assertTrue(is_array($arrayCalendar)); + $this->assertNotEmpty($arrayCalendar); + + $this->assertEquals($arrayCalendar["CAL_NAME"], "私の名前(PHPUnitの)"); + $this->assertEquals($arrayCalendar["CAL_WORK_DAYS"], array("MON", "TUE", "WED", "THU", "FRI")); + $this->assertEquals($arrayCalendar["CAL_STATUS"], "ACTIVE"); + } + + /** + * Test exception when data not is array + * + * @covers \ProcessMaker\BusinessModel\Calendar::create + * + * @expectedException Exception + * @expectedExceptionMessage The data "$arrayData" is not array + */ + public function testCreateExceptionNoIsArrayData() + { + $arrayData = 0; + + $arrayCalendar = self::$calendar->create($arrayData); + } + + /** + * Test exception for empty data + * + * @covers \ProcessMaker\BusinessModel\Calendar::create + * + * @expectedException Exception + * @expectedExceptionMessage The data "$arrayData" is empty + */ + public function testCreateExceptionEmptyData() + { + $arrayData = array(); + + $arrayCalendar = self::$calendar->create($arrayData); + } + + /** + * Test exception for required data (CAL_NAME) + * + * @covers \ProcessMaker\BusinessModel\Calendar::create + * + * @expectedException Exception + * @expectedExceptionMessage The "CAL_NAME" attribute is not defined + */ + public function testCreateExceptionRequiredDataCalName() + { + $arrayData = array( + //"CAL_NAME" => "PHPUnit Calendar", + "CAL_DESCRIPTION" => "Description", + "CAL_WORK_DAYS" => array("MON", "TUE", "WED", "THU", "FRI"), + "CAL_STATUS" => "ACTIVE" + ); + + $arrayCalendar = self::$calendar->create($arrayData); + } + + /** + * Test exception for invalid data (CAL_NAME) + * + * @covers \ProcessMaker\BusinessModel\Calendar::create + * + * @expectedException Exception + * @expectedExceptionMessage The "CAL_NAME" attribute is empty + */ + public function testCreateExceptionInvalidDataCalName() + { + $arrayData = array( + "CAL_NAME" => "", + "CAL_DESCRIPTION" => "Description", + "CAL_WORK_DAYS" => array("MON", "TUE", "WED", "THU", "FRI"), + "CAL_STATUS" => "ACTIVE" + ); + + $arrayCalendar = self::$calendar->create($arrayData); + } + + /** + * Test exception for invalid data (CAL_WORK_DAYS) + * + * @covers \ProcessMaker\BusinessModel\Calendar::create + * + * @expectedException Exception + * @expectedExceptionMessage Invalid value specified for "CAL_WORK_DAYS" + */ + public function testCreateExceptionInvalidDataCalWorkDays() + { + $arrayData = array( + "CAL_NAME" => "PHPUnit Calendar", + "CAL_DESCRIPTION" => "Description", + "CAL_WORK_DAYS" => array("MONDAY", "TUE", "WED", "THU", "FRI"), + "CAL_STATUS" => "ACTIVE" + ); + + $arrayCalendar = self::$calendar->create($arrayData); + } + + /** + * Test exception for calendar name existing + * + * @covers \ProcessMaker\BusinessModel\Calendar::create + * + * @expectedException Exception + * @expectedExceptionMessage The calendar name with CAL_NAME: "PHPUnit Calendar0" already exists + */ + public function testCreateExceptionExistsCalName() + { + $arrayData = array( + "CAL_NAME" => "PHPUnit Calendar0", + "CAL_DESCRIPTION" => "Description", + "CAL_WORK_DAYS" => array("MON", "TUE", "WED", "THU", "FRI"), + "CAL_STATUS" => "ACTIVE" + ); + + $arrayCalendar = self::$calendar->create($arrayData); + } + + /** + * Test exception when data not is array + * + * @covers \ProcessMaker\BusinessModel\Calendar::update + * + * @expectedException Exception + * @expectedExceptionMessage The data "$arrayData" is not array + */ + public function testUpdateExceptionNoIsArrayData() + { + $arrayData = 0; + + $arrayCalendar = self::$calendar->update("", $arrayData); + } + + /** + * Test exception for empty data + * + * @covers \ProcessMaker\BusinessModel\Calendar::update + * + * @expectedException Exception + * @expectedExceptionMessage The data "$arrayData" is empty + */ + public function testUpdateExceptionEmptyData() + { + $arrayData = array(); + + $arrayCalendar = self::$calendar->update("", $arrayData); + } + + /** + * Test exception for invalid calendar UID + * + * @covers \ProcessMaker\BusinessModel\Calendar::update + * + * @expectedException Exception + * @expectedExceptionMessage The calendar with CAL_UID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx does not exists + */ + public function testUpdateExceptionInvalidCalUid() + { + $arrayData = array( + "CAL_NAME" => "PHPUnit Calendar", + "CAL_DESCRIPTION" => "Description", + "CAL_WORK_DAYS" => array("MON", "TUE", "WED", "THU", "FRI"), + "CAL_STATUS" => "ACTIVE" + ); + + $arrayCalendar = self::$calendar->update("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", $arrayData); + } + + /** + * Test exception for invalid data (CAL_NAME) + * + * @covers \ProcessMaker\BusinessModel\Calendar::update + * + * @depends testCreate + * @param array $arrayRecord Data of the calendars + * + * @expectedException Exception + * @expectedExceptionMessage The "CAL_NAME" attribute is empty + */ + public function testUpdateExceptionInvalidDataCalName($arrayRecord) + { + $arrayData = array( + "CAL_NAME" => "", + "CAL_DESCRIPTION" => "Description", + "CAL_WORK_DAYS" => array("MON", "TUE", "WED", "THU", "FRI"), + "CAL_STATUS" => "ACTIVE" + ); + + $arrayCalendar = self::$calendar->update($arrayRecord[0]["CAL_UID"], $arrayData); + } + + /** + * Test exception for invalid data (CAL_WORK_DAYS) + * + * @covers \ProcessMaker\BusinessModel\Calendar::update + * + * @depends testCreate + * @param array $arrayRecord Data of the calendars + * + * @expectedException Exception + * @expectedExceptionMessage Invalid value specified for "CAL_WORK_DAYS" + */ + public function testUpdateExceptionInvalidDataCalWorkDays($arrayRecord) + { + $arrayData = array( + "CAL_NAME" => "PHPUnit Calendar", + "CAL_DESCRIPTION" => "Description", + "CAL_WORK_DAYS" => array("MONDAY", "TUE", "WED", "THU", "FRI"), + "CAL_STATUS" => "ACTIVE" + ); + + $arrayCalendar = self::$calendar->update($arrayRecord[0]["CAL_UID"], $arrayData); + } + + /** + * Test exception for calendar name existing + * + * @covers \ProcessMaker\BusinessModel\Calendar::update + * + * @depends testCreate + * @param array $arrayRecord Data of the calendars + * + * @expectedException Exception + * @expectedExceptionMessage The calendar name with CAL_NAME: "PHPUnit Calendar1" already exists + */ + public function testUpdateExceptionExistsCalName($arrayRecord) + { + $arrayData = $arrayRecord[1]; + + $arrayCalendar = self::$calendar->update($arrayRecord[0]["CAL_UID"], $arrayData); } /** * Test delete calendars * + * @covers \ProcessMaker\BusinessModel\Calendar::delete + * * @depends testCreate * @param array $arrayRecord Data of the calendars - * - * @covers \ProcessMaker\BusinessModel\Calendar::delete */ public function testDelete($arrayRecord) {