Merged in bugfix/PMCORE-3111 (pull request #7990)

PMCORE-3111 Service - CRUD for the custom cases List

Approved-by: Julio Cesar Laura Avendaño
This commit is contained in:
Roly Rudy Gutierrez Pinto
2021-07-21 19:57:06 +00:00
committed by Julio Cesar Laura Avendaño
10 changed files with 2645 additions and 0 deletions

View File

@@ -0,0 +1,275 @@
<?php
namespace tests\unit\workflow\engine\src\ProcessMaker\Model;
use ProcessMaker\Model\CaseList;
use Tests\TestCase;
class CaseListTest extends TestCase
{
/**
* setUp method.
*/
public function setUp()
{
parent::setUp();
}
/**
* teardown method.
*/
public function tearDown()
{
parent::tearDown();
}
/**
* This tests the getColumnNameFromAlias method.
* @test
* @covers \ProcessMaker\Model\CaseList::createSetting()
*/
public function it_should_test_getColumnNameFromAlias()
{
$data = [
'id' => 1,
'type' => 'inbox',
'name' => 'test1',
'description' => 'my description',
'tableUid' => '',
'columns' => [],
'userId' => 1,
'iconList' => 'deafult.png',
'iconColor' => 'red',
'iconColorScreen' => 'blue',
'createDate' => date('Y-m-d H:m:s'),
'updateDate' => date('Y-m-d H:m:s')
];
$array = CaseList::getColumnNameFromAlias($data);
//asserts
$this->assertArrayHasKey("CAL_ID", $array);
$this->assertArrayHasKey("CAL_TYPE", $array);
$this->assertArrayHasKey("CAL_NAME", $array);
$this->assertArrayHasKey("CAL_DESCRIPTION", $array);
$this->assertArrayHasKey("ADD_TAB_UID", $array);
$this->assertArrayHasKey("CAL_COLUMNS", $array);
$this->assertArrayHasKey("USR_ID", $array);
$this->assertArrayHasKey("CAL_ICON_LIST", $array);
$this->assertArrayHasKey("CAL_ICON_COLOR", $array);
$this->assertArrayHasKey("CAL_ICON_COLOR_SCREEN", $array);
$this->assertArrayHasKey("CAL_CREATE_DATE", $array);
$this->assertArrayHasKey("CAL_UPDATE_DATE", $array);
}
/**
* This tests the getAliasFromColumnName method.
* @test
* @covers \ProcessMaker\Model\CaseList::createSetting()
*/
public function it_should_test_getAliasFromColumnName()
{
$data = [
'CAL_ID' => 1,
'CAL_TYPE' => 'inbox',
'CAL_NAME' => 'test1',
'CAL_DESCRIPTION' => 'my description',
'ADD_TAB_UID' => 'my description',
'CAL_COLUMNS' => [],
'USR_ID' => 1,
'CAL_ICON_LIST' => 'deafult.png',
'CAL_ICON_COLOR' => 'red',
'CAL_ICON_COLOR_SCREEN' => 'blue',
'CAL_CREATE_DATE' => date('Y-m-d H:m:s'),
'CAL_UPDATE_DATE' => date('Y-m-d H:m:s')
];
$array = CaseList::getAliasFromColumnName($data);
//asserts
$this->assertArrayHasKey("id", $array);
$this->assertArrayHasKey("type", $array);
$this->assertArrayHasKey("name", $array);
$this->assertArrayHasKey("description", $array);
$this->assertArrayHasKey("tableUid", $array);
$this->assertArrayHasKey("columns", $array);
$this->assertArrayHasKey("userId", $array);
$this->assertArrayHasKey("iconList", $array);
$this->assertArrayHasKey("iconColor", $array);
$this->assertArrayHasKey("iconColorScreen", $array);
$this->assertArrayHasKey("createDate", $array);
$this->assertArrayHasKey("updateDate", $array);
}
/**
* This tests the createSetting method.
* @test
* @covers \ProcessMaker\Model\CaseList::createSetting()
*/
public function it_should_test_createSetting()
{
$data = [
'type' => 'inbox',
'name' => 'test1',
'description' => 'my description',
'tableUid' => '',
'columns' => [],
'userId' => 1,
'iconList' => 'deafult.png',
'iconColor' => 'red',
'iconColorScreen' => 'blue',
'createDate' => date('Y-m-d H:m:s'),
'updateDate' => date('Y-m-d H:m:s')
];
$caseList = CaseList::createSetting($data);
//asserts
$this->assertEquals($data['type'], $caseList->CAL_TYPE);
$this->assertEquals($data['name'], $caseList->CAL_NAME);
$this->assertEquals($data['description'], $caseList->CAL_DESCRIPTION);
$this->assertEquals($data['tableUid'], $caseList->ADD_TAB_UID);
$this->assertEquals($data['columns'], $caseList->CAL_COLUMNS);
$this->assertEquals($data['userId'], $caseList->USR_ID);
$this->assertEquals($data['iconList'], $caseList->CAL_ICON_LIST);
$this->assertEquals($data['iconColor'], $caseList->CAL_ICON_COLOR);
$this->assertEquals($data['iconColorScreen'], $caseList->CAL_ICON_COLOR_SCREEN);
}
/**
* This tests the updateSetting method.
* @test
* @covers \ProcessMaker\Model\CaseList::updateSetting()
*/
public function it_should_test_updateSetting()
{
$data = [
'type' => 'inbox',
'name' => 'test1',
'description' => 'my description',
'tableUid' => '',
'columns' => [],
'userId' => 1,
'iconList' => 'deafult.png',
'iconColor' => 'red',
'iconColorScreen' => 'blue',
'createDate' => date('Y-m-d H:m:s'),
'updateDate' => date('Y-m-d H:m:s')
];
$model = CaseList::createSetting($data);
$id = $model->CAL_ID;
$data2 = [
'type' => 'todo',
'name' => 'new name',
'description' => 'new deescription',
];
$caseList = CaseList::updateSetting($id, $data2);
//asserts
$this->assertEquals($data2['type'], $caseList->CAL_TYPE);
$this->assertEquals($data2['name'], $caseList->CAL_NAME);
$this->assertEquals($data2['description'], $caseList->CAL_DESCRIPTION);
$this->assertEquals($data['tableUid'], $caseList->ADD_TAB_UID);
$this->assertEquals($data['columns'], $caseList->CAL_COLUMNS);
$this->assertEquals($data['userId'], $caseList->USR_ID);
$this->assertEquals($data['iconList'], $caseList->CAL_ICON_LIST);
$this->assertEquals($data['iconColor'], $caseList->CAL_ICON_COLOR);
$this->assertEquals($data['iconColorScreen'], $caseList->CAL_ICON_COLOR_SCREEN);
}
/**
* This tests the deleteSetting method.
* @test
* @covers \ProcessMaker\Model\CaseList::deleteSetting()
*/
public function it_should_test_deleteSetting()
{
$data = [
'type' => 'inbox',
'name' => 'test1',
'description' => 'my description',
'tableUid' => '',
'columns' => [],
'userId' => 1,
'iconList' => 'deafult.png',
'iconColor' => 'red',
'iconColorScreen' => 'blue',
'createDate' => date('Y-m-d H:m:s'),
'updateDate' => date('Y-m-d H:m:s')
];
$model = CaseList::createSetting($data);
$id = $model->CAL_ID;
$caseList = CaseList::deleteSetting($id);
//asserts
$this->assertEquals($data['type'], $caseList->CAL_TYPE);
$this->assertEquals($data['name'], $caseList->CAL_NAME);
$this->assertEquals($data['description'], $caseList->CAL_DESCRIPTION);
$this->assertEquals($data['tableUid'], $caseList->ADD_TAB_UID);
$this->assertEquals($data['columns'], $caseList->CAL_COLUMNS);
$this->assertEquals($data['userId'], $caseList->USR_ID);
$this->assertEquals($data['iconList'], $caseList->CAL_ICON_LIST);
$this->assertEquals($data['iconColor'], $caseList->CAL_ICON_COLOR);
$this->assertEquals($data['iconColorScreen'], $caseList->CAL_ICON_COLOR_SCREEN);
}
/**
* This tests the getSetting method.
* @test
* @covers \ProcessMaker\Model\CaseList::deleteSetting()
*/
public function it_should_test_getSetting()
{
CaseList::truncate();
$data = [
'type' => 'inbox',
'name' => 'test1',
'description' => 'my description',
'tableUid' => '',
'columns' => [],
'userId' => 1,
'iconList' => 'deafult.png',
'iconColor' => 'red',
'iconColorScreen' => 'blue'
];
$model1 = CaseList::createSetting($data);
$model2 = CaseList::createSetting($data);
$model3 = CaseList::createSetting($data);
$model4 = CaseList::createSetting($data);
//assert total
$result = CaseList::getSetting('inbox', '', 0, 10);
$this->assertArrayHasKey("total", $result);
$this->assertArrayHasKey("data", $result);
$this->assertEquals(4, $result['total']);
//assert page 1
$result = CaseList::getSetting('inbox', '', 0, 2);
$this->assertArrayHasKey("total", $result);
$this->assertArrayHasKey("data", $result);
$this->assertEquals(4, $result['total']);
$this->assertEquals(2, count($result['data']));
//assert page 2
$result = CaseList::getSetting('inbox', '', 2, 2);
$this->assertArrayHasKey("total", $result);
$this->assertArrayHasKey("data", $result);
$this->assertEquals(4, $result['total']);
$this->assertEquals(2, count($result['data']));
//assert search
$result = CaseList::getSetting('inbox', 'test1', 0, 10);
$this->assertArrayHasKey("total", $result);
$this->assertArrayHasKey("data", $result);
$this->assertEquals(4, $result['total']);
$this->assertEquals(4, count($result['data']));
//assert search no exist result
$result = CaseList::getSetting('inbox', 'xxxx', 0, 10);
$this->assertArrayHasKey("total", $result);
$this->assertArrayHasKey("data", $result);
$this->assertEquals(0, $result['total']);
$this->assertEquals(0, count($result['data']));
}
}