Skip to content

Commit 29e71f1

Browse files
test: add unit tests for argument array pattern (backport to 1.2.x)
1 parent 86d6151 commit 29e71f1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/*
3+
+-------------------------------------------------------------------------+
4+
| Copyright (C) 2004-2026 The Cacti Group |
5+
| |
6+
| This program is free software; you can redistribute it and/or |
7+
| modify it under the terms of the GNU General Public License |
8+
| as published by the Free Software Foundation; either version 2 |
9+
| of the License, or (at your option) any later version. |
10+
+-------------------------------------------------------------------------+
11+
| Cacti: The Complete RRDtool-based Graphing Solution |
12+
+-------------------------------------------------------------------------+
13+
*/
14+
15+
require_once dirname(__DIR__) . '/Helpers/CactiStubs.php';
16+
17+
// Mock cacti_escapeshellarg if it doesn't exist in testing env
18+
if (!function_exists('cacti_escapeshellarg')) {
19+
function cacti_escapeshellarg($arg) {
20+
return "'" . str_replace("'", "'\\''", $arg) . "'";
21+
}
22+
}
23+
24+
test('__rrd_execute correctly handles array of arguments', function () {
25+
$args = array('graph', '-', '--start', '12345; id');
26+
27+
// Simulated logic from __rrd_execute
28+
$command_line = implode(' ', array_map('cacti_escapeshellarg', $args));
29+
30+
expect($command_line)->toBe("'graph' '-' '--start' '12345; id'");
31+
});
32+
33+
test('exec_background correctly handles array of arguments', function () {
34+
$args = array('--poller=1', '--network=192.168.1.0/24; id');
35+
36+
// Simulated logic from exec_background
37+
$args_string = implode(' ', array_map('cacti_escapeshellarg', $args));
38+
39+
expect($args_string)->toBe("'--poller=1' '--network=192.168.1.0/24; id'");
40+
});

0 commit comments

Comments
 (0)