MediaWiki  1.30.0
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 }
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:268
DifferenceEngineTest\getLoadRevisionDataCases
getLoadRevisionDataCases()
Definition: DifferenceEngineTest.php:95
DifferenceEngineTest\doEdits
doEdits()
Definition: DifferenceEngineTest.php:43
DifferenceEngineTest\testGetNewid
testGetNewid()
Definition: DifferenceEngineTest.php:113
DifferenceEngineTest\testGetOldid
testGetOldid()
Definition: DifferenceEngineTest.php:106
DifferenceEngineTest\$revisions
static $revisions
Definition: DifferenceEngineTest.php:17
DifferenceEngineTest\getMapDiffPrevNextCases
getMapDiffPrevNextCases()
Definition: DifferenceEngineTest.php:71
DifferenceEngineTest\$context
$context
Definition: DifferenceEngineTest.php:15
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:35
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:121
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
DifferenceEngineTest
DifferenceEngine.
Definition: DifferenceEngineTest.php:13
DifferenceEngineTest\testLoadRevisionData
testLoadRevisionData()
Definition: DifferenceEngineTest.php:81
MediaWikiTestCase\getDefaultWikitextNS
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
Definition: MediaWikiTestCase.php:1693
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:33
DifferenceEngineTest\getTitle
getTitle()
Definition: DifferenceEngineTest.php:35
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
DifferenceEngineTest\testMapDiffPrevNext
testMapDiffPrevNext()
Definition: DifferenceEngineTest.php:59
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:9
DifferenceEngine
Definition: DifferenceEngine.php:32
DifferenceEngineTest\setUp
setUp()
Definition: DifferenceEngineTest.php:19