This commit is contained in:
Paula Quispe
2020-12-01 17:42:09 -04:00
64 changed files with 3587 additions and 1098 deletions

View File

@@ -0,0 +1,50 @@
<?php
namespace Tests\unit\workflow\engine\classes;
use Tests\TestCase;
use WorkspaceTools;
class WorkflowToolsTest extends TestCase
{
private $workspaceTools;
/**
* Method set up.
*/
public function setUp()
{
parent::setUp();
$this->workspaceTools = new WorkspaceTools('workflow');
}
/**
* Method tear down.
*/
public function tearDown()
{
parent::tearDown();
}
/**
* This test the addAsyncOptionToSchedulerCommands method.
* @test
* @covers \WorkspaceTools::addAsyncOptionToSchedulerCommands()
*/
public function it_should_test_addAsyncOptionToSchedulerCommands_method()
{
//method "WorkspaceTools::initPropel(true)" crashes all connections
$message = "WorkspaceTools::initPropel(true) crashes all connections";
$this->markTestIncomplete($message);
ob_start();
$this->workspaceTools->addAsyncOptionToSchedulerCommands(false);
$string = ob_get_clean();
$this->assertRegExp("/This was previously updated/", $string);
ob_start();
$this->workspaceTools->addAsyncOptionToSchedulerCommands(true);
$string = ob_get_clean();
$this->assertRegExp("/Adding \+async option/", $string);
}
}

View File

@@ -4,22 +4,26 @@ namespace ProcessMaker\BusinessModel;
use Exception;
use G;
use ProcessMaker\BusinessModel\Cases;
use Illuminate\Support\Facades\DB;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Documents;
use ProcessMaker\Model\ListUnassigned;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Step;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\Triggers;
use ProcessMaker\Model\User;
use RBAC;
use Tests\TestCase;
/**
* Class DelegationTest
* Class CasesTest
*
* @coversDefaultClass \ProcessMaker\BusinessModel\Cases
*/
class CasesTest extends TestCase
{
/**
* Set up method.
*/
@@ -233,4 +237,144 @@ class CasesTest extends TestCase
// Call the uploadFiles method
$case->uploadFiles($user->USR_UID, $application->APP_UID, $varName, -1, null, $delegation->DEL_INDEX);
}
/**
* This test the execution of trigger from cases related to the self services timeout
*
* @covers \ProcessMaker\BusinessModel\Cases::executeSelfServiceTimeout()
* @test
*/
public function it_execute_trigger_from_cases_with_self_service_timeout_every_time()
{
ListUnassigned::truncate();
// Define the Execute Trigger = EVERY_TIME
$application = factory(Application::class)->states('foreign_keys')->create();
// Create a trigger
$trigger = factory(Triggers::class)->create([
'PRO_UID' => $application->PRO_UID,
'TRI_WEBBOT' => 'echo(1);'
]);
// Create a task with the configuration trigger execution
$task = factory(Task::class)->states('sef_service_timeout')->create([
'PRO_UID' => $application->PRO_UID,
'TAS_SELFSERVICE_EXECUTION' => 'EVERY_TIME',
'TAS_SELFSERVICE_TRIGGER_UID' => $trigger->TRI_UID
]);
// Create a unassigned cases
factory(ListUnassigned::class)->create([
'TAS_UID' => $task->TAS_UID,
'TAS_ID' => $task->TAS_ID,
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID,
'PRO_UID' => $application->PRO_UID
]);
// Define the session
$_SESSION["PROCESS"] = $application->PRO_UID;
// todo: the function Cases::loadCase is using propel we need to change this
DB::commit();
$casesExecuted = Cases::executeSelfServiceTimeout();
$this->assertTrue(is_array($casesExecuted));
}
/**
* This test the execution of trigger from cases related to the self services timeout
*
* @covers \ProcessMaker\BusinessModel\Cases::executeSelfServiceTimeout()
* @test
*/
public function it_execute_trigger_from_cases_with_self_service_timeout_once()
{
ListUnassigned::truncate();
// Define the Execute Trigger = ONCE
$application = factory(Application::class)->states('foreign_keys')->create();
// Create a trigger
$trigger = factory(Triggers::class)->create([
'PRO_UID' => $application->PRO_UID,
'TRI_WEBBOT' => 'echo(1);'
]);
// Create a task with the configuration trigger execution
$task = factory(Task::class)->states('sef_service_timeout')->create([
'PRO_UID' => $application->PRO_UID,
'TAS_SELFSERVICE_EXECUTION' => 'ONCE',
'TAS_SELFSERVICE_TRIGGER_UID' => $trigger->TRI_UID
]);
// Create a unassigned cases
factory(ListUnassigned::class)->create([
'TAS_UID' => $task->TAS_UID,
'TAS_ID' => $task->TAS_ID,
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID,
'PRO_UID' => $application->PRO_UID
]);
// Define the session
$_SESSION["PROCESS"] = $application->PRO_UID;
// todo: the function Cases::loadCase is using propel we need to change this
DB::commit();
$casesExecuted = Cases::executeSelfServiceTimeout();
$this->assertTrue(is_array($casesExecuted));
}
/**
* It test get assigned DynaForms as steps by application Uid
*
* @covers \ProcessMaker\BusinessModel\Cases::dynaFormsByApplication()
* @test
*/
public function it_should_test_get_dynaforms_by_application()
{
// Create a process
$process = factory(Process::class)->create();
// Create a task related to the process
$task1 = factory(Task::class)->create([
'PRO_UID' => $process->PRO_UID
]);
// Created another task related to the process
$task2 = factory(Task::class)->create([
'PRO_UID' => $process->PRO_UID
]);
// Created a step related to the first task
factory(Step::class)->create([
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task1->TAS_UID,
'STEP_TYPE_OBJ' => 'DYNAFORM',
'STEP_UID_OBJ' => G::generateUniqueID(),
'STEP_POSITION' => 1
]);
// Created a step related to the second task and with a specific DynaForm Uid
$dynUid = G::generateUniqueID();
factory(Step::class)->create([
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task2->TAS_UID,
'STEP_TYPE_OBJ' => 'DYNAFORM',
'STEP_UID_OBJ' => $dynUid,
'STEP_POSITION' => 1
]);
// Create an application related to the process in draft status
$application = factory(Application::class)->create([
'PRO_UID' => $process->PRO_UID,
'APP_STATUS' => 'DRAFT'
]);
// Get all DynaForms assigned as steps
self::assertCount(2, Cases::dynaFormsByApplication($application->APP_UID));
// Get DynaForms assigned as steps for the first task
self::assertCount(1, Cases::dynaFormsByApplication($application->APP_UID, $task1->TAS_UID));
// Get DynaForms assigned as steps sending a specific DynaForm Uid
self::assertCount(1, Cases::dynaFormsByApplication($application->APP_UID, '', $dynUid));
// Get DynaForms assigned as steps for the second task when the application status is DRAFT
self::assertCount(1, Cases::dynaFormsByApplication($application->APP_UID, $task2->TAS_UID, '', 'TO_DO'));
// Get DynaForms assigned as steps for the second task when the application status is COMPLETED
self::assertCount(2, Cases::dynaFormsByApplication($application->APP_UID, $task2->TAS_UID, '', 'COMPLETED'));
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\AppTimeoutAction;
use Tests\TestCase;
/**
* Class DelegationTest
*
* @coversDefaultClass \ProcessMaker\Model\AppTimeoutAction
*/
class AppTimeoutActionTest extends TestCase
{
use DatabaseTransactions;
/**
* Test set and get the caseUid property
*
* @covers \ProcessMaker\Model\AppTimeoutAction::setCaseUid()
* @covers \ProcessMaker\Model\AppTimeoutAction::getCaseUid()
* @test
*/
public function it_set_get_case_uid()
{
factory(AppTimeoutAction::class)->create();
$timeout = factory(AppTimeoutAction::class)->create();
$timeout->setCaseUid($timeout->APP_UID);
$this->assertEquals($timeout->getCaseUid(), $timeout->APP_UID);
}
/**
* Test set and get the index property
*
* @covers \ProcessMaker\Model\AppTimeoutAction::setIndex()
* @covers \ProcessMaker\Model\AppTimeoutAction::getIndex()
* @test
*/
public function it_set_get_index()
{
factory(AppTimeoutAction::class)->create();
$timeout = factory(AppTimeoutAction::class)->create();
$timeout->setIndex($timeout->DEL_INDEX);
$this->assertEquals($timeout->getIndex(), $timeout->DEL_INDEX);
}
/**
* Test a query to only include a specific case
*
* @covers \ProcessMaker\Model\AppTimeoutAction::scopeCase()
* @test
*/
public function it_filter_a_specific_case()
{
factory(AppTimeoutAction::class)->create();
$timeout = factory(AppTimeoutAction::class)->create();
$this->assertCount(1, $timeout->case($timeout->APP_UID)->get());
}
/**
* Test scope a query to only include a specific case
*
* @covers \ProcessMaker\Model\AppTimeoutAction::scopeIndex()
* @test
*/
public function it_filter_a_specific_index()
{
factory(AppTimeoutAction::class)->create();
$timeout = factory(AppTimeoutAction::class)->create();
$this->assertCount(1, $timeout->case($timeout->APP_UID)->index($timeout->DEL_INDEX)->get());
}
/**
* This checks it returns information about the self service timeout in a sequential thread
*
* @covers \ProcessMaker\Model\AppTimeoutAction::cases()
* @test
*/
public function it_return_the_case_executed_once_one_thread()
{
$records = factory(AppTimeoutAction::class, 5)->create();
foreach ($records as $row) {
$appUid = $row->APP_UID;
$delIndex = $row->DEL_INDEX;
}
$appTimeout = new AppTimeoutAction();
$appTimeout->setCaseUid($appUid);
$appTimeout->setIndex($delIndex);
$caseExecuted = $appTimeout->cases();
$this->assertNotEmpty($caseExecuted);
}
/**
* This checks it returns information about the self service timeout in a parallel thread
*
* @covers \ProcessMaker\Model\AppTimeoutAction::cases()
* @test
*/
public function it_return_the_case_executed_once_more_than_one_thread()
{
$records = factory(AppTimeoutAction::class, 5)->create();
foreach ($records as $row) {
$appUid = $row->APP_UID;
$delIndex = $row->DEL_INDEX;
}
// Create other thread in the same case
factory(AppTimeoutAction::class)->create([
'APP_UID' => $appUid,
'DEL_INDEX' => $delIndex + 1,
]);
$appTimeout = new AppTimeoutAction();
$appTimeout->setCaseUid($appUid);
$appTimeout->setIndex($delIndex);
$caseExecuted = $appTimeout->cases();
$this->assertNotEmpty($caseExecuted);
}
}

View File

@@ -300,5 +300,25 @@ class ListUnassignedTest extends TestCase
$result = ListUnassigned::loadList($user->USR_UID, $filters);
$this->assertCount(2, $result);
}
/**
* This checks the self-service timeout cases
*
* @covers \ProcessMaker\Model\ListUnassigned::selfServiceTimeout()
* @test
*/
public function it_should_return_cases_configured_self_service_timeout()
{
// Create some cases configured the self service timeout
for ($x = 1; $x <= 5; $x++) {
$task = factory(Task::class)->states('sef_service_timeout')->create();
factory(ListUnassigned::class)->create([
'TAS_UID' => $task->TAS_UID,
'TAS_ID' => $task->TAS_ID
]);
}
$results = ListUnassigned::selfServiceTimeout();
$this->assertCount(5, $results);
}
}

View File

@@ -17,6 +17,15 @@ class ProcessTest extends TestCase
{
use DatabaseTransactions;
/**
* Call the setUp parent method
*/
public function setUp()
{
parent::setUp();
Process::query()->delete();
}
/**
* Test belongs to PRO_ID
*
@@ -242,4 +251,92 @@ class ProcessTest extends TestCase
// This asserts the process was converted from private to public
$this->assertEquals('PUBLIC', $p[0]->PRO_TYPE_PROCESS);
}
/**
* It tests the process list
*
* @covers \ProcessMaker\Model\Process::getProcessesFilter()
* @covers \ProcessMaker\Model\Process::scopeNoStatus()
* @covers \ProcessMaker\Model\Process::scopeSubProcess()
* @test
*/
public function it_should_test_process_without_filter()
{
$process = factory(Process::class)->create();
$result = Process::getProcessesFilter(
null,
null,
null,
$process->PRO_CREATE_USER
);
$this->assertEquals($process->PRO_CREATE_USER, $result[0]['USR_UID']);
}
/**
* It tests the process list with specific category
*
* @covers \ProcessMaker\Model\Process::getProcessesFilter()
* @covers \ProcessMaker\Model\Process::scopeCategory()
* @test
*/
public function it_should_test_process_with_category_filter()
{
$process = factory(Process::class)->create([
'PRO_CATEGORY' => function () {
return factory(ProcessCategory::class)->create()->CATEGORY_UID;
}
]);
$result = Process::getProcessesFilter(
$process->PRO_CATEGORY
);
$this->assertEquals($process->PRO_CATEGORY, $result[0]['PRO_CATEGORY']);
}
/**
* It tests the process list with specific process
*
* @covers \ProcessMaker\Model\Process::getProcessesFilter()
* @covers \ProcessMaker\Model\Process::scopeProcess()
* @test
*/
public function it_should_test_process_with_process_filter()
{
$process = factory(Process::class)->create();
$result = Process::getProcessesFilter(
null,
$process->PRO_UID
);
$this->assertEquals($process->PRO_UID, $result[0]['PRO_UID']);
}
/**
* It tests the process list with specific process title
*
* @covers \ProcessMaker\Model\Process::getProcessesFilter()
* @covers \ProcessMaker\Model\Process::scopeTitle()
* @test
*/
public function it_should_test_process_with_title_filter()
{
$process = factory(Process::class)->create();
$result = Process::getProcessesFilter(
null,
null,
$process->PRO_TITLE
);
$this->assertEquals($process->PRO_TITLE, $result[0]['PRO_TITLE']);
}
/**
* It tests the count process
*
* @covers \ProcessMaker\Model\Process::getCounter()
* @test
*/
public function it_should_test_count_process()
{
$process = factory(Process::class)->create();
$total = Process::getCounter($process->PRO_CREATE_USER);
$this->assertEquals(1, $total);
}
}

View File

@@ -2,14 +2,40 @@
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use G;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Triggers;
use Tests\TestCase;
/**
* Class DelegationTest
*
* @coversDefaultClass \ProcessMaker\Model\Triggers
*/
class TriggersTest extends TestCase
{
use DatabaseTransactions;
/**
* Test set and get the trigger property
*
* @covers \ProcessMaker\Model\Triggers::setTrigger()
* @covers \ProcessMaker\Model\Triggers::getTrigger()
* @test
*/
public function it_set_get_trigger()
{
factory(Triggers::class)->create();
$trigger = factory(Triggers::class)->create();
$trigger->setTrigger($trigger->TRI_UID);
$this->assertEquals($trigger->getTrigger(), $trigger->TRI_UID);
}
/**
* It tests the process scope in the trigger model
*
* @covers \ProcessMaker\Model\Triggers::scopeProcess()
* @test
*/
public function it_should_test_process_scope_in_trigger_model()
@@ -74,4 +100,48 @@ class TriggersTest extends TestCase
$this->assertEquals($process[2]['PRO_UID'], $result[0]['PRO_UID']);
$this->assertEquals($process[2]['PRO_UID'], $result[1]['PRO_UID']);
}
}
/**
* Test scope a query to only include a specific case
*
* @covers \ProcessMaker\Model\Triggers::scopeTrigger()
* @test
*/
public function it_filter_specific_tasks()
{
factory(Triggers::class)->create();
$trigger = factory(Triggers::class)->create();
$this->assertCount(1, $trigger->trigger($trigger->TRI_UID)->get());
}
/**
* This checks it returns information about the trigger
*
* @covers \ProcessMaker\Model\Triggers::triggers()
* @test
*/
public function it_return_specific_trigger_information()
{
$triggers = factory(Triggers::class, 5)->create();
$trigger = new Triggers();
$trigger->setTrigger($triggers[0]->TRI_UID);
$triggersList = $trigger->triggers();
$this->assertCount(1, $triggersList);
$this->assertEquals($triggers[0]->TRI_TITLE , $triggersList[0]['TRI_TITLE']);
}
/**
* This checks it returns empty when the trigger does not exist
*
* @covers \ProcessMaker\Model\Triggers::triggers()
* @test
*/
public function it_return_empty_when_the_trigger_not_exist()
{
factory(Triggers::class)->create();
$trigger = new Triggers();
$trigger->setTrigger(G::generateUniqueID());
$triggersList = $trigger->triggers();
$this->assertEmpty($triggersList);
}
}

View File

@@ -0,0 +1,560 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\TaskScheduler;
use App\Jobs\TaskScheduler;
use Faker\Factory;
use Illuminate\Support\Facades\Queue;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\AppThread;
use ProcessMaker\Model\Delegation;
use ProcessMaker\TaskScheduler\Task;
use Tests\TestCase;
/**
* Class TaskTest
*
* @coversDefaultClass \ProcessMaker\TaskScheduler\Task
*/
class TaskTest extends TestCase
{
private $faker;
/**
* Method setUp.
*/
protected function setUp()
{
parent::setUp();
$this->faker = Factory::create();
Delegation::truncate();
AppThread::truncate();
Application::truncate();
}
/**
* Method tearDown.
*/
protected function tearDown()
{
parent::tearDown();
}
/**
* Test synchronous asynchronous cases.
*/
public function asynchronousCases()
{
return [
[true],
[false]
];
}
/**
* This test verify the setExecutionMessage method.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::setExecutionMessage()
* @dataProvider asynchronousCases
*/
public function it_should_test_setExecutionMessage_method($asynchronous)
{
$task = new Task($asynchronous, '');
$message = $this->faker->paragraph;
ob_start();
$task->setExecutionMessage($message);
$printing = ob_get_clean();
//assert if message is contained in output buffer
if ($asynchronous === false) {
$this->assertRegExp("/{$message}/", $printing);
}
//assert if not showing message
if ($asynchronous === true) {
$this->assertEmpty($printing);
}
}
/**
* This test verify the setExecutionResultMessage method.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::setExecutionResultMessage()
* @dataProvider asynchronousCases
*/
public function it_should_test_setExecutionResultMessage_method($asynchronous)
{
$task = new Task($asynchronous, '');
$message = $this->faker->paragraph;
ob_start();
$task->setExecutionResultMessage($message, 'error');
$printing = ob_get_clean();
//assert if message is contained in output buffer
if ($asynchronous === false) {
$this->assertRegExp("/{$message}/", $printing);
}
//assert if not showing message
if ($asynchronous === true) {
$this->assertEmpty($printing);
}
ob_start();
$task->setExecutionResultMessage($message, 'info');
$printing = ob_get_clean();
//assert if message is contained in output buffer
if ($asynchronous === false) {
$this->assertRegExp("/{$message}/", $printing);
}
//assert if not showing message
if ($asynchronous === true) {
$this->assertEmpty($printing);
}
ob_start();
$task->setExecutionResultMessage($message, 'warning');
$printing = ob_get_clean();
//assert if message is contained in output buffer
if ($asynchronous === false) {
$this->assertRegExp("/{$message}/", $printing);
}
//assert if not showing message
if ($asynchronous === true) {
$this->assertEmpty($printing);
}
}
/**
* This test verify the saveLog method.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::saveLog()
* @dataProvider asynchronousCases
*/
public function it_should_test_saveLog_method($asynchronous)
{
$task = new Task(false, '');
$task->saveLog('', '', $this->faker->paragraph);
$file = PATH_DATA . "log/cron.log";
$this->assertFileExists($file);
if ($asynchronous === false) {
$description = $this->faker->paragraph;
$task = new Task($asynchronous, '');
$task->saveLog('', '', $description);
$contentLog = file_get_contents($file);
$this->assertRegExp("/{$description}/", $contentLog);
}
if ($asynchronous === true) {
$description = $this->faker->paragraph;
$task = new Task($asynchronous, '');
$task->saveLog('', '', $description);
$contentLog = file_get_contents($file);
$this->assertNotRegExp("/{$description}/", $contentLog);
}
}
/**
* This test verify the resendEmails activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::resendEmails()
* @dataProvider asynchronousCases
*/
public function it_should_test_resendEmails_method($asynchronous)
{
$task = new Task($asynchronous, '');
$dateSystem = $this->faker->date();
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->resendEmails('', $dateSystem);
$printing = ob_get_clean();
$this->assertRegExp("/DONE/", $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->resendEmails('', $dateSystem);
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* This test verify the unpauseApplications activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::unpauseApplications()
* @dataProvider asynchronousCases
*/
public function it_should_test_unpauseApplications_method($asynchronous)
{
$task = new Task($asynchronous, '');
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->unpauseApplications('');
$printing = ob_get_clean();
$this->assertRegExp("/DONE/", $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->unpauseApplications('');
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* This test verify the calculateDuration activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::calculateDuration()
* @dataProvider asynchronousCases
*/
public function it_should_test_calculateDuration_method($asynchronous)
{
$task = new Task($asynchronous, '');
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->calculateDuration();
$printing = ob_get_clean();
$this->assertRegExp("/DONE/", $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->calculateDuration();
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* This test verify the calculateDuration activity method for synchronous and asynchronous execution.
* @covers ProcessMaker\TaskScheduler\Task::executeCaseSelfService()
* @test
* @dataProvider asynchronousCases
*/
public function it_should_test_unassignedcase($asynchronous)
{
$task = new Task($asynchronous, '');
// Assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->executeCaseSelfService();
$printing = ob_get_clean();
$this->assertRegExp("/Unassigned case/", $printing);
}
// Assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->executeCaseSelfService();
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* This test verify the calculateAppDuration activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::calculateAppDuration()
* @dataProvider asynchronousCases
*/
public function it_should_test_calculateAppDuration_method($asynchronous)
{
$task = new Task($asynchronous, '');
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->calculateAppDuration();
$printing = ob_get_clean();
$this->assertRegExp("/DONE/", $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->calculateAppDuration();
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* This test verify the cleanSelfServiceTables activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::cleanSelfServiceTables()
* @dataProvider asynchronousCases
*/
public function it_should_test_cleanSelfServiceTables_method($asynchronous)
{
$task = new Task($asynchronous, '');
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->cleanSelfServiceTables();
$printing = ob_get_clean();
$this->assertRegExp("/DONE/", $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->cleanSelfServiceTables();
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* This test verify the executePlugins activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::executePlugins()
* @dataProvider asynchronousCases
*/
public function it_should_test_executePlugins_method($asynchronous)
{
$task = new Task($asynchronous, '');
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->executePlugins();
$printing = ob_get_clean();
$this->assertRegExp("/plugins/", $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->executePlugins();
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* This test verify the fillReportByUser activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::fillReportByUser()
* @dataProvider asynchronousCases
*/
public function it_should_test_fillReportByUser_method($asynchronous)
{
$task = new Task($asynchronous, '');
$dateInit = $this->faker->dateTime;
$dateFinish = $this->faker->dateTime;
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->fillReportByUser($dateInit, $dateFinish);
$printing = ob_get_clean();
$this->assertRegExp("/User Reporting/", $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->fillReportByUser($dateInit, $dateFinish);
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* This test verify the fillReportByProcess activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::fillReportByProcess()
* @dataProvider asynchronousCases
*/
public function it_should_test_fillReportByProcess_method($asynchronous)
{
$task = new Task($asynchronous, '');
$dateInit = $this->faker->dateTime;
$dateFinish = $this->faker->dateTime;
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->fillReportByProcess($dateInit, $dateFinish);
$printing = ob_get_clean();
$this->assertRegExp("/Process Reporting/", $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->fillReportByProcess($dateInit, $dateFinish);
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* This test verify the ldapcron activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::ldapcron()
* @dataProvider asynchronousCases
*/
public function it_should_test_ldapcron_method($asynchronous)
{
$task = new Task($asynchronous, '');
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->ldapcron(false);
$printing = ob_get_clean();
$this->assertRegExp("/\+---/", $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->ldapcron(false);
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* This test verify the sendNotifications activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::sendNotifications()
* @dataProvider asynchronousCases
*/
public function it_should_test_sendNotifications_method($asynchronous)
{
$task = new Task($asynchronous, '');
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->sendNotifications();
$printing = ob_get_clean();
$this->assertRegExp("/Resending Notifications/", $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->sendNotifications();
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* This test verify the actionsByEmailResponse activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::actionsByEmailResponse()
* @dataProvider asynchronousCases
*/
public function it_should_test_actionsByEmailResponse_method($asynchronous)
{
$task = new Task($asynchronous, '');
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->actionsByEmailResponse();
$printing = ob_get_clean();
$this->assertEmpty($printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->actionsByEmailResponse();
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* This test verify the messageeventcron activity method for synchronous and asynchronous execution.
* @test
* @covers ProcessMaker\TaskScheduler\Task::runTask()
* @covers ProcessMaker\TaskScheduler\Task::messageeventcron()
* @dataProvider asynchronousCases
*/
public function it_should_test_messageeventcron_method($asynchronous)
{
$task = new Task($asynchronous, '');
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
$task->messageeventcron();
$printing = ob_get_clean();
$this->assertRegExp("/Message-Events/", $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->messageeventcron();
Queue::assertPushed(TaskScheduler::class);
}
}
/**
* Tests the timerEventCron method with jobs in the task scheduler
*
* @test
* @covers ProcessMaker\TaskScheduler\Task::timerEventCron()
* @dataProvider asynchronousCases
*/
public function it_should_test_the_timer_event_cron_method($asynchronous)
{
//Creates a new task
$task = new Task($asynchronous, '');
//Sets the currect date
$date = date('Y-m-d H:i:s');
//assert synchronous for cron file
if ($asynchronous === false) {
ob_start();
//Calls the timerEventCron method
$task->timerEventCron($date, true);
//Gets the result
$printing = ob_get_clean();
//Asserts the result is printing that there is no exisiting records to continue a case in the determined date
$this->assertRegExp('/No existing records to continue a case, on date "' . $date . '/', $printing);
}
//assert asynchronous for job process
if ($asynchronous === true) {
Queue::fake();
Queue::assertNothingPushed();
$task->timerEventCron($date, true);
Queue::assertPushed(TaskScheduler::class);
}
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Util\Helpers;
use Tests\TestCase;
class CalculateDateTest extends TestCase
{
/**
* It tests the addition of days
*
* @test
*/
public function it_test_adding_days()
{
$iniDate = '2019-10-04 12:07:40';
$newDate = calculateDate($iniDate, 'DAYS', 1);
$this->assertEquals('2019-10-05 12:07:40', $newDate);
}
/**
* It tests the addition of hours
*
* @test
*/
public function it_test_adding_hours()
{
$iniDate = '2019-10-04 12:07:40';
$newDate = calculateDate($iniDate, 'HOURS', 1);
$this->assertEquals('2019-10-04 13:07:40', $newDate);
}
/**
* It tests the addition of minutes
*
* @test
*/
public function it_test_adding_minutes()
{
$iniDate = '2019-10-04 12:07:40';
$newDate = calculateDate($iniDate, 'MINUTES', 10);
$this->assertEquals('2019-10-04 12:17:40', $newDate);
}
}

View File

@@ -4,7 +4,7 @@ namespace Tests\unit\workflow\src\ProcessMaker\Util\Helpers;
use Tests\TestCase;
class ChangeAbbreviationOfDirectives extends TestCase
class ChangeAbbreviationOfDirectivesTest extends TestCase
{
/**
* Provider to define different types of configurations in the php.ini and the result expected