*
* @param Config|null $bootstrapConfig The bootstrap config to use with the new
* MediaWikiServices.
+ * @return MediaWikiServices
*/
protected static function resetGlobalServices( Config $bootstrapConfig = null ) {
$oldServices = MediaWikiServices::getInstance();
*
* @return Database[] Array of Database master connections
*/
-
protected static function getExternalStoreDatabaseConnections() {
global $wgDefaultExternalStore;
private function resetDB( $db, $tablesUsed ) {
if ( $db ) {
$userTables = [ 'user', 'user_groups', 'user_properties' ];
- $coreDBDataTables = array_merge( $userTables, [ 'page', 'revision' ] );
+ $pageTables = [ 'page', 'revision', 'ip_changes', 'revision_comment_temp', 'comment' ];
+ $coreDBDataTables = array_merge( $userTables, $pageTables );
- // If any of the user tables were marked as used, we should clear all of them.
+ // If any of the user or page tables were marked as used, we should clear all of them.
if ( array_intersect( $tablesUsed, $userTables ) ) {
$tablesUsed = array_unique( array_merge( $tablesUsed, $userTables ) );
TestUserRegistry::clear();
}
+ if ( array_intersect( $tablesUsed, $pageTables ) ) {
+ $tablesUsed = array_unique( array_merge( $tablesUsed, $pageTables ) );
+ }
$truncate = in_array( $db->getType(), [ 'oracle', 'mysql' ] );
foreach ( $tablesUsed as $tbl ) {
*
* @since 1.20
*
- * @param array $array
+ * @param array &$array
*/
protected function objectAssociativeSort( array &$array ) {
uasort(
*
* @since 1.20
*
- * @param mixed $r The array to remove string keys from.
+ * @param mixed &$r The array to remove string keys from.
*/
protected static function stripStringKeys( &$r ) {
if ( !is_array( $r ) ) {
/**
* Used as a marker to prevent wfResetOutputBuffers from breaking PHPUnit.
+ * @param string $buffer
* @return string
*/
public static function wfResetOutputBuffersBarrier( $buffer ) {
$this->mergeMwGlobalArrayValue( 'wgHooks', [ $hookName => [ $handler ] ] );
}
+ /**
+ * Check whether file contains given data.
+ * @param string $fileName
+ * @param string $actualData
+ * @param bool $createIfMissing If true, and file does not exist, create it with given data
+ * and skip the test.
+ * @param string $msg
+ * @since 1.30
+ */
+ protected function assertFileContains(
+ $fileName,
+ $actualData,
+ $createIfMissing = true,
+ $msg = ''
+ ) {
+ if ( $createIfMissing ) {
+ if ( !file_exists( $fileName ) ) {
+ file_put_contents( $fileName, $actualData );
+ $this->markTestSkipped( 'Data file $fileName does not exist' );
+ }
+ } else {
+ self::assertFileExists( $fileName );
+ }
+ self::assertEquals( file_get_contents( $fileName ), $actualData, $msg );
+ }
}