MediaWiki REL1_28
RecentChangeTest.php
Go to the documentation of this file.
1<?php
2use Wikimedia\ScopedCallback;
3
8 protected $title;
9 protected $target;
10 protected $user;
11 protected $user_comment;
12 protected $context;
13
14 public function setUp() {
15 parent::setUp();
16
17 $this->title = Title::newFromText( 'SomeTitle' );
18 $this->target = Title::newFromText( 'TestTarget' );
19 $this->user = User::newFromName( 'UserName' );
20
21 $this->user_comment = '<User comment about action>';
22 $this->context = RequestContext::newExtraneousContext( $this->title );
23 }
24
29 public function testNewFromRow() {
30 $row = new stdClass();
31 $row->rc_foo = 'AAA';
32 $row->rc_timestamp = '20150921134808';
33 $row->rc_deleted = 'bar';
34
35 $rc = RecentChange::newFromRow( $row );
36
37 $expected = [
38 'rc_foo' => 'AAA',
39 'rc_timestamp' => '20150921134808',
40 'rc_deleted' => 'bar',
41 ];
42 $this->assertEquals( $expected, $rc->getAttributes() );
43 }
44
48 public function testParseParams() {
49 $params = [
50 'root' => [
51 'A' => 1,
52 'B' => 'two'
53 ]
54 ];
55
56 $this->assertParseParams(
57 $params,
58 'a:1:{s:4:"root";a:2:{s:1:"A";i:1;s:1:"B";s:3:"two";}}'
59 );
60
61 $this->assertParseParams(
62 null,
63 null
64 );
65
66 $this->assertParseParams(
67 null,
68 serialize( false )
69 );
70
71 $this->assertParseParams(
72 null,
73 'not-an-array'
74 );
75 }
76
81 protected function assertParseParams( $expectedParseParams, $rawRcParams ) {
82 $rc = new RecentChange;
83 $rc->setAttribs( [ 'rc_params' => $rawRcParams ] );
84
85 $actualParseParams = $rc->parseParams();
86
87 $this->assertEquals( $expectedParseParams, $actualParseParams );
88 }
89
94 public function provideIsInRCLifespan() {
95 return [
96 [ 6000, time() - 3000, 0, true ],
97 [ 3000, time() - 6000, 0, false ],
98 [ 6000, time() - 3000, 6000, true ],
99 [ 3000, time() - 6000, 6000, true ],
100 ];
101 }
102
107 public function testIsInRCLifespan( $maxAge, $timestamp, $tolerance, $expected ) {
108 $this->setMwGlobals( 'wgRCMaxAge', $maxAge );
109 $this->assertEquals( $expected, RecentChange::isInRCLifespan( $timestamp, $tolerance ) );
110 }
111
112 public function provideRCTypes() {
113 return [
114 [ RC_EDIT, 'edit' ],
115 [ RC_NEW, 'new' ],
116 [ RC_LOG, 'log' ],
117 [ RC_EXTERNAL, 'external' ],
118 [ RC_CATEGORIZE, 'categorize' ],
119 ];
120 }
121
126 public function testParseFromRCType( $rcType, $type ) {
127 $this->assertEquals( $type, RecentChange::parseFromRCType( $rcType ) );
128 }
129
134 public function testParseToRCType( $rcType, $type ) {
135 $this->assertEquals( $rcType, RecentChange::parseToRCType( $type ) );
136 }
137
141 private function getMockPageProps() {
142 return $this->getMockBuilder( PageProps::class )
143 ->disableOriginalConstructor()
144 ->getMock();
145 }
146
147 public function provideCategoryContent() {
148 return [
149 [ true ],
150 [ false ],
151 ];
152 }
153
158 public function testHiddenCategoryChange( $isHidden ) {
159 $categoryTitle = Title::newFromText( 'CategoryPage', NS_CATEGORY );
160
161 $pageProps = $this->getMockPageProps();
162 $pageProps->expects( $this->once() )
163 ->method( 'getProperties' )
164 ->with( $categoryTitle, 'hiddencat' )
165 ->will( $this->returnValue( $isHidden ? [ $categoryTitle->getArticleID() => '' ] : [] ) );
166
167 $scopedOverride = PageProps::overrideInstance( $pageProps );
168
170 '0',
171 $categoryTitle,
172 $this->user,
173 $this->user_comment,
174 $this->title,
175 $categoryTitle->getLatestRevID(),
176 $categoryTitle->getLatestRevID(),
177 '0',
178 false
179 );
180
181 $this->assertEquals( $isHidden, $rc->getParam( 'hidden-cat' ) );
182
183 ScopedCallback::consume( $scopedOverride );
184 }
185}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
serialize()
setMwGlobals( $pairs, $value=null)
static overrideInstance(PageProps $store=null)
Overrides the default instance of this class This is intended for use while testing and will fail if ...
Definition PageProps.php:51
testParseFromRCType( $rcType, $type)
provideRCTypes RecentChange::parseFromRCType
testNewFromRow()
RecentChange::newFromRow RecentChange::loadFromRow.
testIsInRCLifespan( $maxAge, $timestamp, $tolerance, $expected)
RecentChange::isInRCLifespan provideIsInRCLifespan.
testParseParams()
RecentChange::parseParams.
testHiddenCategoryChange( $isHidden)
provideCategoryContent RecentChange::newForCategorization
provideIsInRCLifespan()
50 mins and 100 mins are used here as the tests never take that long!
testParseToRCType( $rcType, $type)
provideRCTypes RecentChange::parseToRCType
assertParseParams( $expectedParseParams, $rawRcParams)
Utility class for creating new RC entries.
static parseToRCType( $type)
Parsing text to RC_* constants.
static newFromRow( $row)
static isInRCLifespan( $timestamp, $tolerance=0)
Check whether the given timestamp is new enough to have a RC row with a given tolerance as the recent...
static newForCategorization( $timestamp, Title $categoryTitle, User $user=null, $comment, Title $pageTitle, $oldRevId, $newRevId, $lastTimestamp, $bot, $ip='', $deleted=0)
Constructs a RecentChange object for the given categorization This does not call save() on the object...
setAttribs( $attribs)
static parseFromRCType( $rcType)
Parsing RC_* constants to human-readable test.
static newExtraneousContext(Title $title, $request=[])
Create a new extraneous context.
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 and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Wikitext formatted, in the key only.
const RC_NEW
Definition Defines.php:137
const RC_LOG
Definition Defines.php:138
const RC_EXTERNAL
Definition Defines.php:139
const RC_EDIT
Definition Defines.php:136
const NS_CATEGORY
Definition Defines.php:70
const RC_CATEGORIZE
Definition Defines.php:140
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition hooks.txt:2568
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:1950
processing should stop and the error should be shown to the user * false
Definition hooks.txt:189
if( $limit) $timestamp
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
title
$params