MediaWiki REL1_30
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 $row->rc_comment_text = 'comment';
35 $row->rc_comment_data = null;
36
37 $rc = RecentChange::newFromRow( $row );
38
39 $expected = [
40 'rc_foo' => 'AAA',
41 'rc_timestamp' => '20150921134808',
42 'rc_deleted' => 'bar',
43 'rc_comment' => 'comment',
44 'rc_comment_text' => 'comment',
45 'rc_comment_data' => null,
46 ];
47 $this->assertEquals( $expected, $rc->getAttributes() );
48
49 $row = new stdClass();
50 $row->rc_foo = 'AAA';
51 $row->rc_timestamp = '20150921134808';
52 $row->rc_deleted = 'bar';
53 $row->rc_comment = 'comment';
54
55 MediaWiki\suppressWarnings();
56 $rc = RecentChange::newFromRow( $row );
57 MediaWiki\restoreWarnings();
58
59 $expected = [
60 'rc_foo' => 'AAA',
61 'rc_timestamp' => '20150921134808',
62 'rc_deleted' => 'bar',
63 'rc_comment' => 'comment',
64 'rc_comment_text' => 'comment',
65 'rc_comment_data' => null,
66 ];
67 $this->assertEquals( $expected, $rc->getAttributes() );
68 }
69
73 public function testParseParams() {
74 $params = [
75 'root' => [
76 'A' => 1,
77 'B' => 'two'
78 ]
79 ];
80
81 $this->assertParseParams(
82 $params,
83 'a:1:{s:4:"root";a:2:{s:1:"A";i:1;s:1:"B";s:3:"two";}}'
84 );
85
86 $this->assertParseParams(
87 null,
88 null
89 );
90
91 $this->assertParseParams(
92 null,
93 serialize( false )
94 );
95
96 $this->assertParseParams(
97 null,
98 'not-an-array'
99 );
100 }
101
106 protected function assertParseParams( $expectedParseParams, $rawRcParams ) {
107 $rc = new RecentChange;
108 $rc->setAttribs( [ 'rc_params' => $rawRcParams ] );
109
110 $actualParseParams = $rc->parseParams();
111
112 $this->assertEquals( $expectedParseParams, $actualParseParams );
113 }
114
118 public function provideIsInRCLifespan() {
119 return [
120 [ 6000, -3000, 0, true ],
121 [ 3000, -6000, 0, false ],
122 [ 6000, -3000, 6000, true ],
123 [ 3000, -6000, 6000, true ],
124 ];
125 }
126
131 public function testIsInRCLifespan( $maxAge, $offset, $tolerance, $expected ) {
132 $this->setMwGlobals( 'wgRCMaxAge', $maxAge );
133 // Calculate this here instead of the data provider because the provider
134 // is expanded early on and the full test suite may take longer than 100 minutes
135 // when coverage is enabled.
136 $timestamp = time() + $offset;
137 $this->assertEquals( $expected, RecentChange::isInRCLifespan( $timestamp, $tolerance ) );
138 }
139
140 public function provideRCTypes() {
141 return [
142 [ RC_EDIT, 'edit' ],
143 [ RC_NEW, 'new' ],
144 [ RC_LOG, 'log' ],
145 [ RC_EXTERNAL, 'external' ],
146 [ RC_CATEGORIZE, 'categorize' ],
147 ];
148 }
149
154 public function testParseFromRCType( $rcType, $type ) {
155 $this->assertEquals( $type, RecentChange::parseFromRCType( $rcType ) );
156 }
157
162 public function testParseToRCType( $rcType, $type ) {
163 $this->assertEquals( $rcType, RecentChange::parseToRCType( $type ) );
164 }
165
169 private function getMockPageProps() {
170 return $this->getMockBuilder( PageProps::class )
171 ->disableOriginalConstructor()
172 ->getMock();
173 }
174
175 public function provideCategoryContent() {
176 return [
177 [ true ],
178 [ false ],
179 ];
180 }
181
186 public function testHiddenCategoryChange( $isHidden ) {
187 $categoryTitle = Title::newFromText( 'CategoryPage', NS_CATEGORY );
188
189 $pageProps = $this->getMockPageProps();
190 $pageProps->expects( $this->once() )
191 ->method( 'getProperties' )
192 ->with( $categoryTitle, 'hiddencat' )
193 ->will( $this->returnValue( $isHidden ? [ $categoryTitle->getArticleID() => '' ] : [] ) );
194
195 $scopedOverride = PageProps::overrideInstance( $pageProps );
196
198 '0',
199 $categoryTitle,
200 $this->user,
201 $this->user_comment,
202 $this->title,
203 $categoryTitle->getLatestRevID(),
204 $categoryTitle->getLatestRevID(),
205 '0',
206 false
207 );
208
209 $this->assertEquals( $isHidden, $rc->getParam( 'hidden-cat' ) );
210
211 ScopedCallback::consume( $scopedOverride );
212 }
213}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
serialize()
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
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:50
testParseFromRCType( $rcType, $type)
provideRCTypes RecentChange::parseFromRCType
testNewFromRow()
RecentChange::newFromRow RecentChange::loadFromRow.
testParseParams()
RecentChange::parseParams.
testHiddenCategoryChange( $isHidden)
provideCategoryContent RecentChange::newForCategorization
testParseToRCType( $rcType, $type)
provideRCTypes RecentChange::parseToRCType
testIsInRCLifespan( $maxAge, $offset, $tolerance, $expected)
RecentChange::isInRCLifespan provideIsInRCLifespan.
assertParseParams( $expectedParseParams, $rawRcParams)
Utility class for creating new RC entries.
static parseToRCType( $type)
Parsing text to RC_* constants.
static newFromRow( $row)
static newForCategorization( $timestamp, Title $categoryTitle, User $user=null, $comment, Title $pageTitle, $oldRevId, $newRevId, $lastTimestamp, $bot, $ip='', $deleted=0, $added=null)
Constructs a RecentChange object for the given categorization This does not call save() on the object...
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...
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:144
const RC_LOG
Definition Defines.php:145
const RC_EXTERNAL
Definition Defines.php:146
const RC_EDIT
Definition Defines.php:143
const NS_CATEGORY
Definition Defines.php:79
const RC_CATEGORIZE
Definition Defines.php:147
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:1976
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
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
$params