* @covers ChangesListSpecialPage
*/
class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase {
- protected function setUp() {
- parent::setUp();
-
- # setup the rc object
- $this->changesListSpecialPage = $this->getPage();
- }
-
protected function getPage() {
- return TestingAccessWrapper::newFromObject(
- $this->getMockForAbstractClass(
- 'ChangesListSpecialPage',
+ $mock = $this->getMockBuilder( ChangesListSpecialPage::class )
+ ->setConstructorArgs(
[
'ChangesListSpecialPage',
''
]
)
+ ->setMethods( [ 'getPageTitle' ] )
+ ->getMockForAbstractClass();
+
+ $mock->method( 'getPageTitle' )->willReturn(
+ Title::makeTitle( NS_SPECIAL, 'ChangesListSpecialPage' )
+ );
+
+ $mock = TestingAccessWrapper::newFromObject(
+ $mock
);
+
+ return $mock;
}
/** helper to test SpecialRecentchanges::buildMainQueryConds() */
}
$this->changesListSpecialPage->setContext( $context );
+ $this->changesListSpecialPage->filterGroups = [];
$formOptions = $this->changesListSpecialPage->setup( null );
# Filter out rc_timestamp conditions which depends on the test runtime
[
'namespace' => NS_MAIN,
],
- "rc conditions with no options (aka default setting)"
+ "rc conditions with one namespace"
);
}
);
}
- /**
- * T4429
- * @dataProvider provideNamespacesAssociations
- */
- public function testRcNsFilterAssociation( $ns1, $ns2 ) {
+ public function testRcNsFilterMultiple() {
$this->assertConditions(
[ # expected
- "(rc_namespace = '$ns1' OR rc_namespace = '$ns2')",
+ "rc_namespace IN ('1','2','3')",
],
[
- 'namespace' => $ns1,
+ 'namespace' => '1,2,3',
+ ],
+ "rc conditions with multiple namespaces"
+ );
+ }
+
+ public function testRcNsFilterMultipleAssociated() {
+ $this->assertConditions(
+ [ # expected
+ "rc_namespace IN ('0','1','4','5','6','7')",
+ ],
+ [
+ 'namespace' => '1,4,7',
'associated' => 1,
],
- "rc conditions with namespace inverted"
+ "rc conditions with multiple namespaces and associated"
);
}
- /**
- * T4429
- * @dataProvider provideNamespacesAssociations
- */
- public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
+ public function testRcNsFilterMultipleAssociatedInvert() {
$this->assertConditions(
[ # expected
- "(rc_namespace != '$ns1' AND rc_namespace != '$ns2')",
+ "rc_namespace NOT IN ('2','3','8','9')",
],
[
- 'namespace' => $ns1,
+ 'namespace' => '2,3,9',
'associated' => 1,
- 'invert' => 1,
+ 'invert' => 1
],
- "rc conditions with namespace inverted"
+ "rc conditions with multiple namespaces, associated and inverted"
);
}
- /**
- * Provides associated namespaces to test recent changes
- * namespaces association filtering.
- */
- public static function provideNamespacesAssociations() {
- return [ # (NS => Associated_NS)
- [ NS_MAIN, NS_TALK ],
- [ NS_TALK, NS_MAIN ],
- ];
+ public function testRcNsFilterMultipleInvert() {
+ $this->assertConditions(
+ [ # expected
+ "rc_namespace NOT IN ('1','2','3')",
+ ],
+ [
+ 'namespace' => '1,2,3',
+ 'invert' => 1,
+ ],
+ "rc conditions with multiple namespaces inverted"
+ );
}
public function testRcHidemyselfFilter() {
);
}
- public function testRcHidemyselfHidebyothersFilter() {
- $user = $this->getTestUser()->getUser();
- $this->assertConditions(
- [ # expected
- "rc_user_text != '{$user->getName()}'",
- "rc_user_text = '{$user->getName()}'",
- ],
- [
- 'hidemyself' => 1,
- 'hidebyothers' => 1,
- ],
- "rc conditions: hidemyself=1 hidebyothers=1 (logged in)",
- $user
- );
- }
-
public function testRcHidepageedits() {
$this->assertConditions(
[ # expected
);
}
- public function testRcHidepatrolledHideunpatrolledFilter() {
- $user = $this->getTestSysop()->getUser();
- $this->assertConditions(
- [ # expected
- "rc_patrolled = 0",
- "rc_patrolled = 1",
- ],
- [
- 'hidepatrolled' => 1,
- 'hideunpatrolled' => 1,
- ],
- "rc conditions: hidepatrolled=1 hideunpatrolled=1",
- $user
- );
- }
-
public function testHideCategorization() {
$this->assertConditions(
[
}
public function testFilterUserExpLevel() {
+ $now = time();
$this->setMwGlobals( [
'wgLearnerEdits' => 10,
'wgLearnerMemberSince' => 4,
'Learner3' => [ 'edits' => 460, 'days' => 33 ],
'Learner4' => [ 'edits' => 525, 'days' => 28 ],
'Experienced1' => [ 'edits' => 538, 'days' => 33 ],
- ] );
+ ], $now );
// newcomers only
$this->assertArrayEquals(
[ 'Newcomer1', 'Newcomer2', 'Newcomer3' ],
- $this->fetchUsers( [ 'newcomer' ] )
+ $this->fetchUsers( [ 'newcomer' ], $now )
);
// newcomers and learner
'Newcomer1', 'Newcomer2', 'Newcomer3',
'Learner1', 'Learner2', 'Learner3', 'Learner4',
],
- $this->fetchUsers( [ 'newcomer', 'learner' ] )
+ $this->fetchUsers( [ 'newcomer', 'learner' ], $now )
);
// newcomers and more learner
'Newcomer1', 'Newcomer2', 'Newcomer3',
'Experienced1',
],
- $this->fetchUsers( [ 'newcomer', 'experienced' ] )
+ $this->fetchUsers( [ 'newcomer', 'experienced' ], $now )
);
// learner only
$this->assertArrayEquals(
[ 'Learner1', 'Learner2', 'Learner3', 'Learner4' ],
- $this->fetchUsers( [ 'learner' ] )
+ $this->fetchUsers( [ 'learner' ], $now )
);
// more experienced only
$this->assertArrayEquals(
[ 'Experienced1' ],
- $this->fetchUsers( [ 'experienced' ] )
+ $this->fetchUsers( [ 'experienced' ], $now )
);
// learner and more experienced
'Learner1', 'Learner2', 'Learner3', 'Learner4',
'Experienced1',
],
- $this->fetchUsers( [ 'learner', 'experienced' ] ),
+ $this->fetchUsers( [ 'learner', 'experienced' ], $now ),
'Learner and more experienced'
);
/* 'Learner1', 'Learner2', 'Learner3', 'Learner4', */
/* 'Experienced1', */
/* ], */
- /* $this->fetchUsers( [ 'newcomer', 'learner', 'experienced' ] ) */
+ /* $this->fetchUsers( [ 'newcomer', 'learner', 'experienced' ], $now ) */
/* ); */
}
- private function createUsers( $specs ) {
+ private function createUsers( $specs, $now ) {
$dbw = wfGetDB( DB_MASTER );
foreach ( $specs as $name => $spec ) {
User::createNew(
$name,
[
'editcount' => $spec['edits'],
- 'registration' => $dbw->timestamp( $this->daysAgo( $spec['days'] ) ),
+ 'registration' => $dbw->timestamp( $this->daysAgo( $spec['days'], $now ) ),
'email' => 'ut',
]
);
}
}
- private function fetchUsers( $filters ) {
+ private function fetchUsers( $filters, $now ) {
$tables = [];
$conds = [];
$fields = [];
&$conds,
&$query_options,
&$join_conds,
- $filters
+ $filters,
+ $now
]
);
$result = wfGetDB( DB_MASTER )->select(
- 'user',
+ $tables,
'user_name',
array_filter( $conds ) + [ 'user_email' => 'ut' ]
);
return $usernames;
}
- private function daysAgo( $days ) {
+ private function daysAgo( $days, $now ) {
$secondsPerDay = 86400;
- return time() - $days * $secondsPerDay;
+ return $now - $days * $secondsPerDay;
}
public function testGetFilterGroupDefinitionFromLegacyCustomFilters() {
}
public function testGetStructuredFilterJsData() {
+ $this->changesListSpecialPage->filterGroups = [];
+
$definition = [
[
'name' => 'gub-group',
$this->changesListSpecialPage->areFiltersInConflict()
);
}
+
+ public function validateOptionsProvider() {
+ return [
+ [
+ [ 'hideanons' => 1, 'hideliu' => 1, 'hidebots' => 1 ],
+ true,
+ [ 'hideliu' => 1, 'hidebots' => 1, ],
+ ],
+
+ [
+ [ 'hideanons' => 1, 'hideliu' => 1, 'hidebots' => 0 ],
+ true,
+ [ 'hidebots' => 0, 'hidehumans' => 1 ],
+ ],
+
+ [
+ [ 'hidemyself' => 1, 'hidebyothers' => 1 ],
+ true,
+ [],
+ ],
+ [
+ [ 'hidebots' => 1, 'hidehumans' => 1 ],
+ true,
+ [],
+ ],
+ [
+ [ 'hidepatrolled' => 1, 'hideunpatrolled' => 1 ],
+ true,
+ [],
+ ],
+ [
+ [ 'hideminor' => 1, 'hidemajor' => 1 ],
+ true,
+ [],
+ ],
+ [
+ // changeType
+ [ 'hidepageedits' => 1, 'hidenewpages' => 1, 'hidecategorization' => 1, 'hidelog' => 1, ],
+ true,
+ [],
+ ],
+ ];
+ }
}