Fix - Visibility conditions not working on tree cascade dropdown questions#30
Fix - Visibility conditions not working on tree cascade dropdown questions#30RomainLvr wants to merge 2 commits into
Conversation
|
I have the customer test it |
| if ($item instanceof CommonTreeDropdown) { | ||
| $completename = $item->fields['completename']; | ||
| $text = is_string($completename) ? $completename : ''; | ||
| } else { | ||
| $text = $item->getName(); | ||
| } |
There was a problem hiding this comment.
The else branch ($text = $item->getName()) is dead code. This class is only ever constructed in TreeCascadeDropdownQuestion::getConditionHandlers(), which itself is only reachable for CommonTreeDropdown itemtypes
| if ($item instanceof CommonTreeDropdown) { | |
| $completename = $item->fields['completename']; | |
| $text = is_string($completename) ? $completename : ''; | |
| } else { | |
| $text = $item->getName(); | |
| } | |
| // Use completename for tree dropdowns so that conditions referencing | |
| // ancestor nodes match correctly (e.g. "contains Parent" matches a child | |
| // whose completename is "Parent > Child"). | |
| $completename = $item->fields['completename'] ?? ''; | |
| $text = is_string($completename) ? $completename : ''; |
| * Verify that CONTAINS evaluates to true when the searched text appears in | ||
| * the completename of the selected item but not in its own name alone. | ||
| */ | ||
| public function testContainsMatchesCompletename(): void |
There was a problem hiding this comment.
Can you add a test case where the parent item itself is selected (not a child), confirming that CONTAINS 'Parent Location' still matches when completename = 'Parent Location'? The two existing tests only cover a child item; the root-level selection path is untested.
There was a problem hiding this comment.
Can you add a test case where no item is selected (items_id = 0)? applyValueOperator returns false for both operators in that case, which means a NOT_CONTAINS X condition evaluates to false (dependent question hidden) when nothing is selected. This is non-obvious behavior and worth pinning with a test.
Checklist before requesting a review
Please delete options that are not relevant.
Description
ItemAsTextConditionHandlerusesgetName()which returns only the item's own name. For tree dropdowns, a child item's name does not include its ancestors, so a condition like "contains Parent" always failed. Fixed by introducingTreeCascadeItemAsTextConditionHandlerin the plugin, which usescompletename("Parent > Child") forCommonTreeDropdownitems.TreeCascadeDropdownQuestion::getConditionHandlers()is overridden to substitute this handler.