3 class WikitextContentHandlerTest
extends MediaWikiTestCase
{
7 public function setup() {
8 $this->handler
= ContentHandler
::getForModelName( CONTENT_MODEL_WIKITEXT
);
11 public function teardown() {
14 public function testSerializeContent( ) {
15 $content = new WikitextContent( 'hello world' );
17 $this->assertEquals( 'hello world', $this->handler
->serializeContent( $content ) );
18 $this->assertEquals( 'hello world', $this->handler
->serializeContent( $content, 'application/x-wikitext' ) );
21 $this->handler
->serializeContent( $content, 'dummy/foo' );
22 $this->fail( "serializeContent() should have failed on unknown format" );
23 } catch ( MWException
$e ) {
28 public function testUnserializeContent( ) {
29 $content = $this->handler
->unserializeContent( 'hello world' );
30 $this->assertEquals( 'hello world', $content->getNativeData() );
32 $content = $this->handler
->unserializeContent( 'hello world', 'application/x-wikitext' );
33 $this->assertEquals( 'hello world', $content->getNativeData() );
36 $this->handler
->unserializeContent( 'hello world', 'dummy/foo' );
37 $this->fail( "unserializeContent() should have failed on unknown format" );
38 } catch ( MWException
$e ) {
43 public function testMakeEmptyContent() {
44 $content = $this->handler
->makeEmptyContent();
46 $this->assertTrue( $content->isEmpty() );
47 $this->assertEquals( '', $content->getNativeData() );
50 public function dataIsSupportedFormat( ) {
53 array( 'application/x-wikitext', true ),
54 array( 'dummy/foo', false ),
59 * @dataProvider dataIsSupportedFormat
61 public function testIsSupportedFormat( $format, $supported ) {
62 $this->assertEquals( $supported, $this->handler
->isSupportedFormat( $format ) );
65 public function dataMerge3( ) {
67 array( "first paragraph
84 array( "first paragraph
98 * @dataProvider dataMerge3
100 public function testMerge3( $old, $mine, $yours, $expected ) {
101 $oldContent = new WikitextContent( $old );
102 $myContent = new WikitextContent( $mine );
103 $yourContent = new WikitextContent( $yours );
105 $merged = $this->handler
->merge3( $oldContent, $myContent, $yourContent );
107 $this->assertEquals( $expected, $merged ?
$merged->getNativeData() : $merged );
110 public function dataGetAutosummary( ) {
113 'Hello there, world!',
116 '/^Redirected page .*Foo/'
123 '/^Created page .*Hello/'
127 'Hello there, world!',
134 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
135 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
136 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
139 '/^Replaced .*Hello/'
152 * @dataProvider dataGetAutoSummary
154 public function testGetAutosummary( $old, $new, $flags, $expected ) {
155 global $wgLanguageCode, $wgContLang;
157 $oldContent = is_null( $old ) ?
null : new WikitextContent( $old );
158 $newContent = is_null( $new ) ?
null : new WikitextContent( $new );
160 $summary = $this->handler
->getAutosummary( $oldContent, $newContent, $flags );
162 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
166 * @todo Text case required database!
169 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {
174 * @todo Text case required database!
177 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {