if ( !file_exists( $dir ) ) {
continue;
}
+ $counter = 1;
$dirIterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $dir )
);
foreach ( $dirIterator as $fileInfo ) {
/** @var SplFileInfo $fileInfo */
if ( substr( $fileInfo->getFilename(), -4 ) === '.txt' ) {
- $files[] = $fileInfo->getPathname();
+ $name = $info['name'] . $counter;
+ while ( isset( $files[$name] ) ) {
+ $name = $info['name'] . '_' . $counter++;
+ }
+ $files[$name] = $fileInfo->getPathname();
}
}
}
MediaWikiServices::getInstance()->disableService( 'MediaHandlerFactory' );
MediaWikiServices::getInstance()->redefineService(
'MediaHandlerFactory',
- function () {
- return new MockMediaHandlerFactory();
+ function ( MediaWikiServices $services ) {
+ $handlers = $services->getMainConfig()->get( 'ParserTestMediaHandlers' );
+ return new MediaHandlerFactory( $handlers );
}
);
$teardown[] = function () {
// Changing wgExtraNamespaces invalidates caches in MWNamespace and
// any live Language object, both on setup and teardown
$reset = function () {
- MWNamespace::getCanonicalNamespaces( true );
+ MWNamespace::clearCaches();
$GLOBALS['wgContLang']->resetNamespaces();
};
$setup[] = $reset;
* @see staticSetup
*
* @param array $teardown The snippet array
- * @param ScopedCallback|null A ScopedCallback to consume
+ * @param ScopedCallback|null $nextTeardown A ScopedCallback to consume
* @return ScopedCallback
*/
protected function createTeardownObject( $teardown, $nextTeardown = null ) {
/**
* Ensure a given setup stage has been done, throw an exception if it has
* not.
+ * @param string $funcName
+ * @param string|null $funcName2
*/
protected function checkSetupDone( $funcName, $funcName2 = null ) {
if ( !$this->setupDone[$funcName]
* Determine whether a particular setup function has been run
*
* @param string $funcName
- * @return boolean
+ * @return bool
*/
public function isSetupDone( $funcName ) {
return isset( $this->setupDone[$funcName] ) ? $this->setupDone[$funcName] : false;
/**
* Determine whether the current parser has the hooks registered in it
* that are required by a file read by TestFileReader.
+ * @param array $requirements
+ * @return bool
*/
public function meetsRequirements( $requirements ) {
foreach ( $requirements as $requirement ) {
*/
private function listTables() {
$tables = [ 'user', 'user_properties', 'user_former_groups', 'page', 'page_restrictions',
- 'protected_titles', 'revision', 'text', 'pagelinks', 'imagelinks',
+ 'protected_titles', 'revision', 'ip_changes', 'text', 'pagelinks', 'imagelinks',
'categorylinks', 'templatelinks', 'externallinks', 'langlinks', 'iwlinks',
'site_stats', 'ipblocks', 'image', 'oldimage',
'recentchanges', 'watchlist', 'interwiki', 'logging', 'log_search',
/**
* Add articles to the test DB.
*
- * @param $articles Article info array from TestFileReader
+ * @param array $articles Article info array from TestFileReader
*/
public function addArticles( $articles ) {
global $wgContLang;
throw new MWException( "invalid title '$name' at $file:$line\n" );
}
+ $newContent = ContentHandler::makeContent( $text, $title );
+
$page = WikiPage::factory( $title );
$page->loadPageData( 'fromdbmaster' );
if ( $page->exists() ) {
- throw new MWException( "duplicate article '$name' at $file:$line\n" );
+ $content = $page->getContent( Revision::RAW );
+ // Only reject the title, if the content/content model is different.
+ // This makes it easier to create Template:(( or Template:)) in different extensions
+ if ( $newContent->equals( $content ) ) {
+ return;
+ }
+ throw new MWException(
+ "duplicate article '$name' with different content at $file:$line\n"
+ );
}
// Use mock parser, to make debugging of actual parser tests simpler.
// get a reference to the mock object.
MessageCache::singleton()->getParser();
$restore = $this->executeSetupSnippets( [ 'wgParser' => new ParserTestMockParser ] );
- $status = $page->doEditContent(
- ContentHandler::makeContent( $text, $title ),
- '',
- EDIT_NEW | EDIT_INTERNAL
- );
- $restore();
+ try {
+ $status = $page->doEditContent(
+ $newContent,
+ '',
+ EDIT_NEW | EDIT_INTERNAL
+ );
+ } finally {
+ $restore();
+ }
if ( !$status->isOK() ) {
throw new MWException( $status->getWikiText( false, false, 'en' ) );