|
| 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 = ['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 = ['--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