MediaWiki REL1_30
DifferenceEngineTest.php
Go to the documentation of this file.
1<?php
2
14
15 protected $context;
16
17 private static $revisions;
18
19 protected function setUp() {
20 parent::setUp();
21
22 $title = $this->getTitle();
23
24 $this->context = new RequestContext();
25 $this->context->setTitle( $title );
26
27 if ( !self::$revisions ) {
28 self::$revisions = $this->doEdits();
29 }
30 }
31
35 protected function getTitle() {
36 $namespace = $this->getDefaultWikitextNS();
37 return Title::newFromText( 'Kitten', $namespace );
38 }
39
43 protected function doEdits() {
44 $title = $this->getTitle();
45 $page = WikiPage::factory( $title );
46
47 $strings = [ "it is a kitten", "two kittens", "three kittens", "four kittens" ];
48 $revisions = [];
49
50 foreach ( $strings as $string ) {
51 $content = ContentHandler::makeContent( $string, $title );
52 $page->doEditContent( $content, 'edit page' );
53 $revisions[] = $page->getLatest();
54 }
55
56 return $revisions;
57 }
58
59 public function testMapDiffPrevNext() {
60 $cases = $this->getMapDiffPrevNextCases();
61
62 foreach ( $cases as $case ) {
63 list( $expected, $old, $new, $message ) = $case;
64
65 $diffEngine = new DifferenceEngine( $this->context, $old, $new, 2, true, false );
66 $diffMap = $diffEngine->mapDiffPrevNext( $old, $new );
67 $this->assertEquals( $expected, $diffMap, $message );
68 }
69 }
70
71 private function getMapDiffPrevNextCases() {
72 $revs = self::$revisions;
73
74 return [
75 [ [ $revs[1], $revs[2] ], $revs[2], 'prev', 'diff=prev' ],
76 [ [ $revs[2], $revs[3] ], $revs[2], 'next', 'diff=next' ],
77 [ [ $revs[1], $revs[3] ], $revs[1], $revs[3], 'diff=' . $revs[3] ]
78 ];
79 }
80
81 public function testLoadRevisionData() {
82 $cases = $this->getLoadRevisionDataCases();
83
84 foreach ( $cases as $case ) {
85 list( $expectedOld, $expectedNew, $old, $new, $message ) = $case;
86
87 $diffEngine = new DifferenceEngine( $this->context, $old, $new, 2, true, false );
88 $diffEngine->loadRevisionData();
89
90 $this->assertEquals( $diffEngine->getOldid(), $expectedOld, $message );
91 $this->assertEquals( $diffEngine->getNewid(), $expectedNew, $message );
92 }
93 }
94
95 private function getLoadRevisionDataCases() {
96 $revs = self::$revisions;
97
98 return [
99 [ $revs[2], $revs[3], $revs[3], 'prev', 'diff=prev' ],
100 [ $revs[2], $revs[3], $revs[2], 'next', 'diff=next' ],
101 [ $revs[1], $revs[3], $revs[1], $revs[3], 'diff=' . $revs[3] ],
102 [ $revs[1], $revs[3], $revs[1], 0, 'diff=0' ]
103 ];
104 }
105
106 public function testGetOldid() {
107 $revs = self::$revisions;
108
109 $diffEngine = new DifferenceEngine( $this->context, $revs[1], $revs[2], 2, true, false );
110 $this->assertEquals( $revs[1], $diffEngine->getOldid(), 'diff get old id' );
111 }
112
113 public function testGetNewid() {
114 $revs = self::$revisions;
115
116 $diffEngine = new DifferenceEngine( $this->context, $revs[1], $revs[2], 2, true, false );
117 $this->assertEquals( $revs[2], $diffEngine->getNewid(), 'diff get new id' );
118 }
119
120}
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
Group all the pieces relevant to the context of a request into one instance.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition WikiPage.php:121
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11