2011-03-02 20:40:40 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Test class for SpecialRecentchanges class
|
|
|
|
|
|
*
|
2011-10-24 09:08:13 +00:00
|
|
|
|
* Copyright © 2011, Antoine Musso
|
2011-03-02 20:40:40 +00:00
|
|
|
|
*
|
2011-10-24 09:08:13 +00:00
|
|
|
|
* @author Antoine Musso
|
2011-09-15 20:43:40 +00:00
|
|
|
|
* @group Database
|
2013-10-24 20:30:43 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @covers SpecialRecentChanges
|
2011-03-02 20:40:40 +00:00
|
|
|
|
*/
|
|
|
|
|
|
class SpecialRecentchangesTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
2015-08-24 17:40:06 +00:00
|
|
|
|
protected function setUp() {
|
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
$this->setMwGlobals( 'wgRCWatchCategoryMembership', true );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-03-02 20:40:40 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @var SpecialRecentChanges
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected $rc;
|
|
|
|
|
|
|
|
|
|
|
|
/** helper to test SpecialRecentchanges::buildMainQueryConds() */
|
2016-11-14 14:10:47 +00:00
|
|
|
|
private function assertConditions(
|
|
|
|
|
|
$expected,
|
|
|
|
|
|
$requestOptions = null,
|
|
|
|
|
|
$message = '',
|
|
|
|
|
|
$user = null
|
|
|
|
|
|
) {
|
2011-08-11 14:13:03 +00:00
|
|
|
|
$context = new RequestContext;
|
|
|
|
|
|
$context->setRequest( new FauxRequest( $requestOptions ) );
|
2016-11-14 14:10:47 +00:00
|
|
|
|
if ( $user ) {
|
|
|
|
|
|
$context->setUser( $user );
|
|
|
|
|
|
}
|
2011-03-02 20:40:40 +00:00
|
|
|
|
|
2011-08-11 14:13:03 +00:00
|
|
|
|
# setup the rc object
|
2011-03-02 20:40:40 +00:00
|
|
|
|
$this->rc = new SpecialRecentChanges();
|
2011-08-11 14:13:03 +00:00
|
|
|
|
$this->rc->setContext( $context );
|
2011-03-02 20:40:40 +00:00
|
|
|
|
$formOptions = $this->rc->setup( null );
|
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
|
# Filter out rc_timestamp conditions which depends on the test runtime
|
2011-03-02 20:40:40 +00:00
|
|
|
|
# This condition is not needed as of march 2, 2011 -- hashar
|
2011-05-17 22:03:20 +00:00
|
|
|
|
# @todo FIXME: Find a way to generate the correct rc_timestamp
|
2011-03-02 20:40:40 +00:00
|
|
|
|
$queryConditions = array_filter(
|
|
|
|
|
|
$this->rc->buildMainQueryConds( $formOptions ),
|
|
|
|
|
|
'SpecialRecentchangesTest::filterOutRcTimestampCondition'
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
$expected,
|
|
|
|
|
|
$queryConditions,
|
|
|
|
|
|
$message
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** return false if condition begin with 'rc_timestamp ' */
|
|
|
|
|
|
private static function filterOutRcTimestampCondition( $var ) {
|
2013-02-15 10:24:31 +00:00
|
|
|
|
return ( false === strpos( $var, 'rc_timestamp ' ) );
|
2011-03-02 20:40:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testRcNsFilter() {
|
|
|
|
|
|
$this->assertConditions(
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[ # expected
|
2011-03-02 20:40:40 +00:00
|
|
|
|
'rc_bot' => 0,
|
2015-08-24 17:40:06 +00:00
|
|
|
|
0 => "rc_type != '6'",
|
|
|
|
|
|
1 => "rc_namespace = '0'",
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
|
|
|
|
|
[
|
2011-03-02 20:40:40 +00:00
|
|
|
|
'namespace' => NS_MAIN,
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
2011-03-02 20:40:40 +00:00
|
|
|
|
"rc conditions with no options (aka default setting)"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testRcNsFilterInversion() {
|
|
|
|
|
|
$this->assertConditions(
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[ # expected
|
2011-03-02 20:40:40 +00:00
|
|
|
|
'rc_bot' => 0,
|
2015-08-24 17:40:06 +00:00
|
|
|
|
0 => "rc_type != '6'",
|
|
|
|
|
|
1 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
|
|
|
|
|
[
|
2011-03-02 20:40:40 +00:00
|
|
|
|
'namespace' => NS_MAIN,
|
|
|
|
|
|
'invert' => 1,
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
2013-02-15 10:24:31 +00:00
|
|
|
|
"rc conditions with namespace inverted"
|
2011-03-02 20:40:40 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @bug 2429
|
|
|
|
|
|
* @dataProvider provideNamespacesAssociations
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testRcNsFilterAssociation( $ns1, $ns2 ) {
|
|
|
|
|
|
$this->assertConditions(
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[ # expected
|
2011-03-02 20:40:40 +00:00
|
|
|
|
'rc_bot' => 0,
|
2015-08-24 17:40:06 +00:00
|
|
|
|
0 => "rc_type != '6'",
|
|
|
|
|
|
1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
|
|
|
|
|
[
|
2011-03-02 20:40:40 +00:00
|
|
|
|
'namespace' => $ns1,
|
|
|
|
|
|
'associated' => 1,
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
2013-02-15 10:24:31 +00:00
|
|
|
|
"rc conditions with namespace inverted"
|
2011-03-02 20:40:40 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @bug 2429
|
|
|
|
|
|
* @dataProvider provideNamespacesAssociations
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
|
|
|
|
|
|
$this->assertConditions(
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[ # expected
|
2011-03-02 20:40:40 +00:00
|
|
|
|
'rc_bot' => 0,
|
2015-08-24 17:40:06 +00:00
|
|
|
|
0 => "rc_type != '6'",
|
|
|
|
|
|
1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
|
|
|
|
|
[
|
2013-02-15 10:24:31 +00:00
|
|
|
|
'namespace' => $ns1,
|
2011-03-02 20:40:40 +00:00
|
|
|
|
'associated' => 1,
|
2013-02-15 10:24:31 +00:00
|
|
|
|
'invert' => 1,
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
2013-02-15 10:24:31 +00:00
|
|
|
|
"rc conditions with namespace inverted"
|
2011-03-02 20:40:40 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Provides associated namespaces to test recent changes
|
|
|
|
|
|
* namespaces association filtering.
|
|
|
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
|
public static function provideNamespacesAssociations() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
return [ # (NS => Associated_NS)
|
|
|
|
|
|
[ NS_MAIN, NS_TALK ],
|
|
|
|
|
|
[ NS_TALK, NS_MAIN ],
|
|
|
|
|
|
];
|
2011-03-02 20:40:40 +00:00
|
|
|
|
}
|
2016-11-14 14:10:47 +00:00
|
|
|
|
|
|
|
|
|
|
public function testRcHidemyselfFilter() {
|
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
|
$this->assertConditions(
|
|
|
|
|
|
[ # expected
|
|
|
|
|
|
'rc_bot' => 0,
|
|
|
|
|
|
0 => "rc_user != '{$user->getId()}'",
|
|
|
|
|
|
1 => "rc_type != '6'",
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
'hidemyself' => 1,
|
|
|
|
|
|
],
|
|
|
|
|
|
"rc conditions: hidemyself=1 (logged in)",
|
|
|
|
|
|
$user
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
$user = User::newFromName( '10.11.12.13', false );
|
|
|
|
|
|
$this->assertConditions(
|
|
|
|
|
|
[ # expected
|
|
|
|
|
|
'rc_bot' => 0,
|
|
|
|
|
|
0 => "rc_user_text != '10.11.12.13'",
|
|
|
|
|
|
1 => "rc_type != '6'",
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
'hidemyself' => 1,
|
|
|
|
|
|
],
|
|
|
|
|
|
"rc conditions: hidemyself=1 (anon)",
|
|
|
|
|
|
$user
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testRcHidebyothersFilter() {
|
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
|
$this->assertConditions(
|
|
|
|
|
|
[ # expected
|
|
|
|
|
|
'rc_bot' => 0,
|
|
|
|
|
|
0 => "rc_user = '{$user->getId()}'",
|
|
|
|
|
|
1 => "rc_type != '6'",
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
'hidebyothers' => 1,
|
|
|
|
|
|
],
|
|
|
|
|
|
"rc conditions: hidebyothers=1 (logged in)",
|
|
|
|
|
|
$user
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
$user = User::newFromName( '10.11.12.13', false );
|
|
|
|
|
|
$this->assertConditions(
|
|
|
|
|
|
[ # expected
|
|
|
|
|
|
'rc_bot' => 0,
|
|
|
|
|
|
0 => "rc_user_text = '10.11.12.13'",
|
|
|
|
|
|
1 => "rc_type != '6'",
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
'hidebyothers' => 1,
|
|
|
|
|
|
],
|
|
|
|
|
|
"rc conditions: hidebyothers=1 (anon)",
|
|
|
|
|
|
$user
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testRcHidemyselfHidebyothersFilter() {
|
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
|
$this->assertConditions(
|
|
|
|
|
|
[ # expected
|
|
|
|
|
|
'rc_bot' => 0,
|
|
|
|
|
|
0 => "rc_user != '{$user->getId()}'",
|
|
|
|
|
|
1 => "rc_user = '{$user->getId()}'",
|
|
|
|
|
|
2 => "rc_type != '6'",
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
'hidemyself' => 1,
|
|
|
|
|
|
'hidebyothers' => 1,
|
|
|
|
|
|
],
|
|
|
|
|
|
"rc conditions: hidemyself=1 hidebyothers=1 (logged in)",
|
|
|
|
|
|
$user
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2011-03-02 20:40:40 +00:00
|
|
|
|
}
|