Skip to content

Commit

Permalink
fix(condition): export broken
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Jan 27, 2020
1 parent d3588da commit 9b7a692
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
8 changes: 1 addition & 7 deletions inc/condition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,9 @@ public function export($remove_uuid = false) {
$question = new PluginFormcreatorQuestion();
$question->getFromDB($condition['plugin_formcreator_questions_id']);
$condition['plugin_formcreator_questions_id'] = $question->fields['uuid'];
$containerType = $input['itemtype'];
if (!class_exists($containerType) || !is_subclass_of($containerType, PluginFormcreatorConditionnableInterface::class)) {
return false;
}
$container = new $containerType();
$container->getFromDB($condition['items_id']);
$condition['items_id'] = $container->fields['uuid'];
}
unset($condition[$idToRemove]);
unset($condition['itemtype']);

return $condition;
}
Expand Down
3 changes: 3 additions & 0 deletions inc/conditionnable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public function updateConditions($input) {
return false;
}

$itemtype = $this->getType();
$itemId = $this->getID();

// Delete all existing conditions for the question
$condition = new PluginFormcreatorCondition();
$condition->deleteByCriteria([
Expand Down
29 changes: 15 additions & 14 deletions tests/suite-unit/PluginFormcreatorCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,22 @@ public function testExport() {
'plugin_formcreator_forms_id' => $form->getID(),
]);
$question2->updateConditions([
'id' => $question2->getID(),
'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_HIDDEN,
'plugin_formcreator_questions_id' => [
$question1->getID(),
],
'show_condition' =>[
\PluginFormcreatorCondition::SHOW_CONDITION_EQ,
],
'show_value' => [
'foo',
],
'show_logic' => [
\PluginFormcreatorCondition::SHOW_LOGIC_AND,
]
'_conditions' => [
'id' => $question2->getID(),
'plugin_formcreator_questions_id' => [
$question1->getID(),
],
'show_condition' =>[
\PluginFormcreatorCondition::SHOW_CONDITION_EQ,
],
'show_value' => [
'foo',
],
'show_logic' => [
\PluginFormcreatorCondition::SHOW_LOGIC_AND,
]
],
]);
$instance = $this->getTargetTicket();
$instance->getFromDB($instance->getID());
Expand All @@ -172,7 +174,6 @@ public function testExport() {

// Test the exported data
$fieldsWithoutID = [
'itemtype',
'plugin_formcreator_questions_id',
'show_condition',
'show_value',
Expand Down
5 changes: 3 additions & 2 deletions tests/suite-unit/PluginFormcreatorFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function testIsVisible($show_rule, $conditions, $answers, $expectedVisibi
);
$realAnswers[$questionPool[$id]->getID()]->deserializeValue($answer);
}
$input = $conditions + [
$input = [
'id' => $question->getID(),
'fieldtype' => 'text',
'show_rule' => $show_rule,
Expand All @@ -282,7 +282,8 @@ public function testIsVisible($show_rule, $conditions, $answers, $expectedVisibi
'regex' => ''
]
]
]
],
'_conditions' => $conditions,
];
$question->update($input);
$question->updateConditions($input);
Expand Down

0 comments on commit 9b7a692

Please sign in to comment.