MediaWiki  1.33.0
AbstractChangesListSpecialPageTestCase.php
Go to the documentation of this file.
1 <?php
2 
10  // Must be initialized by subclass
15 
17 
18  protected function setUp() {
19  global $wgGroupPermissions;
20 
21  parent::setUp();
22  $this->setMwGlobals( [
23  'wgRCWatchCategoryMembership' => true,
24  'wgUseRCPatrol' => true,
25  ] );
26 
27  if ( isset( $wgGroupPermissions['patrollers'] ) ) {
28  $this->oldPatrollersGroup = $wgGroupPermissions['patrollers'];
29  }
30 
31  $wgGroupPermissions['patrollers'] = [
32  'patrol' => true,
33  ];
34 
35  # setup the ChangesListSpecialPage (or subclass) object
36  $this->changesListSpecialPage = $this->getPage();
37  $context = $this->changesListSpecialPage->getContext();
39  $context->setUser( $this->getTestUser( [ 'patrollers' ] )->getUser() );
40  $this->changesListSpecialPage->setContext( $context );
41  $this->changesListSpecialPage->registerFilters();
42  }
43 
44  abstract protected function getPage();
45 
46  protected function tearDown() {
47  global $wgGroupPermissions;
48 
49  parent::tearDown();
50 
51  if ( $this->oldPatrollersGroup !== null ) {
53  }
54  }
55 
56  abstract public function provideParseParameters();
57 
61  public function testParseParameters( $params, $expected ) {
62  $opts = new FormOptions();
63  foreach ( $expected as $key => $value ) {
64  // Register it as null so sets aren't rejected.
65  $opts->add(
66  $key,
67  null,
68  FormOptions::guessType( $expected )
69  );
70  }
71 
72  $this->changesListSpecialPage->parseParameters(
73  $params,
74  $opts
75  );
76 
77  $this->assertArrayEquals(
78  $expected,
79  $opts->getAllValues(), false, true
82  );
83  }
84 
88  public function testValidateOptions(
89  $optionsToSet,
90  $expectedRedirect,
91  $expectedRedirectOptions,
92  $rcfilters
93  ) {
94  $redirectQuery = [];
95  $redirected = false;
96  $output = $this->getMockBuilder( OutputPage::class )
97  ->disableProxyingToOriginalMethods()
98  ->disableOriginalConstructor()
99  ->getMock();
100  $output->method( 'redirect' )->willReturnCallback(
101  function ( $url ) use ( &$redirectQuery, &$redirected ) {
102  $urlParts = wfParseUrl( $url );
103  $query = $urlParts[ 'query' ] ?? '';
104  parse_str( $query, $redirectQuery );
105  $redirected = true;
106  }
107  );
108  $ctx = new RequestContext();
109 
110  // Give users patrol permissions so we can test that.
111  $user = $this->getTestSysop()->getUser();
112  $user->setOption( 'rcenhancedfilters-disable', $rcfilters ? 0 : 1 );
113  $ctx->setUser( $user );
114 
115  // Disable this hook or it could break changeType
116  // depending on which other extensions are running.
117  $this->setTemporaryHook(
118  'ChangesListSpecialPageStructuredFilters',
119  null
120  );
121 
122  $ctx->setOutput( $output );
124  $clsp->setContext( $ctx );
125  $opts = $clsp->getDefaultOptions();
126 
127  foreach ( $optionsToSet as $option => $value ) {
128  $opts->setValue( $option, $value );
129  }
130 
131  $clsp->validateOptions( $opts );
132 
133  $this->assertEquals( $expectedRedirect, $redirected, 'redirection' );
134 
135  if ( $expectedRedirect ) {
136  if ( count( $expectedRedirectOptions ) > 0 ) {
137  $expectedRedirectOptions += [
138  'title' => $clsp->getPageTitle()->getPrefixedText(),
139  ];
140  }
141 
142  $this->assertArrayEquals(
143  $expectedRedirectOptions,
144  $redirectQuery,
145  /* $ordered= */ false,
146  /* $named= */ true,
147  'redirection query'
148  );
149  }
150  }
151 }
AbstractChangesListSpecialPageTestCase\testValidateOptions
testValidateOptions( $optionsToSet, $expectedRedirect, $expectedRedirectOptions, $rcfilters)
validateOptionsProvider
Definition: AbstractChangesListSpecialPageTestCase.php:88
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:2070
$context
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2636
MediaWikiTestCase\getTestUser
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
Definition: MediaWikiTestCase.php:180
captcha-old.count
count
Definition: captcha-old.py:249
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:36
AbstractChangesListSpecialPageTestCase\testParseParameters
testParseParameters( $params, $expected)
provideParseParameters
Definition: AbstractChangesListSpecialPageTestCase.php:61
$params
$params
Definition: styleTest.css.php:44
AbstractChangesListSpecialPageTestCase\$changesListSpecialPage
ChangesListSpecialPage $changesListSpecialPage
Definition: AbstractChangesListSpecialPageTestCase.php:14
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
$query
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1588
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:30
wfParseUrl
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
Definition: GlobalFunctions.php:817
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:709
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$output
$output
Definition: SyntaxHighlight.php:334
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:32
$value
$value
Definition: styleTest.css.php:49
FormOptions\guessType
static guessType( $data)
Used to find out which type the data is.
Definition: FormOptions.php:117
MediaWikiTestCase\getTestSysop
static getTestSysop()
Convenience method for getting an immutable admin test user.
Definition: MediaWikiTestCase.php:204
AbstractChangesListSpecialPageTestCase\setUp
setUp()
Definition: AbstractChangesListSpecialPageTestCase.php:18
AbstractChangesListSpecialPageTestCase\tearDown
tearDown()
Definition: AbstractChangesListSpecialPageTestCase.php:46
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
SpecialPage\setContext
setContext( $context)
Sets the context this SpecialPage is executed in.
Definition: SpecialPage.php:688
true
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 true
Definition: hooks.txt:1985
AbstractChangesListSpecialPageTestCase\provideParseParameters
provideParseParameters()
$wgGroupPermissions
$wgGroupPermissions['sysop']['replacetext']
Definition: ReplaceText.php:56
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
MediaWikiTestCase\setTemporaryHook
setTemporaryHook( $hookName, $handler)
Create a temporary hook handler which will be reset by tearDown.
Definition: MediaWikiTestCase.php:2325
AbstractChangesListSpecialPageTestCase\getPage
getPage()
AbstractChangesListSpecialPageTestCase
Abstract base class for shared logic when testing ChangesListSpecialPage and subclasses.
Definition: AbstractChangesListSpecialPageTestCase.php:9
AbstractChangesListSpecialPageTestCase\$oldPatrollersGroup
$oldPatrollersGroup
Definition: AbstractChangesListSpecialPageTestCase.php:16