Files
luos/tests/unit/workflow/engine/classes/WorkspaceToolsTest.php
Luciana Nuñez 6c814e6d9d PMCORE-3898
2022-08-16 10:20:19 -04:00

120 lines
4.0 KiB
PHP
Executable File

<?php
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use Tests\CreateTestSite;
use Tests\TestCase;
class WorkspaceToolsTest extends TestCase
{
use CreateTestSite;
public $workspace;
/**
* Call the setUp parent method
*/
public function setUp()
{
parent::setUp(); // TODO: Change the autogenerated stub
config(["system.workspace" => "new_site"]);
$this->workspace = config("system.workspace");
$this->createDBFile($this->workspace);
}
/**
* Tests the updateIsoCountry method
*
* @covers \WorkspaceTools::updateIsoCountry
* @test
*/
public function it_should_test_upgrade_Iso_Country_method()
{
$workspaceTools = new WorkspaceTools($this->workspace);
$workspaceTools->updateIsoCountry();
$result = ob_get_contents();
$this->assertRegExp("/-> Update table ISO_COUNTRY Done/", $result);
$res = IsoCountry::findById('CI');
// Assert the result is the expected
$this->assertEquals('Côte d\'Ivoire', $res['IC_NAME']);
}
/**
* Tests the migrateCaseTitleToThreads method
*
* @covers \WorkspaceTools::migrateCaseTitleToThreads
* @test
*/
public function it_should_test_migrate_case_title_to_threads_method()
{
$application1 = factory(Application::class)->create([
'APP_STATUS' => 'TO_DO',
'APP_STATUS_ID' => 2,
]);
$application2 = factory(Application::class)->create([
'APP_STATUS' => 'COMPLETED',
'APP_STATUS_ID' => 3,
]);
$application3 = factory(Application::class)->create([
'APP_STATUS' => 'CANCELED',
'APP_STATUS_ID' => 4,
]);
factory(Delegation::class)->create([
'APP_UID' => $application1->APP_UID,
'APP_NUMBER' => $application1->APP_NUMBER,
'DEL_INDEX' => 1
]);
factory(Delegation::class)->create([
'APP_UID' => $application1->APP_UID,
'APP_NUMBER' => $application1->APP_NUMBER,
'DEL_INDEX' => 2
]);
$delegation1 = factory(Delegation::class)->create([
'APP_UID' => $application1->APP_UID,
'APP_NUMBER' => $application1->APP_NUMBER,
'DEL_INDEX' => 3,
]);
factory(Delegation::class)->create([
'APP_UID' => $application2->APP_UID,
'APP_NUMBER' => $application2->APP_NUMBER,
'DEL_INDEX' => 1
]);
$delegation2 = factory(Delegation::class)->create([
'APP_UID' => $application2->APP_UID,
'APP_NUMBER' => $application2->APP_NUMBER,
'DEL_INDEX' => 2,
'DEL_LAST_INDEX' => 1
]);
factory(Delegation::class)->create([
'APP_UID' => $application3->APP_UID,
'APP_NUMBER' => $application3->APP_NUMBER,
'DEL_INDEX' => 1
]);
$delegation3 = factory(Delegation::class)->create([
'APP_UID' => $application3->APP_UID,
'APP_NUMBER' => $application3->APP_NUMBER,
'DEL_INDEX' => 2,
'DEL_LAST_INDEX' => 1
]);
$workspaceTools = new WorkspaceTools('');
$workspaceTools->migrateCaseTitleToThreads(['testexternal']);
$result = ob_get_contents();
$this->assertRegExp("/The Case Title has been updated successfully in APP_DELEGATION table./", $result);
$r = Delegation::select('DEL_TITLE')->where('DELEGATION_ID', $delegation1->DELEGATION_ID)->get()->values()->toArray();
$this->assertEquals($r[0]['DEL_TITLE'], $application1->APP_TITLE);
$r = Delegation::select('DEL_TITLE')->where('DELEGATION_ID', $delegation2->DELEGATION_ID)->get()->values()->toArray();
$this->assertEquals($r[0]['DEL_TITLE'], $application2->APP_TITLE);
$r = Delegation::select('DEL_TITLE')->where('DELEGATION_ID', $delegation3->DELEGATION_ID)->get()->values()->toArray();
$this->assertEquals($r[0]['DEL_TITLE'], $application3->APP_TITLE);
}
}