Remove superfluous re- from confirmemail_body_set
[mediawiki.git] / tests / phpunit / includes / content / WikitextContentHandlerTest.php
blobd21325158300887874c3e7c130a489d9b54ff7ed
1 <?php
3 /**
4 * @group ContentHandler
5 */
6 class WikitextContentHandlerTest extends MediaWikiLangTestCase {
8 /**
9 * @var ContentHandler
11 var $handler;
13 public function setUp() {
14 parent::setUp();
16 $this->handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT );
19 public function testSerializeContent() {
20 $content = new WikitextContent( 'hello world' );
22 $this->assertEquals( 'hello world', $this->handler->serializeContent( $content ) );
23 $this->assertEquals( 'hello world', $this->handler->serializeContent( $content, CONTENT_FORMAT_WIKITEXT ) );
25 try {
26 $this->handler->serializeContent( $content, 'dummy/foo' );
27 $this->fail( "serializeContent() should have failed on unknown format" );
28 } catch ( MWException $e ) {
29 // ok, as expected
33 public function testUnserializeContent() {
34 $content = $this->handler->unserializeContent( 'hello world' );
35 $this->assertEquals( 'hello world', $content->getNativeData() );
37 $content = $this->handler->unserializeContent( 'hello world', CONTENT_FORMAT_WIKITEXT );
38 $this->assertEquals( 'hello world', $content->getNativeData() );
40 try {
41 $this->handler->unserializeContent( 'hello world', 'dummy/foo' );
42 $this->fail( "unserializeContent() should have failed on unknown format" );
43 } catch ( MWException $e ) {
44 // ok, as expected
48 public function testMakeEmptyContent() {
49 $content = $this->handler->makeEmptyContent();
51 $this->assertTrue( $content->isEmpty() );
52 $this->assertEquals( '', $content->getNativeData() );
55 public static function dataIsSupportedFormat() {
56 return array(
57 array( null, true ),
58 array( CONTENT_FORMAT_WIKITEXT, true ),
59 array( 99887766, false ),
63 /**
64 * @dataProvider provideMakeRedirectContent
65 * @param Title|string $title Title object or string for Title::newFromText()
66 * @param string $expected Serialized form of the content object built
68 public function testMakeRedirectContent( $title, $expected ) {
69 global $wgContLang;
70 $wgContLang->resetNamespaces();
72 if ( is_string( $title ) ) {
73 $title = Title::newFromText( $title );
75 $content = $this->handler->makeRedirectContent( $title );
76 $this->assertEquals( $expected, $content->serialize() );
79 public static function provideMakeRedirectContent() {
80 return array(
81 array( 'Hello', '#REDIRECT [[Hello]]' ),
82 array( 'Template:Hello', '#REDIRECT [[Template:Hello]]' ),
83 array( 'Hello#section', '#REDIRECT [[Hello#section]]' ),
84 array( 'user:john_doe#section', '#REDIRECT [[User:John doe#section]]' ),
85 array( 'MEDIAWIKI:FOOBAR', '#REDIRECT [[MediaWiki:FOOBAR]]' ),
86 array( 'Category:Foo', '#REDIRECT [[:Category:Foo]]' ),
87 array( Title::makeTitle( NS_MAIN, 'en:Foo' ), '#REDIRECT [[en:Foo]]' ),
88 array( Title::makeTitle( NS_MAIN, 'Foo', '', 'en' ), '#REDIRECT [[:en:Foo]]' ),
89 array( Title::makeTitle( NS_MAIN, 'Bar', 'fragment', 'google' ), '#REDIRECT [[google:Bar#fragment]]' ),
93 /**
94 * @dataProvider dataIsSupportedFormat
96 public function testIsSupportedFormat( $format, $supported ) {
97 $this->assertEquals( $supported, $this->handler->isSupportedFormat( $format ) );
100 public static function dataMerge3() {
101 return array(
102 array(
103 "first paragraph
105 second paragraph\n",
107 "FIRST paragraph
109 second paragraph\n",
111 "first paragraph
113 SECOND paragraph\n",
115 "FIRST paragraph
117 SECOND paragraph\n",
120 array( "first paragraph
121 second paragraph\n",
123 "Bla bla\n",
125 "Blubberdibla\n",
127 false,
133 * @dataProvider dataMerge3
135 public function testMerge3( $old, $mine, $yours, $expected ) {
136 $this->checkHasDiff3();
138 // test merge
139 $oldContent = new WikitextContent( $old );
140 $myContent = new WikitextContent( $mine );
141 $yourContent = new WikitextContent( $yours );
143 $merged = $this->handler->merge3( $oldContent, $myContent, $yourContent );
145 $this->assertEquals( $expected, $merged ? $merged->getNativeData() : $merged );
148 public static function dataGetAutosummary() {
149 return array(
150 array(
151 'Hello there, world!',
152 '#REDIRECT [[Foo]]',
154 '/^Redirected page .*Foo/'
157 array(
158 null,
159 'Hello world!',
160 EDIT_NEW,
161 '/^Created page .*Hello/'
164 array(
165 'Hello there, world!',
168 '/^Blanked/'
171 array(
172 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
173 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
174 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
175 'Hello world!',
177 '/^Replaced .*Hello/'
180 array(
181 'foo',
182 'bar',
184 '/^$/'
190 * @dataProvider dataGetAutosummary
192 public function testGetAutosummary( $old, $new, $flags, $expected ) {
193 $oldContent = is_null( $old ) ? null : new WikitextContent( $old );
194 $newContent = is_null( $new ) ? null : new WikitextContent( $new );
196 $summary = $this->handler->getAutosummary( $oldContent, $newContent, $flags );
198 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
202 * @todo Text case requires database, should be done by a test class in the Database group
205 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {}
209 * @todo Text case requires database, should be done by a test class in the Database group
212 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {}