merged from master
[lhc/web/wiklou.git] / tests / phpunit / includes / WikitextContentHandlerTest.php
1 <?php
2
3 class WikitextContentHandlerTest extends MediaWikiTestCase {
4
5 /**
6 * @var ContentHandler
7 */
8 var $handler;
9
10 public function setup() {
11 $this->handler = ContentHandler::getForModelName( CONTENT_MODEL_WIKITEXT );
12 }
13
14 public function teardown() {
15 }
16
17 public function testSerializeContent( ) {
18 $content = new WikitextContent( 'hello world' );
19
20 $this->assertEquals( 'hello world', $this->handler->serializeContent( $content ) );
21 $this->assertEquals( 'hello world', $this->handler->serializeContent( $content, 'application/x-wiki' ) );
22
23 try {
24 $this->handler->serializeContent( $content, 'dummy/foo' );
25 $this->fail( "serializeContent() should have failed on unknown format" );
26 } catch ( MWException $e ) {
27 // ok, as expected
28 }
29 }
30
31 public function testUnserializeContent( ) {
32 $content = $this->handler->unserializeContent( 'hello world' );
33 $this->assertEquals( 'hello world', $content->getNativeData() );
34
35 $content = $this->handler->unserializeContent( 'hello world', 'application/x-wiki' );
36 $this->assertEquals( 'hello world', $content->getNativeData() );
37
38 try {
39 $this->handler->unserializeContent( 'hello world', 'dummy/foo' );
40 $this->fail( "unserializeContent() should have failed on unknown format" );
41 } catch ( MWException $e ) {
42 // ok, as expected
43 }
44 }
45
46 public function testMakeEmptyContent() {
47 $content = $this->handler->makeEmptyContent();
48
49 $this->assertTrue( $content->isEmpty() );
50 $this->assertEquals( '', $content->getNativeData() );
51 }
52
53 public function dataIsSupportedFormat( ) {
54 return array(
55 array( null, true ),
56 array( 'application/x-wiki', true ),
57 array( 'dummy/foo', false ),
58 );
59 }
60
61 /**
62 * @dataProvider dataIsSupportedFormat
63 */
64 public function testIsSupportedFormat( $format, $supported ) {
65 $this->assertEquals( $supported, $this->handler->isSupportedFormat( $format ) );
66 }
67
68 public function dataMerge3( ) {
69 return array(
70 array( "first paragraph
71
72 second paragraph\n",
73
74 "FIRST paragraph
75
76 second paragraph\n",
77
78 "first paragraph
79
80 SECOND paragraph\n",
81
82 "FIRST paragraph
83
84 SECOND paragraph\n",
85 ),
86
87 array( "first paragraph
88 second paragraph\n",
89
90 "Bla bla\n",
91
92 "Blubberdibla\n",
93
94 false,
95 ),
96
97 );
98 }
99
100 /**
101 * @dataProvider dataMerge3
102 */
103 public function testMerge3( $old, $mine, $yours, $expected ) {
104 $oldContent = new WikitextContent( $old );
105 $myContent = new WikitextContent( $mine );
106 $yourContent = new WikitextContent( $yours );
107
108 $merged = $this->handler->merge3( $oldContent, $myContent, $yourContent );
109
110 $this->assertEquals( $expected, $merged ? $merged->getNativeData() : $merged );
111 }
112
113 public function dataGetAutosummary( ) {
114 return array(
115 array(
116 'Hello there, world!',
117 '#REDIRECT [[Foo]]',
118 0,
119 '/^Redirected page .*Foo/'
120 ),
121
122 array(
123 null,
124 'Hello world!',
125 EDIT_NEW,
126 '/^Created page .*Hello/'
127 ),
128
129 array(
130 'Hello there, world!',
131 '',
132 0,
133 '/^Blanked/'
134 ),
135
136 array(
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.',
140 'Hello world!',
141 0,
142 '/^Replaced .*Hello/'
143 ),
144
145 array(
146 'foo',
147 'bar',
148 0,
149 '/^$/'
150 ),
151 );
152 }
153
154 /**
155 * @dataProvider dataGetAutoSummary
156 */
157 public function testGetAutosummary( $old, $new, $flags, $expected ) {
158 global $wgLanguageCode, $wgContLang;
159
160 $oldContent = is_null( $old ) ? null : new WikitextContent( $old );
161 $newContent = is_null( $new ) ? null : new WikitextContent( $new );
162
163 $summary = $this->handler->getAutosummary( $oldContent, $newContent, $flags );
164
165 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
166 }
167
168 /**
169 * @todo Text case required database!
170 */
171 /*
172 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {
173 }
174 */
175
176 /**
177 * @todo Text case required database!
178 */
179 /*
180 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {
181 }
182 */
183
184 }