X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fshell%2FShellTest.php;h=986a66560e901ffa46b71cf479274dc501324679;hb=1d47891cc3d43bc6b47e30d0b605436c3dac1fc9;hp=1e91074fd40049bf56c152eb21af6f02551a54ee;hpb=949dc920ee61e838320186565cb6dc146a013b25;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/shell/ShellTest.php b/tests/phpunit/includes/shell/ShellTest.php index 1e91074fd4..3c05583806 100644 --- a/tests/phpunit/includes/shell/ShellTest.php +++ b/tests/phpunit/includes/shell/ShellTest.php @@ -1,11 +1,17 @@ assertInternalType( 'bool', Shell::isDisabled() ); // sanity } @@ -25,6 +31,76 @@ class ShellTest extends PHPUnit_Framework_TestCase { 'simple' => [ [ 'true' ], "'true'" ], 'with args' => [ [ 'convert', '-font', 'font name' ], "'convert' '-font' 'font name'" ], 'array' => [ [ [ 'convert', '-font', 'font name' ] ], "'convert' '-font' 'font name'" ], + 'skip nulls' => [ [ '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' ], + ], ]; } }