3 class WikitextContentHandlerTest
extends MediaWikiTestCase
{
10 public function setup() {
11 $this->handler
= ContentHandler
::getForModelName( CONTENT_MODEL_WIKITEXT
);
14 public function teardown() {
17 public function testSerializeContent( ) {
18 $content = new WikitextContent( 'hello world' );
20 $this->assertEquals( 'hello world', $this->handler
->serializeContent( $content ) );
21 $this->assertEquals( 'hello world', $this->handler
->serializeContent( $content, 'application/x-wiki' ) );
24 $this->handler
->serializeContent( $content, 'dummy/foo' );
25 $this->fail( "serializeContent() should have failed on unknown format" );
26 } catch ( MWException
$e ) {
31 public function testUnserializeContent( ) {
32 $content = $this->handler
->unserializeContent( 'hello world' );
33 $this->assertEquals( 'hello world', $content->getNativeData() );
35 $content = $this->handler
->unserializeContent( 'hello world', 'application/x-wiki' );
36 $this->assertEquals( 'hello world', $content->getNativeData() );
39 $this->handler
->unserializeContent( 'hello world', 'dummy/foo' );
40 $this->fail( "unserializeContent() should have failed on unknown format" );
41 } catch ( MWException
$e ) {
46 public function testMakeEmptyContent() {
47 $content = $this->handler
->makeEmptyContent();
49 $this->assertTrue( $content->isEmpty() );
50 $this->assertEquals( '', $content->getNativeData() );
53 public function dataIsSupportedFormat( ) {
56 array( 'application/x-wiki', true ),
57 array( 'dummy/foo', false ),
62 * @dataProvider dataIsSupportedFormat
64 public function testIsSupportedFormat( $format, $supported ) {
65 $this->assertEquals( $supported, $this->handler
->isSupportedFormat( $format ) );
68 public function dataMerge3( ) {
70 array( "first paragraph
87 array( "first paragraph
101 * @dataProvider dataMerge3
103 public function testMerge3( $old, $mine, $yours, $expected ) {
104 $oldContent = new WikitextContent( $old );
105 $myContent = new WikitextContent( $mine );
106 $yourContent = new WikitextContent( $yours );
108 $merged = $this->handler
->merge3( $oldContent, $myContent, $yourContent );
110 $this->assertEquals( $expected, $merged ?
$merged->getNativeData() : $merged );
113 public function dataGetAutosummary( ) {
116 'Hello there, world!',
119 '/^Redirected page .*Foo/'
126 '/^Created page .*Hello/'
130 'Hello there, world!',
137 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
138 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
139 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
142 '/^Replaced .*Hello/'
155 * @dataProvider dataGetAutoSummary
157 public function testGetAutosummary( $old, $new, $flags, $expected ) {
158 global $wgLanguageCode, $wgContLang;
160 $oldContent = is_null( $old ) ?
null : new WikitextContent( $old );
161 $newContent = is_null( $new ) ?
null : new WikitextContent( $new );
163 $summary = $this->handler
->getAutosummary( $oldContent, $newContent, $flags );
165 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
169 * @todo Text case required database!
172 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {
177 * @todo Text case required database!
180 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {