2 use Wikimedia\ScopedCallback
;
7 class RecentChangeTest
extends MediaWikiTestCase
{
11 protected $user_comment;
14 public function setUp() {
17 $this->title
= Title
::newFromText( 'SomeTitle' );
18 $this->target
= Title
::newFromText( 'TestTarget' );
19 $this->user
= User
::newFromName( 'UserName' );
21 $this->user_comment
= '<User comment about action>';
22 $this->context
= RequestContext
::newExtraneousContext( $this->title
);
26 * @covers RecentChange::newFromRow
27 * @covers RecentChange::loadFromRow
29 public function testNewFromRow() {
30 $row = new stdClass();
32 $row->rc_timestamp
= '20150921134808';
33 $row->rc_deleted
= 'bar';
35 $rc = RecentChange
::newFromRow( $row );
39 'rc_timestamp' => '20150921134808',
40 'rc_deleted' => 'bar',
42 $this->assertEquals( $expected, $rc->getAttributes() );
46 * @covers RecentChange::parseParams
48 public function testParseParams() {
56 $this->assertParseParams(
58 'a:1:{s:4:"root";a:2:{s:1:"A";i:1;s:1:"B";s:3:"two";}}'
61 $this->assertParseParams(
66 $this->assertParseParams(
71 $this->assertParseParams(
78 * @param array $expectedParseParams
79 * @param string|null $rawRcParams
81 protected function assertParseParams( $expectedParseParams, $rawRcParams ) {
82 $rc = new RecentChange
;
83 $rc->setAttribs( [ 'rc_params' => $rawRcParams ] );
85 $actualParseParams = $rc->parseParams();
87 $this->assertEquals( $expectedParseParams, $actualParseParams );
91 * 50 mins and 100 mins are used here as the tests never take that long!
94 public function provideIsInRCLifespan() {
96 [ 6000, time() - 3000, 0, true ],
97 [ 3000, time() - 6000, 0, false ],
98 [ 6000, time() - 3000, 6000, true ],
99 [ 3000, time() - 6000, 6000, true ],
104 * @covers RecentChange::isInRCLifespan
105 * @dataProvider provideIsInRCLifespan
107 public function testIsInRCLifespan( $maxAge, $timestamp, $tolerance, $expected ) {
108 $this->setMwGlobals( 'wgRCMaxAge', $maxAge );
109 $this->assertEquals( $expected, RecentChange
::isInRCLifespan( $timestamp, $tolerance ) );
112 public function provideRCTypes() {
117 [ RC_EXTERNAL
, 'external' ],
118 [ RC_CATEGORIZE
, 'categorize' ],
123 * @dataProvider provideRCTypes
124 * @covers RecentChange::parseFromRCType
126 public function testParseFromRCType( $rcType, $type ) {
127 $this->assertEquals( $type, RecentChange
::parseFromRCType( $rcType ) );
131 * @dataProvider provideRCTypes
132 * @covers RecentChange::parseToRCType
134 public function testParseToRCType( $rcType, $type ) {
135 $this->assertEquals( $rcType, RecentChange
::parseToRCType( $type ) );
139 * @return PHPUnit_Framework_MockObject_MockObject|PageProps
141 private function getMockPageProps() {
142 return $this->getMockBuilder( PageProps
::class )
143 ->disableOriginalConstructor()
147 public function provideCategoryContent() {
155 * @dataProvider provideCategoryContent
156 * @covers RecentChange::newForCategorization
158 public function testHiddenCategoryChange( $isHidden ) {
159 $categoryTitle = Title
::newFromText( 'CategoryPage', NS_CATEGORY
);
161 $pageProps = $this->getMockPageProps();
162 $pageProps->expects( $this->once() )
163 ->method( 'getProperties' )
164 ->with( $categoryTitle, 'hiddencat' )
165 ->will( $this->returnValue( $isHidden ?
[ $categoryTitle->getArticleID() => '' ] : [] ) );
167 $scopedOverride = PageProps
::overrideInstance( $pageProps );
169 $rc = RecentChange
::newForCategorization(
175 $categoryTitle->getLatestRevID(),
176 $categoryTitle->getLatestRevID(),
181 $this->assertEquals( $isHidden, $rc->getParam( 'hidden-cat' ) );
183 ScopedCallback
::consume( $scopedOverride );