/**
* @group ContentHandler
+ *
+ * @group Database
+ * ^--- needed, because we do need the database to test link updates
*/
class WikitextContentTest extends MediaWikiTestCase {
public function setup() {
+ global $wgUser;
+
+ // anon user
+ $wgUser = new User();
+ $wgUser->setName( '127.0.0.1' );
+
$this->context = new RequestContext( new FauxRequest() );
$this->context->setTitle( Title::newFromText( "Test" ) );
+ $this->context->setUser( $wgUser );
}
public function newContent( $text ) {
public function dataGetParserOutput() {
return array(
- array("WikitextContentTest_testGetParserOutput", "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...?
);
}
/**
* @dataProvider dataGetParserOutput
*/
- public function testGetParserOutput( $title, $text, $expectedHtml ) {
+ public function testGetParserOutput( $title, $model, $text, $expectedHtml ) {
$title = Title::newFromText( $title );
- $content = ContentHandler::makeContent( $text, $title );
+ $content = ContentHandler::makeContent( $text, $title, $model );
$po = $content->getParserOutput( $title );
public function dataGetSecondaryDataUpdates() {
return array(
- array("WikitextContentTest_testGetSecondaryDataUpdates_1", "hello ''world''\n",
+ array("WikitextContentTest_testGetSecondaryDataUpdates_1",
+ CONTENT_MODEL_WIKITEXT, "hello ''world''\n",
array( 'LinksUpdate' => array( 'mRecursive' => true,
'mLinks' => array() ) )
),
- array("WikitextContentTest_testGetSecondaryDataUpdates_2", "hello [[world test 21344]]\n",
+ array("WikitextContentTest_testGetSecondaryDataUpdates_2",
+ CONTENT_MODEL_WIKITEXT, "hello [[world test 21344]]\n",
array( 'LinksUpdate' => array( 'mRecursive' => true,
'mLinks' => array( array( 'World_test_21344' => 0 ) ) ) )
),
* @dataProvider dataGetSecondaryDataUpdates
* @group Database
*/
- public function testGetSecondaryDataUpdates( $title, $text, $expectedStuff ) {
+ 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!
- $handler = ContentHandler::getForModelID( $title->getContentModel() );
- $content = ContentHandler::makeContent( $text, $title );
+ $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;
+ $updates[$class] = $update;
}
foreach ( $expectedStuff as $class => $fieldValues ) {
$this->assertArrayHasKey( $class, $updates, "missing an update of type $class" );
- $update = $updates[ $class ];
+ $update = $updates[$class];
foreach ( $fieldValues as $field => $value ) {
$v = $update->$field; #if the field doesn't exist, just crash and burn
* @dataProvider dataPreSaveTransform
*/
public function testPreSaveTransform( $text, $expected ) {
- global $wgUser, $wgContLang;
- $options = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
+ global $wgContLang;
+
+ $options = ParserOptions::newFromUserAndLang( $this->context->getUser(), $wgContLang );
$content = $this->newContent( $text );
$content = $content->preSaveTransform( $this->context->getTitle(), $this->context->getUser(), $options );
* @dataProvider dataPreloadTransform
*/
public function testPreloadTransform( $text, $expected ) {
- global $wgUser, $wgContLang;
- $options = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
+ global $wgContLang;
+ $options = ParserOptions::newFromUserAndLang( $this->context->getUser(), $wgContLang );
$content = $this->newContent( $text );
$content = $content->preloadTransform( $this->context->getTitle(), $options );
$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() );
+ if ( is_null( $expected ) ) {
+ $this->assertNull( $t, "text should not have generated a redirect target: $text" );
+ } else {
+ $this->assertEquals( $expected, $t->getPrefixedText() );
+ }
}
/**
/**
- * @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 dataGetDeletionUpdates() {
return array(
- array("WikitextContentTest_testGetSecondaryDataUpdates_1", "hello ''world''\n",
+ array("WikitextContentTest_testGetSecondaryDataUpdates_1",
+ CONTENT_MODEL_WIKITEXT, "hello ''world''\n",
array( 'LinksDeletionUpdate' => array( ) )
),
- array("WikitextContentTest_testGetSecondaryDataUpdates_2", "hello [[world test 21344]]\n",
+ array("WikitextContentTest_testGetSecondaryDataUpdates_2",
+ CONTENT_MODEL_WIKITEXT, "hello [[world test 21344]]\n",
array( 'LinksDeletionUpdate' => array( ) )
),
// @todo: more...?
/**
* @dataProvider dataGetDeletionUpdates
*/
- public function testDeletionUpdates( $title, $text, $expectedStuff ) {
+ public function testDeletionUpdates( $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!
- $handler = ContentHandler::getForModelID( $title->getContentModel() );
- $content = ContentHandler::makeContent( $text, $title );
+ $content = ContentHandler::makeContent( $text, $title, $model );
- $updates = $content->getDeletionUpdates( $title );
+ $updates = $content->getDeletionUpdates( WikiPage::factory( $title ) );
// make updates accessible by class name
foreach ( $updates as $update ) {