diff --git a/database/factories/BpmnDiagramFactory.php b/database/factories/BpmnDiagramFactory.php new file mode 100644 index 000000000..817fe6d3c --- /dev/null +++ b/database/factories/BpmnDiagramFactory.php @@ -0,0 +1,14 @@ +define(\ProcessMaker\Model\BpmnDiagram::class, function(Faker $faker) { + return [ + 'DIA_UID' => $faker->regexify("/[a-zA-Z]{32}/"), + 'PRJ_UID' => function() { + return factory(\ProcessMaker\Model\BpmnProject::class)->create()->PRJ_UID; + }, + 'DIA_NAME' => $faker->name, + 'DIA_IS_CLOSABLE' => 0, + ]; +}); diff --git a/database/factories/BpmnEventFactory.php b/database/factories/BpmnEventFactory.php new file mode 100644 index 000000000..5f411972d --- /dev/null +++ b/database/factories/BpmnEventFactory.php @@ -0,0 +1,32 @@ +define(\ProcessMaker\Model\BpmnEvent::class, function(Faker $faker) { + $bpmnProcess = factory(\ProcessMaker\Model\BpmnProcess::class)->create(); + return [ + 'EVN_UID' => $faker->regexify("/[a-zA-Z]{32}/"), + 'PRJ_UID' => $bpmnProcess->PRJ_UID, + 'PRO_UID' => $bpmnProcess->PRO_UID, + 'EVN_NAME' => $faker->name, + 'EVN_TYPE' => 'START', + 'EVN_MARKER' => 'EMPTY', + 'EVN_IS_INTERRUPTING' => 1, + 'EVN_ATTACHED_TO' => '', + 'EVN_CANCEL_ACTIVITY' => 0, + 'EVN_ACTIVITY_REF' => null, + 'EVN_WAIT_FOR_COMPLETION' => 0, + 'EVN_ERROR_NAME' => null, + 'EVN_ERROR_CODE' => null, + 'EVN_ESCALATION_NAME' => null, + 'EVN_ESCALATION_CODE' => null, + 'EVN_CONDITION' => null, + 'EVN_MESSAGE' => '', + 'EVN_OPERATION_NAME' => null, + 'EVN_OPERATION_IMPLEMENTATION_REF' => null, + 'EVN_TIME_DATE' => null, + 'EVN_TIME_CYCLE' => null, + 'EVN_TIME_DURATION' => null, + 'EVN_BEHAVIOR' => 'THROW', + ]; +}); diff --git a/database/factories/BpmnProcessFactory.php b/database/factories/BpmnProcessFactory.php new file mode 100644 index 000000000..f83d90a7b --- /dev/null +++ b/database/factories/BpmnProcessFactory.php @@ -0,0 +1,20 @@ +define(\ProcessMaker\Model\BpmnProcess::class, function(Faker $faker) { + return [ + 'PRO_UID' => $faker->regexify("/[a-zA-Z]{32}/"), + 'PRJ_UID' => function() { + return factory(\ProcessMaker\Model\BpmnProject::class)->create()->PRJ_UID; + }, + 'DIA_UID' => function() { + return factory(\ProcessMaker\Model\BpmnDiagram::class)->create()->DIA_UID; + }, + 'PRO_NAME' => $faker->title, + 'PRO_TYPE' => 'NONE', + 'PRO_IS_EXECUTABLE' => 0, + 'PRO_IS_CLOSED' => 0, + 'PRO_IS_SUBPROCESS' => 0, + ]; +}); diff --git a/database/factories/EmailEventFactory.php b/database/factories/EmailEventFactory.php new file mode 100644 index 000000000..f4839f65b --- /dev/null +++ b/database/factories/EmailEventFactory.php @@ -0,0 +1,21 @@ +define(\ProcessMaker\Model\EmailEvent::class, function(Faker $faker) { + $bpmnEvent = factory(\ProcessMaker\Model\BpmnEvent::class)->create(); + return [ + 'EMAIL_EVENT_UID' => $faker->regexify("/[a-zA-Z]{32}/"), + 'PRJ_UID' => $bpmnEvent->PRJ_UID, + 'EVN_UID' => $bpmnEvent->EVN_UID, + 'EMAIL_EVENT_FROM' => $faker->email, + 'EMAIL_EVENT_TO' => $faker->email, + 'EMAIL_EVENT_SUBJECT' => $faker->title, + 'PRF_UID' => function() { + return factory(\ProcessMaker\Model\ProcessFiles::class)->create()->PRF_UID; + }, + 'EMAIL_SERVER_UID' => function() { + return factory(\ProcessMaker\Model\EmailServerModel::class)->create()->MESS_UID; + }, + ]; +}); diff --git a/database/factories/ProcessFactory.php b/database/factories/ProcessFactory.php index 90d64621b..4cd3e026c 100644 --- a/database/factories/ProcessFactory.php +++ b/database/factories/ProcessFactory.php @@ -8,7 +8,7 @@ $factory->define(\ProcessMaker\Model\Process::class, function(Faker $faker) { // Return with default values return [ 'PRO_UID' => G::generateUniqueID(), - 'PRO_ID' => $faker->unique()->numberBetween(1, 200000), + 'PRO_ID' => $faker->unique()->numberBetween(1, 1000000), 'PRO_TITLE' => $faker->sentence(3), 'PRO_DESCRIPTION' => $faker->paragraph(3), 'PRO_CREATE_USER' => '00000000000000000000000000000001', @@ -28,7 +28,7 @@ $factory->state(\ProcessMaker\Model\Process::class, 'foreign_keys', function (Fa $user = factory(\ProcessMaker\Model\User::class)->create(); return [ 'PRO_UID' => G::generateUniqueID(), - 'PRO_ID' => $faker->unique()->numberBetween(1, 200000), + 'PRO_ID' => $faker->unique()->numberBetween(1, 1000000), 'PRO_TITLE' => $faker->sentence(3), 'PRO_DESCRIPTION' => $faker->paragraph(3), 'PRO_CREATE_USER' => $user->USR_UID, @@ -49,7 +49,7 @@ $factory->state(\ProcessMaker\Model\Process::class, 'flow', function (Faker $fak $user = factory(\ProcessMaker\Model\User::class)->create(); $process = [ 'PRO_UID' => G::generateUniqueID(), - 'PRO_ID' => $faker->unique()->numberBetween(1, 200000), + 'PRO_ID' => $faker->unique()->numberBetween(1, 1000000), 'PRO_TITLE' => $faker->sentence(3), 'PRO_DESCRIPTION' => $faker->paragraph(3), 'PRO_CREATE_USER' => $user->USR_UID, diff --git a/tests/unit/workflow/engine/classes/WsBaseTest.php b/tests/unit/workflow/engine/classes/WsBaseTest.php index ffb16875b..a7f541096 100755 --- a/tests/unit/workflow/engine/classes/WsBaseTest.php +++ b/tests/unit/workflow/engine/classes/WsBaseTest.php @@ -2,6 +2,7 @@ use App\Jobs\EmailEvent; use Faker\Factory; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Queue; use ProcessMaker\Model\Application; use ProcessMaker\Model\AppThread; @@ -13,8 +14,15 @@ use ProcessMaker\Model\User; use ProcessMaker\Util\WsMessageResponse; use Tests\TestCase; +/** + * Class WsBase + * + * @coversDefaultClass WsBase + */ class WsBaseTest extends TestCase { + use DatabaseTransactions; + /** * Constructor of the class. * @@ -207,9 +215,10 @@ class WsBaseTest extends TestCase /** * This should send an email of types elements to the work queue jobs. * Queue-fake has been used, see more at: https://laravel.com/docs/5.7/mocking#queue-fake + * * @test * @dataProvider messageTypesWithQueue - * @covers \WsBase::sendMessage + * @covers WsBase::sendMessage() */ public function it_should_send_an_sendMessage_with_queue_jobs($messageType) { @@ -246,9 +255,10 @@ class WsBaseTest extends TestCase /** * This should send an email of types elements without work queue jobs. * Queue-fake has been used, see more at: https://laravel.com/docs/5.7/mocking#queue-fake + * * @test * @dataProvider messageTypesWithoutQueue - * @covers \WsBase::sendMessage + * @covers WsBase::sendMessage() */ public function it_should_execute_an_sendMessage_without_queue_jobs($messageTypes) { @@ -284,9 +294,10 @@ class WsBaseTest extends TestCase /** * It should send an sendMessage with queue jobs and empty config parameter. + * * @test * @dataProvider messageTypesWithQueue - * @covers \WsBase::sendMessage + * @covers WsBase::sendMessage() */ public function it_should_send_an_sendMessage_with_queue_jobs_and_empty_config_parameter($messageTypes) { @@ -322,9 +333,10 @@ class WsBaseTest extends TestCase /** * It should send an sendMessage without queue jobs and empty config parameter. + * * @test * @dataProvider messageTypesWithoutQueue - * @covers \WsBase::sendMessage + * @covers WsBase::sendMessage() */ public function it_should_send_an_sendMessage_without_queue_jobs_and_empty_config_parameter($messageTypes) { @@ -360,9 +372,10 @@ class WsBaseTest extends TestCase /** * It should send an sendMessage with queue jobs and config parameter like id. + * * @test * @dataProvider messageTypesWithQueue - * @covers \WsBase::sendMessage + * @covers WsBase::sendMessage() */ public function it_should_send_an_sendMessage_with_queue_jobs_and_config_parameter_like_id($messageTypes) { @@ -398,9 +411,10 @@ class WsBaseTest extends TestCase /** * It should send an sendMessage without queue jobs and config parameter like id. + * * @test * @dataProvider messageTypesWithoutQueue - * @covers \WsBase::sendMessage + * @covers WsBase::sendMessage() */ public function it_should_send_an_sendMessage_without_queue_jobs_and_config_parameter_like_id($messageTypes) { @@ -436,9 +450,10 @@ class WsBaseTest extends TestCase /** * It should send an sendMessage without queue jobs and gmail parameter like one. + * * @test * @dataProvider messageTypesWithoutQueue - * @covers \WsBase::sendMessage + * @covers WsBase::sendMessage() */ public function it_should_send_an_sendMessage_without_queue_jobs_and_gmail_parameter_like_one($messageTypes) { @@ -476,7 +491,7 @@ class WsBaseTest extends TestCase * Test that the casesList method returns the case title value * * @test - * @covers \WsBase::caseList + * @covers WsBase::caseList() */ public function it_should_test_that_the_cases_list_method_returns_the_case_title() { @@ -550,7 +565,7 @@ class WsBaseTest extends TestCase * Test the casesList method when the result is empty * * @test - * @covers \WsBase::caseList + * @covers WsBase::caseList() */ public function it_should_test_the_cases_list_method_when_there_are_no_results() { @@ -617,7 +632,7 @@ class WsBaseTest extends TestCase /** * This test ensures obtaining the email configuration with all fields. * @test - * @covers \WsBase::sendMessage() + * @covers WsBase::sendMessage() */ public function it_should_get_email_configuration() { @@ -645,4 +660,287 @@ class WsBaseTest extends TestCase //assertions $this->assertInstanceOf(WsMessageResponse::class, $result); } + + /** + * Review if the flag is true when the cancel case is related to the same case in SESSION + * + * @covers WsBase::cancelCase() + * @test + */ + public function it_should_set_flag_when_is_same_case() + { + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_STATUS' => 'TO_DO' + ]); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $_SESSION["APPLICATION"] = $delegation->APP_UID; + $ws = new WsBase(); + $response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, $delegation->APP_UID); + $this->assertEquals($ws->getFlagSameCase(), true); + $this->assertNotEmpty($response); + } + + /** + * Review the required field caseUid + * + * @covers WsBase::cancelCase() + * @test + */ + public function it_should_validate_required_app_uid() + { + $delegation = factory(Delegation::class)->states('foreign_keys')->create(); + $ws = new WsBase(); + $response = (object)$ws->cancelCase('', $delegation->DE_INDEX, $delegation->URS_UID); + $this->assertEquals($response->status_code, 100); + $this->assertEquals($response->message, G::LoadTranslation("ID_REQUIRED_FIELD") . ' caseUid'); + } + + /** + * Review the required field status = TO_DO + * + * @covers WsBase::cancelCase() + * @test + */ + public function it_should_validate_required_status_todo() + { + // Create a case in DRAFT status + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 1, + 'APP_STATUS' => 'DRAFT' + ]); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $ws = new WsBase(); + $response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DE_INDEX, $delegation->URS_UID); + $this->assertEquals($response->status_code, 100); + $this->assertEquals($response->message, G::LoadTranslation("ID_CASE_IN_STATUS") . ' DRAFT'); + + // Create a case in COMPLETED status + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 3, + 'APP_STATUS' => 'COMPLETED' + ]); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $ws = new WsBase(); + $response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DE_INDEX, $delegation->URS_UID); + $this->assertEquals($response->status_code, 100); + $this->assertEquals($response->message, G::LoadTranslation("ID_CASE_IN_STATUS") . ' COMPLETED'); + + // Create a case in CANCELLED status + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 4, + 'APP_STATUS' => 'CANCELLED' + ]); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $ws = new WsBase(); + $response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DE_INDEX, $delegation->URS_UID); + $this->assertEquals($response->status_code, 100); + $this->assertEquals($response->message, G::LoadTranslation("ID_CASE_IN_STATUS") . ' CANCELLED'); + } + + /** + * Review the required field delIndex + * + * @covers WsBase::cancelCase() + * @test + */ + public function it_should_validate_required_del_index() + { + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_STATUS' => 'TO_DO' + ]); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $ws = new WsBase(); + $response = (object)$ws->cancelCase($delegation->APP_UID, '', $delegation->USR_UID); + $this->assertEquals($response->status_code, 100); + $this->assertEquals($response->message, G::LoadTranslation("ID_REQUIRED_FIELD") . ' delIndex'); + } + + /** + * Review the required field open thread + * + * @covers WsBase::cancelCase() + * @test + */ + public function it_should_validate_required_open_thread() + { + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_STATUS' => 'TO_DO' + ]); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + 'DEL_THREAD_STATUS' => 'CLOSED' + ]); + $ws = new WsBase(); + $response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, ''); + $this->assertEquals($response->status_code, 100); + $this->assertEquals($response->message, G::LoadTranslation("ID_CASE_DELEGATION_ALREADY_CLOSED")); + } + + /** + * Review the required field userUid + * + * @covers WsBase::cancelCase() + * @test + */ + public function it_should_validate_required_usr_uid() + { + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_STATUS' => 'TO_DO' + ]); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $ws = new WsBase(); + $response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, ''); + $this->assertEquals($response->status_code, 100); + $this->assertEquals($response->message, G::LoadTranslation("ID_REQUIRED_FIELD") . ' userUid'); + } + + /** + * Review cancel case with parallel threads + * + * @covers WsBase::cancelCase() + * @test + */ + public function it_should_validate_only_one_thread_opened() + { + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_STATUS' => 'TO_DO' + ]); + factory(AppThread::class)->create([ + 'APP_UID' => $application->APP_UID, + 'APP_THREAD_INDEX' => 1, + 'APP_THREAD_PARENT' => 1, + 'APP_THREAD_STATUS' => 'OPEN', + 'DEL_INDEX' => 1 + ]); + factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + 'DEL_THREAD_STATUS' => 'OPEN' + ]); + factory(AppThread::class)->create([ + 'APP_UID' => $application->APP_UID, + 'APP_THREAD_INDEX' => 2, + 'APP_THREAD_PARENT' => 1, + 'APP_THREAD_STATUS' => 'OPEN', + 'DEL_INDEX' => 2 + ]); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'DEL_INDEX' => 2, + ]); + + $ws = new WsBase(); + $response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, $delegation->USR_UID); + $this->assertEquals($response->status_code, 100); + $this->assertEquals($response->message, G::LoadTranslation("ID_CASE_CANCELLED_PARALLEL")); + } + + /** + * Review the cancel case with one thread open + * + * @covers WsBase::cancelCase() + * @test + */ + public function it_should_cancel_case() + { + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_STATUS' => 'TO_DO' + ]); + factory(AppThread::class)->create([ + 'APP_UID' => $application->APP_UID, + 'APP_THREAD_INDEX' => 1, + 'APP_THREAD_PARENT' => 1, + 'APP_THREAD_STATUS' => 'OPEN', + 'DEL_INDEX' => 2 + ]); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'DEL_INDEX' => 2, + ]); + + $ws = new WsBase(); + // todo: the action Case::cancelCase() use Propel queries + $response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, $delegation->USR_UID); + $this->assertNotEmpty($response); + $this->markTestIncomplete( + 'This test was not fully implemented.' + ); + } + + /** + * Review the cancel case with parallel threads + * + * @covers WsBase::cancelCase() + * @test + */ + public function it_should_cancel_case_parallel() + { + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_STATUS' => 'TO_DO' + ]); + factory(AppThread::class)->create([ + 'APP_UID' => $application->APP_UID, + 'APP_THREAD_INDEX' => 1, + 'APP_THREAD_PARENT' => 1, + 'APP_THREAD_STATUS' => 'OPEN', + 'DEL_INDEX' => 1 + ]); + factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + 'DEL_THREAD_STATUS' => 'OPEN' + ]); + factory(AppThread::class)->create([ + 'APP_UID' => $application->APP_UID, + 'APP_THREAD_INDEX' => 2, + 'APP_THREAD_PARENT' => 1, + 'APP_THREAD_STATUS' => 'OPEN', + 'DEL_INDEX' => 2 + ]); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'DEL_INDEX' => 2, + ]); + + $ws = new WsBase(); + // todo: the action Case::cancelCase() use Propel queries + $response = (object)$ws->cancelCase($delegation->APP_UID, null, null); + $this->assertNotEmpty($response); + // Stop here and mark this test as incomplete. + $this->markTestIncomplete( + 'This test was not fully implemented.' + ); + } } diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/EmailServerTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/EmailServerTest.php index f41d49188..37da4f50b 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/EmailServerTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/EmailServerTest.php @@ -250,4 +250,101 @@ class EmailServerTest extends TestCase $this->expectException(Exception::class); $actual = $this->emailServer->getEmailServer($emailServerUid); } + + /** + * It tests the sendTestMail method with a successful result + * + * @covers \ProcessMaker\BusinessModel\EmailServer::sendTestMail() + * @test + */ + public function it_should_test_the_send_test_mail_method() + { + // The data that will be sent to the method + $data = [ + "FROM_EMAIL" => "admin@processmaker.com", + "FROM_NAME" => "Administrator", + "MESS_ENGINE" => "MAIL", + "MESS_SERVER" => "localhost", + "MESS_PORT" => 25, + "MESS_ACCOUNT" => "admin@processmaker.com", + "MESS_PASSWORD" => "", + "TO" => "admin@processmaker.com", + "MESS_RAUTH" => true + ]; + + // Create the EmailServer object + $emailServer = new EmailServer(); + // Call the sendTestMail method + $result = $emailServer->sendTestMail($data); + + // Assert the status is true + $this->assertTrue($result['status']); + // Assert the success is true + $this->assertTrue($result['success']); + // Assert the message of the result + $this->assertEquals('**ID_MAIL_TEST_SUCCESS**', $result['msg']); + } + + /** + * It tests the sendTestMail method with a failed result + * + * @covers \ProcessMaker\BusinessModel\EmailServer::sendTestMail() + * @test + */ + public function it_should_test_the_send_test_mail_method_failure() + { + // The data that will be sent to the method + $data = [ + "FROM_EMAIL" => "admin@processmaker.com", + "FROM_NAME" => "Administrator", + "MESS_ENGINE" => "PHPMAILER", + "MESS_SERVER" => "smtp.gmail.com", + "MESS_PORT" => 587, + "MESS_ACCOUNT" => "admin@processmaker.com", + "MESS_PASSWORD" => "", + "TO" => "admin@processmaker.com", + "MESS_RAUTH" => false, + ]; + + // Create the EmailServer object + $emailServer = new EmailServer(); + // Call the sendTestMail method + $result = $emailServer->sendTestMail($data); + + // Assert the status is false + $this->assertFalse($result['status']); + // Assert the status is false + $this->assertFalse($result['success']); + // Assert the message of the result is empty + $this->assertEmpty($result['msg']); + } + + /** + * It tests the sendTestMail method with an exception + * + * @covers \ProcessMaker\BusinessModel\EmailServer::sendTestMail() + * @test + */ + public function it_should_test_the_send_test_mail_method_exception() + { + // The data that will be sent to the method + $data = []; + + // Create the EmailServer object + $emailServer = new EmailServer(); + + // This expects an exception message + $this->expectExceptionMessage("Undefined index: MESS_ENGINE"); + + // Call the sendTestMail method + $emailServer->sendTestMail($data); + } + + /** + * Call the tearDown method + */ + public function tearDown() + { + parent::tearDown(); // TODO: Change the autogenerated stub + } } diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/FilesManagerTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/FilesManagerTest.php new file mode 100644 index 000000000..650e795d2 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/FilesManagerTest.php @@ -0,0 +1,208 @@ +faker = Factory::create(); + $this->directories = []; + } + + /** + * Tear down method. + */ + public function tearDown() + { + parent::tearDown(); + $this->directories = array_reverse($this->directories); + foreach ($this->directories as $value) { + rmdir($value); + } + } + + /** + * This test verifies if a file is missing. + * @test + * @covers \ProcessMaker\BusinessModel\FilesManager::deleteProcessFilesManager() + */ + public function it_should_deleted_public_files_when_not_exist() + { + $proUid = G::generateUniqueID(); + $prfUid = G::generateUniqueID(); + $filesManager = new FilesManager(); + + $this->expectException(Exception::class); + $filesManager->deleteProcessFilesManager($proUid, $prfUid); + } + + /** + * This represents the windows and linux separators. + */ + public function directorySeparator() + { + return [ + ["linux", "/"], + ["windows", "\\"] + ]; + } + + /** + * This test verifies the deletion of a template. + * @test + * @covers \ProcessMaker\BusinessModel\FilesManager::deleteProcessFilesManager() + * @dataProvider directorySeparator + */ + public function it_should_deleted_a_template_file($type, $separator) + { + $user = factory(UserModel::class)->create([ + 'USR_UID' => G::generateUniqueID() + ]); + + $process = factory(ProcessModel::class)->create([ + 'PRO_UID' => G::generateUniqueID() + ]); + + //create a template file + $directory = PATH_DATA_SITE; + if (!is_dir($directory)) { + mkdir($directory); + $this->directories[] = $directory; + } + $directory = PATH_DATA_PUBLIC; + if (!is_dir($directory)) { + mkdir($directory); + $this->directories[] = $directory; + } + $directory = PATH_DATA_PUBLIC . $process->PRO_UID; + if (!is_dir($directory)) { + mkdir($directory); + $this->directories[] = $directory; + } + $fileName = "template1.html"; + $path = $directory . "/" . $fileName; + file_put_contents($path, $this->faker->randomHtml()); + + $processFiles = factory(ProcessFilesModel::class)->create([ + 'PRF_UID' => G::generateUniqueID(), + 'PRO_UID' => $process->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PRF_PATH' => $separator . $fileName + ]); + + $filesManager = new FilesManager(); + $filesManager->deleteProcessFilesManager($process->PRO_UID, $processFiles->PRF_UID); + + //assert empty registry + $expectedEmptyObject = ProcessFilesModel::where('PRF_UID', '=', $processFiles->PRF_UID)->first(); + $this->assertTrue(empty($expectedEmptyObject)); + + //assert empty file + $this->assertTrue(!file_exists($path)); + } + + /** + * This test verifies the deletion of a public file. + * @test + * @covers \ProcessMaker\BusinessModel\FilesManager::deleteProcessFilesManager() + * @dataProvider directorySeparator + */ + public function it_should_deleted_a_public_file($type, $separator) + { + $user = factory(UserModel::class)->create([ + 'USR_UID' => G::generateUniqueID() + ]); + + $process = factory(ProcessModel::class)->create([ + 'PRO_UID' => G::generateUniqueID() + ]); + + //create a temporal file + $directory = PATH_DATA_SITE; + if (!is_dir($directory)) { + mkdir($directory); + $this->directories[] = $directory; + } + $directory = PATH_DATA_MAILTEMPLATES; + if (!is_dir($directory)) { + mkdir($directory); + $this->directories[] = $directory; + } + $directory = PATH_DATA_MAILTEMPLATES . $process->PRO_UID; + if (!is_dir($directory)) { + mkdir($directory); + $this->directories[] = $directory; + } + $fileName = "temporal.html"; + $path = $directory . "/" . $fileName; + file_put_contents($path, $this->faker->randomHtml()); + + $processFiles = factory(ProcessFilesModel::class)->create([ + 'PRF_UID' => G::generateUniqueID(), + 'PRO_UID' => $process->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PRF_PATH' => $separator . $fileName + ]); + + $filesManager = new FilesManager(); + $filesManager->deleteProcessFilesManager($process->PRO_UID, $processFiles->PRF_UID); + + //assert empty registry + $expectedEmptyObject = ProcessFilesModel::where('PRF_UID', '=', $processFiles->PRF_UID)->first(); + $this->assertTrue(empty($expectedEmptyObject)); + + //assert empty file + $this->assertTrue(!file_exists($path)); + } + + /** + * This test verifies the removal of a template that is being used by an + * intermediate email event. + * @test + * @covers \ProcessMaker\BusinessModel\FilesManager::deleteProcessFilesManager() + */ + public function it_should_deleted_public_files_with_event_relation() + { + $user = factory(UserModel::class)->create([ + 'USR_UID' => G::generateUniqueID() + ]); + + $process = factory(ProcessModel::class)->create([ + 'PRO_UID' => G::generateUniqueID() + ]); + + $processFiles = factory(ProcessFilesModel::class)->create([ + 'PRF_UID' => G::generateUniqueID(), + 'PRO_UID' => $process->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PRF_PATH' => '/' + ]); + + $emailEvent = factory(EmailEventModel::class)->create([ + 'PRF_UID' => $processFiles->PRF_UID + ]); + + $filesManager = new FilesManager(); + + $this->expectException(Exception::class); + $filesManager->deleteProcessFilesManager($process->PRO_UID, $processFiles->PRF_UID); + } +} diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 27d0de8a9..ea443ec0d 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -928,70 +928,6 @@ class DelegationTest extends TestCase $this->assertEquals(25, $result); } - /** - * This checks the counters is working properly in self-service and self-service value based - * - * @covers \ProcessMaker\Model\Delegation::countSelfService() - * @test - */ - public function it_should_count_cases_by_user_with_self_service_mixed_with_self_service_value_based() - { - //Create process - $process = factory(Process::class)->create(); - //Create a case - $application = factory(Application::class)->create(); - //Create user - $user = factory(User::class)->create(); - //Create a task self service - $task = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process->PRO_UID - ]); - //Assign a user in the task - factory(TaskUser::class)->create([ - 'TAS_UID' => $task->TAS_UID, - 'USR_UID' => $user->USR_UID, - 'TU_RELATION' => 1, //Related to the user - 'TU_TYPE' => 1 - ]); - //Create the register in self service - factory(Delegation::class, 15)->create([ - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - //Create a task self service value based - $task1 = factory(Task::class)->create([ - 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', - 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process->PRO_UID - ]); - //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'DEL_INDEX' => 2, - 'TAS_ID' => $task1->TAS_ID - ]); - factory(AppAssignSelfServiceValueGroup::class)->create([ - 'ID' => $appSelfValue->ID, - 'GRP_UID' => $user->USR_UID, - 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId - 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 - ]); - //Create the register in self service value based - factory(Delegation::class, 15)->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'DEL_INDEX' => $appSelfValue->DEL_INDEX, - 'TAS_ID' => $task->TAS_ID, - 'DEL_THREAD_STATUS' => 'OPEN', - 'USR_ID' => 0, - ]); - //Review the count self-service - $result = Delegation::countSelfService($user->USR_UID); - $this->assertEquals(30, $result); - } - /** * This checks the counters is working properly in self-service group assigned * @@ -1095,6 +1031,83 @@ class DelegationTest extends TestCase $this->assertEquals(25, $result); } + /** + * This checks the counters is working properly with self-service and self-service-value-based + * + * @covers \ProcessMaker\Model\Delegation::countSelfService() + * @test + */ + public function it_should_count_cases_by_user_with_self_service_and_self_service_value_based() + { + //Create process + $process = factory(Process::class)->create(); + //Create group + $group = factory(Groupwf::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID + ]); + //Create a task self service + $taskSelfService = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $taskSelfService->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in self service + factory(Delegation::class)->create([ + 'TAS_ID' => $taskSelfService->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + + //Create a task self service value based + $taskSelfServiceByVariable = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $taskSelfServiceByVariable->TAS_UID, + 'USR_UID' => $group->GRP_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appAssignSelfService = factory(AppAssignSelfServiceValue::class)->create([ + 'TAS_ID' => $taskSelfServiceByVariable->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appAssignSelfService->ID, + 'GRP_UID' => $group->GRP_UID, + 'ASSIGNEE_ID' => $group->GRP_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 2 //Related to the user=1 related to the group=2 + ]); + //Create the register in self service value based + factory(Delegation::class)->create([ + 'APP_NUMBER' => $appAssignSelfService->APP_NUMBER, + 'DEL_INDEX' => $appAssignSelfService->DEL_INDEX, + 'TAS_ID' => $taskSelfServiceByVariable->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + + //Review the count self-service + $result = Delegation::countSelfService($user->USR_UID); + $this->assertEquals(2, $result); + } + /** * This checks the counters is working properly in self-service user and group assigned in parallel task * diff --git a/workflow/engine/methods/cases/ajaxListener.php b/workflow/engine/methods/cases/ajaxListener.php index 55d1ec1bf..0d825c386 100644 --- a/workflow/engine/methods/cases/ajaxListener.php +++ b/workflow/engine/methods/cases/ajaxListener.php @@ -546,45 +546,36 @@ class Ajax G::RenderPage('publish', 'extJs'); } + /** + * Cancel case from actions menu + * + * @link https://wiki.processmaker.com/3.3/Cases/Actions#Cancel + * + * @return void + */ public function cancelCase() { - $oCase = new Cases(); - $multiple = false; - - if (isset($_POST['APP_UID']) && isset($_POST['DEL_INDEX'])) { - $APP_UID = $_POST['APP_UID']; - $DEL_INDEX = $_POST['DEL_INDEX']; - - $appUids = explode(',', $APP_UID); - $delIndexes = explode(',', $DEL_INDEX); - if (count($appUids) > 1 && count($delIndexes) > 1) { - $multiple = true; + try { + $appUid = !empty($_SESSION['APPLICATION']) ? $_SESSION['APPLICATION'] : ''; + $index = !empty($_SESSION['INDEX']) ? $_SESSION['INDEX'] : ''; + $usrUid = !empty($_SESSION['USER_LOGGED']) ? $_SESSION['USER_LOGGED'] : ''; + $result = new stdclass(); + if (!empty($appUid) && !empty($index) && !empty($usrUid)) { + $ws = new WsBase(); + $response = (object)$ws->cancelCase($appUid, $index, $usrUid); + // Review if the case was cancelled, true if the case was cancelled + $result->status = ($response->status_code == 0) ? true : false; + $result->msg = $response->message; + } else { + $result->status = false; + $result->msg = G::LoadTranslation("ID_CASE_USER_INVALID_CANCEL_CASE", [$usrUid]); } - } elseif (isset($_POST['sApplicationUID']) && isset($_POST['iIndex'])) { - $APP_UID = $_POST['sApplicationUID']; - $DEL_INDEX = $_POST['iIndex']; - } else { - $APP_UID = $_SESSION['APPLICATION']; - $DEL_INDEX = $_SESSION['INDEX']; + } catch (Exception $e) { + $result->status = false; + $result->msg = $e->getMessage(); } - // Save the note pause reason - if ($_POST['NOTE_REASON'] != '') { - require_once("classes/model/AppNotes.php"); - $appNotes = new AppNotes(); - $noteContent = addslashes($_POST['NOTE_REASON']); - $appNotes->postNewNote($APP_UID, $_SESSION['USER_LOGGED'], $noteContent, $_POST['NOTIFY_PAUSE']); - } - // End save - - - if ($multiple) { - foreach ($appUids as $i => $appUid) { - $oCase->cancelCase($appUid, $delIndexes[$i], $_SESSION['USER_LOGGED']); - } - } else { - $oCase->cancelCase($APP_UID, $DEL_INDEX, $_SESSION['USER_LOGGED']); - } + print G::json_encode($result); } public function getUsersToReassign() diff --git a/workflow/engine/methods/cases/cases_Derivate.php b/workflow/engine/methods/cases/cases_Derivate.php index 6b227d636..ce16237a7 100644 --- a/workflow/engine/methods/cases/cases_Derivate.php +++ b/workflow/engine/methods/cases/cases_Derivate.php @@ -311,9 +311,8 @@ try { } } - //close tab only if IE11 - - if ($isIE && !isset($_SESSION['__OUTLOOK_CONNECTOR__'])) { + //close tab only if IE11 add a validation was added if the current skin is uxs + if ($isIE && !isset($_SESSION['__OUTLOOK_CONNECTOR__']) && SYS_SKIN !== "uxs") { $script = "