Skip to content

Commit

Permalink
fix(formanswer): fix call to saveForm
Browse files Browse the repository at this point in the history
Signed-off-by: btry <tbugier@teclib.com>
  • Loading branch information
btry committed Sep 26, 2018
1 parent ca64d5f commit 17bd8c5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
4 changes: 1 addition & 3 deletions front/form_answer.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@
$formanswer->redirectToList();

} else if (isset($_POST['save_formanswer'])) {
$_POST['plugin_formcreator_forms_id'] = intval($_POST['formcreator_form']);
$_POST['status'] = 'waiting';
$formanswer->saveAnswers($_POST);
$formanswer->updateAnswers($_POST);
if (plugin_formcreator_replaceHelpdesk()) {
$issue = new PluginFormcreatorIssue();
$issue->redirectToList();
Expand Down
27 changes: 27 additions & 0 deletions inc/form_answer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,9 @@ public function pre_deleteItem() {
/**
* Create or update answers of a form
*
* @param PluginFormcreatorForm $form
* @param array $data answers
* @param array $fields array of field: question id => instance
* @return boolean
*/
public function saveAnswers(PluginFormcreatorForm $form, $data, $fields) {
Expand Down Expand Up @@ -884,6 +886,31 @@ public function saveAnswers(PluginFormcreatorForm $form, $data, $fields) {
}
}

/**
* Update the answers
*
* @param [type] $input
* @return void
*/
public function updateAnswers($input) {
$form = new PluginFormcreatorForm();
$form->getID((int) $_POST['formcreator_form']);
$input['status'] = 'waiting';
$fields = [];
// Prepare form fields for validation
$question = new PluginFormcreatorQuestion();

$found_questions = $question->getQuestionsFromForm($this->getID());
foreach ($found_questions as $id => $question) {
$key = 'formcreator_field_' . $id;
$fields[$id] = PluginFormcreatorFields::getFieldInstance(
$question->fields['fieldtype'],
$question
);
}
$this->saveAnswers($form, $input, $fields);
}

/**
* Mark answers of a form as refused
*
Expand Down
1 change: 1 addition & 0 deletions tests/src/CommonTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ protected function getForm($input = []) {
}
$form = new \PluginFormcreatorForm();
$form->add($input);
$form->getFromDB($form->getID());

return $form;
}
Expand Down
10 changes: 4 additions & 6 deletions tests/suite-unit/PluginFormcreatorForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,23 +182,21 @@ public function testCreateValidationNotification() {
'glpi@localhost.com',
]
]);
$form = new \PluginFormcreatorForm();
$form->add([
$form = $this->getForm([
'name' => 'validation notification',
'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER,
'_validator_users' => [$_SESSION['glpiID']],
]);
$section = new \PluginFormcreatorSection();
$section->add([
$section =$this->getSection([
$form::getForeignKeyField() => $form->getID(),
'name' => 'section',
]);

$formAnswer = new \PluginFormcreatorForm_Answer();
$formAnswerId = $formAnswer->saveAnswers([
$formAnswerId = $formAnswer->saveAnswers($form, [
'formcreator_form' => $form->getID(),
'formcreator_validator' => $_SESSION['glpiID'],
]);
], []);
$this->integer($formAnswerId)->isGreaterThan(0);

// 1 notification to the validator
Expand Down

0 comments on commit 17bd8c5

Please sign in to comment.