// 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;
/**
* 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 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 ) {
$out = $parser->getPreloadText( $test['input'], $title, $options );
} else {
$output = $parser->parse( $test['input'], $title, $options, true, true, 1337 );
- $output->setTOCEnabled( !isset( $opts['notoc'] ) );
- $out = $output->getText();
+ $out = $output->getText( [
+ 'allowTOC' => !isset( $opts['notoc'] )
+ ] );
if ( isset( $opts['tidy'] ) ) {
$out = preg_replace( '/\s+$/', '', $out );
}
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' ) );