diff --git a/database/factories/ApplicationFactory.php b/database/factories/ApplicationFactory.php index ca6e89756..c545b3e11 100644 --- a/database/factories/ApplicationFactory.php +++ b/database/factories/ApplicationFactory.php @@ -56,6 +56,7 @@ $factory->state(\ProcessMaker\Model\Application::class, 'foreign_keys', function 'APP_PROC_CODE' => '', 'APP_PARALLEL' => 'N', 'APP_INIT_USER' => $user->USR_UID, + 'APP_INIT_USER_ID' => $user->USR_ID, 'APP_CUR_USER' => $user->USR_UID, 'APP_PIN' => G::generateUniqueID(), 'APP_CREATE_DATE' => $faker->dateTime(), @@ -84,10 +85,14 @@ $factory->state(\ProcessMaker\Model\Application::class, 'todo', function (Faker }); $factory->state(\ProcessMaker\Model\Application::class, 'draft', function (Faker $faker) { + $user = factory(\ProcessMaker\Model\User::class)->create(); + return [ 'APP_NUMBER' => $faker->unique()->numberBetween(1000), 'APP_STATUS_ID' => 1, - 'APP_STATUS' => 'DRAFT' + 'APP_STATUS' => 'DRAFT', + 'APP_INIT_USER' => $user->USR_UID, + 'APP_INIT_USER_ID' => $user->USR_ID, ]; }); diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php index ca9269c31..49fa8ac94 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php @@ -143,6 +143,22 @@ class AbstractCasesTest extends TestCase $this->assertEquals($users->USR_ID, $actual); } + /** + * This check the getter and setter related to the user sender + * + * @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setSendBy() + * @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getSendBy() + * @test + */ + public function it_return_set_get_user_send() + { + $users = factory(User::class)->create(); + $absCases = new AbstractCases(); + $absCases->setSendBy($users->USR_UID); + $actual = $absCases->getSendBy(); + $this->assertEquals($users->USR_UID, $actual); + } + /** * This check the getter and setter related to the priority * diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php index 6c7931c4c..427fce0ed 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php @@ -40,12 +40,11 @@ class DraftTest extends TestCase public function createDraft() { $application = factory(Application::class)->states('draft')->create(); - $usrId = User::getId($application['APP_INIT_USER']); $delegation = factory(Delegation::class)->states('foreign_keys')->create([ 'DEL_THREAD_STATUS' => 'OPEN', 'DEL_INDEX' => 1, 'USR_UID' => $application->APP_INIT_USER, - 'USR_ID' => $usrId, + 'USR_ID' => $application->APP_INIT_USER_ID, 'APP_UID' => $application->APP_UID, 'APP_NUMBER' => $application->APP_NUMBER, ]); @@ -66,6 +65,7 @@ class DraftTest extends TestCase for ($i = 0; $i < $cases; $i = $i + 1) { $application = factory(Application::class)->states('draft')->create([ 'APP_INIT_USER' => $user->USR_UID, + 'APP_INIT_USER_ID' => $user->USR_ID, 'APP_CUR_USER' => $user->USR_UID, ]); factory(Delegation::class)->states('foreign_keys')->create([ @@ -73,7 +73,8 @@ class DraftTest extends TestCase 'DEL_INDEX' => 1, 'APP_UID' => $application->APP_UID, 'APP_NUMBER' => $application->APP_NUMBER, - 'USR_ID' => $user->USR_ID + 'USR_UID' => $application->APP_INIT_USER, + 'USR_ID' => $application->APP_INIT_USER_ID, ]); } diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php index ae47e2ffa..2b9e5b92c 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php @@ -104,7 +104,7 @@ class ApplicationTest extends TestCase public function it_return_scope_creator() { $table = factory(Application::class)->states('foreign_keys')->create(); - $this->assertCount(1, $table->creator($table->APP_INIT_USER)->get()); + $this->assertCount(1, $table->creator($table->APP_INIT_USER_ID)->get()); } /** diff --git a/workflow/engine/classes/Derivation.php b/workflow/engine/classes/Derivation.php index 1ad2fbbff..405725933 100644 --- a/workflow/engine/classes/Derivation.php +++ b/workflow/engine/classes/Derivation.php @@ -1090,7 +1090,9 @@ class Derivation // Load Case Data again because the information could be change in method "doDerivation" $lastData = $this->case->loadCase($appUid); // Update the thread title related to the last index created - $this->case->updateThreadTitle($appUid, $lastData['APP_NUMBER'], $iNewDelIndex, $lastData['APP_DATA']); + if (!is_null($iNewDelIndex)) { + $this->case->updateThreadTitle($appUid, $lastData['APP_NUMBER'], $iNewDelIndex, $lastData['APP_DATA']); + } $appFields['APP_DATA'] = $lastData['APP_DATA']; // When the users route the case in the same time if($iNewDelIndex !== 0) { diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php index dbe64bf4d..d8ca562a7 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php @@ -332,6 +332,26 @@ class AbstractCases implements CasesInterface return $this->userStarted; } + /** + * Set send by + * + * @param type $sendBy + */ + public function setSendBy(string $sendBy) + { + $this->sendBy = $sendBy; + } + + /** + * Get send by. + * + * @return string + */ + public function getSendBy() + { + return $this->sendBy; + } + /** * Set value to search * @@ -752,26 +772,6 @@ class AbstractCases implements CasesInterface return $this->casesUids; } - /** - * Set send by. - * - * @param type $sendBy - */ - public function setSendBy(string $sendBy) - { - $this->sendBy = $sendBy; - } - - /** - * Get send by. - * - * @return string - */ - public function getSendBy() - { - return $this->sendBy; - } - /** * Set Cases Numbers * diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php index 21df184d9..a24d07631 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php @@ -150,7 +150,7 @@ class Draft extends AbstractCases // Add the initial scope for draft cases $query->statusId(Application::STATUS_DRAFT); // Filter the creator - $query->creator($this->getUserUid()); + $query->creator($this->getUserId()); // Return the number of rows return $query->count(['APPLICATION.APP_NUMBER']); }