Right now they're treated as empty strings, however
this doesn't allow skipping parameters in the middle like
$params = [
'foo',
$x ? '--bar' : null,
'--baz',
];
In some cases this matters, e.g. `ls` works while `ls ''` doesn't.
Also, fix spacing problems the new tests uncovered:
* Extra space when using params()
* Missing space when combining params() and unsafeParams()
Change-Id: Icb29d4c48ae7f92fb5635e3865346c98f47abb01
31 lines
840 B
PHP
31 lines
840 B
PHP
<?php
|
|
|
|
use MediaWiki\Shell\Shell;
|
|
|
|
/**
|
|
* @group Shell
|
|
*/
|
|
class ShellTest extends PHPUnit_Framework_TestCase {
|
|
public function testIsDisabled() {
|
|
$this->assertInternalType( 'bool', Shell::isDisabled() ); // sanity
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideEscape
|
|
*/
|
|
public function testEscape( $args, $expected ) {
|
|
if ( wfIsWindows() ) {
|
|
$this->markTestSkipped( 'This test requires a POSIX environment.' );
|
|
}
|
|
$this->assertSame( $expected, call_user_func_array( [ Shell::class, 'escape' ], $args ) );
|
|
}
|
|
|
|
public function provideEscape() {
|
|
return [
|
|
'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'" ],
|
|
];
|
|
}
|
|
}
|