2012-02-25 21:22:49 +00:00
|
|
|
<?php
|
2014-03-12 17:08:40 +00:00
|
|
|
|
2012-03-23 17:18:07 +00:00
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2012-02-25 21:22:49 +00:00
|
|
|
class RecentChangeTest extends MediaWikiTestCase {
|
|
|
|
|
protected $title;
|
|
|
|
|
protected $target;
|
|
|
|
|
protected $user;
|
|
|
|
|
protected $user_comment;
|
2012-03-05 21:21:34 +00:00
|
|
|
protected $context;
|
2012-02-25 21:22:49 +00:00
|
|
|
|
2015-09-21 09:25:24 +00:00
|
|
|
public function setUp() {
|
|
|
|
|
parent::setUp();
|
2012-02-25 21:22:49 +00:00
|
|
|
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->title = Title::newFromText( 'SomeTitle' );
|
2012-02-25 21:22:49 +00:00
|
|
|
$this->target = Title::newFromText( 'TestTarget' );
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->user = User::newFromName( 'UserName' );
|
2012-02-25 21:22:49 +00:00
|
|
|
|
|
|
|
|
$this->user_comment = '<User comment about action>';
|
2012-03-05 21:21:34 +00:00
|
|
|
$this->context = RequestContext::newExtraneousContext( $this->title );
|
2012-02-25 21:22:49 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-21 13:51:44 +00:00
|
|
|
/**
|
|
|
|
|
* @covers RecentChange::newFromRow
|
|
|
|
|
* @covers RecentChange::loadFromRow
|
|
|
|
|
*/
|
|
|
|
|
public function testNewFromRow() {
|
|
|
|
|
$row = new stdClass();
|
|
|
|
|
$row->rc_foo = 'AAA';
|
|
|
|
|
$row->rc_timestamp = '20150921134808';
|
|
|
|
|
$row->rc_deleted = 'bar';
|
|
|
|
|
|
|
|
|
|
$rc = RecentChange::newFromRow( $row );
|
|
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
|
'rc_foo' => 'AAA',
|
|
|
|
|
'rc_timestamp' => '20150921134808',
|
|
|
|
|
'rc_deleted' => 'bar',
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals( $expected, $rc->getAttributes() );
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-10 12:39:17 +00:00
|
|
|
/**
|
|
|
|
|
* @covers RecentChange::parseParams
|
|
|
|
|
*/
|
|
|
|
|
public function testParseParams() {
|
|
|
|
|
$params = array(
|
|
|
|
|
'root' => array(
|
|
|
|
|
'A' => 1,
|
|
|
|
|
'B' => 'two'
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertParseParams(
|
|
|
|
|
$params,
|
|
|
|
|
'a:1:{s:4:"root";a:2:{s:1:"A";i:1;s:1:"B";s:3:"two";}}'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertParseParams(
|
|
|
|
|
null,
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertParseParams(
|
|
|
|
|
null,
|
|
|
|
|
serialize( false )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertParseParams(
|
|
|
|
|
null,
|
|
|
|
|
'not-an-array'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $expectedParseParams
|
|
|
|
|
* @param string|null $rawRcParams
|
|
|
|
|
*/
|
|
|
|
|
protected function assertParseParams( $expectedParseParams, $rawRcParams ) {
|
|
|
|
|
$rc = new RecentChange;
|
|
|
|
|
$rc->setAttribs( array( 'rc_params' => $rawRcParams ) );
|
|
|
|
|
|
|
|
|
|
$actualParseParams = $rc->parseParams();
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expectedParseParams, $actualParseParams );
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 09:34:13 +00:00
|
|
|
/**
|
|
|
|
|
* 50 mins and 100 mins are used here as the tests never take that long!
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function provideIsInRCLifespan() {
|
|
|
|
|
return array(
|
|
|
|
|
array( 6000, time() - 3000, 0, true ),
|
|
|
|
|
array( 3000, time() - 6000, 0, false ),
|
|
|
|
|
array( 6000, time() - 3000, 6000, true ),
|
|
|
|
|
array( 3000, time() - 6000, 6000, true ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers RecentChange::isInRCLifespan
|
|
|
|
|
* @dataProvider provideIsInRCLifespan
|
|
|
|
|
*/
|
|
|
|
|
public function testIsInRCLifespan( $maxAge, $timestamp, $tolerance, $expected ) {
|
|
|
|
|
$this->setMwGlobals( 'wgRCMaxAge', $maxAge );
|
|
|
|
|
$this->assertEquals( $expected, RecentChange::isInRCLifespan( $timestamp, $tolerance ) );
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 13:58:56 +00:00
|
|
|
public function provideRCTypes() {
|
|
|
|
|
return array(
|
|
|
|
|
array( RC_EDIT, 'edit' ),
|
|
|
|
|
array( RC_NEW, 'new' ),
|
|
|
|
|
array( RC_LOG, 'log' ),
|
|
|
|
|
array( RC_EXTERNAL, 'external' ),
|
2015-09-17 09:51:25 +00:00
|
|
|
array( RC_CATEGORIZE, 'categorize' ),
|
2015-09-21 13:58:56 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideRCTypes
|
|
|
|
|
* @covers RecentChange::parseFromRCType
|
|
|
|
|
*/
|
|
|
|
|
public function testParseFromRCType( $rcType, $type ) {
|
|
|
|
|
$this->assertEquals( $type, RecentChange::parseFromRCType( $rcType ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideRCTypes
|
|
|
|
|
* @covers RecentChange::parseToRCType
|
|
|
|
|
*/
|
|
|
|
|
public function testParseToRCType( $rcType, $type ) {
|
|
|
|
|
$this->assertEquals( $rcType, RecentChange::parseToRCType( $type ) );
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-25 21:22:49 +00:00
|
|
|
}
|