tests: always call parent setUp
[lhc/web/wiklou.git] / tests / phpunit / includes / WikitextContentHandlerTest.php
1 <?php
2
3 /**
4 * @group ContentHandler
5 */
6 class WikitextContentHandlerTest extends MediaWikiTestCase {
7
8 /**
9 * @var ContentHandler
10 */
11 var $handler;
12
13 public function setup() {
14 parent::setUp();
15 $this->handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT );
16 }
17
18 public function testSerializeContent( ) {
19 $content = new WikitextContent( 'hello world' );
20
21 $this->assertEquals( 'hello world', $this->handler->serializeContent( $content ) );
22 $this->assertEquals( 'hello world', $this->handler->serializeContent( $content, CONTENT_FORMAT_WIKITEXT ) );
23
24 try {
25 $this->handler->serializeContent( $content, 'dummy/foo' );
26 $this->fail( "serializeContent() should have failed on unknown format" );
27 } catch ( MWException $e ) {
28 // ok, as expected
29 }
30 }
31
32 public function testUnserializeContent( ) {
33 $content = $this->handler->unserializeContent( 'hello world' );
34 $this->assertEquals( 'hello world', $content->getNativeData() );
35
36 $content = $this->handler->unserializeContent( 'hello world', CONTENT_FORMAT_WIKITEXT );
37 $this->assertEquals( 'hello world', $content->getNativeData() );
38
39 try {
40 $this->handler->unserializeContent( 'hello world', 'dummy/foo' );
41 $this->fail( "unserializeContent() should have failed on unknown format" );
42 } catch ( MWException $e ) {
43 // ok, as expected
44 }
45 }
46
47 public function testMakeEmptyContent() {
48 $content = $this->handler->makeEmptyContent();
49
50 $this->assertTrue( $content->isEmpty() );
51 $this->assertEquals( '', $content->getNativeData() );
52 }
53
54 public function dataIsSupportedFormat( ) {
55 return array(
56 array( null, true ),
57 array( CONTENT_FORMAT_WIKITEXT, true ),
58 array( 99887766, false ),
59 );
60 }
61
62 /**
63 * @dataProvider dataIsSupportedFormat
64 */
65 public function testIsSupportedFormat( $format, $supported ) {
66 $this->assertEquals( $supported, $this->handler->isSupportedFormat( $format ) );
67 }
68
69 public function dataMerge3( ) {
70 return array(
71 array( "first paragraph
72
73 second paragraph\n",
74
75 "FIRST paragraph
76
77 second paragraph\n",
78
79 "first paragraph
80
81 SECOND paragraph\n",
82
83 "FIRST paragraph
84
85 SECOND paragraph\n",
86 ),
87
88 array( "first paragraph
89 second paragraph\n",
90
91 "Bla bla\n",
92
93 "Blubberdibla\n",
94
95 false,
96 ),
97
98 );
99 }
100
101 /**
102 * @dataProvider dataMerge3
103 */
104 public function testMerge3( $old, $mine, $yours, $expected ) {
105 global $wgDiff3;
106
107 if ( !$wgDiff3 ) {
108 $this->markTestSkipped( "Can't test merge3(), since \$wgDiff3 is not configured" );
109 }
110
111 if ( !file_exists( $wgDiff3 ) ) {
112 #XXX: this sucks, since it uses arcane internal knowledge about TextContentHandler::merge3 and wfMerge.
113 $this->markTestSkipped( "Can't test merge3(), since \$wgDiff3 is misconfigured: can't find $wgDiff3" );
114 }
115
116 // test merge
117 $oldContent = new WikitextContent( $old );
118 $myContent = new WikitextContent( $mine );
119 $yourContent = new WikitextContent( $yours );
120
121 $merged = $this->handler->merge3( $oldContent, $myContent, $yourContent );
122
123 $this->assertEquals( $expected, $merged ? $merged->getNativeData() : $merged );
124 }
125
126 public function dataGetAutosummary( ) {
127 return array(
128 array(
129 'Hello there, world!',
130 '#REDIRECT [[Foo]]',
131 0,
132 '/^Redirected page .*Foo/'
133 ),
134
135 array(
136 null,
137 'Hello world!',
138 EDIT_NEW,
139 '/^Created page .*Hello/'
140 ),
141
142 array(
143 'Hello there, world!',
144 '',
145 0,
146 '/^Blanked/'
147 ),
148
149 array(
150 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
151 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
152 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
153 'Hello world!',
154 0,
155 '/^Replaced .*Hello/'
156 ),
157
158 array(
159 'foo',
160 'bar',
161 0,
162 '/^$/'
163 ),
164 );
165 }
166
167 /**
168 * @dataProvider dataGetAutoSummary
169 */
170 public function testGetAutosummary( $old, $new, $flags, $expected ) {
171 global $wgLanguageCode, $wgContLang;
172
173 $oldContent = is_null( $old ) ? null : new WikitextContent( $old );
174 $newContent = is_null( $new ) ? null : new WikitextContent( $new );
175
176 $summary = $this->handler->getAutosummary( $oldContent, $newContent, $flags );
177
178 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
179 }
180
181 /**
182 * @todo Text case requires database, should be done by a test class in the Database group
183 */
184 /*
185 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {
186 }
187 */
188
189 /**
190 * @todo Text case requires database, should be done by a test class in the Database group
191 */
192 /*
193 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {
194 }
195 */
196
197 }