X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FMediaWikiTestCase.php;h=f04eec73b4d6e1801711107e648a19ca1920d2bc;hb=354c8fa3d5a72709f53c692ffa8fd4b703cf91d3;hp=18e6e97d5d4a57621de94be4f4116050b337a1bc;hpb=84b6d5c2e5be3b2fcd1808a7bb82f24a494e3426;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 18e6e97d5d..f04eec73b4 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -213,6 +213,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * * @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(); @@ -1254,7 +1255,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * * @return Database[] Array of Database master connections */ - protected static function getExternalStoreDatabaseConnections() { global $wgDefaultExternalStore; @@ -1304,13 +1304,17 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { 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 ) { @@ -1588,7 +1592,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * * @since 1.20 * - * @param array $array + * @param array &$array */ protected function objectAssociativeSort( array &$array ) { uasort( @@ -1606,7 +1610,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * * @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 ) ) { @@ -1829,6 +1833,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { /** * Used as a marker to prevent wfResetOutputBuffers from breaking PHPUnit. + * @param string $buffer * @return string */ public static function wfResetOutputBuffersBarrier( $buffer ) { @@ -1846,4 +1851,29 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $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 ); + } }