6 class RecentChangeTest
extends MediaWikiTestCase
{
10 protected $user_comment;
13 public function setUp() {
16 $this->title
= Title
::newFromText( 'SomeTitle' );
17 $this->target
= Title
::newFromText( 'TestTarget' );
18 $this->user
= User
::newFromName( 'UserName' );
20 $this->user_comment
= '<User comment about action>';
21 $this->context
= RequestContext
::newExtraneousContext( $this->title
);
25 * @covers RecentChange::newFromRow
26 * @covers RecentChange::loadFromRow
28 public function testNewFromRow() {
29 $row = new stdClass();
31 $row->rc_timestamp
= '20150921134808';
32 $row->rc_deleted
= 'bar';
34 $rc = RecentChange
::newFromRow( $row );
38 'rc_timestamp' => '20150921134808',
39 'rc_deleted' => 'bar',
41 $this->assertEquals( $expected, $rc->getAttributes() );
45 * The testIrcMsgForAction* tests are supposed to cover the hacky
46 * LogFormatter::getIRCActionText / bug 34508
48 * Third parties bots listen to those messages. They are clever enough
49 * to fetch the i18n messages from the wiki and then analyze the IRC feed
50 * to reverse engineer the $1, $2 messages.
51 * One thing bots can not detect is when MediaWiki change the meaning of
52 * a message like what happened when we deployed 1.19. $1 became the user
53 * performing the action which broke basically all bots around.
55 * Should cover the following log actions (which are most commonly used by bots):
63 * - newusers/autocreate
67 * - protect/modifyprotect
75 * As well as the following Auto Edit Summaries:
83 * @covers RecentChange::parseParams
85 public function testParseParams() {
93 $this->assertParseParams(
95 'a:1:{s:4:"root";a:2:{s:1:"A";i:1;s:1:"B";s:3:"two";}}'
98 $this->assertParseParams(
103 $this->assertParseParams(
108 $this->assertParseParams(
115 * @param array $expectedParseParams
116 * @param string|null $rawRcParams
118 protected function assertParseParams( $expectedParseParams, $rawRcParams ) {
119 $rc = new RecentChange
;
120 $rc->setAttribs( array( 'rc_params' => $rawRcParams ) );
122 $actualParseParams = $rc->parseParams();
124 $this->assertEquals( $expectedParseParams, $actualParseParams );
128 * 50 mins and 100 mins are used here as the tests never take that long!
131 public function provideIsInRCLifespan() {
133 array( 6000, time() - 3000, 0, true ),
134 array( 3000, time() - 6000, 0, false ),
135 array( 6000, time() - 3000, 6000, true ),
136 array( 3000, time() - 6000, 6000, true ),
141 * @covers RecentChange::isInRCLifespan
142 * @dataProvider provideIsInRCLifespan
144 public function testIsInRCLifespan( $maxAge, $timestamp, $tolerance, $expected ) {
145 $this->setMwGlobals( 'wgRCMaxAge', $maxAge );
146 $this->assertEquals( $expected, RecentChange
::isInRCLifespan( $timestamp, $tolerance ) );
149 public function provideRCTypes() {
151 array( RC_EDIT
, 'edit' ),
152 array( RC_NEW
, 'new' ),
153 array( RC_LOG
, 'log' ),
154 array( RC_EXTERNAL
, 'external' ),
159 * @dataProvider provideRCTypes
160 * @covers RecentChange::parseFromRCType
162 public function testParseFromRCType( $rcType, $type ) {
163 $this->assertEquals( $type, RecentChange
::parseFromRCType( $rcType ) );
167 * @dataProvider provideRCTypes
168 * @covers RecentChange::parseToRCType
170 public function testParseToRCType( $rcType, $type ) {
171 $this->assertEquals( $rcType, RecentChange
::parseToRCType( $type ) );