From bd4e856f41ff1b873a0e526e9d0fcc7711b76ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 20 Mar 2025 08:15:05 +0100 Subject: [PATCH] test: Fix getting returned sharees when there are several results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- .../features/bootstrap/Sharing.php | 31 +++++++++++++++++++ .../sharees_features/sharees.feature | 4 +++ 2 files changed, 35 insertions(+) diff --git a/build/integration/features/bootstrap/Sharing.php b/build/integration/features/bootstrap/Sharing.php index 29bae9843c2..b83edec7caf 100644 --- a/build/integration/features/bootstrap/Sharing.php +++ b/build/integration/features/bootstrap/Sharing.php @@ -729,6 +729,37 @@ trait Sharing { $shareeType = substr($shareeType, 6); } + // "simplexml_load_string" creates a SimpleXMLElement object for each + // XML element with child elements. In turn, each child is indexed by + // its tag in the SimpleXMLElement object. However, when there are + // several child XML elements with the same tag, an array with all the + // children with the same tag is indexed instead. Therefore, when the + // XML contains + // + // + // + // ... + // + // + // the "$elements[$shareeType]" variable contains an "element" key which + // in turn contains "label" and "value" keys, but when the XML contains + // + // + // + // ... + // + // + // + // ... + // + // + // the "$elements[$shareeType]" variable contains an "element" key which + // in turn contains "0" and "1" keys, and in turn each one contains + // "label" and "value" keys. + if (array_key_exists('element', $elements[$shareeType]) && is_int(array_keys($elements[$shareeType]['element'])[0])) { + $elements[$shareeType] = $elements[$shareeType]['element']; + } + $sharees = []; foreach ($elements[$shareeType] as $element) { $sharee = [$element['label'], $element['value']['shareType'], $element['value']['shareWith']]; diff --git a/build/integration/sharees_features/sharees.feature b/build/integration/sharees_features/sharees.feature index 7b0d8b903dc..29e185e5d63 100644 --- a/build/integration/sharees_features/sharees.feature +++ b/build/integration/sharees_features/sharees.feature @@ -8,6 +8,7 @@ Feature: sharees And user "Sharee1" exists And group "ShareeGroup" exists And user "test" belongs to group "ShareeGroup" + And user "Sharee2" exists Scenario: Search without exact match Given As an "test" @@ -19,6 +20,7 @@ Feature: sharees And "exact users" sharees returned is empty And "users" sharees returned are | Sharee1 | 0 | Sharee1 | Sharee1 | + | Sharee2 | 0 | Sharee2 | Sharee2 | And "exact groups" sharees returned is empty And "groups" sharees returned are | ShareeGroup | 1 | ShareeGroup | @@ -35,6 +37,7 @@ Feature: sharees And "exact users" sharees returned is empty And "users" sharees returned are | Sharee1 | 0 | Sharee1 | Sharee1 | + | Sharee2 | 0 | Sharee2 | Sharee2 | And "exact groups" sharees returned is empty And "groups" sharees returned are | ShareeGroup | 1 | ShareeGroup | @@ -254,6 +257,7 @@ Feature: sharees And "exact users" sharees returned is empty And "users" sharees returned are | Sharee1 | 0 | Sharee1 | Sharee1 | + | Sharee2 | 0 | Sharee2 | Sharee2 | And "exact groups" sharees returned is empty And "groups" sharees returned is empty And "exact remotes" sharees returned is empty