*/
private $mwGlobalsToUnset = [];
+ /**
+ * Holds original values of ini settings to be restored
+ * in tearDown().
+ * @see setIniSettings()
+ * @var array
+ */
+ private $iniSettings = [];
+
/**
* Holds original loggers which have been replaced by setLogger()
* @var LoggerInterface[]
foreach ( $this->mwGlobalsToUnset as $value ) {
unset( $GLOBALS[$value] );
}
+ foreach ( $this->iniSettings as $name => $value ) {
+ ini_set( $name, $value );
+ }
if (
array_key_exists( 'wgExtraNamespaces', $this->mwGlobals ) ||
in_array( 'wgExtraNamespaces', $this->mwGlobalsToUnset )
* touch.
*/
private function doSetMwGlobals( $pairs, $value = null ) {
- $this->stashMwGlobals( array_keys( $pairs ) );
+ $this->doStashMwGlobals( array_keys( $pairs ) );
foreach ( $pairs as $key => $value ) {
$GLOBALS[$key] = $value;
}
}
+ /**
+ * Set an ini setting for the duration of the test
+ * @param string $name Name of the setting
+ * @param string $value Value to set
+ * @since 1.32
+ */
+ protected function setIniSetting( $name, $value ) {
+ $original = ini_get( $name );
+ $this->iniSettings[$name] = $original;
+ ini_set( $name, $value );
+ }
+
/**
* Must be called whenever namespaces are changed, e.g., $wgExtraNamespaces is altered.
* Otherwise old namespace data will lurk and cause bugs.
* call overrideMwServices().
*
* @since 1.23
+ * @deprecated since 1.32, use setMwGlobals() and don't alter globals directly
*/
protected function stashMwGlobals( $globalKeys ) {
+ wfDeprecated( __METHOD__, '1.32' );
+ $this->doStashMwGlobals( $globalKeys );
+ }
+
+ private function doStashMwGlobals( $globalKeys ) {
if ( is_string( $globalKeys ) ) {
$globalKeys = [ $globalKeys ];
}
public function setGroupPermissions( $newPerms, $newKey = null, $newValue = null ) {
global $wgGroupPermissions;
- $this->stashMwGlobals( 'wgGroupPermissions' );
-
if ( is_string( $newPerms ) ) {
$newPerms = [ $newPerms => [ $newKey => $newValue ] ];
}
+ $newPermissions = $wgGroupPermissions;
foreach ( $newPerms as $group => $permissions ) {
foreach ( $permissions as $key => $value ) {
- $wgGroupPermissions[$group][$key] = $value;
+ $newPermissions[$group][$key] = $value;
}
}
+
+ $this->setMwGlobals( 'wgGroupPermissions', $newPermissions );
}
/**