From 0cf80ca6a0b9139542aa0af2b041b1ac419ea9eb Mon Sep 17 00:00:00 2001 From: Andrea Adamczyk Date: Wed, 31 Jul 2019 11:46:12 -0400 Subject: [PATCH] PMC-1019 --- .../engine/classes/model/IsoCountryTest.php | 41 +++++++++++ .../engine/classes/model/IsoLocationTest.php | 41 +++++++++++ .../classes/model/IsoSubdivisionTest.php | 41 +++++++++++ .../engine/methods/users/UsersAjaxTest.php | 71 +++++++++++++++++++ .../src/ProcessMaker/Model/Configuration.php | 2 + 5 files changed, 196 insertions(+) create mode 100644 tests/unit/workflow/engine/classes/model/IsoCountryTest.php create mode 100644 tests/unit/workflow/engine/classes/model/IsoLocationTest.php create mode 100644 tests/unit/workflow/engine/classes/model/IsoSubdivisionTest.php create mode 100644 tests/unit/workflow/engine/methods/users/UsersAjaxTest.php diff --git a/tests/unit/workflow/engine/classes/model/IsoCountryTest.php b/tests/unit/workflow/engine/classes/model/IsoCountryTest.php new file mode 100644 index 000000000..02cdb6e67 --- /dev/null +++ b/tests/unit/workflow/engine/classes/model/IsoCountryTest.php @@ -0,0 +1,41 @@ +assertEquals('Bolivia', $res['IC_NAME']); + + //Call the findById method + $res = IsoCountry::findById('DE'); + //Assert the result is the expected + $this->assertEquals('Germany', $res['IC_NAME']); + + } + + /** + * It tests the result is null if the country does not exist + * + * @test + */ + public function it_should_return_null_if_the_country_does_not_exist() + { + //Call the findById method + $res = IsoCountry::findById('ZZ'); + //Assert the result is null + $this->assertNull($res); + } +} \ No newline at end of file diff --git a/tests/unit/workflow/engine/classes/model/IsoLocationTest.php b/tests/unit/workflow/engine/classes/model/IsoLocationTest.php new file mode 100644 index 000000000..45179090e --- /dev/null +++ b/tests/unit/workflow/engine/classes/model/IsoLocationTest.php @@ -0,0 +1,41 @@ +assertEquals('Cochabamba', $res['IL_NAME']); + + //Call the findById method + $res = IsoLocation::findById('DE', 'NW', 'DUN'); + //Assert the result is the expected + $this->assertEquals('Dulmen', $res['IL_NAME']); + + } + + /** + * It tests the result is null if the location does not exist + * + * @test + */ + public function it_should_return_null_if_the_location_does_not_exist() + { + //Call the findById method + $res = IsoLocation::findById('ZZ', 'ZZ', 'ZZ'); + //Assert the result is null + $this->assertNull($res); + } +} \ No newline at end of file diff --git a/tests/unit/workflow/engine/classes/model/IsoSubdivisionTest.php b/tests/unit/workflow/engine/classes/model/IsoSubdivisionTest.php new file mode 100644 index 000000000..64eecff19 --- /dev/null +++ b/tests/unit/workflow/engine/classes/model/IsoSubdivisionTest.php @@ -0,0 +1,41 @@ +assertEquals('La Paz', $res['IS_NAME']); + + //Call the findById method + $res = IsoSubdivision::findById('DE', 'BE'); + //Assert the result is the expected + $this->assertEquals('Berlin', $res['IS_NAME']); + + } + + /** + * It tests the result is null if the subdivision does not exist + * + * @test + */ + public function it_should_return_null_if_the_subdivision_does_not_exist() + { + //Call the findById method + $res = IsoSubdivision::findById('ZZ', 'ZZ'); + //Assert the result is null + $this->assertNull($res); + } +} \ No newline at end of file diff --git a/tests/unit/workflow/engine/methods/users/UsersAjaxTest.php b/tests/unit/workflow/engine/methods/users/UsersAjaxTest.php new file mode 100644 index 000000000..a04a43364 --- /dev/null +++ b/tests/unit/workflow/engine/methods/users/UsersAjaxTest.php @@ -0,0 +1,71 @@ +create(); + //Creates the configuration factory + factory(Configuration::class)->create([ + 'CFG_UID' => 'USER_PREFERENCES', + 'OBJ_UID' => '', + 'CFG_VALUE' => 'a:3:{s:12:"DEFAULT_LANG";s:0:"";s:12:"DEFAULT_MENU";s:8:"PM_SETUP";s:18:"DEFAULT_CASES_MENU";s:0:"";}', + 'PRO_UID' => '', + 'USR_UID' => $user['USR_UID'], + 'APP_UID' => '', + ]); + + //Sets the needed variables + $_SESSION['USER_LOGGED'] = $user['USR_UID']; + $_POST['action'] = 'userData'; + $_POST['USR_UID'] = $user['USR_UID']; + $RBAC = RBAC::getSingleton(PATH_DATA, session_id()); + $RBAC->initRBAC(); + $RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']); + + //Turn on output buffering + ob_start(); + + //Call the tested file + require_once PATH_TRUNK . PATH_SEP . 'workflow/engine/methods/users/usersAjax.php'; + + //Return the contents of the output buffer + $outputBuffer = ob_get_contents(); + //Clean the output buffer and turn off output buffering + ob_end_clean(); + + //Decode the JSON string + $res = json_decode($outputBuffer); + + //Assert the call was success + $this->assertTrue($res->success); + //Assert the result corresponds to the user logged + $this->assertEquals($user['USR_UID'], $res->user->USR_UID); + //Assert the default menu is set + $this->assertEquals('PM_EDIT_USER_PROFILE_DEFAULT_MAIN_MENU_OPTIONS', + $res->permission->PREF_DEFAULT_MENUSELECTED); + } +} \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Model/Configuration.php b/workflow/engine/src/ProcessMaker/Model/Configuration.php index 6579b691b..6ca5d7c02 100644 --- a/workflow/engine/src/ProcessMaker/Model/Configuration.php +++ b/workflow/engine/src/ProcessMaker/Model/Configuration.php @@ -12,4 +12,6 @@ class Configuration extends Model protected $primaryKey = ['CFG_UID', 'OBJ_UID', 'PRO_UID', 'USR_UID', 'APP_UID']; // No timestamps public $timestamps = false; + + public $incrementing = false; }