X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fshell%2FShellTest.php;h=3c0558380658fc610c3c34cf2d0f2e119c2a18d8;hp=8162bc02999a44b1872150c9bad6490e6867fbfb;hb=633b6532fa4df83df61fc2c5b9003c1003e7af5b;hpb=ec262cbb893e1675df9a87f4e41d3aa1a7d99156 diff --git a/tests/phpunit/includes/shell/ShellTest.php b/tests/phpunit/includes/shell/ShellTest.php index 8162bc0299..3c05583806 100644 --- a/tests/phpunit/includes/shell/ShellTest.php +++ b/tests/phpunit/includes/shell/ShellTest.php @@ -1,12 +1,14 @@ [ [ 'ls', null ], "'ls'" ], ]; } + + /** + * @covers \MediaWiki\Shell\Shell::makeScriptCommand + * @dataProvider provideMakeScriptCommand + * + * @param string $expected + * @param string $script + * @param string[] $parameters + * @param string[] $options + * @param callable|null $hook + */ + public function testMakeScriptCommand( + $expected, + $script, + $parameters, + $options = [], + $hook = null + ) { + // Running tests under Vagrant involves MWMultiVersion that uses the below hook + $this->setMwGlobals( 'wgHooks', [] ); + + if ( $hook ) { + $this->setTemporaryHook( 'wfShellWikiCmd', $hook ); + } + + $command = Shell::makeScriptCommand( $script, $parameters, $options ); + $command->params( 'safe' ) + ->unsafeParams( 'unsafe' ); + + $this->assertType( Command::class, $command ); + + $wrapper = TestingAccessWrapper::newFromObject( $command ); + $this->assertEquals( $expected, $wrapper->command ); + $this->assertEquals( 0, $wrapper->restrictions & Shell::NO_LOCALSETTINGS ); + } + + public function provideMakeScriptCommand() { + global $wgPhpCli; + + return [ + [ + "'$wgPhpCli' 'maintenance/foobar.php' 'bar'\\''\"baz' 'safe' unsafe", + 'maintenance/foobar.php', + [ 'bar\'"baz' ], + ], + [ + "'$wgPhpCli' 'changed.php' '--wiki=somewiki' 'bar'\\''\"baz' 'safe' unsafe", + 'maintenance/foobar.php', + [ 'bar\'"baz' ], + [], + function ( &$script, array &$parameters ) { + $script = 'changed.php'; + array_unshift( $parameters, '--wiki=somewiki' ); + } + ], + [ + "'/bin/perl' 'maintenance/foobar.php' 'bar'\\''\"baz' 'safe' unsafe", + 'maintenance/foobar.php', + [ 'bar\'"baz' ], + [ 'php' => '/bin/perl' ], + ], + [ + "'$wgPhpCli' 'foobinize' 'maintenance/foobar.php' 'bar'\\''\"baz' 'safe' unsafe", + 'maintenance/foobar.php', + [ 'bar\'"baz' ], + [ 'wrapper' => 'foobinize' ], + ], + ]; + } }