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