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 * @covers RecentChange::parseParams
47 public function testParseParams() {
55 $this->assertParseParams(
57 'a:1:{s:4:"root";a:2:{s:1:"A";i:1;s:1:"B";s:3:"two";}}'
60 $this->assertParseParams(
65 $this->assertParseParams(
70 $this->assertParseParams(
77 * @param array $expectedParseParams
78 * @param string|null $rawRcParams
80 protected function assertParseParams( $expectedParseParams, $rawRcParams ) {
81 $rc = new RecentChange
;
82 $rc->setAttribs( array( 'rc_params' => $rawRcParams ) );
84 $actualParseParams = $rc->parseParams();
86 $this->assertEquals( $expectedParseParams, $actualParseParams );
90 * 50 mins and 100 mins are used here as the tests never take that long!
93 public function provideIsInRCLifespan() {
95 array( 6000, time() - 3000, 0, true ),
96 array( 3000, time() - 6000, 0, false ),
97 array( 6000, time() - 3000, 6000, true ),
98 array( 3000, time() - 6000, 6000, true ),
103 * @covers RecentChange::isInRCLifespan
104 * @dataProvider provideIsInRCLifespan
106 public function testIsInRCLifespan( $maxAge, $timestamp, $tolerance, $expected ) {
107 $this->setMwGlobals( 'wgRCMaxAge', $maxAge );
108 $this->assertEquals( $expected, RecentChange
::isInRCLifespan( $timestamp, $tolerance ) );
111 public function provideRCTypes() {
113 array( RC_EDIT
, 'edit' ),
114 array( RC_NEW
, 'new' ),
115 array( RC_LOG
, 'log' ),
116 array( RC_EXTERNAL
, 'external' ),
117 array( RC_CATEGORIZE
, 'categorize' ),
122 * @dataProvider provideRCTypes
123 * @covers RecentChange::parseFromRCType
125 public function testParseFromRCType( $rcType, $type ) {
126 $this->assertEquals( $type, RecentChange
::parseFromRCType( $rcType ) );
130 * @dataProvider provideRCTypes
131 * @covers RecentChange::parseToRCType
133 public function testParseToRCType( $rcType, $type ) {
134 $this->assertEquals( $rcType, RecentChange
::parseToRCType( $type ) );