|
43 | 43 | use Glpi\Form\AccessControl\FormAccessControl; |
44 | 44 | use Glpi\Form\AnswersHandler\AnswersHandler; |
45 | 45 | use Glpi\Form\Comment; |
| 46 | +use Glpi\Form\Condition\LogicOperator; |
| 47 | +use Glpi\Form\Condition\Type; |
| 48 | +use Glpi\Form\Condition\ValueOperator; |
| 49 | +use Glpi\Form\Condition\VisibilityStrategy; |
46 | 50 | use Glpi\Form\Destination\FormDestination; |
47 | 51 | use Glpi\Form\Destination\FormDestinationChange; |
48 | 52 | use Glpi\Form\Destination\FormDestinationProblem; |
@@ -811,4 +815,29 @@ public function testDefinedTabs( |
811 | 815 | // Assert: the tabs should match the expected data |
812 | 816 | $this->assertEquals($expected_tabs, $tabs); |
813 | 817 | } |
| 818 | + |
| 819 | + public function testSubmitConditionsDataIsCleanedWhenStrategyIsReset(): void |
| 820 | + { |
| 821 | + // Arrange: create a form with some conditions |
| 822 | + $builder = new FormBuilder(); |
| 823 | + $builder->addQuestion("My question", QuestionTypeShortText::class); |
| 824 | + $builder->setSubmitButtonVisibility(VisibilityStrategy::VISIBLE_IF, [ |
| 825 | + [ |
| 826 | + 'logic_operator' => LogicOperator::AND, |
| 827 | + 'item_name' => "My question", |
| 828 | + 'item_type' => Type::QUESTION, |
| 829 | + 'value_operator' => ValueOperator::EQUALS, |
| 830 | + 'value' => "Yes", |
| 831 | + ], |
| 832 | + ]); |
| 833 | + $form = $this->createForm($builder); |
| 834 | + |
| 835 | + // Act: reset the visibility strategy |
| 836 | + $form = $this->updateItem(Form::class, $form->getID(), [ |
| 837 | + 'submit_button_visibility_strategy' => VisibilityStrategy::ALWAYS_VISIBLE->value |
| 838 | + ]); |
| 839 | + |
| 840 | + // Assert: the conditions should be deleted |
| 841 | + $this->assertEmpty($form->getConfiguredConditionsData()); |
| 842 | + } |
814 | 843 | } |
0 commit comments