MediaWiki REL1_31
DifferenceEngineTest.php
Go to the documentation of this file.
1<?php
2
3use Wikimedia\TestingAccessWrapper;
4
16
17 protected $context;
18
19 private static $revisions;
20
21 protected function setUp() {
22 parent::setUp();
23
24 $title = $this->getTitle();
25
26 $this->context = new RequestContext();
27 $this->context->setTitle( $title );
28
29 if ( !self::$revisions ) {
30 self::$revisions = $this->doEdits();
31 }
32 }
33
37 protected function getTitle() {
38 $namespace = $this->getDefaultWikitextNS();
39 return Title::newFromText( 'Kitten', $namespace );
40 }
41
45 protected function doEdits() {
46 $title = $this->getTitle();
47 $page = WikiPage::factory( $title );
48
49 $strings = [ "it is a kitten", "two kittens", "three kittens", "four kittens" ];
50 $revisions = [];
51
52 foreach ( $strings as $string ) {
53 $content = ContentHandler::makeContent( $string, $title );
54 $page->doEditContent( $content, 'edit page' );
55 $revisions[] = $page->getLatest();
56 }
57
58 return $revisions;
59 }
60
61 public function testMapDiffPrevNext() {
62 $cases = $this->getMapDiffPrevNextCases();
63
64 foreach ( $cases as $case ) {
65 list( $expected, $old, $new, $message ) = $case;
66
67 $diffEngine = new DifferenceEngine( $this->context, $old, $new, 2, true, false );
68 $diffMap = $diffEngine->mapDiffPrevNext( $old, $new );
69 $this->assertEquals( $expected, $diffMap, $message );
70 }
71 }
72
73 private function getMapDiffPrevNextCases() {
74 $revs = self::$revisions;
75
76 return [
77 [ [ $revs[1], $revs[2] ], $revs[2], 'prev', 'diff=prev' ],
78 [ [ $revs[2], $revs[3] ], $revs[2], 'next', 'diff=next' ],
79 [ [ $revs[1], $revs[3] ], $revs[1], $revs[3], 'diff=' . $revs[3] ]
80 ];
81 }
82
83 public function testLoadRevisionData() {
84 $cases = $this->getLoadRevisionDataCases();
85
86 foreach ( $cases as $case ) {
87 list( $expectedOld, $expectedNew, $old, $new, $message ) = $case;
88
89 $diffEngine = new DifferenceEngine( $this->context, $old, $new, 2, true, false );
90 $diffEngine->loadRevisionData();
91
92 $this->assertEquals( $diffEngine->getOldid(), $expectedOld, $message );
93 $this->assertEquals( $diffEngine->getNewid(), $expectedNew, $message );
94 }
95 }
96
97 private function getLoadRevisionDataCases() {
98 $revs = self::$revisions;
99
100 return [
101 [ $revs[2], $revs[3], $revs[3], 'prev', 'diff=prev' ],
102 [ $revs[2], $revs[3], $revs[2], 'next', 'diff=next' ],
103 [ $revs[1], $revs[3], $revs[1], $revs[3], 'diff=' . $revs[3] ],
104 [ $revs[1], $revs[3], $revs[1], 0, 'diff=0' ]
105 ];
106 }
107
108 public function testGetOldid() {
109 $revs = self::$revisions;
110
111 $diffEngine = new DifferenceEngine( $this->context, $revs[1], $revs[2], 2, true, false );
112 $this->assertEquals( $revs[1], $diffEngine->getOldid(), 'diff get old id' );
113 }
114
115 public function testGetNewid() {
116 $revs = self::$revisions;
117
118 $diffEngine = new DifferenceEngine( $this->context, $revs[1], $revs[2], 2, true, false );
119 $this->assertEquals( $revs[2], $diffEngine->getNewid(), 'diff get new id' );
120 }
121
123 return [
124 'moved paragraph left shoud get new location title' => [
125 '<a class="mw-diff-movedpara-left">⚫</a>',
126 '<a class="mw-diff-movedpara-left" title="(diff-paragraph-moved-tonew)">⚫</a>',
127 ],
128 'moved paragraph right shoud get old location title' => [
129 '<a class="mw-diff-movedpara-right">⚫</a>',
130 '<a class="mw-diff-movedpara-right" title="(diff-paragraph-moved-toold)">⚫</a>',
131 ],
132 'nothing changed when key not hit' => [
133 '<a class="mw-diff-movedpara-rightis">⚫</a>',
134 '<a class="mw-diff-movedpara-rightis">⚫</a>',
135 ],
136 ];
137 }
138
142 public function testAddLocalisedTitleTooltips( $input, $expected ) {
143 $this->setContentLang( 'qqx' );
144 $diffEngine = TestingAccessWrapper::newFromObject( new DifferenceEngine() );
145 $this->assertEquals( $expected, $diffEngine->addLocalisedTitleTooltips( $input ) );
146 }
147
148}
testAddLocalisedTitleTooltips( $input, $expected)
provideLocaliseTitleTooltipsTestData
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.
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
if(is_array($mode)) switch( $mode) $input