2012-04-23 16:16:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
/**
|
|
|
|
|
* @group ContentHandler
|
|
|
|
|
*/
|
2012-04-23 16:16:36 +00:00
|
|
|
class WikitextContentTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
|
|
public function setup() {
|
2012-08-29 18:00:28 +00:00
|
|
|
global $wgUser;
|
|
|
|
|
|
|
|
|
|
// anon user
|
|
|
|
|
$wgUser = new User();
|
|
|
|
|
$wgUser->setName( '127.0.0.1' );
|
|
|
|
|
|
2012-04-23 16:16:36 +00:00
|
|
|
$this->context = new RequestContext( new FauxRequest() );
|
|
|
|
|
$this->context->setTitle( Title::newFromText( "Test" ) );
|
2012-08-29 18:00:28 +00:00
|
|
|
$this->context->setUser( $wgUser );
|
2012-04-23 16:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-23 17:13:54 +00:00
|
|
|
public function newContent( $text ) {
|
|
|
|
|
return new WikitextContent( $text );
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-23 21:52:34 +00:00
|
|
|
|
2012-04-23 16:16:36 +00:00
|
|
|
public function dataGetParserOutput() {
|
|
|
|
|
return array(
|
2012-07-23 21:52:34 +00:00
|
|
|
array("WikitextContentTest_testGetParserOutput", "hello ''world''\n", "<p>hello <i>world</i>\n</p>"),
|
2012-04-23 16:16:36 +00:00
|
|
|
// @todo: more...?
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetParserOutput
|
|
|
|
|
*/
|
2012-07-23 21:52:34 +00:00
|
|
|
public function testGetParserOutput( $title, $text, $expectedHtml ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
$content = ContentHandler::makeContent( $text, $title );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
2012-07-23 21:52:34 +00:00
|
|
|
$po = $content->getParserOutput( $title );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $expectedHtml, $po->getText() );
|
2012-07-23 21:52:34 +00:00
|
|
|
// @todo: assert more properties
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dataGetSecondaryDataUpdates() {
|
|
|
|
|
return array(
|
|
|
|
|
array("WikitextContentTest_testGetSecondaryDataUpdates_1", "hello ''world''\n",
|
|
|
|
|
array( 'LinksUpdate' => array( 'mRecursive' => true,
|
|
|
|
|
'mLinks' => array() ) )
|
|
|
|
|
),
|
|
|
|
|
array("WikitextContentTest_testGetSecondaryDataUpdates_2", "hello [[world test 21344]]\n",
|
|
|
|
|
array( 'LinksUpdate' => array( 'mRecursive' => true,
|
|
|
|
|
'mLinks' => array( array( 'World_test_21344' => 0 ) ) ) )
|
|
|
|
|
),
|
|
|
|
|
// @todo: more...?
|
|
|
|
|
);
|
2012-04-23 16:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-23 21:52:34 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetSecondaryDataUpdates
|
2012-07-27 20:49:58 +00:00
|
|
|
* @group Database
|
2012-07-23 21:52:34 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetSecondaryDataUpdates( $title, $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 );
|
|
|
|
|
|
|
|
|
|
$updates = $content->getSecondaryDataUpdates( $title );
|
|
|
|
|
|
|
|
|
|
// make updates accessible by class name
|
|
|
|
|
foreach ( $updates as $update ) {
|
|
|
|
|
$class = get_class( $update );
|
|
|
|
|
$updates[ $class ] = $update;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $expectedStuff as $class => $fieldValues ) {
|
|
|
|
|
$this->assertArrayHasKey( $class, $updates, "missing an update of type $class" );
|
|
|
|
|
|
|
|
|
|
$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" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-04-23 16:16:36 +00:00
|
|
|
static $sections =
|
|
|
|
|
|
|
|
|
|
"Intro
|
|
|
|
|
|
|
|
|
|
== stuff ==
|
|
|
|
|
hello world
|
|
|
|
|
|
|
|
|
|
== test ==
|
|
|
|
|
just a test
|
|
|
|
|
|
|
|
|
|
== foo ==
|
|
|
|
|
more stuff
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
public function dataGetSection() {
|
|
|
|
|
return array(
|
|
|
|
|
array( WikitextContentTest::$sections,
|
|
|
|
|
"0",
|
|
|
|
|
"Intro"
|
|
|
|
|
),
|
|
|
|
|
array( WikitextContentTest::$sections,
|
|
|
|
|
"2",
|
|
|
|
|
"== test ==
|
|
|
|
|
just a test"
|
|
|
|
|
),
|
|
|
|
|
array( WikitextContentTest::$sections,
|
|
|
|
|
"8",
|
|
|
|
|
false
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetSection
|
|
|
|
|
*/
|
|
|
|
|
public function testGetSection( $text, $sectionId, $expectedText ) {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( $text );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
|
|
|
|
$sectionContent = $content->getSection( $sectionId );
|
|
|
|
|
|
2012-04-23 17:13:54 +00:00
|
|
|
$this->assertEquals( $expectedText, is_null( $sectionContent ) ? null : $sectionContent->getNativeData() );
|
2012-04-23 16:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dataReplaceSection() {
|
|
|
|
|
return array(
|
|
|
|
|
array( WikitextContentTest::$sections,
|
|
|
|
|
"0",
|
|
|
|
|
"No more",
|
|
|
|
|
null,
|
|
|
|
|
trim( preg_replace( '/^Intro/sm', 'No more', WikitextContentTest::$sections ) )
|
|
|
|
|
),
|
|
|
|
|
array( WikitextContentTest::$sections,
|
|
|
|
|
"",
|
|
|
|
|
"No more",
|
|
|
|
|
null,
|
2012-04-24 14:23:55 +00:00
|
|
|
"No more"
|
2012-04-23 16:16:36 +00:00
|
|
|
),
|
|
|
|
|
array( WikitextContentTest::$sections,
|
|
|
|
|
"2",
|
|
|
|
|
"== TEST ==\nmore fun",
|
|
|
|
|
null,
|
|
|
|
|
trim( preg_replace( '/^== test ==.*== foo ==/sm', "== TEST ==\nmore fun\n\n== foo ==", WikitextContentTest::$sections ) )
|
|
|
|
|
),
|
|
|
|
|
array( WikitextContentTest::$sections,
|
|
|
|
|
"8",
|
|
|
|
|
"No more",
|
|
|
|
|
null,
|
|
|
|
|
WikitextContentTest::$sections
|
|
|
|
|
),
|
|
|
|
|
array( WikitextContentTest::$sections,
|
|
|
|
|
"new",
|
|
|
|
|
"No more",
|
|
|
|
|
"New",
|
|
|
|
|
trim( WikitextContentTest::$sections ) . "\n\n\n== New ==\n\nNo more"
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataReplaceSection
|
|
|
|
|
*/
|
|
|
|
|
public function testReplaceSection( $text, $section, $with, $sectionTitle, $expected ) {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( $text );
|
|
|
|
|
$c = $content->replaceSection( $section, $this->newContent( $with ), $sectionTitle );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
2012-04-23 17:13:54 +00:00
|
|
|
$this->assertEquals( $expected, is_null( $c ) ? null : $c->getNativeData() );
|
2012-04-23 16:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAddSectionHeader( ) {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( 'hello world' );
|
2012-04-23 16:16:36 +00:00
|
|
|
$content = $content->addSectionHeader( 'test' );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( "== test ==\n\nhello world", $content->getNativeData() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dataPreSaveTransform() {
|
|
|
|
|
return array(
|
|
|
|
|
array( 'hello this is ~~~',
|
|
|
|
|
"hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
|
|
|
|
|
),
|
|
|
|
|
array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
|
|
|
|
|
'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataPreSaveTransform
|
|
|
|
|
*/
|
|
|
|
|
public function testPreSaveTransform( $text, $expected ) {
|
2012-08-29 18:00:28 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
|
|
|
|
|
$options = ParserOptions::newFromUserAndLang( $this->context->getUser(), $wgContLang );
|
2012-04-30 10:50:31 +00:00
|
|
|
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( $text );
|
2012-04-30 10:50:31 +00:00
|
|
|
$content = $content->preSaveTransform( $this->context->getTitle(), $this->context->getUser(), $options );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $content->getNativeData() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dataPreloadTransform() {
|
|
|
|
|
return array(
|
|
|
|
|
array( 'hello this is ~~~',
|
|
|
|
|
"hello this is ~~~",
|
|
|
|
|
),
|
|
|
|
|
array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
|
|
|
|
|
'hello \'\'this\'\' is bar',
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataPreloadTransform
|
|
|
|
|
*/
|
|
|
|
|
public function testPreloadTransform( $text, $expected ) {
|
2012-08-29 18:00:28 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
$options = ParserOptions::newFromUserAndLang( $this->context->getUser(), $wgContLang );
|
2012-04-30 10:50:31 +00:00
|
|
|
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( $text );
|
2012-04-30 10:50:31 +00:00
|
|
|
$content = $content->preloadTransform( $this->context->getTitle(), $options );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $content->getNativeData() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dataGetRedirectTarget() {
|
|
|
|
|
return array(
|
|
|
|
|
array( '#REDIRECT [[Test]]',
|
|
|
|
|
'Test',
|
|
|
|
|
),
|
|
|
|
|
array( '#REDIRECT Test',
|
|
|
|
|
null,
|
|
|
|
|
),
|
|
|
|
|
array( '* #REDIRECT [[Test]]',
|
|
|
|
|
null,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetRedirectTarget
|
|
|
|
|
*/
|
|
|
|
|
public function testGetRedirectTarget( $text, $expected ) {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( $text );
|
2012-04-23 16:16:36 +00:00
|
|
|
$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 ) {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( $text );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( !is_null($expected), $content->isRedirect() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @todo: test needs database!
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
public function getRedirectChain() {
|
|
|
|
|
$text = $this->getNativeData();
|
|
|
|
|
return Title::newFromRedirectArray( $text );
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @todo: test needs database!
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
public function getUltimateRedirectTarget() {
|
|
|
|
|
$text = $this->getNativeData();
|
|
|
|
|
return Title::newFromRedirectRecurse( $text );
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function dataIsCountable() {
|
|
|
|
|
return array(
|
|
|
|
|
array( '',
|
|
|
|
|
null,
|
|
|
|
|
'any',
|
|
|
|
|
true
|
|
|
|
|
),
|
|
|
|
|
array( 'Foo',
|
|
|
|
|
null,
|
|
|
|
|
'any',
|
|
|
|
|
true
|
|
|
|
|
),
|
|
|
|
|
array( 'Foo',
|
|
|
|
|
null,
|
|
|
|
|
'comma',
|
|
|
|
|
false
|
|
|
|
|
),
|
|
|
|
|
array( 'Foo, bar',
|
|
|
|
|
null,
|
|
|
|
|
'comma',
|
|
|
|
|
true
|
|
|
|
|
),
|
|
|
|
|
array( 'Foo',
|
|
|
|
|
null,
|
|
|
|
|
'link',
|
|
|
|
|
false
|
|
|
|
|
),
|
|
|
|
|
array( 'Foo [[bar]]',
|
|
|
|
|
null,
|
|
|
|
|
'link',
|
|
|
|
|
true
|
|
|
|
|
),
|
|
|
|
|
array( 'Foo',
|
|
|
|
|
true,
|
|
|
|
|
'link',
|
|
|
|
|
true
|
|
|
|
|
),
|
|
|
|
|
array( 'Foo [[bar]]',
|
|
|
|
|
false,
|
|
|
|
|
'link',
|
|
|
|
|
false
|
|
|
|
|
),
|
|
|
|
|
array( '#REDIRECT [[bar]]',
|
|
|
|
|
true,
|
|
|
|
|
'any',
|
|
|
|
|
false
|
|
|
|
|
),
|
|
|
|
|
array( '#REDIRECT [[bar]]',
|
|
|
|
|
true,
|
|
|
|
|
'comma',
|
|
|
|
|
false
|
|
|
|
|
),
|
|
|
|
|
array( '#REDIRECT [[bar]]',
|
|
|
|
|
true,
|
|
|
|
|
'link',
|
|
|
|
|
false
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataIsCountable
|
2012-07-27 20:49:58 +00:00
|
|
|
* @group Database
|
2012-04-23 16:16:36 +00:00
|
|
|
*/
|
|
|
|
|
public function testIsCountable( $text, $hasLinks, $mode, $expected ) {
|
|
|
|
|
global $wgArticleCountMethod;
|
|
|
|
|
|
|
|
|
|
$old = $wgArticleCountMethod;
|
|
|
|
|
$wgArticleCountMethod = $mode;
|
|
|
|
|
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( $text );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
2012-05-23 06:53:01 +00:00
|
|
|
$v = $content->isCountable( $hasLinks, $this->context->getTitle() );
|
2012-04-23 16:16:36 +00:00
|
|
|
$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 ) {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( $text );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $content->getTextForSummary( $maxlength ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetTextForSearchIndex( ) {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( "hello world." );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( "hello world.", $content->getTextForSearchIndex() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCopy() {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( "hello world." );
|
2012-04-23 16:16:36 +00:00
|
|
|
$copy = $content->copy();
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( $content->equals( $copy ), "copy must be equal to original" );
|
|
|
|
|
$this->assertEquals( "hello world.", $copy->getNativeData() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetSize( ) {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( "hello world." );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( 12, $content->getSize() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetNativeData( ) {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( "hello world." );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( "hello world.", $content->getNativeData() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetWikitextForTransclusion( ) {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( "hello world." );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( "hello world.", $content->getWikitextForTransclusion() );
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-21 15:08:49 +00:00
|
|
|
public function testMatchMagicWord( ) {
|
|
|
|
|
$mw = MagicWord::get( "staticredirect" );
|
|
|
|
|
|
|
|
|
|
$content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
|
|
|
|
|
$this->assertTrue( $content->matchMagicWord( $mw ), "should have matched magic word" );
|
|
|
|
|
|
|
|
|
|
$content = $this->newContent( "#REDIRECT [[FOO]]" );
|
|
|
|
|
$this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word" );
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-21 15:32:44 +00:00
|
|
|
public function testUpdateRedirect( ) {
|
|
|
|
|
$target = Title::newFromText( "testUpdateRedirect_target" );
|
|
|
|
|
|
|
|
|
|
// test with non-redirect page
|
|
|
|
|
$content = $this->newContent( "hello world." );
|
|
|
|
|
$newContent = $content->updateRedirect( $target );
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( $content->equals( $newContent ), "content should be unchanged" );
|
|
|
|
|
|
|
|
|
|
// test with actual redirect
|
|
|
|
|
$content = $this->newContent( "#REDIRECT [[Someplace]]" );
|
|
|
|
|
$newContent = $content->updateRedirect( $target );
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $content->equals( $newContent ), "content should have changed" );
|
|
|
|
|
$this->assertTrue( $newContent->isRedirect(), "new content should be a redirect" );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $target->getFullText(), $newContent->getRedirectTarget()->getFullText() );
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-23 16:16:36 +00:00
|
|
|
# =================================================================================================================
|
|
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
public function testGetModel() {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( "hello world." );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getModel() );
|
2012-04-23 16:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
public function testGetContentHandler() {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( "hello world." );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getContentHandler()->getModelID() );
|
2012-04-23 16:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dataIsEmpty( ) {
|
|
|
|
|
return array(
|
|
|
|
|
array( '', true ),
|
|
|
|
|
array( ' ', false ),
|
|
|
|
|
array( '0', false ),
|
|
|
|
|
array( 'hallo welt.', false ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataIsEmpty
|
|
|
|
|
*/
|
|
|
|
|
public function testIsEmpty( $text, $empty ) {
|
2012-04-23 17:13:54 +00:00
|
|
|
$content = $this->newContent( $text );
|
2012-04-23 16:16:36 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $empty, $content->isEmpty() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dataEquals( ) {
|
|
|
|
|
return array(
|
|
|
|
|
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 WikitextContent( "HALLO" ), false ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataEquals
|
|
|
|
|
*/
|
|
|
|
|
public function testEquals( Content $a, Content $b = null, $equal = false ) {
|
|
|
|
|
$this->assertEquals( $equal, $a->equals( $b ) );
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-23 20:54:25 +00:00
|
|
|
public function dataGetDeletionUpdates() {
|
|
|
|
|
return array(
|
|
|
|
|
array("WikitextContentTest_testGetSecondaryDataUpdates_1", "hello ''world''\n",
|
|
|
|
|
array( 'LinksDeletionUpdate' => array( ) )
|
|
|
|
|
),
|
|
|
|
|
array("WikitextContentTest_testGetSecondaryDataUpdates_2", "hello [[world test 21344]]\n",
|
|
|
|
|
array( 'LinksDeletionUpdate' => array( ) )
|
|
|
|
|
),
|
|
|
|
|
// @todo: more...?
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetDeletionUpdates
|
|
|
|
|
*/
|
|
|
|
|
public function testDeletionUpdates( $title, $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 );
|
|
|
|
|
|
|
|
|
|
$updates = $content->getDeletionUpdates( $title );
|
|
|
|
|
|
|
|
|
|
// make updates accessible by class name
|
|
|
|
|
foreach ( $updates as $update ) {
|
|
|
|
|
$class = get_class( $update );
|
|
|
|
|
$updates[ $class ] = $update;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $expectedStuff as $class => $fieldValues ) {
|
|
|
|
|
$this->assertArrayHasKey( $class, $updates, "missing an update of type $class" );
|
|
|
|
|
|
|
|
|
|
$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" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-23 16:16:36 +00:00
|
|
|
}
|