2012-04-23 12:28:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
/**
|
|
|
|
|
* @group ContentHandler
|
|
|
|
|
*/
|
2012-10-30 22:48:17 +00:00
|
|
|
class WikitextContentHandlerTest extends MediaWikiLangTestCase {
|
2012-04-23 12:28:57 +00:00
|
|
|
|
2012-04-25 16:34:36 +00:00
|
|
|
/**
|
|
|
|
|
* @var ContentHandler
|
|
|
|
|
*/
|
2012-04-23 12:28:57 +00:00
|
|
|
var $handler;
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public function setUp() {
|
2012-10-23 17:02:36 +00:00
|
|
|
parent::setUp();
|
2012-10-20 01:51:15 +00:00
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT );
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
2012-04-23 12:28:57 +00:00
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
public function testSerializeContent() {
|
2012-04-23 12:28:57 +00:00
|
|
|
$content = new WikitextContent( 'hello world' );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( 'hello world', $this->handler->serializeContent( $content ) );
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->assertEquals( 'hello world', $this->handler->serializeContent( $content, CONTENT_FORMAT_WIKITEXT ) );
|
2012-04-23 12:28:57 +00:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$this->handler->serializeContent( $content, 'dummy/foo' );
|
|
|
|
|
$this->fail( "serializeContent() should have failed on unknown format" );
|
|
|
|
|
} catch ( MWException $e ) {
|
|
|
|
|
// ok, as expected
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
public function testUnserializeContent() {
|
2012-04-23 12:28:57 +00:00
|
|
|
$content = $this->handler->unserializeContent( 'hello world' );
|
|
|
|
|
$this->assertEquals( 'hello world', $content->getNativeData() );
|
|
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
$content = $this->handler->unserializeContent( 'hello world', CONTENT_FORMAT_WIKITEXT );
|
2012-04-23 12:28:57 +00:00
|
|
|
$this->assertEquals( 'hello world', $content->getNativeData() );
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$this->handler->unserializeContent( 'hello world', 'dummy/foo' );
|
|
|
|
|
$this->fail( "unserializeContent() should have failed on unknown format" );
|
|
|
|
|
} catch ( MWException $e ) {
|
|
|
|
|
// ok, as expected
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testMakeEmptyContent() {
|
|
|
|
|
$content = $this->handler->makeEmptyContent();
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( $content->isEmpty() );
|
|
|
|
|
$this->assertEquals( '', $content->getNativeData() );
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
public static function dataIsSupportedFormat() {
|
2012-04-23 12:28:57 +00:00
|
|
|
return array(
|
|
|
|
|
array( null, true ),
|
2012-05-13 22:02:29 +00:00
|
|
|
array( CONTENT_FORMAT_WIKITEXT, true ),
|
|
|
|
|
array( 99887766, false ),
|
2012-04-23 12:28:57 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-30 08:02:37 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideMakeRedirectContent
|
|
|
|
|
* @param Title|string $title Title object or string for Title::newFromText()
|
|
|
|
|
* @param string $expected Serialized form of the content object built
|
|
|
|
|
*/
|
|
|
|
|
public function testMakeRedirectContent( $title, $expected ) {
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
$wgContLang->resetNamespaces();
|
|
|
|
|
|
|
|
|
|
if ( is_string( $title ) ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
}
|
|
|
|
|
$content = $this->handler->makeRedirectContent( $title );
|
|
|
|
|
$this->assertEquals( $expected, $content->serialize() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideMakeRedirectContent() {
|
|
|
|
|
return array(
|
|
|
|
|
array( 'Hello', '#REDIRECT [[Hello]]' ),
|
|
|
|
|
array( 'Template:Hello', '#REDIRECT [[Template:Hello]]' ),
|
|
|
|
|
array( 'Hello#section', '#REDIRECT [[Hello#section]]' ),
|
|
|
|
|
array( 'user:john_doe#section', '#REDIRECT [[User:John doe#section]]' ),
|
|
|
|
|
array( 'MEDIAWIKI:FOOBAR', '#REDIRECT [[MediaWiki:FOOBAR]]' ),
|
|
|
|
|
array( 'Category:Foo', '#REDIRECT [[:Category:Foo]]' ),
|
|
|
|
|
array( Title::makeTitle( NS_MAIN, 'en:Foo' ), '#REDIRECT [[en:Foo]]' ),
|
|
|
|
|
array( Title::makeTitle( NS_MAIN, 'Foo', '', 'en' ), '#REDIRECT [[:en:Foo]]' ),
|
|
|
|
|
array( Title::makeTitle( NS_MAIN, 'Bar', 'fragment', 'google' ), '#REDIRECT [[google:Bar#fragment]]' ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-23 12:28:57 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider dataIsSupportedFormat
|
|
|
|
|
*/
|
|
|
|
|
public function testIsSupportedFormat( $format, $supported ) {
|
|
|
|
|
$this->assertEquals( $supported, $this->handler->isSupportedFormat( $format ) );
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
public static function dataMerge3() {
|
2012-04-23 12:28:57 +00:00
|
|
|
return array(
|
2013-02-14 13:10:38 +00:00
|
|
|
array(
|
|
|
|
|
"first paragraph
|
2012-04-23 12:28:57 +00:00
|
|
|
|
|
|
|
|
second paragraph\n",
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
"FIRST paragraph
|
2012-04-23 12:28:57 +00:00
|
|
|
|
|
|
|
|
second paragraph\n",
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
"first paragraph
|
2012-04-23 12:28:57 +00:00
|
|
|
|
|
|
|
|
SECOND paragraph\n",
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
"FIRST paragraph
|
2012-04-23 12:28:57 +00:00
|
|
|
|
|
|
|
|
SECOND paragraph\n",
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
array( "first paragraph
|
|
|
|
|
second paragraph\n",
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
"Bla bla\n",
|
2012-04-23 12:28:57 +00:00
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
"Blubberdibla\n",
|
2012-04-23 12:28:57 +00:00
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
false,
|
2012-04-23 12:28:57 +00:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataMerge3
|
|
|
|
|
*/
|
|
|
|
|
public function testMerge3( $old, $mine, $yours, $expected ) {
|
2012-11-22 16:45:50 +00:00
|
|
|
$this->checkHasDiff3();
|
2012-05-29 10:43:53 +00:00
|
|
|
|
|
|
|
|
// test merge
|
2012-04-23 12:28:57 +00:00
|
|
|
$oldContent = new WikitextContent( $old );
|
|
|
|
|
$myContent = new WikitextContent( $mine );
|
|
|
|
|
$yourContent = new WikitextContent( $yours );
|
|
|
|
|
|
|
|
|
|
$merged = $this->handler->merge3( $oldContent, $myContent, $yourContent );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $merged ? $merged->getNativeData() : $merged );
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
public static function dataGetAutosummary() {
|
2012-04-23 12:28:57 +00:00
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
'Hello there, world!',
|
|
|
|
|
'#REDIRECT [[Foo]]',
|
|
|
|
|
0,
|
|
|
|
|
'/^Redirected page .*Foo/'
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
array(
|
|
|
|
|
null,
|
|
|
|
|
'Hello world!',
|
|
|
|
|
EDIT_NEW,
|
|
|
|
|
'/^Created page .*Hello/'
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
array(
|
|
|
|
|
'Hello there, world!',
|
|
|
|
|
'',
|
|
|
|
|
0,
|
|
|
|
|
'/^Blanked/'
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
array(
|
|
|
|
|
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
|
|
|
|
|
labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
|
|
|
|
|
ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
|
|
|
|
|
'Hello world!',
|
|
|
|
|
0,
|
|
|
|
|
'/^Replaced .*Hello/'
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
array(
|
|
|
|
|
'foo',
|
|
|
|
|
'bar',
|
|
|
|
|
0,
|
|
|
|
|
'/^$/'
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-20 01:51:15 +00:00
|
|
|
* @dataProvider dataGetAutosummary
|
2012-04-23 12:28:57 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetAutosummary( $old, $new, $flags, $expected ) {
|
|
|
|
|
$oldContent = is_null( $old ) ? null : new WikitextContent( $old );
|
|
|
|
|
$newContent = is_null( $new ) ? null : new WikitextContent( $new );
|
|
|
|
|
|
|
|
|
|
$summary = $this->handler->getAutosummary( $oldContent, $newContent, $flags );
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 15:26:11 +00:00
|
|
|
* @todo Text case requires database, should be done by a test class in the Database group
|
2012-04-23 12:28:57 +00:00
|
|
|
*/
|
|
|
|
|
/*
|
2012-10-20 01:51:15 +00:00
|
|
|
public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {}
|
2012-04-23 12:28:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 15:26:11 +00:00
|
|
|
* @todo Text case requires database, should be done by a test class in the Database group
|
2012-04-23 12:28:57 +00:00
|
|
|
*/
|
|
|
|
|
/*
|
2012-10-20 01:51:15 +00:00
|
|
|
public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {}
|
2012-04-23 12:28:57 +00:00
|
|
|
*/
|
|
|
|
|
}
|