From 5a332dd2bb31947b53e3e57930c76037b34b4218 Mon Sep 17 00:00:00 2001
From: jrfnl <jrfnl@users.noreply.github.com>
Date: Thu, 18 Jul 2019 06:28:26 +0200
Subject: [PATCH] Simplify & modernize unit test util xml_find()
---
tests/phpunit/includes/utils.php | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php
index a6c963806c..67e7f18e50 100644
|
a
|
b
|
function xml_to_array( $in ) { |
| 243 | 243 | return $p->data; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | | function xml_find( $tree /*, $el1, $el2, $el3, .. */ ) { |
| 247 | | $a = func_get_args(); |
| 248 | | $a = array_slice( $a, 1 ); |
| 249 | | $n = count( $a ); |
| | 246 | function xml_find( $tree, ...$elms ) { |
| | 247 | $n = count( $elms ); |
| 250 | 248 | $out = array(); |
| 251 | 249 | |
| 252 | 250 | if ( $n < 1 ) { |
| … |
… |
function xml_find( $tree /*, $el1, $el2, $el3, .. */ ) { |
| 254 | 252 | } |
| 255 | 253 | |
| 256 | 254 | for ( $i = 0; $i < count( $tree ); $i++ ) { |
| 257 | | # echo "checking '{$tree[$i][name]}' == '{$a[0]}'\n"; |
| 258 | | # var_dump($tree[$i]['name'], $a[0]); |
| 259 | | if ( $tree[ $i ]['name'] === $a[0] ) { |
| | 255 | # echo "checking '{$tree[$i][name]}' == '{$elms[0]}'\n"; |
| | 256 | # var_dump($tree[$i]['name'], $elms[0]); |
| | 257 | if ( $tree[ $i ]['name'] === $elms[0] ) { |
| 260 | 258 | # echo "n == {$n}\n"; |
| 261 | 259 | if ( 1 === $n ) { |
| 262 | 260 | $out[] = $tree[ $i ]; |
| 263 | 261 | } else { |
| 264 | | $subtree =& $tree[ $i ]['child']; |
| 265 | | $call_args = array( $subtree ); |
| 266 | | $call_args = array_merge( $call_args, array_slice( $a, 1 ) ); |
| 267 | | $out = array_merge( $out, call_user_func_array( 'xml_find', $call_args ) ); |
| | 262 | $subtree =& $tree[ $i ]['child']; |
| | 263 | $out = array_merge( $out, xml_find( $subtree, ...array_slice( $elms, 1 ) ) ); |
| 268 | 264 | } |
| 269 | 265 | } |
| 270 | 266 | } |