From 8463abaf367565456be7fc715c35a177acdb8ab5 Mon Sep 17 00:00:00 2001 From: Brayan Osmar Pereyra Suxo Date: Tue, 25 Mar 2014 12:08:00 -0400 Subject: [PATCH 1/2] Correciones en phpunit para CASESLIST --- .../engine/src/BusinessModel/Validator.php | 4 ++-- .../src/Tests/BusinessModel/CasesTest.php | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/workflow/engine/src/BusinessModel/Validator.php b/workflow/engine/src/BusinessModel/Validator.php index de3b01f1c..a02f7b786 100644 --- a/workflow/engine/src/BusinessModel/Validator.php +++ b/workflow/engine/src/BusinessModel/Validator.php @@ -237,11 +237,11 @@ class Validator{ { $date = trim($date); if ($date == '') { - throw (new \Exception("The value '' is not valid fot the format '$format'.")); + throw (new \Exception("The value '' is not a valid date for the format '$format'.")); } $d = \DateTime::createFromFormat($format, $date); if (!($d && $d->format($format) == $date)) { - throw (new \Exception("The value '$date' is not valid fot the format '$format'.")); + throw (new \Exception("The value '$date' is not a valid date for the format '$format'.")); } return $date; } diff --git a/workflow/engine/src/Tests/BusinessModel/CasesTest.php b/workflow/engine/src/Tests/BusinessModel/CasesTest.php index 6f83fe541..4007c284b 100644 --- a/workflow/engine/src/Tests/BusinessModel/CasesTest.php +++ b/workflow/engine/src/Tests/BusinessModel/CasesTest.php @@ -67,14 +67,14 @@ class CasesTest extends \PHPUnit_Framework_TestCase * * @covers \BusinessModel\Cases::getList * @expectedException Exception - * @expectedExceptionMessage The user with userId: 'UidInexistente' does not exist. + * @expectedExceptionMessage The user with userId: 'IdDoesNotExists' does not exist. * * @author Brayan Pereyra (Cochalo) * @copyright Colosa - Bolivia */ public function testGetListCasesErrorNotExistsUserIdArray() { - $this->oCases->getList(array('userId' => 'UidInexistente')); + $this->oCases->getList(array('userId' => 'IdDoesNotExists')); } /** @@ -97,7 +97,7 @@ class CasesTest extends \PHPUnit_Framework_TestCase * * @covers \BusinessModel\Cases::getList * @expectedException Exception - * @expectedExceptionMessage The process with $pro_uid: 'UidInexistente' does not exist. + * @expectedExceptionMessage The process with $pro_uid: 'IdDoesNotExists' does not exist. * * @author Brayan Pereyra (Cochalo) * @copyright Colosa - Bolivia @@ -106,7 +106,7 @@ class CasesTest extends \PHPUnit_Framework_TestCase { $this->oCases->getList(array( 'userId' => '00000000000000000000000000000001', - 'process' => 'UidInexistente' + 'process' => 'IdDoesNotExists' )); } @@ -115,7 +115,7 @@ class CasesTest extends \PHPUnit_Framework_TestCase * * @covers \BusinessModel\Cases::getList * @expectedException Exception - * @expectedExceptionMessage The category with $cat_uid: 'UidInexistente' does not exist. + * @expectedExceptionMessage The category with $cat_uid: 'IdDoesNotExists' does not exist. * * @author Brayan Pereyra (Cochalo) * @copyright Colosa - Bolivia @@ -124,7 +124,7 @@ class CasesTest extends \PHPUnit_Framework_TestCase { $this->oCases->getList(array( 'userId' => '00000000000000000000000000000001', - 'category' => 'UidInexistente' + 'category' => 'IdDoesNotExists' )); } @@ -133,7 +133,7 @@ class CasesTest extends \PHPUnit_Framework_TestCase * * @covers \BusinessModel\Cases::getList * @expectedException Exception - * @expectedExceptionMessage The user with $usr_uid: 'UidInexistente' does not exist. + * @expectedExceptionMessage The user with $usr_uid: 'IdDoesNotExists' does not exist. * * @author Brayan Pereyra (Cochalo) * @copyright Colosa - Bolivia @@ -142,7 +142,7 @@ class CasesTest extends \PHPUnit_Framework_TestCase { $this->oCases->getList(array( 'userId' => '00000000000000000000000000000001', - 'user' => 'UidInexistente' + 'user' => 'IdDoesNotExists' )); } @@ -151,7 +151,7 @@ class CasesTest extends \PHPUnit_Framework_TestCase * * @covers \BusinessModel\Cases::getList * @expectedException Exception - * @expectedExceptionMessage The value '2014-44-44' is not valid fot the format 'Y-m-d'. + * @expectedExceptionMessage The value '2014-44-44' is not a valid date for the format 'Y-m-d'. * * @author Brayan Pereyra (Cochalo) * @copyright Colosa - Bolivia @@ -169,7 +169,7 @@ class CasesTest extends \PHPUnit_Framework_TestCase * * @covers \BusinessModel\Cases::getList * @expectedException Exception - * @expectedExceptionMessage The value '2014-44-44' is not valid fot the format 'Y-m-d'. + * @expectedExceptionMessage The value '2014-44-44' is not a valid date for the format 'Y-m-d'. * * @author Brayan Pereyra (Cochalo) * @copyright Colosa - Bolivia From e434052cf65495a506a777fd7db823a5c8dd4ed0 Mon Sep 17 00:00:00 2001 From: Brayan Osmar Pereyra Suxo Date: Tue, 25 Mar 2014 16:22:28 -0400 Subject: [PATCH 2/2] Phpunit para CASES ACTIONS --- workflow/engine/src/BusinessModel/Cases.php | 35 +- .../engine/src/BusinessModel/Validator.php | 34 ++ .../BusinessModel/CasesActionTest13_17.php | 392 ++++++++++++++++++ 3 files changed, 453 insertions(+), 8 deletions(-) create mode 100644 workflow/engine/src/Tests/BusinessModel/CasesActionTest13_17.php diff --git a/workflow/engine/src/BusinessModel/Cases.php b/workflow/engine/src/BusinessModel/Cases.php index bcc76ad65..fb1d10f9b 100644 --- a/workflow/engine/src/BusinessModel/Cases.php +++ b/workflow/engine/src/BusinessModel/Cases.php @@ -636,12 +636,16 @@ class Cases * @copyright Colosa - Bolivia */ public function putCancelCase($app_uid, $usr_uid, $del_index = false) { - Validator::appUid($app_uid, '$cas_uid'); + Validator::isString($app_uid, '$app_uid'); + Validator::isString($usr_uid, '$usr_uid'); + + Validator::appUid($app_uid, '$app_uid'); Validator::usrUid($usr_uid, '$usr_uid'); if ($del_index === false) { $del_index = \AppDelegation::getCurrentIndex($app_uid); } + Validator::isInteger($del_index, '$del_index'); $case = new \Cases(); $case->cancelCase( $app_uid, $del_index, $usr_uid ); @@ -661,15 +665,20 @@ class Cases * @copyright Colosa - Bolivia */ public function putPauseCase($app_uid, $usr_uid, $del_index = false, $unpaused_date = null) { - Validator::appUid($app_uid, '$cas_uid'); + Validator::isString($app_uid, '$app_uid'); + Validator::isString($usr_uid, '$usr_uid'); + + Validator::appUid($app_uid, '$app_uid'); Validator::usrUid($usr_uid, '$usr_uid'); - if ($unpaused_date != null) { - Validator::isDate($unpaused_date, 'Y-m-d', '$unpaused_date'); - } if ($del_index === false) { $del_index = \AppDelegation::getCurrentIndex($app_uid); } + Validator::isInteger($del_index, '$del_index'); + + if ($unpaused_date != null) { + Validator::isDate($unpaused_date, 'Y-m-d', '$unpaused_date'); + } $case = new \Cases(); $case->pauseCase( $app_uid, $del_index, $usr_uid, $unpaused_date ); @@ -687,12 +696,16 @@ class Cases * @copyright Colosa - Bolivia */ public function putUnpauseCase($app_uid, $usr_uid, $del_index = false) { - Validator::appUid($app_uid, '$cas_uid'); + Validator::isString($app_uid, '$app_uid'); + Validator::isString($usr_uid, '$usr_uid'); + + Validator::appUid($app_uid, '$app_uid'); Validator::usrUid($usr_uid, '$usr_uid'); if ($del_index === false) { $del_index = \AppDelegation::getCurrentIndex($app_uid); } + Validator::isInteger($del_index, '$del_index'); $case = new \Cases(); $case->unpauseCase( $app_uid, $del_index, $usr_uid ); @@ -710,13 +723,18 @@ class Cases * @copyright Colosa - Bolivia */ public function putExecuteTriggerCase($app_uid, $tri_uid, $usr_uid, $del_index = false) { - Validator::appUid($app_uid, '$cas_uid'); + Validator::isString($app_uid, '$app_uid'); + Validator::isString($tri_uid, '$tri_uid'); + Validator::isString($usr_uid, '$usr_uid'); + + Validator::appUid($app_uid, '$app_uid'); Validator::triUid($tri_uid, '$tri_uid'); Validator::usrUid($usr_uid, '$usr_uid'); if ($del_index === false) { $del_index = \AppDelegation::getCurrentIndex($app_uid); } + Validator::isInteger($del_index, '$del_index'); $case = new \wsBase(); $case->executeTrigger( $usr_uid, $app_uid, $tri_uid, $del_index ); @@ -733,7 +751,8 @@ class Cases * @copyright Colosa - Bolivia */ public function deleteCase($app_uid) { - Validator::appUid($app_uid, '$cas_uid'); + Validator::isString($app_uid, '$app_uid'); + Validator::appUid($app_uid, '$app_uid'); $case = new \Cases(); $case->removeCase( $app_uid ); } diff --git a/workflow/engine/src/BusinessModel/Validator.php b/workflow/engine/src/BusinessModel/Validator.php index a02f7b786..88041e0a0 100644 --- a/workflow/engine/src/BusinessModel/Validator.php +++ b/workflow/engine/src/BusinessModel/Validator.php @@ -263,6 +263,40 @@ class Validator{ } } + /** + * Validate is string + * @var array $field. Field type string + * + * @access public + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @return void + */ + static public function isString($field, $nameField) + { + if (!is_string($field)) { + throw (new \Exception("Invalid value for '$nameField' it must be a string.")); + } + } + + /** + * Validate is integer + * @var array $field. Field type integer + * + * @access public + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @return void + */ + static public function isInteger($field, $nameField) + { + if (!is_integer($field)) { + throw (new \Exception("Invalid value for '$nameField' it must be a integer.")); + } + } + /** * Validate is boolean * @var boolean $field. Field type boolean diff --git a/workflow/engine/src/Tests/BusinessModel/CasesActionTest13_17.php b/workflow/engine/src/Tests/BusinessModel/CasesActionTest13_17.php new file mode 100644 index 000000000..861b7a7d3 --- /dev/null +++ b/workflow/engine/src/Tests/BusinessModel/CasesActionTest13_17.php @@ -0,0 +1,392 @@ + + * @copyright Colosa - Bolivia + * + * @protected + * @package Tests\BusinessModel + */ +class CasesAction13_17Test extends \PHPUnit_Framework_TestCase +{ + protected $oCases; + protected $nowCountTodo = 0; + protected $nowCountDraft = 0; + protected $nowCountPaused = 0; + protected $idCaseToDo = ''; + protected $idCaseDraft = ''; + + /** + * Set class for test + * + * @coversNothing + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function setUp() + { + \G::loadClass('pmFunctions'); + + $usrUid = '00000000000000000000000000000001'; + $proUid = '2317283235320c1a36972b2028131767'; + $tasUid = '7983935495320c1a75e1df6068322280'; + $idCaseToDo = PMFNewCase($proUid, $usrUid, $tasUid, array()); + PMFDerivateCase($idCaseToDo, 1); + $this->idCaseToDo = $idCaseToDo; + + $idCaseDraft = PMFNewCase($proUid, $usrUid, $tasUid, array()); + $this->idCaseDraft = $idCaseDraft; + + $this->oCases = new \BusinessModel\Cases(); + $listToDo = $this->oCases->getList(array('userId' => '00000000000000000000000000000001')); + $this->nowCountTodo = $listToDo['total']; + + $listDraft = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'draft')); + $this->nowCountDraft = $listDraft['total']; + + $listPaused = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'paused')); + $this->nowCountPaused = $listPaused['total']; + } + + /** + * Test error for type in first field the function + * + * @covers \BusinessModel\Cases::putCancelCase + * @expectedException Exception + * @expectedExceptionMessage Invalid value for '$app_uid' it must be a string. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutCancelCaseErrorAppUidArray() + { + $this->oCases->putCancelCase(array(), '00000000000000000000000000000001'); + } + + /** + * Test error for type in first field the function + * + * @covers \BusinessModel\Cases::putCancelCase + * @expectedException Exception + * @expectedExceptionMessage The application with $app_uid: 'IdDoesNotExists' does not exist. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutCancelCaseErrorAppUidIncorrect() + { + $this->oCases->putCancelCase('IdDoesNotExists', '00000000000000000000000000000001'); + } + + /** + * Test error for type in second field the function + * + * @covers \BusinessModel\Cases::putCancelCase + * @expectedException Exception + * @expectedExceptionMessage Invalid value for '$usr_uid' it must be a string. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutCancelCaseErrorUsrUidArray() + { + $this->oCases->putCancelCase($this->idCaseDraft, array()); + } + + /** + * Test error for type in second field the function + * + * @covers \BusinessModel\Cases::putCancelCase + * @expectedException Exception + * @expectedExceptionMessage The user with $usr_uid: 'IdDoesNotExists' does not exist. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutCancelCaseErrorUsrUidIncorrect() + { + $this->oCases->putCancelCase($this->idCaseDraft, 'IdDoesNotExists'); + } + + /** + * Test error for type in third field the function + * + * @covers \BusinessModel\Cases::putCancelCase + * @expectedException Exception + * @expectedExceptionMessage Invalid value for '$del_index' it must be a integer. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutCancelCaseErrorDelIndexIncorrect() + { + $this->oCases->putCancelCase($this->idCaseDraft, '00000000000000000000000000000001', 'string'); + } + + /** + * Test for cancel case + * + * @covers \BusinessModel\Cases::putCancelCase + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutCancelCase() + { + $this->oCases->putCancelCase($this->idCaseDraft, '00000000000000000000000000000001'); + $this->oCases = new \BusinessModel\Cases(); + $listDraft = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'draft')); + $this->assertNotEquals($this->nowCountDraft, $listDraft['total']); + } + + /** + * Test error for type in first field the function + * + * @covers \BusinessModel\Cases::putPauseCase + * @expectedException Exception + * @expectedExceptionMessage Invalid value for '$app_uid' it must be a string. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutPauseCaseErrorAppUidArray() + { + $this->oCases->putPauseCase(array(), '00000000000000000000000000000001'); + } + + /** + * Test error for type in first field the function + * + * @covers \BusinessModel\Cases::putPauseCase + * @expectedException Exception + * @expectedExceptionMessage The application with $app_uid: 'IdDoesNotExists' does not exist. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutPauseCaseErrorAppUidIncorrect() + { + $this->oCases->putPauseCase('IdDoesNotExists', '00000000000000000000000000000001'); + } + + /** + * Test error for type in second field the function + * + * @covers \BusinessModel\Cases::putPauseCase + * @expectedException Exception + * @expectedExceptionMessage Invalid value for '$usr_uid' it must be a string. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutPauseCaseErrorUsrUidArray() + { + $this->oCases->putPauseCase($this->idCaseDraft, array()); + } + + /** + * Test error for type in second field the function + * + * @covers \BusinessModel\Cases::putPauseCase + * @expectedException Exception + * @expectedExceptionMessage The user with $usr_uid: 'IdDoesNotExists' does not exist. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutPauseCaseErrorUsrUidIncorrect() + { + $this->oCases->putPauseCase($this->idCaseDraft, 'IdDoesNotExists'); + } + + /** + * Test error for type in third field the function + * + * @covers \BusinessModel\Cases::putPauseCase + * @expectedException Exception + * @expectedExceptionMessage Invalid value for '$del_index' it must be a integer. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutPauseCaseErrorDelIndexIncorrect() + { + $this->oCases->putPauseCase($this->idCaseDraft, '00000000000000000000000000000001', 'string'); + } + + /** + * Test error for type in fourth field the function + * + * @covers \BusinessModel\Cases::putPauseCase + * @expectedException Exception + * @expectedExceptionMessage The value '2014-44-44' is not a valid date for the format 'Y-m-d'. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutPauseCaseErrorDateIncorrect() + { + $this->oCases->putPauseCase($this->idCaseDraft, '00000000000000000000000000000001', false, '2014-44-44'); + } + + /** + * Test for cancel case + * + * @covers \BusinessModel\Cases::putPauseCase + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutPauseCase() + { + $this->oCases->putPauseCase($this->idCaseToDo, '00000000000000000000000000000001'); + $this->oCases = new \BusinessModel\Cases(); + $listPaused = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'paused')); + $this->assertNotEquals($this->nowCountPaused, $listPaused['total']); + } + + /** + * Test error for type in first field the function + * + * @covers \BusinessModel\Cases::putUnpauseCase + * @expectedException Exception + * @expectedExceptionMessage Invalid value for '$app_uid' it must be a string. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutUnpauseCaseErrorAppUidArray() + { + $this->oCases->putUnpauseCase(array(), '00000000000000000000000000000001'); + } + + /** + * Test error for type in first field the function + * + * @covers \BusinessModel\Cases::putUnpauseCase + * @expectedException Exception + * @expectedExceptionMessage The application with $app_uid: 'IdDoesNotExists' does not exist. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutUnpauseCaseErrorAppUidIncorrect() + { + $this->oCases->putUnpauseCase('IdDoesNotExists', '00000000000000000000000000000001'); + } + + /** + * Test error for type in second field the function + * + * @covers \BusinessModel\Cases::putUnpauseCase + * @expectedException Exception + * @expectedExceptionMessage Invalid value for '$usr_uid' it must be a string. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutUnpauseCaseErrorUsrUidArray() + { + $this->oCases->putUnpauseCase($this->idCaseDraft, array()); + } + + /** + * Test error for type in second field the function + * + * @covers \BusinessModel\Cases::putUnpauseCase + * @expectedException Exception + * @expectedExceptionMessage The user with $usr_uid: 'IdDoesNotExists' does not exist. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutUnpauseCaseErrorUsrUidIncorrect() + { + $this->oCases->putUnpauseCase($this->idCaseDraft, 'IdDoesNotExists'); + } + + /** + * Test error for type in third field the function + * + * @covers \BusinessModel\Cases::putUnpauseCase + * @expectedException Exception + * @expectedExceptionMessage Invalid value for '$del_index' it must be a integer. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutUnpauseCaseErrorDelIndexIncorrect() + { + $this->oCases->putUnpauseCase($this->idCaseDraft, '00000000000000000000000000000001', 'string'); + } + + /** + * Test for cancel case + * + * @covers \BusinessModel\Cases::putUnpauseCase + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testPutUnpauseCase() + { + $this->oCases->putUnpauseCase($this->idCaseToDo, '00000000000000000000000000000001'); + $this->oCases = new \BusinessModel\Cases(); + $listPaused = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'paused')); + $this->assertEquals($this->nowCountPaused, $listPaused['total']); + } + + /** + * Test error for type in first field the function + * + * @covers \BusinessModel\Cases::deleteCase + * @expectedException Exception + * @expectedExceptionMessage Invalid value for '$app_uid' it must be a string. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testDeleteCaseErrorAppUidArray() + { + $this->oCases->deleteCase(array()); + } + + /** + * Test error for type in first field the function + * + * @covers \BusinessModel\Cases::deleteCase + * @expectedException Exception + * @expectedExceptionMessage The application with $app_uid: 'IdDoesNotExists' does not exist. + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testDeleteCaseErrorAppUidIncorrect() + { + $this->oCases->deleteCase('IdDoesNotExists'); + } + + /** + * Test for cancel case + * + * @covers \BusinessModel\Cases::deleteCase + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function testDeleteCase() + { + $this->oCases->deleteCase($this->idCaseToDo); + $this->oCases = new \BusinessModel\Cases(); + $listToDo = $this->oCases->getList(array('userId' => '00000000000000000000000000000001')); + $this->assertNotEquals($this->nowCountTodo, $listToDo['total']); + } +} \ No newline at end of file