diff --git a/workflow/engine/src/BusinessModel/Cases.php b/workflow/engine/src/BusinessModel/Cases.php index 6f1451416..6ecc72e1d 100644 --- a/workflow/engine/src/BusinessModel/Cases.php +++ b/workflow/engine/src/BusinessModel/Cases.php @@ -23,8 +23,14 @@ class Cases */ public function getList($dataList = array()) { - G::LoadClass("applications"); + Validator::isArray($dataList, '$dataList'); + if (!isset($dataList["userId"])) { + throw (new \Exception("The user with userId: '' does not exist.")); + } else { + Validator::usrUid($dataList["userId"], "userId"); + } + G::LoadClass("applications"); $solrEnabled = false; $userUid = $dataList["userId"]; $callback = isset( $dataList["callback"] ) ? $dataList["callback"] : "stcCallback1001"; @@ -44,6 +50,11 @@ class Cases $dateTo = isset( $dataList["dateTo"] ) ? substr( $dataList["dateTo"], 0, 10 ) : ""; $first = isset( $dataList["first"] ) ? true :false; + $valuesCorrect = array('todo', 'draft', 'paused', 'sent', 'selfservice', 'unassigned', 'search'); + if (!in_array($action, $valuesCorrect)) { + throw (new \Exception('The value for $action is incorrect.')); + } + if ($action == 'search' || $action == 'to_reassign') { $userUid = ($user == "CURRENT_USER") ? $userUid : $user; if ($first) { @@ -115,6 +126,11 @@ class Cases $category ); } + if (!empty($result['data'])) { + foreach ($result['data'] as &$value) { + $value = array_change_key_case($value, CASE_LOWER); + } + } return $result; } @@ -403,4 +419,3 @@ class Cases } } - diff --git a/workflow/engine/src/Tests/BusinessModel/CasesTest.php b/workflow/engine/src/Tests/BusinessModel/CasesTest.php new file mode 100644 index 000000000..4ff197711 --- /dev/null +++ b/workflow/engine/src/Tests/BusinessModel/CasesTest.php @@ -0,0 +1,175 @@ + + * @copyright Colosa - Bolivia + * + * @protected + * @package Tests\BusinessModel + */ +class CasesTest extends \PHPUnit_Framework_TestCase +{ + protected $oCases; + + /** + * Set class for test + * + * @coversNothing + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function setUp() + { + $this->oCases = new \BusinessModel\Cases(); + return true; + } + + /** + * Test error for type in first field the function + * + * @covers \BusinessModel\Cases::getList + * @expectedException Exception + * @expectedExceptionMessage Invalid value for '$dataList' it must be an array. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testGetListCasesErrorArray() + { + $this->oCases->getList(true); + } + + /** + * Test error for empty userId in array + * + * @covers \BusinessModel\Cases::getList + * @expectedException Exception + * @expectedExceptionMessage The user with userId: '' does not exist. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testGetListCasesErrorUserIdArray() + { + $this->oCases->getList(array()); + } + + /** + * Test error for not exists userId in array + * + * @covers \BusinessModel\Cases::getList + * @expectedException Exception + * @expectedExceptionMessage The user with userId: 'UidInexistente' does not exist. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testGetListCasesErrorNotExistsUserIdArray() + { + $this->oCases->getList(array('userId' => 'UidInexistente')); + } + + /** + * Test error for incorrect value $action in array + * + * @covers \BusinessModel\Cases::getList + * @expectedException Exception + * @expectedExceptionMessage The value for $action is incorrect. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testGetListCasesErrorIncorrectValueArray() + { + $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'incorrect')); + } + + /** + * Test get list to do + * + * @covers \BusinessModel\Cases::getList + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testGetListCasesToDo() + { + $response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001')); + $this->assertTrue(is_array($response)); + $this->assertTrue(is_numeric($response['totalCount'])); + $this->assertTrue(is_array($response['data'])); + } + + /** + * Test get list draft + * + * @covers \BusinessModel\Cases::getList + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testGetListCasesDraft() + { + $response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'draft')); + $this->assertTrue(is_array($response)); + $this->assertTrue(is_numeric($response['totalCount'])); + $this->assertTrue(is_array($response['data'])); + } + + /** + * Test get list participated + * + * @covers \BusinessModel\Cases::getList + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testGetListCasesParticipated() + { + $response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'sent')); + $this->assertTrue(is_array($response)); + $this->assertTrue(is_numeric($response['totalCount'])); + $this->assertTrue(is_array($response['data'])); + } + + /** + * Test get list unassigned + * + * @covers \BusinessModel\Cases::getList + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testGetListCasesUnassigned() + { + $response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'unassigned')); + $this->assertTrue(is_array($response)); + $this->assertTrue(is_numeric($response['totalCount'])); + $this->assertTrue(is_array($response['data'])); + } + + /** + * Test get list search + * + * @covers \BusinessModel\Cases::getList + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testGetListCasesSearch() + { + $response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'search')); + $this->assertTrue(is_array($response)); + $this->assertTrue(is_numeric($response['totalCount'])); + $this->assertTrue(is_array($response['data'])); + } +} +