MediaWiki  1.27.1
RecentChangeTest.php
Go to the documentation of this file.
1 <?php
2 
7  protected $title;
8  protected $target;
9  protected $user;
10  protected $user_comment;
11  protected $context;
12 
13  public function setUp() {
14  parent::setUp();
15 
16  $this->title = Title::newFromText( 'SomeTitle' );
17  $this->target = Title::newFromText( 'TestTarget' );
18  $this->user = User::newFromName( 'UserName' );
19 
20  $this->user_comment = '<User comment about action>';
21  $this->context = RequestContext::newExtraneousContext( $this->title );
22  }
23 
28  public function testNewFromRow() {
29  $row = new stdClass();
30  $row->rc_foo = 'AAA';
31  $row->rc_timestamp = '20150921134808';
32  $row->rc_deleted = 'bar';
33 
34  $rc = RecentChange::newFromRow( $row );
35 
36  $expected = [
37  'rc_foo' => 'AAA',
38  'rc_timestamp' => '20150921134808',
39  'rc_deleted' => 'bar',
40  ];
41  $this->assertEquals( $expected, $rc->getAttributes() );
42  }
43 
47  public function testParseParams() {
48  $params = [
49  'root' => [
50  'A' => 1,
51  'B' => 'two'
52  ]
53  ];
54 
55  $this->assertParseParams(
56  $params,
57  'a:1:{s:4:"root";a:2:{s:1:"A";i:1;s:1:"B";s:3:"two";}}'
58  );
59 
60  $this->assertParseParams(
61  null,
62  null
63  );
64 
65  $this->assertParseParams(
66  null,
67  serialize( false )
68  );
69 
70  $this->assertParseParams(
71  null,
72  'not-an-array'
73  );
74  }
75 
80  protected function assertParseParams( $expectedParseParams, $rawRcParams ) {
81  $rc = new RecentChange;
82  $rc->setAttribs( [ 'rc_params' => $rawRcParams ] );
83 
84  $actualParseParams = $rc->parseParams();
85 
86  $this->assertEquals( $expectedParseParams, $actualParseParams );
87  }
88 
93  public function provideIsInRCLifespan() {
94  return [
95  [ 6000, time() - 3000, 0, true ],
96  [ 3000, time() - 6000, 0, false ],
97  [ 6000, time() - 3000, 6000, true ],
98  [ 3000, time() - 6000, 6000, true ],
99  ];
100  }
101 
106  public function testIsInRCLifespan( $maxAge, $timestamp, $tolerance, $expected ) {
107  $this->setMwGlobals( 'wgRCMaxAge', $maxAge );
108  $this->assertEquals( $expected, RecentChange::isInRCLifespan( $timestamp, $tolerance ) );
109  }
110 
111  public function provideRCTypes() {
112  return [
113  [ RC_EDIT, 'edit' ],
114  [ RC_NEW, 'new' ],
115  [ RC_LOG, 'log' ],
116  [ RC_EXTERNAL, 'external' ],
117  [ RC_CATEGORIZE, 'categorize' ],
118  ];
119  }
120 
125  public function testParseFromRCType( $rcType, $type ) {
126  $this->assertEquals( $type, RecentChange::parseFromRCType( $rcType ) );
127  }
128 
133  public function testParseToRCType( $rcType, $type ) {
134  $this->assertEquals( $rcType, RecentChange::parseToRCType( $type ) );
135  }
136 
140  private function getMockPageProps() {
141  return $this->getMockBuilder( PageProps::class )
142  ->disableOriginalConstructor()
143  ->getMock();
144  }
145 
146  public function provideCategoryContent() {
147  return [
148  [ true ],
149  [ false ],
150  ];
151  }
152 
157  public function testHiddenCategoryChange( $isHidden ) {
158  $categoryTitle = Title::newFromText( 'CategoryPage', NS_CATEGORY );
159 
160  $pageProps = $this->getMockPageProps();
161  $pageProps->expects( $this->once() )
162  ->method( 'getProperties' )
163  ->with( $categoryTitle, 'hiddencat' )
164  ->will( $this->returnValue( $isHidden ? [ $categoryTitle->getArticleID() => '' ] : [] ) );
165 
166  $scopedOverride = PageProps::overrideInstance( $pageProps );
167 
169  '0',
170  $categoryTitle,
171  $this->user,
172  $this->user_comment,
173  $this->title,
174  $categoryTitle->getLatestRevID(),
175  $categoryTitle->getLatestRevID(),
176  '0',
177  false
178  );
179 
180  $this->assertEquals( $isHidden, $rc->getParam( 'hidden-cat' ) );
181 
182  ScopedCallback::consume( $scopedOverride );
183  }
184 }
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Definition: User.php:568
const RC_CATEGORIZE
Definition: Defines.php:173
Utility class for creating new RC entries.
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...
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:277
testIsInRCLifespan($maxAge, $timestamp, $tolerance, $expected)
RecentChange::isInRCLifespan provideIsInRCLifespan.
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...
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:1798
testParseToRCType($rcType, $type)
provideRCTypes RecentChange::parseToRCType
if($limit) $timestamp
assertParseParams($expectedParseParams, $rawRcParams)
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.
Definition: distributors.txt:9
$params
const NS_CATEGORY
Definition: Defines.php:83
static newExtraneousContext(Title $title, $request=[])
Create a new extraneous context.
title
testParseParams()
RecentChange::parseParams.
static array static newFromRow($row)
static parseFromRCType($rcType)
Parsing RC_* constants to human-readable test.
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
testParseFromRCType($rcType, $type)
provideRCTypes RecentChange::parseFromRCType
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
setAttribs($attribs)
testHiddenCategoryChange($isHidden)
provideCategoryContent RecentChange::newForCategorization
testNewFromRow()
RecentChange::newFromRow RecentChange::loadFromRow.
static consume(ScopedCallback &$sc=null)
Trigger a scoped callback and destroy it.
const RC_EXTERNAL
Definition: Defines.php:172
const RC_NEW
Definition: Defines.php:170
serialize()
Definition: ApiMessage.php:94
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
setMwGlobals($pairs, $value=null)
provideIsInRCLifespan()
50 mins and 100 mins are used here as the tests never take that long!
static parseToRCType($type)
Parsing text to RC_* constants.
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:2338
const RC_EDIT
Definition: Defines.php:169
const RC_LOG
Definition: Defines.php:171