MediaWiki  1.28.0
EnhancedChangesListTest.php
Go to the documentation of this file.
1 <?php
2 
11 
16 
17  public function __construct( $name = null, array $data = [], $dataName = '' ) {
18  parent::__construct( $name, $data, $dataName );
19 
20  $this->testRecentChangesHelper = new TestRecentChangesHelper();
21  }
22 
24  $enhancedChangesList = $this->newEnhancedChangesList();
25  $enhancedChangesList->beginRecentChangesList();
26 
27  $styleModules = $enhancedChangesList->getOutput()->getModuleStyles();
28 
29  $this->assertContains(
30  'mediawiki.special.changeslist',
31  $styleModules,
32  'has mediawiki.special.changeslist'
33  );
34 
35  $this->assertContains(
36  'mediawiki.special.changeslist.enhanced',
37  $styleModules,
38  'has mediawiki.special.changeslist.enhanced'
39  );
40  }
41 
43  $enhancedChangesList = $this->newEnhancedChangesList();
44  $enhancedChangesList->beginRecentChangesList();
45 
46  $modules = $enhancedChangesList->getOutput()->getModules();
47 
48  $this->assertContains( 'jquery.makeCollapsible', $modules, 'has jquery.makeCollapsible' );
49  $this->assertContains( 'mediawiki.icon', $modules, 'has mediawiki.icon' );
50  }
51 
52  public function testBeginRecentChangesList_html() {
53  $enhancedChangesList = $this->newEnhancedChangesList();
54  $html = $enhancedChangesList->beginRecentChangesList();
55 
56  $this->assertEquals( '<div class="mw-changeslist">', $html );
57  }
58 
62  public function testRecentChangesLine() {
63  $enhancedChangesList = $this->newEnhancedChangesList();
64  $enhancedChangesList->beginRecentChangesList();
65 
66  $recentChange = $this->getEditChange( '20131103092153' );
67  $html = $enhancedChangesList->recentChangesLine( $recentChange, false );
68 
69  $this->assertInternalType( 'string', $html );
70 
71  $recentChange2 = $this->getEditChange( '20131103092253' );
72  $html = $enhancedChangesList->recentChangesLine( $recentChange2, false );
73 
74  $this->assertEquals( '', $html );
75  }
76 
79  $this->getCategorizationChange( '20150629191735', 0, 0 )
80  );
81  $this->assertNotContains( '(diff | hist)', strip_tags( $html ) );
82  }
83 
86  $this->getCategorizationChange( '20150629191735', 1025, 1024 )
87  );
88  $this->assertContains( '(diff | hist)', strip_tags( $html ) );
89  }
90 
94  public function testEndRecentChangesList() {
95  $enhancedChangesList = $this->newEnhancedChangesList();
96  $enhancedChangesList->beginRecentChangesList();
97 
98  $recentChange = $this->getEditChange( '20131103092153' );
99  $enhancedChangesList->recentChangesLine( $recentChange, false );
100 
101  $recentChange2 = $this->getEditChange( '20131103092253' );
102  $enhancedChangesList->recentChangesLine( $recentChange2, false );
103 
104  $html = $enhancedChangesList->endRecentChangesList();
105 
106  preg_match_all( '/td class="mw-enhanced-rc-nested"/', $html, $matches );
107  $this->assertCount( 2, $matches[0] );
108  }
109 
113  private function newEnhancedChangesList() {
114  $user = User::newFromId( 0 );
115  $context = $this->testRecentChangesHelper->getTestContext( $user );
116 
117  return new EnhancedChangesList( $context );
118  }
119 
123  private function getEditChange( $timestamp ) {
124  $user = $this->getMutableTestUser()->getUser();
125  $recentChange = $this->testRecentChangesHelper->makeEditRecentChange(
126  $user, 'Cat', $timestamp, 5, 191, 190, 0, 0
127  );
128 
129  return $recentChange;
130  }
131 
135  private function getCategorizationChange( $timestamp, $thisId, $lastId ) {
136  $wikiPage = new WikiPage( Title::newFromText( 'Testpage' ) );
137  $wikiPage->doEditContent( new WikitextContent( 'Some random text' ), 'page created' );
138 
139  $wikiPage = new WikiPage( Title::newFromText( 'Category:Foo' ) );
140  $wikiPage->doEditContent( new WikitextContent( 'Some random text' ), 'category page created' );
141 
142  $user = $this->getMutableTestUser()->getUser();
143  $recentChange = $this->testRecentChangesHelper->makeCategorizationRecentChange(
144  $user, 'Category:Foo', $wikiPage->getId(), $thisId, $lastId, $timestamp
145  );
146 
147  return $recentChange;
148  }
149 
150  private function createCategorizationLine( $recentChange ) {
151  $enhancedChangesList = $this->newEnhancedChangesList();
152  $cacheEntry = $this->testRecentChangesHelper->getCacheEntry( $recentChange );
153 
154  $reflection = new \ReflectionClass( get_class( $enhancedChangesList ) );
155  $method = $reflection->getMethod( 'recentChangesBlockLine' );
156  $method->setAccessible( true );
157 
158  return $method->invokeArgs( $enhancedChangesList, [ $cacheEntry ] );
159  }
160 
161 }
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1936
the array() calling protocol came about after MediaWiki 1.4rc1.
$context
Definition: load.php:50
TestRecentChangesHelper $testRecentChangesHelper
Helper for generating test recent changes entries.
static newFromId($id)
Static factory method for creation from a given user ID.
Definition: User.php:548
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:262
__construct($name=null, array $data=[], $dataName= '')
$modules
if($limit) $timestamp
Base class that store and restore the Language objects.
Content object for wiki text pages.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
Class representing a MediaWiki article and history.
Definition: WikiPage.php:32
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
static getMutableTestUser($groups=[])
Convenience method for getting a mutable test user.
getCategorizationChange($timestamp, $thisId, $lastId)
$matches
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300