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