MediaWiki  1.33.0
ShellTest.php
Go to the documentation of this file.
1 <?php
2 
5 use Wikimedia\TestingAccessWrapper;
6 
12 
13  use MediaWikiCoversValidator;
14 
15  public function testIsDisabled() {
16  $this->assertInternalType( 'bool', Shell::isDisabled() ); // sanity
17  }
18 
22  public function testEscape( $args, $expected ) {
23  if ( wfIsWindows() ) {
24  $this->markTestSkipped( 'This test requires a POSIX environment.' );
25  }
26  $this->assertSame( $expected, call_user_func_array( [ Shell::class, 'escape' ], $args ) );
27  }
28 
29  public function provideEscape() {
30  return [
31  'simple' => [ [ 'true' ], "'true'" ],
32  'with args' => [ [ 'convert', '-font', 'font name' ], "'convert' '-font' 'font name'" ],
33  'array' => [ [ [ 'convert', '-font', 'font name' ] ], "'convert' '-font' 'font name'" ],
34  'skip nulls' => [ [ 'ls', null ], "'ls'" ],
35  ];
36  }
37 
48  public function testMakeScriptCommand(
49  $expected,
50  $script,
51  $parameters,
52  $options = [],
53  $hook = null
54  ) {
55  // Running tests under Vagrant involves MWMultiVersion that uses the below hook
56  $this->setMwGlobals( 'wgHooks', [] );
57 
58  if ( $hook ) {
59  $this->setTemporaryHook( 'wfShellWikiCmd', $hook );
60  }
61 
62  $command = Shell::makeScriptCommand( $script, $parameters, $options );
63  $command->params( 'safe' )
64  ->unsafeParams( 'unsafe' );
65 
67 
68  $wrapper = TestingAccessWrapper::newFromObject( $command );
69  $this->assertEquals( $expected, $wrapper->command );
70  $this->assertEquals( 0, $wrapper->restrictions & Shell::NO_LOCALSETTINGS );
71  }
72 
73  public function provideMakeScriptCommand() {
74  global $wgPhpCli;
75 
76  return [
77  [
78  "'$wgPhpCli' 'maintenance/foobar.php' 'bar'\\''\"baz' 'safe' unsafe",
79  'maintenance/foobar.php',
80  [ 'bar\'"baz' ],
81  ],
82  [
83  "'$wgPhpCli' 'changed.php' '--wiki=somewiki' 'bar'\\''\"baz' 'safe' unsafe",
84  'maintenance/foobar.php',
85  [ 'bar\'"baz' ],
86  [],
87  function ( &$script, array &$parameters ) {
88  $script = 'changed.php';
89  array_unshift( $parameters, '--wiki=somewiki' );
90  }
91  ],
92  [
93  "'/bin/perl' 'maintenance/foobar.php' 'bar'\\''\"baz' 'safe' unsafe",
94  'maintenance/foobar.php',
95  [ 'bar\'"baz' ],
96  [ 'php' => '/bin/perl' ],
97  ],
98  [
99  "'$wgPhpCli' 'foobinize' 'maintenance/foobar.php' 'bar'\\''\"baz' 'safe' unsafe",
100  'maintenance/foobar.php',
101  [ 'bar\'"baz' ],
102  [ 'wrapper' => 'foobinize' ],
103  ],
104  ];
105  }
106 }
$wgPhpCli
$wgPhpCli
Executable path of the PHP cli binary.
Definition: DefaultSettings.php:8311
ShellTest\testEscape
testEscape( $args, $expected)
provideEscape
Definition: ShellTest.php:22
MediaWiki\Shell\Shell
Executes shell commands.
Definition: Shell.php:44
MediaWiki\Shell\Command
Class used for executing shell commands.
Definition: Command.php:35
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ShellTest\testMakeScriptCommand
testMakeScriptCommand( $expected, $script, $parameters, $options=[], $hook=null)
\MediaWiki\Shell\Shell::makeScriptCommand provideMakeScriptCommand
Definition: ShellTest.php:48
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:709
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ShellTest
\MediaWiki\Shell\Shell Shell
Definition: ShellTest.php:11
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
null
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
$command
$command
Definition: cdb.php:65
wfIsWindows
wfIsWindows()
Check if the operating system is Windows.
Definition: GlobalFunctions.php:1951
ShellTest\provideEscape
provideEscape()
Definition: ShellTest.php:29
$args
if( $line===false) $args
Definition: cdb.php:64
ShellTest\testIsDisabled
testIsDisabled()
Definition: ShellTest.php:15
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1985
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MediaWikiTestCase\setTemporaryHook
setTemporaryHook( $hookName, $handler)
Create a temporary hook handler which will be reset by tearDown.
Definition: MediaWikiTestCase.php:2325
MediaWikiTestCase\assertType
assertType( $type, $actual, $message='')
Asserts the type of the provided value.
Definition: MediaWikiTestCase.php:2177
ShellTest\provideMakeScriptCommand
provideMakeScriptCommand()
Definition: ShellTest.php:73