MediaWiki  REL1_31
DifferenceEngineTest.php
Go to the documentation of this file.
1 <?php
2 
3 use 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 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:273
DifferenceEngineTest\getLoadRevisionDataCases
getLoadRevisionDataCases()
Definition: DifferenceEngineTest.php:97
DifferenceEngineTest\doEdits
doEdits()
Definition: DifferenceEngineTest.php:45
DifferenceEngineTest\testGetNewid
testGetNewid()
Definition: DifferenceEngineTest.php:115
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
DifferenceEngineTest\testGetOldid
testGetOldid()
Definition: DifferenceEngineTest.php:108
DifferenceEngineTest\$revisions
static $revisions
Definition: DifferenceEngineTest.php:19
DifferenceEngineTest\getMapDiffPrevNextCases
getMapDiffPrevNextCases()
Definition: DifferenceEngineTest.php:73
DifferenceEngineTest\$context
$context
Definition: DifferenceEngineTest.php:17
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:115
$input
if(is_array( $mode)) switch( $mode) $input
Definition: postprocess-phan.php:145
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
DifferenceEngineTest
DifferenceEngine.
Definition: DifferenceEngineTest.php:15
DifferenceEngineTest\testLoadRevisionData
testLoadRevisionData()
Definition: DifferenceEngineTest.php:83
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
DifferenceEngineTest\testAddLocalisedTitleTooltips
testAddLocalisedTitleTooltips( $input, $expected)
provideLocaliseTitleTooltipsTestData
Definition: DifferenceEngineTest.php:142
MediaWikiTestCase\getDefaultWikitextNS
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
Definition: MediaWikiTestCase.php:1912
DifferenceEngineTest\provideLocaliseTitleTooltipsTestData
provideLocaliseTitleTooltipsTestData()
Definition: DifferenceEngineTest.php:122
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:32
DifferenceEngineTest\getTitle
getTitle()
Definition: DifferenceEngineTest.php:37
list
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
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:129
MediaWikiTestCase\setContentLang
setContentLang( $lang)
Definition: MediaWikiTestCase.php:892
DifferenceEngineTest\testMapDiffPrevNext
testMapDiffPrevNext()
Definition: DifferenceEngineTest.php:61
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
DifferenceEngine
Definition: DifferenceEngine.php:30
DifferenceEngineTest\setUp
setUp()
Definition: DifferenceEngineTest.php:21