<?php
-class WikitextContentTest extends MediaWikiTestCase {
-
- public function setup() {
- $this->context = new RequestContext( new FauxRequest() );
- $this->context->setTitle( Title::newFromText( "Test" ) );
- }
+/**
+ * @group ContentHandler
+ *
+ * @group Database
+ * ^--- needed, because we do need the database to test link updates
+ */
+class WikitextContentTest extends TextContentTest {
public function newContent( $text ) {
return new WikitextContent( $text );
public function dataGetParserOutput() {
return array(
- array("hello ''world''\n", "<p>hello <i>world</i>\n</p>"),
+ array("WikitextContentTest_testGetParserOutput", CONTENT_MODEL_WIKITEXT, "hello ''world''\n", "<p>hello <i>world</i>\n</p>"),
+ // @todo: more...?
+ );
+ }
+
+ public function dataGetSecondaryDataUpdates() {
+ return array(
+ array("WikitextContentTest_testGetSecondaryDataUpdates_1",
+ CONTENT_MODEL_WIKITEXT, "hello ''world''\n",
+ array( 'LinksUpdate' => array( 'mRecursive' => true,
+ 'mLinks' => array() ) )
+ ),
+ array("WikitextContentTest_testGetSecondaryDataUpdates_2",
+ CONTENT_MODEL_WIKITEXT, "hello [[world test 21344]]\n",
+ array( 'LinksUpdate' => array( 'mRecursive' => true,
+ 'mLinks' => array( array( 'World_test_21344' => 0 ) ) ) )
+ ),
// @todo: more...?
);
}
/**
- * @dataProvider dataGetParserOutput
+ * @dataProvider dataGetSecondaryDataUpdates
+ * @group Database
*/
- public function testGetParserOutput( $text, $expectedHtml ) {
- $content = $this->newContent( $text );
+ public function testGetSecondaryDataUpdates( $title, $model, $text, $expectedStuff ) {
+ $title = Title::newFromText( $title );
+ $title->resetArticleID( 2342 ); //dummy id. fine as long as we don't try to execute the updates!
+
+ $content = ContentHandler::makeContent( $text, $title, $model );
+
+ $updates = $content->getSecondaryDataUpdates( $title );
+
+ // make updates accessible by class name
+ foreach ( $updates as $update ) {
+ $class = get_class( $update );
+ $updates[$class] = $update;
+ }
- $po = $content->getParserOutput( $this->context );
+ foreach ( $expectedStuff as $class => $fieldValues ) {
+ $this->assertArrayHasKey( $class, $updates, "missing an update of type $class" );
- $this->assertEquals( $expectedHtml, $po->getText() );
- return $po;
+ $update = $updates[$class];
+
+ foreach ( $fieldValues as $field => $value ) {
+ $v = $update->$field; #if the field doesn't exist, just crash and burn
+ $this->assertEquals( $value, $v, "unexpected value for field $field in instance of $class" );
+ }
+ }
}
+
static $sections =
"Intro
$content = $this->newContent( $text );
$sectionContent = $content->getSection( $sectionId );
+ if ( is_object( $sectionContent ) ) {
+ $sectionText = $sectionContent->getNativeData();
+ } else {
+ $sectionText = $sectionContent;
+ }
- $this->assertEquals( $expectedText, is_null( $sectionContent ) ? null : $sectionContent->getNativeData() );
+ $this->assertEquals( $expectedText, $sectionText );
}
public function dataReplaceSection() {
);
}
- /**
- * @dataProvider dataPreSaveTransform
- */
- public function testPreSaveTransform( $text, $expected ) {
- global $wgUser, $wgContLang;
- $options = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
-
- $content = $this->newContent( $text );
- $content = $content->preSaveTransform( $this->context->getTitle(), $this->context->getUser(), $options );
-
- $this->assertEquals( $expected, $content->getNativeData() );
- }
-
public function dataPreloadTransform() {
return array(
array( 'hello this is ~~~',
);
}
- /**
- * @dataProvider dataPreloadTransform
- */
- public function testPreloadTransform( $text, $expected ) {
- global $wgUser, $wgContLang;
- $options = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
-
- $content = $this->newContent( $text );
- $content = $content->preloadTransform( $this->context->getTitle(), $options );
-
- $this->assertEquals( $expected, $content->getNativeData() );
- }
-
public function dataGetRedirectTarget() {
return array(
array( '#REDIRECT [[Test]]',
);
}
- /**
- * @dataProvider dataGetRedirectTarget
- */
- public function testGetRedirectTarget( $text, $expected ) {
- $content = $this->newContent( $text );
- $t = $content->getRedirectTarget( );
-
- if ( is_null( $expected ) ) $this->assertNull( $t, "text should not have generated a redirect target: $text" );
- else $this->assertEquals( $expected, $t->getPrefixedText() );
- }
-
- /**
- * @dataProvider dataGetRedirectTarget
- */
- public function isRedirect( $text, $expected ) {
- $content = $this->newContent( $text );
-
- $this->assertEquals( !is_null($expected), $content->isRedirect() );
+ public function dataGetTextForSummary() {
+ return array(
+ array( "hello\nworld.",
+ 16,
+ 'hello world.',
+ ),
+ array( 'hello world.',
+ 8,
+ 'hello...',
+ ),
+ array( '[[hello world]].',
+ 8,
+ 'hel...',
+ ),
+ );
}
-
/**
- * @todo: test needs database!
+ * @todo: test needs database! Should be done by a test class in the Database group.
*/
/*
public function getRedirectChain() {
*/
/**
- * @todo: test needs database!
+ * @todo: test needs database! Should be done by a test class in the Database group.
*/
/*
public function getUltimateRedirectTarget() {
);
}
+ public function testMatchMagicWord( ) {
+ $mw = MagicWord::get( "staticredirect" );
- /**
- * @dataProvider dataIsCountable
- */
- public function testIsCountable( $text, $hasLinks, $mode, $expected ) {
- global $wgArticleCountMethod;
-
- $old = $wgArticleCountMethod;
- $wgArticleCountMethod = $mode;
-
- $content = $this->newContent( $text );
-
- $v = $content->isCountable( $hasLinks, $this->context );
- $wgArticleCountMethod = $old;
-
- $this->assertEquals( $expected, $v, "isCountable() returned unexpected value " . var_export( $v, true )
- . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );
- }
-
- public function dataGetTextForSummary() {
- return array(
- array( "hello\nworld.",
- 16,
- 'hello world.',
- ),
- array( 'hello world.',
- 8,
- 'hello...',
- ),
- array( '[[hello world]].',
- 8,
- 'hel...',
- ),
- );
- }
-
- /**
- * @dataProvider dataGetTextForSummary
- */
- public function testGetTextForSummary( $text, $maxlength, $expected ) {
- $content = $this->newContent( $text );
-
- $this->assertEquals( $expected, $content->getTextForSummary( $maxlength ) );
- }
-
-
- public function testGetTextForSearchIndex( ) {
- $content = $this->newContent( "hello world." );
+ $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
+ $this->assertTrue( $content->matchMagicWord( $mw ), "should have matched magic word" );
- $this->assertEquals( "hello world.", $content->getTextForSearchIndex() );
+ $content = $this->newContent( "#REDIRECT [[FOO]]" );
+ $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word" );
}
- public function testCopy() {
- $content = $this->newContent( "hello world." );
- $copy = $content->copy();
-
- $this->assertTrue( $content->equals( $copy ), "copy must be equal to original" );
- $this->assertEquals( "hello world.", $copy->getNativeData() );
- }
+ public function testUpdateRedirect( ) {
+ $target = Title::newFromText( "testUpdateRedirect_target" );
- public function testGetSize( ) {
+ // test with non-redirect page
$content = $this->newContent( "hello world." );
+ $newContent = $content->updateRedirect( $target );
- $this->assertEquals( 12, $content->getSize() );
- }
+ $this->assertTrue( $content->equals( $newContent ), "content should be unchanged" );
- public function testGetNativeData( ) {
- $content = $this->newContent( "hello world." );
+ // test with actual redirect
+ $content = $this->newContent( "#REDIRECT [[Someplace]]" );
+ $newContent = $content->updateRedirect( $target );
- $this->assertEquals( "hello world.", $content->getNativeData() );
- }
+ $this->assertFalse( $content->equals( $newContent ), "content should have changed" );
+ $this->assertTrue( $newContent->isRedirect(), "new content should be a redirect" );
- public function testGetWikitextForTransclusion( ) {
- $content = $this->newContent( "hello world." );
-
- $this->assertEquals( "hello world.", $content->getWikitextForTransclusion() );
+ $this->assertEquals( $target->getFullText(), $newContent->getRedirectTarget()->getFullText() );
}
# =================================================================================================================
- public function getModelName() {
+ public function testGetModel() {
$content = $this->newContent( "hello world." );
- $this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getModelName() );
+ $this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getModel() );
}
- public function getContentHandler() {
+ public function testGetContentHandler() {
$content = $this->newContent( "hello world." );
- $this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getContentHandler()->getModelName() );
- }
-
- public function dataIsEmpty( ) {
- return array(
- array( '', true ),
- array( ' ', false ),
- array( '0', false ),
- array( 'hallo welt.', false ),
- );
- }
-
- /**
- * @dataProvider dataIsEmpty
- */
- public function testIsEmpty( $text, $empty ) {
- $content = $this->newContent( $text );
-
- $this->assertEquals( $empty, $content->isEmpty() );
+ $this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getContentHandler()->getModelID() );
}
public function dataEquals( ) {
array( new WikitextContent( "hallo" ), null, false ),
array( new WikitextContent( "hallo" ), new WikitextContent( "hallo" ), true ),
array( new WikitextContent( "hallo" ), new JavascriptContent( "hallo" ), false ),
+ array( new WikitextContent( "hallo" ), new TextContent( "hallo" ), false ),
array( new WikitextContent( "hallo" ), new WikitextContent( "HALLO" ), false ),
);
}
- /**
- * @dataProvider dataEquals
- */
- public function testEquals( Content $a, Content $b = null, $equal = false ) {
- $this->assertEquals( $equal, $a->equals( $b ) );
+ public function dataGetDeletionUpdates() {
+ return array(
+ array("WikitextContentTest_testGetSecondaryDataUpdates_1",
+ CONTENT_MODEL_WIKITEXT, "hello ''world''\n",
+ array( 'LinksDeletionUpdate' => array( ) )
+ ),
+ array("WikitextContentTest_testGetSecondaryDataUpdates_2",
+ CONTENT_MODEL_WIKITEXT, "hello [[world test 21344]]\n",
+ array( 'LinksDeletionUpdate' => array( ) )
+ ),
+ // @todo: more...?
+ );
}
}