From 8050fea45362840ad4f9e54a6d35bb343cd298f7 Mon Sep 17 00:00:00 2001 From: Marco Antonio Nina Mena Date: Fri, 11 May 2018 12:12:46 -0400 Subject: [PATCH 1/3] Change model Dynaform --- .../Api/Designer/DynaformController.php | 10 +- ProcessMaker/Managers/DynaformManager.php | 33 +- ProcessMaker/Model/Dynaform.php | 100 ++-- database/factories/DynaformFactory.php | 14 +- ...018_04_11_183825_create_DYNAFORM_table.php | 60 ++- ...2018_04_12_123951_update_process_table.php | 457 ------------------ ...018_04_26_000001_update_various_tables.php | 2 +- .../2018_05_02_124700_update_dynaform.php | 42 -- .../Api/Designer/DynaformManagerTest.php | 164 +++---- 9 files changed, 187 insertions(+), 695 deletions(-) delete mode 100644 database/migrations/2018_04_12_123951_update_process_table.php delete mode 100644 database/migrations/2018_05_02_124700_update_dynaform.php diff --git a/ProcessMaker/Http/Controllers/Api/Designer/DynaformController.php b/ProcessMaker/Http/Controllers/Api/Designer/DynaformController.php index 2865917788..bb27e8b24e 100644 --- a/ProcessMaker/Http/Controllers/Api/Designer/DynaformController.php +++ b/ProcessMaker/Http/Controllers/Api/Designer/DynaformController.php @@ -51,8 +51,8 @@ public function show(Process $process, Dynaform $dynaform) public function store(Process $process, Request $request) { $data = [ - 'DYN_TITLE' => $request->input('dyn_title', ''), - 'DYN_DESCRIPTION' => $request->input('dyn_description', '') + 'title' => $request->input('dyn_title', ''), + 'description' => $request->input('dyn_description', '') ]; $data = array_merge($data, $this->formatData($request, ['dyn_content'])); @@ -111,7 +111,7 @@ public function remove(Process $process, Dynaform $dynaform) */ private function belongsToProcess(Process $process, Dynaform $dynaform): void { - if ($process->PRO_ID !== $dynaform->PRO_ID) { + if ($process->id !== $dynaform->process_id) { Throw new DoesNotBelongToProcessException(__('The Dynaform does not belong to this process.')); } } @@ -124,12 +124,12 @@ private function belongsToProcess(Process $process, Dynaform $dynaform): void * * @return array */ - private function formatData(Request $request, array $fields) + private function formatData(Request $request, array $fields): array { $data = []; foreach ($fields as $field) { if ($request->has($field)) { - $data[strtoupper($field)] = $request->input($field); + $data[substr($field, 4)] = $request->input($field); } } return $data; diff --git a/ProcessMaker/Managers/DynaformManager.php b/ProcessMaker/Managers/DynaformManager.php index 797916f64f..6e4702b25e 100644 --- a/ProcessMaker/Managers/DynaformManager.php +++ b/ProcessMaker/Managers/DynaformManager.php @@ -23,7 +23,7 @@ class DynaformManager */ public function index(Process $process): Paginator { - return Dynaform::where('PRO_UID', $process->PRO_UID)->simplePaginate(20); + return Dynaform::where('process_id', $process->id)->simplePaginate(20); } /** @@ -39,12 +39,12 @@ public function save(Process $process, $data): Dynaform { $this->validate($data); - $data['DYN_UID'] = str_replace('-', '', Uuid::uuid4()); - $data['PRO_UID'] = $process->PRO_UID; - $data['PRO_ID'] = $process->PRO_ID; + $data['uid'] = Uuid::uuid4(); +// $data['PRO_UID'] = $process->uid; + $data['process_id'] = $process->id; - if (!isset($data['DYN_CONTENT']) || empty($data['DYN_CONTENT'])) { - $data['DYN_CONTENT'] = $this->generateContent($data['DYN_UID'], $data['DYN_TITLE'], $data['DYN_DESCRIPTION']); + if (!isset($data['content']) || empty($data['content'])) { + $data['content'] = $this->generateContent($data['uid'], $data['title'], $data['description']); } $dynaform = new Dynaform(); @@ -66,23 +66,23 @@ public function save(Process $process, $data): Dynaform public function copyImport(Process $process, $data): Dynaform { $this->validate($data); - $oldProcess = Process::where('PRO_UID', $data['COPY_IMPORT']['pro_uid'])->get(); + $oldProcess = Process::where('uid', $data['COPY_IMPORT']['pro_uid'])->get(); if ($oldProcess->isEmpty()) { throw new ModelNotFoundException(__('The process not exists.')); } - $copyDynaform = Dynaform::where('DYN_UID', $data['COPY_IMPORT']['dyn_uid'])->get(); + $copyDynaform = Dynaform::where('uid', $data['COPY_IMPORT']['dyn_uid'])->get(); if ($copyDynaform->isEmpty()) { throw new ModelNotFoundException(__('The Dynaform not exists')); } - if ($oldProcess->first()->PRO_ID !== $copyDynaform->first()->PRO_ID) { + if ($oldProcess->first()->id !== $copyDynaform->first()->process_id) { Throw new DoesNotBelongToProcessException(__('The Dynaform does not belong to this process.')); } - if (!isset($data['DYN_CONTENT'])) { - $data['DYN_CONTENT'] = $copyDynaform->first()->DYN_CONTENT; + if (!isset($data['content'])) { + $data['content'] = $copyDynaform->first()->content; } unset($data['COPY_IMPORT']); @@ -102,12 +102,11 @@ public function copyImport(Process $process, $data): Dynaform */ public function update(Process $process, Dynaform $dynaform, $data): Dynaform { - $data['PRO_UID'] = $process->PRO_UID; - $data['PRO_ID'] = $process->PRO_ID; + $data['process_id'] = $process->id; $dynaform->fill($data); $this->validate($dynaform->toArray()); - if (empty($dynaform->DYN_CONTENT)) { - $dynaform->DYN_CONTENT = $this->generateContent($dynaform->DYN_UID, $dynaform->DYN_TITLE, $dynaform->DYN_DESCRIPTION); + if (empty($dynaform->content)) { + $dynaform->content = $this->generateContent($dynaform->uid, $dynaform->title, $dynaform->description); } $dynaform->saveOrFail(); return $dynaform; @@ -147,8 +146,8 @@ private function validate($data): void $data, [ 'COPY_IMPORT' => 'required|array', - 'COPY_IMPORT.pro_uid' => 'required|string|max:32', - 'COPY_IMPORT.dyn_uid' => 'required|string|max:32' + 'COPY_IMPORT.pro_uid' => 'required|string|max:36', + 'COPY_IMPORT.dyn_uid' => 'required|string|max:36' ] ); if ($validator->fails()) { diff --git a/ProcessMaker/Model/Dynaform.php b/ProcessMaker/Model/Dynaform.php index 1d948b76c5..50fcb60e9c 100644 --- a/ProcessMaker/Model/Dynaform.php +++ b/ProcessMaker/Model/Dynaform.php @@ -4,79 +4,71 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; +use ProcessMaker\Model\Traits\Uuid; use Watson\Validating\ValidatingTrait; /** * Class dynaform + * * @package ProcessMaker\Model * - * @property int DYN_ID - * @property string DYN_UID - * @property int PRO_ID - * @property string PRO_UID - * @property string DYN_TITLE - * @property string DYN_DESCRIPTION - * @property array DYN_CONTENT - * @property string DYN_LABEL - * @property Carbon DYN_UPDATE_DATE + * @property int id + * @property string uid + * @property int process_id + * @property string title + * @property string description + * @property array content + * @property string label + * @property Carbon type * */ class Dynaform extends Model { use ValidatingTrait; + use Uuid; - protected $table = 'DYNAFORM'; - protected $primaryKey = 'DYN_ID'; - - const CREATED_AT = null; - - /** - * The name of the "updated at" column. - */ - const UPDATED_AT = 'DYN_UPDATE_DATE'; + protected $table = 'dynaform'; protected $fillable = [ - 'DYN_UID', - 'PRO_ID', - 'PRO_UID', - 'DYN_TITLE', - 'DYN_DESCRIPTION', - 'DYN_CONTENT', - 'DYN_LABEL', - 'DYN_UPDATE_DATE' + 'uid', + 'title', + 'description', + 'content', + 'label', + 'type', + 'created_at', + 'updated_at', + 'process_id', ]; protected $attributes = [ - 'DYN_UID' => null, - 'PRO_ID' => '', - 'PRO_UID' => null, - 'DYN_TITLE' => null, - 'DYN_DESCRIPTION' => null, - 'DYN_CONTENT' => null, - 'DYN_LABEL' => null, - 'DYN_UPDATE_DATE' => null, + 'uid' => null, + 'process_id' => '', + 'title' => null, + 'description' => null, + 'content' => null, + 'label' => null, + 'type' => 'form', ]; protected $casts = [ - 'DYN_UID' => 'string', - 'PRO_ID' => 'int', - 'PRO_UID' => 'string', - 'DYN_TITLE' => 'string', - 'DYN_DESCRIPTION' => 'string', - 'DYN_CONTENT' => 'array', - 'DYN_LABEL' => 'string', - 'DYN_UPDATE_DATE' => 'string', + 'uid' => 'string', + 'process_id' => 'int', + 'title' => 'string', + 'description' => 'string', + 'content' => 'array', + 'label' => 'string', + 'type' => 'string', ]; protected $rules = [ - 'DYN_UID' => 'required|max:32', - 'PRO_ID' => 'required', - 'PRO_UID' => 'required|max:32', - 'DYN_TITLE' => 'required|unique:DYNAFORM,DYN_TITLE', + 'uid' => 'required|max:36', + 'process_id' => 'exists:processes,id', + 'title' => 'required|unique:dynaform,title', ]; protected $validationMessages = [ - 'DYN_TITLE.unique' => 'A Dynaform with the same name already exists in this process.' + 'title.unique' => 'A Dynaform with the same name already exists in this process.' ]; /** @@ -84,33 +76,33 @@ class Dynaform extends Model * * @return string */ - public function getRouteKeyName() + public function getRouteKeyName(): string { - return 'DYN_UID'; + return 'uid'; } /** - * Accessor DYN_CONTENT to json + * Accessor content to json * * @param $value * * @return array|null */ - public function getDynContentAttribute($value): ?array + public function getContentAttribute($value): ?array { return json_decode($value, true); } /** - * Mutator DYN_CONTENT json decode + * Mutator content json decode * * @param $value * * @return void */ - public function setDynContentAttribute($value): void + public function setContentAttribute($value): void { - $this->attributes['DYN_CONTENT'] = empty($value) ? null : json_encode($value); + $this->attributes['content'] = empty($value) ? null : json_encode($value); } } diff --git a/database/factories/DynaformFactory.php b/database/factories/DynaformFactory.php index 98b4c6e91f..0d43df1e30 100644 --- a/database/factories/DynaformFactory.php +++ b/database/factories/DynaformFactory.php @@ -1,20 +1,20 @@ define(Dynaform::class, function (Faker $faker) { - $pro = factory(Process::class)->create(); return [ - 'DYN_UID' => str_replace('-', '', Uuid::uuid4()), - 'PRO_ID' => $pro->PRO_ID, - 'PRO_UID' => $pro->PRO_UID, - 'DYN_TITLE' => $faker->sentence(3), - 'DYN_DESCRIPTION' => $faker->sentence(5) + 'uid' => Uuid::uuid4(), + 'process_id' => function () { + return factory(Process::class)->create()->id; + }, + 'title' => $faker->sentence(3), + 'description' => $faker->sentence(5) ]; }); \ No newline at end of file diff --git a/database/migrations/2018_04_11_183825_create_DYNAFORM_table.php b/database/migrations/2018_04_11_183825_create_DYNAFORM_table.php index c1c6075caf..22aa796241 100644 --- a/database/migrations/2018_04_11_183825_create_DYNAFORM_table.php +++ b/database/migrations/2018_04_11_183825_create_DYNAFORM_table.php @@ -3,39 +3,37 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateDYNAFORMTable extends Migration { +class CreateDYNAFORMTable extends Migration +{ - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('DYNAFORM', function(Blueprint $table) - { - $table->string('DYN_UID', 32)->default('')->primary(); - $table->text('DYN_TITLE', 16777215); - $table->text('DYN_DESCRIPTION', 16777215)->nullable(); - $table->string('PRO_UID', 32)->default('0'); - $table->string('DYN_TYPE', 20)->default('xmlform'); - $table->string('DYN_FILENAME', 100)->default(''); - $table->text('DYN_CONTENT', 16777215)->nullable(); - $table->text('DYN_LABEL', 16777215)->nullable(); - $table->integer('DYN_VERSION'); - $table->dateTime('DYN_UPDATE_DATE')->nullable(); - }); - } + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('dynaform', function (Blueprint $table) { + $table->increments('id'); + $table->uuid('uid')->unique(); + $table->text('title', 16777215); + $table->text('description', 16777215)->nullable(); + $table->string('type', 20)->default('form'); + $table->text('content', 16777215)->nullable(); + $table->text('label', 16777215)->nullable(); + $table->timestamps(); + }); + } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('DYNAFORM'); - } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('dynaform'); + } } diff --git a/database/migrations/2018_04_12_123951_update_process_table.php b/database/migrations/2018_04_12_123951_update_process_table.php deleted file mode 100644 index 83acd090d6..0000000000 --- a/database/migrations/2018_04_12_123951_update_process_table.php +++ /dev/null @@ -1,457 +0,0 @@ -dropForeign('fk_bpmn_diagram_project'); - $table->dropColumn('PRJ_UID'); - }); - Schema::table('BPMN_BOUND', function(Blueprint $table) { - $table->dropForeign('fk_bpmn_bound_project'); - $table->dropColumn('PRJ_UID'); - }); - Schema::table('BPMN_ACTIVITY', function(Blueprint $table) { - $table->dropForeign('fk_bpmn_activity_project'); - $table->dropColumn('PRJ_UID'); - $table->dropForeign('fk_bpmn_activity_process'); - $table->dropColumn('PRO_UID'); - }); - Schema::table('BPMN_EVENT', function(Blueprint $table) { - $table->dropForeign('fk_bpmn_event_project'); - $table->dropColumn('PRJ_UID'); - $table->dropForeign('fk_bpmn_event_process'); - $table->dropColumn('PRO_UID'); - }); - Schema::table('BPMN_GATEWAY', function(Blueprint $table) { - $table->dropForeign('fk_bpmn_gateway_project'); - $table->dropColumn('PRJ_UID'); - $table->dropForeign('fk_bpmn_gateway_process'); - $table->dropColumn('PRO_UID'); - }); - Schema::table('BPMN_FLOW', function(Blueprint $table) { - $table->dropForeign('fk_bpmn_flow_project'); - $table->dropColumn('PRJ_UID'); - $table->dropForeign('fk_bpmn_flow_diagram'); - }); - Schema::table('BPMN_ARTIFACT', function(Blueprint $table) { - $table->dropForeign('fk_bpmn_artifact_project'); - $table->dropColumn('PRJ_UID'); - $table->dropForeign('fk_bpmn_artifact_process'); - $table->dropColumn('PRO_UID'); - }); - Schema::table('EMAIL_EVENT', function(Blueprint $table) { - $table->dropColumn('PRJ_UID'); - }); - Schema::table('PROCESS', function(Blueprint $table) { - //From the merge of PROJECT and PROCESS, PRO_NAME was chosen - $table->renameColumn('PRO_TITLE', 'PRO_NAME'); - //PRO_TYPE_PROCESS defines if the process is PRIVATE o PUBLIC - // then PRO_VISIBILITY describes better this behavior. - $table->renameColumn('PRO_TYPE_PROCESS', 'PRO_VISIBILITY'); - //Not used, this property is defined at the TASK. - $table->dropColumn('PRO_TYPE_DAY'); - //Industry and sub category is not being used. - $table->dropColumn('PRO_INDUSTRY'); - $table->dropColumn('PRO_SUB_CATEGORY'); - //Not used, this property is defined at the TASK. - $table->dropColumn('PRO_ASSIGNMENT'); - - //Columns merged from BPMN_PROCESS - $table->string('DIA_UID', 32)->nullable()->default(null); - $table->tinyInteger('PRO_IS_EXECUTABLE')->default('0'); - $table->tinyInteger('PRO_IS_CLOSED')->default('0'); - $table->tinyInteger('PRO_IS_SUBPROCESS')->default('0'); - - //Columns merged from PROJECT - $table->mediumText('PRO_TARGET_NAMESPACE')->nullable()->default(null); - $table->mediumText('PRO_EXPRESSION_LANGUAGE')->nullable()->default(null); - $table->mediumText('PRO_TYPE_LANGUAGE')->nullable()->default(null); - $table->mediumText('PRO_EXPORTER')->nullable()->default(null); - $table->mediumText('PRO_EXPORTER_VERSION')->nullable()->default(null); - $table->mediumText('PRO_AUTHOR')->nullable()->default(null); - $table->mediumText('PRO_AUTHOR_VERSION')->nullable()->default(null); - $table->mediumText('PRO_ORIGINAL_SOURCE')->nullable()->default(null); - }); - - //DELETE THE PROCESS DEFINITION WHEN THE PROCESS IS DELETED - - //BPMN ACTIVITIES - Schema::table('BPMN_ACTIVITY', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //BPMN ARTIFACTS - Schema::table('BPMN_ARTIFACT', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //BPMN BOUNDS - Schema::table('BPMN_BOUND', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //BPMN DATA SHAPES - Schema::table('BPMN_DATA', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //BPMN DIAGRAM(S) - Schema::table('BPMN_DIAGRAM', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //BPMN DOCUMENTATIONS - Schema::table('BPMN_DOCUMENTATION', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //BPMN EVENTS - Schema::table('BPMN_EVENT', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //BPMN EXTENSIONS - Schema::table('BPMN_EXTENSION', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //BPMN FLOWS - Schema::table('BPMN_FLOW', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //BPMN GATEWAYS - Schema::table('BPMN_GATEWAY', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //BPMN LANES - Schema::table('BPMN_LANE', function(Blueprint $table) { - $table->dropForeign('fk_bpmn_lane_project'); - $table->dropColumn('PRJ_UID'); - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //BPMN LANESETS - Schema::table('BPMN_LANESET', function(Blueprint $table) { - $table->dropForeign('fk_bpmn_laneset_project'); - $table->dropColumn('PRJ_UID'); - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - $table->dropColumn('LNS_STATE'); - }); - - //BPMN PARTICIPANTS - Schema::table('BPMN_PARTICIPANT', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //PROCESS SCHEDULED START CASES (CLASSIC) - Schema::table('CASE_SCHEDULER', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //LOG OF PROCESS CASES SCHEDULER - Schema::table('LOG_CASES_SCHEDULER', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //PROCESS CASE TRACKER GENERAL CONFIGURATION - Schema::table('CASE_TRACKER', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //PROCESS CASE TRACKER OBJECTS CONFIGURATION (CLASSIC) - Schema::table('CASE_TRACKER_OBJECT', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //DB SOURCE CONNECTIONS - Schema::table('DB_SOURCE', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //DYNAFORMS - Schema::table('DYNAFORM', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //ELEMENT(GATEWAY, EVENT) TO DUMMY TASK RELATIONS - Schema::table('ELEMENT_TASK_RELATION', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //EMAIL EVENTS (CLASSIC) - Schema::table('EMAIL_EVENT', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //EVENTS - Schema::table('EVENT', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //GATEWAYS - Schema::table('GATEWAY', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //INPUT DOCUMENTS - Schema::table('INPUT_DOCUMENT', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //MESSAGE EVENT DEFINITIONS - Schema::table('MESSAGE_EVENT_DEFINITION', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //MESSAGE EVENT RELATIONS - Schema::table('MESSAGE_EVENT_RELATION', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //MESSAGE TYPES - Schema::table('MESSAGE_TYPE', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //OBJECT PERMISSIONS - Schema::table('OBJECT_PERMISSION', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //OUTPUT DOCUMENTS - Schema::table('OUTPUT_DOCUMENT', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //PROCESS FILES - Schema::table('PROCESS_FILES', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //PROCESS USERS (like SUPERVISORS) - Schema::table('PROCESS_USER', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //STATISTICAL INFORMATION AND KPIs OF THE PROCESS - Schema::table('PRO_REPORTING', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //REPORT TABLES (TABLE DEFINITION MAINTAINED FROM v1.x) - Schema::table('REPORT_TABLE', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //REPORT VARIABLE DEFINITION (TABLE DEFINITION MAINTAINED FROM v1.x) - Schema::table('REPORT_VAR', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //ROUTES - Schema::table('ROUTE', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //SCRIPT TASKS - Schema::table('SCRIPT_TASK', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //STAGES (CLASSIC) - Schema::table('STAGE', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //STEPS - Schema::table('STEP', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //STEP SUPERVISORS - Schema::table('STEP_SUPERVISOR', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //SUB PROCESSES - Schema::table('SUB_PROCESS', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //SWIMLANES ELEMENTS - Schema::table('SWIMLANES_ELEMENTS', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //TASKS - Schema::table('TASK', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //TIMER EVENTS - Schema::table('TIMER_EVENT', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //TRIGGERS - Schema::table('TRIGGERS', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //USR REPORTING - Schema::table('USR_REPORTING', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //WEB ENTRIES - Schema::table('WEB_ENTRY', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //WEB ENTRY EVENTS - Schema::table('WEB_ENTRY_EVENT', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('CASCADE'); - }); - - //RESTRICT THE PROCESS DELETION IF IT IS USED IN CASES EXECUTION - //CASES - Schema::table('APPLICATION', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //CASES ASSIGNMENT, SELF SERVICE VALUES - Schema::table('APP_ASSIGN_SELF_SERVICE_VALUE', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //CASES LIST CACHE - Schema::table('APP_CACHE_VIEW', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //CASES DELAY FROM PAUSE/UNPAUSE/CANCEL - Schema::table('APP_DELAY', function(Blueprint $table) { - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //CASES DELEGATIONS - Schema::table('APP_DELEGATION', function(Blueprint $table) { - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //CASES HISTORY - Schema::table('APP_HISTORY', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //LIST OF CANCELED CASES - Schema::table('LIST_CANCELED', function(Blueprint $table) { - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //LIST OF COMPLETED CASES - Schema::table('LIST_COMPLETED', function(Blueprint $table) { - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //LIST INBOX - Schema::table('LIST_INBOX', function(Blueprint $table) { - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //HISTORIC OF PARTICIPATION - Schema::table('LIST_PARTICIPATED_HISTORY', function(Blueprint $table) { - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //LIST OF THE LAST PARTICIPATED IN EACH CASE - Schema::table('LIST_PARTICIPATED_LAST', function(Blueprint $table) { - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //LIST OF PAUSED CASES - Schema::table('LIST_PAUSED', function(Blueprint $table) { - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //LIST OF UNASSIGNED CASES - Schema::table('LIST_UNASSIGNED', function(Blueprint $table) { - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - - //MESSAGE EVENTS THROUGH THE CASES - Schema::table('MESSAGE_APPLICATION', function(Blueprint $table) { - $table->integer('PRO_ID')->nullable(); - $table->foreign('PRO_ID')->references('PRO_ID')->on('PROCESS')->onDelete('RESTRICT'); - }); - } -} diff --git a/database/migrations/2018_04_26_000001_update_various_tables.php b/database/migrations/2018_04_26_000001_update_various_tables.php index aafcccbdcb..5d0eeb5b35 100644 --- a/database/migrations/2018_04_26_000001_update_various_tables.php +++ b/database/migrations/2018_04_26_000001_update_various_tables.php @@ -41,7 +41,7 @@ public function up() }); //DYNAFORMS - Schema::table('DYNAFORM', function(Blueprint $table) { + Schema::table('dynaform', function(Blueprint $table) { $table->unsignedInteger('process_id')->nullable(); $table->foreign('process_id')->references('id')->on('processes')->onDelete('CASCADE'); }); diff --git a/database/migrations/2018_05_02_124700_update_dynaform.php b/database/migrations/2018_05_02_124700_update_dynaform.php deleted file mode 100644 index 2ae21706a6..0000000000 --- a/database/migrations/2018_05_02_124700_update_dynaform.php +++ /dev/null @@ -1,42 +0,0 @@ -dropPrimary('DYN_UID'); - $table->integer('DYN_ID')->first(); - $table->primary('DYN_ID'); - $table->dropColumn('DYN_VERSION'); - $table->dropColumn('DYN_FILENAME'); - $table->dropColumn('DYN_TYPE'); - }); - DB::statement('ALTER TABLE DYNAFORM MODIFY DYN_ID INTEGER NOT NULL AUTO_INCREMENT'); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('DYNAFORM', function (Blueprint $table) { - $table->dropColumn('DYN_ID'); - $table->primary('DYN_UID'); - $table->integer('DYN_VERSION'); - $table->string('DYN_FILENAME', 100); - $table->string('DYN_TYPE', 20); - }); - } -} diff --git a/tests/Feature/Api/Designer/DynaformManagerTest.php b/tests/Feature/Api/Designer/DynaformManagerTest.php index 320e6675e6..a5ee7a93fe 100644 --- a/tests/Feature/Api/Designer/DynaformManagerTest.php +++ b/tests/Feature/Api/Designer/DynaformManagerTest.php @@ -15,18 +15,6 @@ class DynaformManagerTest extends ApiTestCase const API_ROUTE = '/api/1.0/project/'; const DEFAULT_PASS = 'password'; - /** - * Create process - * @return Process - */ - public function testCreateProcess(): Process - { - $process = factory(Process::class)->create(); - $this->assertNotNull($process); - $this->assertNotNull($process->PRO_UID); - return $process; - } - /** * create User * @return User @@ -35,15 +23,34 @@ public function testCreateProcess(): Process public function testCreateUser(): User { $user = factory(User::class)->create([ - 'USR_PASSWORD' => Hash::make(self::DEFAULT_PASS), - 'USR_ROLE' => Role::PROCESSMAKER_ADMIN + 'password' => Hash::make(self::DEFAULT_PASS), + 'role_id' => Role::where('code', Role::PROCESSMAKER_ADMIN)->first()->id ]); $this->assertNotNull($user); - $this->assertNotNull($user->USR_UID); - $this->assertNotNull($user->USR_ID); + $this->assertNotNull($user->uid); + $this->assertNotNull($user->id); return $user; } + /** + * Create process + * @param User $user + * + * @depends testCreateUser + * @return Process + */ + public function testCreateProcess(User $user): Process + { + $process = factory(Process::class)->create([ + 'creator_user_id' => $user->id + ]); + $this->assertNotNull($process); + $this->assertNotNull($process->id); + return $process; + } + + + /** * Create new Dynaform in process * @@ -57,21 +64,20 @@ public function testCreateUser(): User */ public function testCreateDynaform(Process $process, User $user): Dynaform { - $this->auth($user->USR_USERNAME, self::DEFAULT_PASS); + $this->auth($user->username, self::DEFAULT_PASS); $structure = [ - 'DYN_UID', - 'PRO_ID', - 'PRO_UID', - 'DYN_TITLE', - 'DYN_DESCRIPTION', - 'DYN_CONTENT', - 'DYN_LABEL' + 'uid', + 'process_id', + 'title', + 'description', + 'content', + 'label' ]; $data = []; //Post should have the parameter dyn_title - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform'; + $url = self::API_ROUTE . $process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is an error $response->assertStatus(422); @@ -81,20 +87,20 @@ public function testCreateDynaform(Process $process, User $user): Dynaform $data['dyn_title'] = $faker->sentence(3); $data['dyn_description'] = $faker->sentence(10); - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform'; + $url = self::API_ROUTE . $process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is correct. $response->assertStatus(201); - $id = $response->json('DYN_ID'); + $id = $response->json('id'); //Check structure of response. $response->assertJsonStructure($structure); //Post title duplicated - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform'; + $url = self::API_ROUTE . $process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is correct. $response->assertStatus(422); - return Dynaform::where('DYN_ID', $id)->get()->first(); + return Dynaform::where('id', $id)->get()->first(); } /** @@ -112,23 +118,22 @@ public function testCreateDynaform(Process $process, User $user): Dynaform */ public function testCopyImportDynaform(Process $process, User $user, Dynaform $dynaform): Dynaform { - $this->auth($user->USR_USERNAME, self::DEFAULT_PASS); + $this->auth($user->username, self::DEFAULT_PASS); $structure = [ - 'DYN_UID', - 'PRO_ID', - 'PRO_UID', - 'DYN_TITLE', - 'DYN_DESCRIPTION', - 'DYN_CONTENT', - 'DYN_LABEL' + 'uid', + 'process_id', + 'title', + 'description', + 'content', + 'label' ]; $data = [ 'copy_import' => 'test' ]; - //copy_import must be an array and fields prj_uid and dyn_uid are required. - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform'; + //copy_import must be an array and fields pro_uid and dyn_uid are required. + $url = self::API_ROUTE . $process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is an error $response->assertStatus(422); @@ -136,9 +141,9 @@ public function testCopyImportDynaform(Process $process, User $user, Dynaform $d //Process not exist $data['copy_import'] = [ 'pro_uid' => 'otheruid', - 'dyn_uid' => $dynaform->DYN_UID + 'dyn_uid' => $dynaform->uid ]; - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform'; + $url = self::API_ROUTE . $process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is an error $response->assertStatus(404); @@ -146,10 +151,10 @@ public function testCopyImportDynaform(Process $process, User $user, Dynaform $d //Dynaform not exist $otherProcess = $process; $data['copy_import'] = [ - 'pro_uid' => $otherProcess->PRO_UID, + 'pro_uid' => $otherProcess->uid, 'dyn_uid' => 'otherDynaformUid' ]; - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform'; + $url = self::API_ROUTE . $process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is an error $response->assertStatus(404); @@ -158,10 +163,10 @@ public function testCopyImportDynaform(Process $process, User $user, Dynaform $d $otherProcess = $process; $otherDynaform = factory(Dynaform::class)->create(); $data['copy_import'] = [ - 'pro_uid' => $otherProcess->PRO_UID, - 'dyn_uid' => $otherDynaform->DYN_UID + 'pro_uid' => $otherProcess->uid, + 'dyn_uid' => $otherDynaform->uid ]; - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform'; + $url = self::API_ROUTE . $process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is an error $response->assertStatus(404); @@ -172,25 +177,25 @@ public function testCopyImportDynaform(Process $process, User $user, Dynaform $d $data['dyn_description'] = $faker->sentence(10); $data['copy_import'] = [ - 'pro_uid' => $otherProcess->PRO_UID, - 'dyn_uid' => $dynaform->DYN_UID + 'pro_uid' => $otherProcess->uid, + 'dyn_uid' => $dynaform->uid ]; $process = factory(Process::class)->create(); - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform'; + $url = self::API_ROUTE . $process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is correct. $response->assertStatus(201); - $id = $response->json('DYN_ID'); + $id = $response->json('id'); //Check structure of response. $response->assertJsonStructure($structure); //Post title duplicated - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform'; + $url = self::API_ROUTE . $process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is correct. $response->assertStatus(422); - return Dynaform::where('DYN_ID', $id)->get()->first(); + return Dynaform::where('id', $id)->get()->first(); } /** @@ -205,7 +210,7 @@ public function testCopyImportDynaform(Process $process, User $user, Dynaform $d */ public function testListDynaform(Process $process, User $user): void { - $this->auth($user->USR_USERNAME, self::DEFAULT_PASS); + $this->auth($user->username, self::DEFAULT_PASS); $structurePaginate = [ 'current_page', 'data', @@ -219,12 +224,11 @@ public function testListDynaform(Process $process, User $user): void ]; //add Dynaform to process factory(Dynaform::class, 10)->create([ - 'PRO_UID' => $process->PRO_UID, - 'PRO_ID' => $process->PRO_ID + 'process_id' => $process->id ]); //List Dynaform - $url = self::API_ROUTE . $process->PRO_UID . '/dynaforms'; + $url = self::API_ROUTE . $process->uid . '/dynaforms'; $response = $this->api('GET', $url); //Validate the answer is correct $response->assertStatus(200); @@ -241,27 +245,25 @@ public function testListDynaform(Process $process, User $user): void * * @param Process $process * @param User $user - * @param Dynaform $Dynaform + * @param Dynaform $dynaform * * @depends testCreateProcess * @depends testCreateUser * @depends testCreateDynaform */ - public function testGetDynaform(Process $process, User $user, Dynaform $Dynaform): void + public function testGetDynaform(Process $process, User $user, Dynaform $dynaform): void { - $this->auth($user->USR_USERNAME, self::DEFAULT_PASS); + $this->auth($user->username, self::DEFAULT_PASS); $structure = [ - 'DYN_UID', - 'PRO_ID', - 'PRO_UID', - 'DYN_TITLE', - 'DYN_DESCRIPTION', - 'DYN_CONTENT', - 'DYN_LABEL', - 'DYN_UPDATE_DATE' + 'uid', + 'process_id', + 'title', + 'description', + 'content', + 'label' ]; //load Dynaform - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform/' . $Dynaform->DYN_UID; + $url = self::API_ROUTE . $process->uid . '/dynaform/' . $dynaform->uid; $response = $this->api('GET', $url); //Validate the answer is correct $response->assertStatus(200); @@ -270,8 +272,8 @@ public function testGetDynaform(Process $process, User $user, Dynaform $Dynaform $response->assertJsonStructure($structure); //Dynaform not belong to process. - $Dynaform = factory(Dynaform::class)->create(); - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform/' . $Dynaform->DYN_UID; + $dynaform = factory(Dynaform::class)->create(); + $url = self::API_ROUTE . $process->uid . '/dynaform/' . $dynaform->uid; $response = $this->api('GET', $url); //Validate the answer is incorrect $response->assertStatus(404); @@ -283,15 +285,15 @@ public function testGetDynaform(Process $process, User $user, Dynaform $Dynaform * * @param Process $process * @param User $user - * @param Dynaform $Dynaform + * @param Dynaform $dynaform * * @depends testCreateProcess * @depends testCreateUser * @depends testCreateDynaform */ - public function testUpdateDynaform(Process $process, User $user, Dynaform $Dynaform): void + public function testUpdateDynaform(Process $process, User $user, Dynaform $dynaform): void { - $this->auth($user->USR_USERNAME, self::DEFAULT_PASS); + $this->auth($user->username, self::DEFAULT_PASS); $faker = Faker::create(); $data = [ @@ -299,7 +301,7 @@ public function testUpdateDynaform(Process $process, User $user, Dynaform $Dynaf 'dyn_description' => '' ]; //Post should have the parameter tri_title - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform/' . $Dynaform->DYN_UID; + $url = self::API_ROUTE . $process->uid . '/dynaform/' . $dynaform->uid; $response = $this->api('PUT', $url, $data); //Validate the answer is incorrect $response->assertStatus(422); @@ -308,7 +310,7 @@ public function testUpdateDynaform(Process $process, User $user, Dynaform $Dynaf $data['dyn_title'] = $faker->sentence(2); $data['dyn_description'] = $faker->sentence(5); $data['dyn_content'] = ''; - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform/' . $Dynaform->DYN_UID; + $url = self::API_ROUTE . $process->uid . '/dynaform/' . $dynaform->uid; $response = $this->api('PUT', $url, $data); //Validate the answer is correct $response->assertStatus(200); @@ -319,26 +321,26 @@ public function testUpdateDynaform(Process $process, User $user, Dynaform $Dynaf * * @param Process $process * @param User $user - * @param Dynaform $Dynaform + * @param Dynaform $dynaform * * @depends testCreateProcess * @depends testCreateUser * @depends testCreateDynaform */ - public function testDeleteDynaform(Process $process, User $user, Dynaform $Dynaform): void + public function testDeleteDynaform(Process $process, User $user, Dynaform $dynaform): void { - $this->auth($user->USR_USERNAME, self::DEFAULT_PASS); + $this->auth($user->username, self::DEFAULT_PASS); //Remove Dynaform - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform/' . $Dynaform->DYN_UID; + $url = self::API_ROUTE . $process->uid . '/dynaform/' . $dynaform->uid; $response = $this->api('DELETE', $url); //Validate the answer is correct $response->assertStatus(200); - $Dynaform = factory(Dynaform::class)->make(); + $dynaform = factory(Dynaform::class)->make(); //Dynaform not exist - $url = self::API_ROUTE . $process->PRO_UID . '/dynaform/' . $Dynaform->DYN_UID; + $url = self::API_ROUTE . $process->uid . '/dynaform/' . $dynaform->uid; $response = $this->api('DELETE', $url); //Validate the answer is correct $response->assertStatus(404); From 30dcfd73d8b1b018216e10fa92e786762eea50b5 Mon Sep 17 00:00:00 2001 From: Marco Antonio Nina Mena Date: Fri, 11 May 2018 15:10:35 -0400 Subject: [PATCH 2/3] Fix CR --- ProcessMaker/Exception/Handler.php | 16 ++ .../Api/Designer/DynaformController.php | 2 +- ProcessMaker/Managers/DynaformManager.php | 1 - .../Api/Designer/DynaformManagerTest.php | 210 +++++++----------- 4 files changed, 97 insertions(+), 132 deletions(-) diff --git a/ProcessMaker/Exception/Handler.php b/ProcessMaker/Exception/Handler.php index 93515969e6..971655e79b 100644 --- a/ProcessMaker/Exception/Handler.php +++ b/ProcessMaker/Exception/Handler.php @@ -3,8 +3,10 @@ use Exception; use Illuminate\Auth\AuthenticationException; +use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Support\Facades\App; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Our general exception handler @@ -52,6 +54,20 @@ public function report(Exception $exception) */ public function render($request, Exception $exception) { + // This will replace our 404 response with + // a JSON response. + /*if ($exception instanceof ModelNotFoundException) { + $exception = new NotFoundHttpException($exception->getMessage(), $exception); + $code = 422; + $error = [ + 'error' => [ + 'code' => $code, + 'message' => __('This element does not exist!'), + ], + 'errors' => $exception->getMessage() + ]; + return response()->json(['error' => $error], $code); + }*/ return parent::render($request, $exception); } diff --git a/ProcessMaker/Http/Controllers/Api/Designer/DynaformController.php b/ProcessMaker/Http/Controllers/Api/Designer/DynaformController.php index bb27e8b24e..0ab0c20fc3 100644 --- a/ProcessMaker/Http/Controllers/Api/Designer/DynaformController.php +++ b/ProcessMaker/Http/Controllers/Api/Designer/DynaformController.php @@ -98,7 +98,7 @@ public function remove(Process $process, Dynaform $dynaform) { $this->belongsToProcess($process, $dynaform); DynaformManager::remove($dynaform); - return response([], 200); + return response([], 204); } /** diff --git a/ProcessMaker/Managers/DynaformManager.php b/ProcessMaker/Managers/DynaformManager.php index 6e4702b25e..1b5a2f6b66 100644 --- a/ProcessMaker/Managers/DynaformManager.php +++ b/ProcessMaker/Managers/DynaformManager.php @@ -40,7 +40,6 @@ public function save(Process $process, $data): Dynaform $this->validate($data); $data['uid'] = Uuid::uuid4(); -// $data['PRO_UID'] = $process->uid; $data['process_id'] = $process->id; if (!isset($data['content']) || empty($data['content'])) { diff --git a/tests/Feature/Api/Designer/DynaformManagerTest.php b/tests/Feature/Api/Designer/DynaformManagerTest.php index a5ee7a93fe..9dcd0b6fb8 100644 --- a/tests/Feature/Api/Designer/DynaformManagerTest.php +++ b/tests/Feature/Api/Designer/DynaformManagerTest.php @@ -15,69 +15,37 @@ class DynaformManagerTest extends ApiTestCase const API_ROUTE = '/api/1.0/project/'; const DEFAULT_PASS = 'password'; + protected static $user; + protected static $process; + /** - * create User - * @return User - * + * Init variables User and Process */ - public function testCreateUser(): User + private function initProcess(): void { - $user = factory(User::class)->create([ + self::$user = factory(User::class)->create([ 'password' => Hash::make(self::DEFAULT_PASS), 'role_id' => Role::where('code', Role::PROCESSMAKER_ADMIN)->first()->id ]); - $this->assertNotNull($user); - $this->assertNotNull($user->uid); - $this->assertNotNull($user->id); - return $user; - } - /** - * Create process - * @param User $user - * - * @depends testCreateUser - * @return Process - */ - public function testCreateProcess(User $user): Process - { - $process = factory(Process::class)->create([ - 'creator_user_id' => $user->id + self::$process = factory(Process::class)->create([ + 'creator_user_id' => self::$user->id ]); - $this->assertNotNull($process); - $this->assertNotNull($process->id); - return $process; } - - /** * Create new Dynaform in process * - * @param Process $process - * @param User $user - * * @return Dynaform - * - * @depends testCreateProcess - * @depends testCreateUser */ - public function testCreateDynaform(Process $process, User $user): Dynaform + public function testCreateDynaform(): Dynaform { - $this->auth($user->username, self::DEFAULT_PASS); - - $structure = [ - 'uid', - 'process_id', - 'title', - 'description', - 'content', - 'label' - ]; + $this->initProcess(); + $this->auth(self::$user->username, self::DEFAULT_PASS); $data = []; //Post should have the parameter dyn_title - $url = self::API_ROUTE . $process->uid . '/dynaform'; + $url = self::API_ROUTE . self::$process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is an error $response->assertStatus(422); @@ -87,53 +55,47 @@ public function testCreateDynaform(Process $process, User $user): Dynaform $data['dyn_title'] = $faker->sentence(3); $data['dyn_description'] = $faker->sentence(10); - $url = self::API_ROUTE . $process->uid . '/dynaform'; + $url = self::API_ROUTE . self::$process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is correct. $response->assertStatus(201); $id = $response->json('id'); //Check structure of response. - $response->assertJsonStructure($structure); + $response->assertJsonStructure([ + 'uid', + 'process_id', + 'title', + 'description', + 'content', + 'label' + ]); //Post title duplicated - $url = self::API_ROUTE . $process->uid . '/dynaform'; + $url = self::API_ROUTE . self::$process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is correct. $response->assertStatus(422); - return Dynaform::where('id', $id)->get()->first(); + return Dynaform::where('id', $id)->first(); } /** * Copy/import Dynaform in process * - * @param Process $process - * @param User $user * @param Dynaform $dynaform * * @return Dynaform * - * @depends testCreateProcess - * @depends testCreateUser * @depends testCreateDynaform */ - public function testCopyImportDynaform(Process $process, User $user, Dynaform $dynaform): Dynaform + public function testCopyImportDynaform(Dynaform $dynaform): Dynaform { - $this->auth($user->username, self::DEFAULT_PASS); - - $structure = [ - 'uid', - 'process_id', - 'title', - 'description', - 'content', - 'label' - ]; + $this->auth(self::$user->username, self::DEFAULT_PASS); $data = [ 'copy_import' => 'test' ]; //copy_import must be an array and fields pro_uid and dyn_uid are required. - $url = self::API_ROUTE . $process->uid . '/dynaform'; + $url = self::API_ROUTE . self::$process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is an error $response->assertStatus(422); @@ -143,30 +105,29 @@ public function testCopyImportDynaform(Process $process, User $user, Dynaform $d 'pro_uid' => 'otheruid', 'dyn_uid' => $dynaform->uid ]; - $url = self::API_ROUTE . $process->uid . '/dynaform'; + $url = self::API_ROUTE . self::$process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is an error $response->assertStatus(404); //Dynaform not exist - $otherProcess = $process; + $otherProcess = self::$process; $data['copy_import'] = [ 'pro_uid' => $otherProcess->uid, 'dyn_uid' => 'otherDynaformUid' ]; - $url = self::API_ROUTE . $process->uid . '/dynaform'; + $url = self::API_ROUTE . self::$process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is an error $response->assertStatus(404); //Dynaform does not belong to the process. - $otherProcess = $process; $otherDynaform = factory(Dynaform::class)->create(); $data['copy_import'] = [ - 'pro_uid' => $otherProcess->uid, + 'pro_uid' => self::$process->uid, 'dyn_uid' => $otherDynaform->uid ]; - $url = self::API_ROUTE . $process->uid . '/dynaform'; + $url = self::API_ROUTE . self::$process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is an error $response->assertStatus(404); @@ -177,7 +138,7 @@ public function testCopyImportDynaform(Process $process, User $user, Dynaform $d $data['dyn_description'] = $faker->sentence(10); $data['copy_import'] = [ - 'pro_uid' => $otherProcess->uid, + 'pro_uid' => self::$process->uid, 'dyn_uid' => $dynaform->uid ]; $process = factory(Process::class)->create(); @@ -186,49 +147,41 @@ public function testCopyImportDynaform(Process $process, User $user, Dynaform $d $response = $this->api('POST', $url, $data); //validating the answer is correct. $response->assertStatus(201); - $id = $response->json('id'); + $dynaformCreated = $response->original; //Check structure of response. - $response->assertJsonStructure($structure); + $response->assertJsonStructure([ + 'uid', + 'process_id', + 'title', + 'description', + 'content', + 'label' + ]); //Post title duplicated $url = self::API_ROUTE . $process->uid . '/dynaform'; $response = $this->api('POST', $url, $data); //validating the answer is correct. $response->assertStatus(422); - return Dynaform::where('id', $id)->get()->first(); + return $dynaformCreated; } /** * Get a list of Dynaform in a project. * - * @param Process $process - * @param User $user - * - * @depends testCreateProcess - * @depends testCreateUser * @depends testCreateDynaform */ - public function testListDynaform(Process $process, User $user): void + public function testListDynaform(): void { - $this->auth($user->username, self::DEFAULT_PASS); - $structurePaginate = [ - 'current_page', - 'data', - 'first_page_url', - 'from', - 'next_page_url', - 'path', - 'per_page', - 'prev_page_url', - 'to', - ]; + $this->auth(self::$user->username, self::DEFAULT_PASS); + //add Dynaform to process factory(Dynaform::class, 10)->create([ - 'process_id' => $process->id + 'process_id' => self::$process->id ]); //List Dynaform - $url = self::API_ROUTE . $process->uid . '/dynaforms'; + $url = self::API_ROUTE . self::$process->uid . '/dynaforms'; $response = $this->api('GET', $url); //Validate the answer is correct $response->assertStatus(200); @@ -236,44 +189,49 @@ public function testListDynaform(Process $process, User $user): void $response->assertJsonCount(11, 'data'); //verify structure paginate - $response->assertJsonStructure($structurePaginate); - + $response->assertJsonStructure([ + 'current_page', + 'data', + 'first_page_url', + 'from', + 'next_page_url', + 'path', + 'per_page', + 'prev_page_url', + 'to', + ]); } /** * Get a Dynaform of a project. * - * @param Process $process - * @param User $user * @param Dynaform $dynaform * - * @depends testCreateProcess - * @depends testCreateUser * @depends testCreateDynaform */ - public function testGetDynaform(Process $process, User $user, Dynaform $dynaform): void + public function testGetDynaform(Dynaform $dynaform): void { - $this->auth($user->username, self::DEFAULT_PASS); - $structure = [ - 'uid', - 'process_id', - 'title', - 'description', - 'content', - 'label' - ]; + $this->auth(self::$user->username, self::DEFAULT_PASS); + //load Dynaform - $url = self::API_ROUTE . $process->uid . '/dynaform/' . $dynaform->uid; + $url = self::API_ROUTE . self::$process->uid . '/dynaform/' . $dynaform->uid; $response = $this->api('GET', $url); //Validate the answer is correct $response->assertStatus(200); //verify structure paginate - $response->assertJsonStructure($structure); + $response->assertJsonStructure([ + 'uid', + 'process_id', + 'title', + 'description', + 'content', + 'label' + ]); //Dynaform not belong to process. $dynaform = factory(Dynaform::class)->create(); - $url = self::API_ROUTE . $process->uid . '/dynaform/' . $dynaform->uid; + $url = self::API_ROUTE . self::$process->uid . '/dynaform/' . $dynaform->uid; $response = $this->api('GET', $url); //Validate the answer is incorrect $response->assertStatus(404); @@ -283,17 +241,13 @@ public function testGetDynaform(Process $process, User $user, Dynaform $dynaform /** * Update Dynaform in process * - * @param Process $process - * @param User $user * @param Dynaform $dynaform * - * @depends testCreateProcess - * @depends testCreateUser * @depends testCreateDynaform */ - public function testUpdateDynaform(Process $process, User $user, Dynaform $dynaform): void + public function testUpdateDynaform(Dynaform $dynaform): void { - $this->auth($user->username, self::DEFAULT_PASS); + $this->auth(self::$user->username, self::DEFAULT_PASS); $faker = Faker::create(); $data = [ @@ -301,7 +255,7 @@ public function testUpdateDynaform(Process $process, User $user, Dynaform $dynaf 'dyn_description' => '' ]; //Post should have the parameter tri_title - $url = self::API_ROUTE . $process->uid . '/dynaform/' . $dynaform->uid; + $url = self::API_ROUTE . self::$process->uid . '/dynaform/' . $dynaform->uid; $response = $this->api('PUT', $url, $data); //Validate the answer is incorrect $response->assertStatus(422); @@ -310,7 +264,7 @@ public function testUpdateDynaform(Process $process, User $user, Dynaform $dynaf $data['dyn_title'] = $faker->sentence(2); $data['dyn_description'] = $faker->sentence(5); $data['dyn_content'] = ''; - $url = self::API_ROUTE . $process->uid . '/dynaform/' . $dynaform->uid; + $url = self::API_ROUTE . self::$process->uid . '/dynaform/' . $dynaform->uid; $response = $this->api('PUT', $url, $data); //Validate the answer is correct $response->assertStatus(200); @@ -319,28 +273,24 @@ public function testUpdateDynaform(Process $process, User $user, Dynaform $dynaf /** * Delete Dynaform in process * - * @param Process $process - * @param User $user * @param Dynaform $dynaform * - * @depends testCreateProcess - * @depends testCreateUser * @depends testCreateDynaform */ - public function testDeleteDynaform(Process $process, User $user, Dynaform $dynaform): void + public function testDeleteDynaform(Dynaform $dynaform): void { - $this->auth($user->username, self::DEFAULT_PASS); + $this->auth(self::$user->username, self::DEFAULT_PASS); //Remove Dynaform - $url = self::API_ROUTE . $process->uid . '/dynaform/' . $dynaform->uid; + $url = self::API_ROUTE . self::$process->uid . '/dynaform/' . $dynaform->uid; $response = $this->api('DELETE', $url); //Validate the answer is correct - $response->assertStatus(200); + $response->assertStatus(204); $dynaform = factory(Dynaform::class)->make(); //Dynaform not exist - $url = self::API_ROUTE . $process->uid . '/dynaform/' . $dynaform->uid; + $url = self::API_ROUTE . self::$process->uid . '/dynaform/' . $dynaform->uid; $response = $this->api('DELETE', $url); //Validate the answer is correct $response->assertStatus(404); From d26810d93910f5d7d206e87a5f69f627f2d323a1 Mon Sep 17 00:00:00 2001 From: Marco Antonio Nina Mena Date: Fri, 11 May 2018 15:11:12 -0400 Subject: [PATCH 3/3] Fix CR --- ProcessMaker/Exception/Handler.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/ProcessMaker/Exception/Handler.php b/ProcessMaker/Exception/Handler.php index 971655e79b..77b72f1caf 100644 --- a/ProcessMaker/Exception/Handler.php +++ b/ProcessMaker/Exception/Handler.php @@ -54,20 +54,6 @@ public function report(Exception $exception) */ public function render($request, Exception $exception) { - // This will replace our 404 response with - // a JSON response. - /*if ($exception instanceof ModelNotFoundException) { - $exception = new NotFoundHttpException($exception->getMessage(), $exception); - $code = 422; - $error = [ - 'error' => [ - 'code' => $code, - 'message' => __('This element does not exist!'), - ], - 'errors' => $exception->getMessage() - ]; - return response()->json(['error' => $error], $code); - }*/ return parent::render($request, $exception); }