summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/WikiPageTest.php
blob: 0e1e1ce862d4d9daf4784d94021b1bb8ef610b2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
<?php
/**
* @group Database
* ^--- important, causes temporary tables to be used instead of the real database
* @group medium
**/

class WikiPageTest extends MediaWikiLangTestCase {

	var $pages_to_delete;

	function  __construct( $name = null, array $data = array(), $dataName = '' ) {
		parent::__construct( $name, $data, $dataName );

		$this->tablesUsed = array_merge ( $this->tablesUsed,
		                                  array( 'page',
		                                       'revision',
		                                       'text',

		                                       'recentchanges',
		                                       'logging',

		                                       'page_props',
		                                       'pagelinks',
		                                       'categorylinks',
		                                       'langlinks',
		                                       'externallinks',
		                                       'imagelinks',
		                                       'templatelinks',
		                                       'iwlinks' ) );
	}

	public function setUp() {
		parent::setUp();
		$this->pages_to_delete = array();
	}

	public function tearDown() {
		foreach ( $this->pages_to_delete as $p ) {
			/* @var $p WikiPage */

			try {
				if ( $p->exists() ) {
					$p->doDeleteArticle( "testing done." );
				}
			} catch ( MWException $ex ) {
				// fail silently
			}
		}
		parent::tearDown();
	}

	protected function newPage( $title ) {
		if ( is_string( $title ) ) $title = Title::newFromText( $title );

		$p = new WikiPage( $title );

		$this->pages_to_delete[] = $p;

		return $p;
	}

	protected function createPage( $page, $text, $model = null ) {
		if ( is_string( $page ) ) $page = Title::newFromText( $page );
		if ( $page instanceof Title ) $page = $this->newPage( $page );

		$page->doEdit( $text, "testing", EDIT_NEW );

		return $page;
	}

	public function testDoEdit() {
		$title = Title::newFromText( "WikiPageTest_testDoEdit" );

		$page = $this->newPage( $title );

		$text = "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
		       . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.";

		$page->doEdit( $text, "testing 1" );

		$this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" );
		$this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );

		$id = $page->getId();

		# ------------------------
		$page = new WikiPage( $title );

		$retrieved = $page->getText();
		$this->assertEquals( $text, $retrieved, 'retrieved text doesn\'t equal original' );

		# ------------------------
		$text = "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
		       . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.";

		$page->doEdit( $text, "testing 2" );

		# ------------------------
		$page = new WikiPage( $title );

		$retrieved = $page->getText();
		$this->assertEquals( $text, $retrieved, 'retrieved text doesn\'t equal original' );

		# ------------------------
		$dbr = wfGetDB( DB_SLAVE );
		$res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
		$n = $res->numRows();
		$res->free();

		$this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' );
	}

	public function testDoQuickEdit() {
		global $wgUser;

		$page = $this->createPage( "WikiPageTest_testDoQuickEdit", "original text" );

		$text = "quick text";
		$page->doQuickEdit( $text, $wgUser, "testing q" );

		# ---------------------
		$page = new WikiPage( $page->getTitle() );
		$this->assertEquals( $text, $page->getText() );
	}

	public function testDoDeleteArticle() {
		$page = $this->createPage( "WikiPageTest_testDoDeleteArticle", "[[original text]] foo" );
		$id = $page->getId();

		$page->doDeleteArticle( "testing deletion" );

		$this->assertFalse( $page->exists(), "WikiPage::exists should return false after page was deleted" );
		$this->assertFalse( $page->getText(), "WikiPage::getText should return false after page was deleted" );

		$t = Title::newFromText( $page->getTitle()->getPrefixedText() );
		$this->assertFalse( $t->exists(), "Title::exists should return false after page was deleted" );

		# ------------------------
		$dbr = wfGetDB( DB_SLAVE );
		$res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
		$n = $res->numRows();
		$res->free();

		$this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
	}

	public function testDoDeleteUpdates() {
		$page = $this->createPage( "WikiPageTest_testDoDeleteArticle", "[[original text]] foo" );
		$id = $page->getId();

		$page->doDeleteUpdates( $id );

		# ------------------------
		$dbr = wfGetDB( DB_SLAVE );
		$res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
		$n = $res->numRows();
		$res->free();

		$this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
	}

	public function testGetRevision() {
		$page = $this->newPage( "WikiPageTest_testGetRevision" );

		$rev = $page->getRevision();
		$this->assertNull( $rev );

		# -----------------
		$this->createPage( $page, "some text" );

		$rev = $page->getRevision();

		$this->assertEquals( $page->getLatest(), $rev->getId() );
		$this->assertEquals( "some text", $rev->getText() );
	}

	public function testGetText() {
		$page = $this->newPage( "WikiPageTest_testGetText" );

		$text = $page->getText();
		$this->assertFalse( $text );

		# -----------------
		$this->createPage( $page, "some text" );

		$text = $page->getText();
		$this->assertEquals( "some text", $text );
	}

	public function testGetRawText() {
		$page = $this->newPage( "WikiPageTest_testGetRawText" );

		$text = $page->getRawText();
		$this->assertFalse( $text );

		# -----------------
		$this->createPage( $page, "some text" );

		$text = $page->getRawText();
		$this->assertEquals( "some text", $text );
	}

	
	public function testExists() {
		$page = $this->newPage( "WikiPageTest_testExists" );
		$this->assertFalse( $page->exists() );

		# -----------------
		$this->createPage( $page, "some text" );
		$this->assertTrue( $page->exists() );

		$page = new WikiPage( $page->getTitle() );
		$this->assertTrue( $page->exists() );

		# -----------------
		$page->doDeleteArticle( "done testing" );
		$this->assertFalse( $page->exists() );

		$page = new WikiPage( $page->getTitle() );
		$this->assertFalse( $page->exists() );
	}

	public function dataHasViewableContent() {
		return array(
			array( 'WikiPageTest_testHasViewableContent', false, true ),
			array( 'Special:WikiPageTest_testHasViewableContent', false ),
			array( 'MediaWiki:WikiPageTest_testHasViewableContent', false ),
			array( 'Special:Userlogin', true ),
			array( 'MediaWiki:help', true ),
		);
	}

	/**
	 * @dataProvider dataHasViewableContent
	 */
	public function testHasViewableContent( $title, $viewable, $create = false ) {
		$page = $this->newPage( $title );
		$this->assertEquals( $viewable, $page->hasViewableContent() );

		if ( $create ) {
			$this->createPage( $page, "some text" );
			$this->assertTrue( $page->hasViewableContent() );

			$page = new WikiPage( $page->getTitle() );
			$this->assertTrue( $page->hasViewableContent() );
		}
	}

	public function dataGetRedirectTarget() {
		return array(
			array( 'WikiPageTest_testGetRedirectTarget_1', "hello world", null ),
			array( 'WikiPageTest_testGetRedirectTarget_2', "#REDIRECT [[hello world]]", "Hello world" ),
		);
	}

	/**
	 * @dataProvider dataGetRedirectTarget
	 */
	public function testGetRedirectTarget( $title, $text, $target ) {
		$page = $this->createPage( $title, $text );

		# now, test the actual redirect
		$t = $page->getRedirectTarget();
		$this->assertEquals( $target, is_null( $t ) ? null : $t->getPrefixedText() );
	}

	/**
	 * @dataProvider dataGetRedirectTarget
	 */
	public function testIsRedirect( $title, $text, $target ) {
		$page = $this->createPage( $title, $text );
		$this->assertEquals( !is_null( $target ), $page->isRedirect() );
	}

	public function dataIsCountable() {
		return array(

			// any
			array( 'WikiPageTest_testIsCountable',
			       '',
			       'any',
			       true
			),
			array( 'WikiPageTest_testIsCountable',
			       'Foo',
			       'any',
			       true
			),

			// comma
			array( 'WikiPageTest_testIsCountable',
			       'Foo',
			       'comma',
			       false
			),
			array( 'WikiPageTest_testIsCountable',
			       'Foo, bar',
			       'comma',
			       true
			),

			// link
			array( 'WikiPageTest_testIsCountable',
			       'Foo',
			       'link',
			       false
			),
			array( 'WikiPageTest_testIsCountable',
			       'Foo [[bar]]',
			       'link',
			       true
			),

			// redirects
			array( 'WikiPageTest_testIsCountable',
			       '#REDIRECT [[bar]]',
			       'any',
			       false
			),
			array( 'WikiPageTest_testIsCountable',
			       '#REDIRECT [[bar]]',
			       'comma',
			       false
			),
			array( 'WikiPageTest_testIsCountable',
			       '#REDIRECT [[bar]]',
			       'link',
			       false
			),

			// not a content namespace
			array( 'Talk:WikiPageTest_testIsCountable',
			       'Foo',
			       'any',
			       false
			),
			array( 'Talk:WikiPageTest_testIsCountable',
			       'Foo, bar',
			       'comma',
			       false
			),
			array( 'Talk:WikiPageTest_testIsCountable',
			       'Foo [[bar]]',
			       'link',
			       false
			),

			// not a content namespace, different model
			array( 'MediaWiki:WikiPageTest_testIsCountable.js',
			       'Foo',
			       'any',
			       false
			),
			array( 'MediaWiki:WikiPageTest_testIsCountable.js',
			       'Foo, bar',
			       'comma',
			       false
			),
			array( 'MediaWiki:WikiPageTest_testIsCountable.js',
			       'Foo [[bar]]',
			       'link',
			       false
			),
		);
	}


	/**
	 * @dataProvider dataIsCountable
	 */
	public function testIsCountable( $title, $text, $mode, $expected ) {
		global $wgArticleCountMethod;

		$old = $wgArticleCountMethod;
		$wgArticleCountMethod = $mode;

		$page = $this->createPage( $title, $text );
		$editInfo = $page->prepareTextForEdit( $page->getText() );

		$v = $page->isCountable();
		$w = $page->isCountable( $editInfo );
		$wgArticleCountMethod = $old;

		$this->assertEquals( $expected, $v, "isCountable( null ) returned unexpected value " . var_export( $v, true )
		                                    . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );

		$this->assertEquals( $expected, $w, "isCountable( \$editInfo ) returned unexpected value " . var_export( $v, true )
		                                    . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );
	}

	public function dataGetParserOutput() {
		return array(
			array("hello ''world''\n", "<p>hello <i>world</i></p>"),
			// @todo: more...?
		);
	}

	/**
	 * @dataProvider dataGetParserOutput
	 */
	public function testGetParserOutput( $text, $expectedHtml ) {
		$page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text );

		$opt = new ParserOptions();
		$po = $page->getParserOutput( $opt );
		$text = $po->getText();

		$text = trim( preg_replace( '/<!--.*?-->/sm', '', $text ) ); # strip injected comments
		$text = preg_replace( '!\s*(</p>)!sm', '\1', $text ); # don't let tidy confuse us

		$this->assertEquals( $expectedHtml, $text );
		return $po;
	}

	static $sections =

		"Intro

== stuff ==
hello world

== test ==
just a test

== foo ==
more stuff
";


	public function dataReplaceSection() {
		return array(
			array( 'WikiPageTest_testReplaceSection',
			       WikiPageTest::$sections,
			       "0",
			       "No more",
			       null,
			       trim( preg_replace( '/^Intro/sm', 'No more', WikiPageTest::$sections ) )
			),
			array( 'WikiPageTest_testReplaceSection',
			       WikiPageTest::$sections,
			       "",
			       "No more",
			       null,
			       "No more"
			),
			array( 'WikiPageTest_testReplaceSection',
			       WikiPageTest::$sections,
			       "2",
			       "== TEST ==\nmore fun",
			       null,
			       trim( preg_replace( '/^== test ==.*== foo ==/sm', "== TEST ==\nmore fun\n\n== foo ==", WikiPageTest::$sections ) )
			),
			array( 'WikiPageTest_testReplaceSection',
			       WikiPageTest::$sections,
			       "8",
			       "No more",
			       null,
			       trim( WikiPageTest::$sections )
			),
			array( 'WikiPageTest_testReplaceSection',
			       WikiPageTest::$sections,
			       "new",
			       "No more",
			       "New",
			       trim( WikiPageTest::$sections ) . "\n\n== New ==\n\nNo more"
			),
		);
	}

	/**
	 * @dataProvider dataReplaceSection
	 */
	public function testReplaceSection( $title, $text, $section, $with, $sectionTitle, $expected ) {
		$page = $this->createPage( $title, $text );
		$text = $page->replaceSection( $section, $with, $sectionTitle );
		$text = trim( $text );

		$this->assertEquals( $expected, $text );
	}

	/* @todo FIXME: fix this!
	public function testGetUndoText() {
		global $wgDiff3;

		wfSuppressWarnings();
		$haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 );
		wfRestoreWarnings();

		if( !$haveDiff3 ) {
			$this->markTestSkipped( "diff3 not installed or not found" );
			return;
		}

		$text = "one";
		$page = $this->createPage( "WikiPageTest_testGetUndoText", $text );
		$rev1 = $page->getRevision();

		$text .= "\n\ntwo";
		$page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section two");
		$rev2 = $page->getRevision();

		$text .= "\n\nthree";
		$page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section three");
		$rev3 = $page->getRevision();

		$text .= "\n\nfour";
		$page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section four");
		$rev4 = $page->getRevision();

		$text .= "\n\nfive";
		$page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section five");
		$rev5 = $page->getRevision();

		$text .= "\n\nsix";
		$page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section six");
		$rev6 = $page->getRevision();

		$undo6 = $page->getUndoText( $rev6 );
		if ( $undo6 === false ) $this->fail( "getUndoText failed for rev6" );
		$this->assertEquals( "one\n\ntwo\n\nthree\n\nfour\n\nfive", $undo6 );

		$undo3 = $page->getUndoText( $rev4, $rev2 );
		if ( $undo3 === false ) $this->fail( "getUndoText failed for rev4..rev2" );
		$this->assertEquals( "one\n\ntwo\n\nfive", $undo3 );

		$undo2 = $page->getUndoText( $rev2 );
		if ( $undo2 === false ) $this->fail( "getUndoText failed for rev2" );
		$this->assertEquals( "one\n\nfive", $undo2 );
	}
	*/

	/**
	 * @todo FIXME: this is a better rollback test than the one below, but it keeps failing in jenkins for some reason.
	 */
	public function broken_testDoRollback() {
		$admin = new User();
		$admin->setName("Admin");

		$text = "one";
		$page = $this->newPage( "WikiPageTest_testDoRollback" );
		$page->doEdit( $text, "section one", EDIT_NEW, false, $admin );

		$user1 = new User();
		$user1->setName( "127.0.1.11" );
		$text .= "\n\ntwo";
		$page = new WikiPage( $page->getTitle() );
		$page->doEdit( $text, "adding section two", 0, false, $user1 );

		$user2 = new User();
		$user2->setName( "127.0.2.13" );
		$text .= "\n\nthree";
		$page = new WikiPage( $page->getTitle() );
		$page->doEdit( $text, "adding section three", 0, false, $user2 );

		# we are having issues with doRollback spuriously failing. apparently the last revision somehow goes missing
		# or not committed under some circumstances. so, make sure the last revision has the right user name.
		$dbr = wfGetDB( DB_SLAVE );
		$this->assertEquals( 3, Revision::countByPageId( $dbr, $page->getId() ) );

		$page = new WikiPage( $page->getTitle() );
		$rev3 = $page->getRevision();
		$this->assertEquals( '127.0.2.13', $rev3->getUserText() );

		$rev2 = $rev3->getPrevious();
		$this->assertEquals( '127.0.1.11', $rev2->getUserText() );

		$rev1 = $rev2->getPrevious();
		$this->assertEquals( 'Admin', $rev1->getUserText() );

		# now, try the actual rollback
		$admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
		$token = $admin->getEditToken( array( $page->getTitle()->getPrefixedText(), $user2->getName() ), null );
		$errors = $page->doRollback( $user2->getName(), "testing revert", $token, false, $details, $admin );

		if ( $errors ) {
			$this->fail( "Rollback failed:\n" . print_r( $errors, true ) . ";\n" . print_r( $details, true ) );
		}

		$page = new WikiPage( $page->getTitle() );
		$this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(), "rollback did not revert to the correct revision" );
		$this->assertEquals( "one\n\ntwo", $page->getText() );
	}

	/**
	 * @todo FIXME: the above rollback test is better, but it keeps failing in jenkins for some reason.
	 */
	public function testDoRollback() {
		$admin = new User();
		$admin->setName("Admin");

		$text = "one";
		$page = $this->newPage( "WikiPageTest_testDoRollback" );
		$page->doEdit( $text, "section one", EDIT_NEW, false, $admin );
		$rev1 = $page->getRevision();

		$user1 = new User();
		$user1->setName( "127.0.1.11" );
		$text .= "\n\ntwo";
		$page = new WikiPage( $page->getTitle() );
		$page->doEdit( $text, "adding section two", 0, false, $user1 );

		# now, try the rollback
		$admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
		$token = $admin->getEditToken( array( $page->getTitle()->getPrefixedText(), $user1->getName() ), null );
		$errors = $page->doRollback( $user1->getName(), "testing revert", $token, false, $details, $admin );

		if ( $errors ) {
			$this->fail( "Rollback failed:\n" . print_r( $errors, true ) . ";\n" . print_r( $details, true ) );
		}

		$page = new WikiPage( $page->getTitle() );
		$this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(), "rollback did not revert to the correct revision" );
		$this->assertEquals( "one", $page->getText() );
	}

	public function dataGetAutosummary( ) {
		return array(
			array(
				'Hello there, world!',
				'#REDIRECT [[Foo]]',
				0,
				'/^Redirected page .*Foo/'
			),

			array(
				null,
				'Hello world!',
				EDIT_NEW,
				'/^Created page .*Hello/'
			),

			array(
				'Hello there, world!',
				'',
				0,
				'/^Blanked/'
			),

			array(
				'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
				labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
				ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
				'Hello world!',
				0,
				'/^Replaced .*Hello/'
			),

			array(
				'foo',
				'bar',
				0,
				'/^$/'
			),
		);
	}

	/**
	 * @dataProvider dataGetAutoSummary
	 */
	public function testGetAutosummary( $old, $new, $flags, $expected ) {
		$page = $this->newPage( "WikiPageTest_testGetAutosummary" );

		$summary = $page->getAutosummary( $old, $new, $flags );

		$this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
	}

	public function dataGetAutoDeleteReason( ) {
		return array(
			array(
				array(),
				false,
				false
			),

			array(
				array(
					array( "first edit", null ),
				),
				"/first edit.*only contributor/",
				false
			),

			array(
				array(
					array( "first edit", null ),
					array( "second edit", null ),
				),
				"/second edit.*only contributor/",
				true
			),

			array(
				array(
					array( "first edit", "127.0.2.22" ),
					array( "second edit", "127.0.3.33" ),
				),
				"/second edit/",
				true
			),

			array(
				array(
					array( "first edit: "
					     . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
					     . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. "
					     . "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea "
					     . "takimata sanctus est Lorem ipsum dolor sit amet.'", null ),
				),
				'/first edit:.*\.\.\."/',
				false
			),

			array(
				array(
					array( "first edit", "127.0.2.22" ),
					array( "", "127.0.3.33" ),
				),
				"/before blanking.*first edit/",
				true
			),

		);
	}

	/**
	 * @dataProvider dataGetAutoDeleteReason
	 */
	public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
		global $wgUser;

		$page = $this->newPage( "WikiPageTest_testGetAutoDeleteReason" );

		$c = 1;

		foreach ( $edits as $edit ) {
			$user = new User();

			if ( !empty( $edit[1] ) ) $user->setName( $edit[1] );
			else $user = $wgUser;

			$page->doEdit( $edit[0], "test edit $c", $c < 2 ? EDIT_NEW : 0, false, $user );

			$c += 1;
		}

		$reason = $page->getAutoDeleteReason( $hasHistory );

		if ( is_bool( $expectedResult ) || is_null( $expectedResult ) ) $this->assertEquals( $expectedResult, $reason );
		else $this->assertTrue( (bool)preg_match( $expectedResult, $reason ), "Autosummary didn't match expected pattern $expectedResult: $reason" );

		$this->assertEquals( $expectedHistory, $hasHistory, "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );

		$page->doDeleteArticle( "done" );
	}

	public function dataPreSaveTransform() {
		return array(
			array( 'hello this is ~~~',
			       "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
			),
			array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
			       'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
			),
		);
	}

	/**
	 * @dataProvider dataPreSaveTransform
	 */
	public function testPreSaveTransform( $text, $expected ) {
		$this->hideDeprecated( 'WikiPage::preSaveTransform' );
		$user = new User();
		$user->setName("127.0.0.1");

		$page = $this->newPage( "WikiPageTest_testPreloadTransform" );
		$text = $page->preSaveTransform( $text, $user );

		$this->assertEquals( $expected, $text );
	}

}