* Reset global services, and install testing environment.
* This is the testing equivalent of MediaWikiServices::resetGlobalInstance().
* This should only be used to set up the testing environment, not when
- * runnnig unit tests. Use overrideMwServices() for that.
+ * running unit tests. Use overrideMwServices() for that.
*
* @see MediaWikiServices::resetGlobalInstance()
* @see prepareServices()
/**
* Create a config suitable for testing, based on a base config, default overrides,
- * and custom overrdies.
+ * and custom overrides.
*
* @param Config|null $baseConfig
* @param Config|null $customOverrides
/**
* @param ConfigFactory $oldFactory
- * @param Config[] $config
+ * @param Config[] $configurations
*
* @return Closure
*/
private function doLightweightServiceReset() {
global $wgRequest;
- $services = MediaWikiServices::getInstance();
-
JobQueueGroup::destroySingletons();
ObjectCache::clear();
FileBackendGroup::destroySingleton();
* Sets a service, maintaining a stashed version of the previous service to be
* restored in tearDown
*
+ * @since 1.27
+ *
* @param string $name
* @param object $object
*/
if ( $user->idForName() == 0 ) {
$user->addToDatabase();
TestUser::setPasswordForUser( $user, 'UTSysopPassword' );
+ $user->addGroup( 'sysop' );
+ $user->addGroup( 'bureaucrat' );
}
- // Always set groups, because $this->resetDB() wipes them out
- $user->addGroup( 'sysop' );
- $user->addGroup( 'bureaucrat' );
-
// Make 1 page with 1 revision
$page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
if ( $page->getId() == 0 ) {
*/
private function resetDB( $db, $tablesUsed ) {
if ( $db ) {
+ $userTables = [ 'user', 'user_groups', 'user_properties' ];
+ $coreDBDataTables = array_merge( $userTables, [ 'page', 'revision' ] );
+
+ // If any of the user tables were marked as used, we should clear all of them.
+ if ( array_intersect( $tablesUsed, $userTables ) ) {
+ $tablesUsed = array_unique( array_merge( $tablesUsed, $userTables ) );
+
+ // Totally clear User class in-process cache to avoid CAS errors
+ TestingAccessWrapper::newFromClass( 'User' )
+ ->getInProcessCache()
+ ->clear();
+ }
+
$truncate = in_array( $db->getType(), [ 'oracle', 'mysql' ] );
foreach ( $tablesUsed as $tbl ) {
- // TODO: reset interwiki and user tables to their original content.
- if ( $tbl == 'interwiki' || $tbl == 'user' ) {
+ // TODO: reset interwiki table to its original content.
+ if ( $tbl == 'interwiki' ) {
continue;
}
if ( $truncate ) {
$db->query( 'TRUNCATE TABLE ' . $db->tableName( $tbl ), __METHOD__ );
} else {
-
$db->delete( $tbl, '*', __METHOD__ );
}
LinkCache::singleton()->clear();
}
}
+
+ if ( array_intersect( $tablesUsed, $coreDBDataTables ) ) {
+ // Re-add core DB data that was deleted
+ $this->addCoreDBData();
+ }
}
}