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( [ '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 [ 6000, time() - 3000, 0, true ],
96 [ 3000, time() - 6000, 0, false ],
97 [ 6000, time() - 3000, 6000, true ],
98 [ 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() {
116 [ RC_EXTERNAL
, 'external' ],
117 [ 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 ) );
138 * @return PHPUnit_Framework_MockObject_MockObject|PageProps
140 private function getMockPageProps() {
141 return $this->getMockBuilder( PageProps
::class )
142 ->disableOriginalConstructor()
146 public function provideCategoryContent() {
154 * @dataProvider provideCategoryContent
155 * @covers RecentChange::newForCategorization
157 public function testHiddenCategoryChange( $isHidden ) {
158 $categoryTitle = Title
::newFromText( 'CategoryPage', NS_CATEGORY
);
160 $pageProps = $this->getMockPageProps();
161 $pageProps->expects( $this->once() )
162 ->method( 'getProperties' )
163 ->with( $categoryTitle, 'hiddencat' )
164 ->will( $this->returnValue( $isHidden ?
[ $categoryTitle->getArticleID() => '' ] : [] ) );
166 $scopedOverride = PageProps
::overrideInstance( $pageProps );
168 $rc = RecentChange
::newForCategorization(
174 $categoryTitle->getLatestRevID(),
175 $categoryTitle->getLatestRevID(),
180 $this->assertEquals( $isHidden, $rc->getParam( 'hidden-cat' ) );
182 ScopedCallback
::consume( $scopedOverride );