Skip to content

Commit

Permalink
refactor(form): replace obsolete method
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Feb 23, 2022
1 parent d0cb564 commit 809d68a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 55 deletions.
3 changes: 1 addition & 2 deletions inc/abstractfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ protected function getParametersHtmlForDesign() {

$question = new PluginFormcreatorQuestion();
$question->getFromDB($this->question->getID());
$form = PluginFormcreatorCommon::getForm();
$form->getByQuestionId($question->getID());
$form = PluginFormcreatorForm::getByItem($question);

/** @var integer $column 0 for 2 first columns, 1 for 2 right ones */
$column = 0;
Expand Down
32 changes: 0 additions & 32 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1264,38 +1264,6 @@ public function increaseUsageCount(): bool {
]);
}

/**
* gets a form from database from a question
*
* @param int $questionId
*/
public function getByQuestionId(int $questionId) : void {
$formTable = PluginFormcreatorForm::getTable();
$formFk = PluginFormcreatorForm::getForeignKeyField();
$sectionTable = PluginFormcreatorSection::getTable();
$sectionFk = PluginFormcreatorSection::getForeignKeyField();
$questionTable = PluginFormcreatorQuestion::getTable();
$this->getFromDBByRequest([
'INNER JOIN' => [
$sectionTable => [
'FKEY' => [
$formTable => 'id',
$sectionTable => $formFk,
]
],
$questionTable => [
'FKEY' => [
$questionTable => $sectionFk,
$sectionTable => 'id'
]
]
],
'WHERE' => [
$questionTable . '.id' => $questionId,
]
]);
}

public function duplicate(array $options = []) {
$linker = new PluginFormcreatorLinker($options);

Expand Down
11 changes: 0 additions & 11 deletions tests/3-unit/PluginFormcreatorForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,6 @@ public function testIncreateUsageCount() {
$this->integer((int) $form->fields['usage_count'])->isEqualTo(1);
}

public function testGetByQuestionId() {
$question = $this->getQuestion();
$section = new \PluginFormcreatorSection();
$section->getFromDB($question->fields['plugin_formcreator_sections_id']);
$expected = $section->fields['plugin_formcreator_forms_id'];
$form = $this->newTestedInstance();
$form->getByQuestionId($question->getID());

$this->integer((int) $form->getID())->isEqualTo($expected);
}

public function testCreateValidationNotification() {
global $DB, $CFG_GLPI;

Expand Down
15 changes: 5 additions & 10 deletions tests/3-unit/PluginFormcreatorTargetTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,7 @@ public function providerSetTargetAssociatedItem_1() {
'fieldtype' => 'glpiselect',
'glpi_objects' => \Computer::class,
]);
$form = new \PluginFormcreatorForm();
$form->getByQuestionId($question->getID());
$form = \PluginFormcreatorForm::getByItem($question);

// Have an item to associate
$computer = new \Computer();
Expand Down Expand Up @@ -1049,8 +1048,7 @@ public function providerSetTargetAssociatedItem_LastItem() {
'fieldtype' => 'glpiselect',
'glpi_objects' => $validItemtype,
]);
$form1 = new \PluginFormcreatorForm();
$form1->getByQuestionId($question1->getID());
$form1 = \PluginFormcreatorForm::getByItem($question1);
$sectionId = $question1->fields['plugin_formcreator_sections_id'];
$question2 = $this->getQuestion([
'plugin_formcreator_sections_id' => $sectionId,
Expand Down Expand Up @@ -1079,8 +1077,7 @@ public function providerSetTargetAssociatedItem_LastItem() {
'fieldtype' => 'glpiselect',
'glpi_objects' => $validItemtype,
]);
$form2 = new \PluginFormcreatorForm();
$form2->getByQuestionId($question3->getID());
$form2 = \PluginFormcreatorForm::getByItem($question3);
$sectionId = $question3->fields['plugin_formcreator_sections_id'];
$question4 = $this->getQuestion([
'plugin_formcreator_sections_id' => $sectionId,
Expand Down Expand Up @@ -1112,8 +1109,7 @@ public function providerSetTargetAssociatedItem_LastItem() {
'fieldtype' => 'glpiselect',
'glpi_objects' => $invalidItemtype,
]);
$form3 = new \PluginFormcreatorForm();
$form3->getByQuestionId($question5->getID());
$form3 = \PluginFormcreatorForm::getByItem($question5);
$sectionId = $question5->fields['plugin_formcreator_sections_id'];
$question6 = $this->getQuestion([
'plugin_formcreator_sections_id' => $sectionId,
Expand Down Expand Up @@ -1146,8 +1142,7 @@ public function providerSetTargetAssociatedItem_LastItem() {
'fieldtype' => 'glpiselect',
'glpi_objects' => $validItemtype,
]);
$form4 = new \PluginFormcreatorForm();
$form4->getByQuestionId($question7->getID());
$form4 = \PluginFormcreatorForm::getByItem($question7);
$sectionId = $question7->fields['plugin_formcreator_sections_id'];
$question8 = $this->getQuestion([
'plugin_formcreator_sections_id' => $sectionId,
Expand Down

0 comments on commit 809d68a

Please sign in to comment.