Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / specials / SpecialRecentchangesTest.php
blobc3d75aa58cebdd8c5d4765231a4cae2a379ce227
1 <?php
2 /**
3 * Test class for SpecialRecentchanges class
5 * Copyright © 2011, Antoine Musso
7 * @author Antoine Musso
8 * @group Database
10 * @covers SpecialRecentChanges
12 class SpecialRecentchangesTest extends MediaWikiTestCase {
14 /**
15 * @var SpecialRecentChanges
17 protected $rc;
19 /** helper to test SpecialRecentchanges::buildMainQueryConds() */
20 private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
21 $context = new RequestContext;
22 $context->setRequest( new FauxRequest( $requestOptions ) );
24 # setup the rc object
25 $this->rc = new SpecialRecentChanges();
26 $this->rc->setContext( $context );
27 $formOptions = $this->rc->setup( null );
29 # Filter out rc_timestamp conditions which depends on the test runtime
30 # This condition is not needed as of march 2, 2011 -- hashar
31 # @todo FIXME: Find a way to generate the correct rc_timestamp
32 $queryConditions = array_filter(
33 $this->rc->buildMainQueryConds( $formOptions ),
34 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
37 $this->assertEquals(
38 $expected,
39 $queryConditions,
40 $message
44 /** return false if condition begin with 'rc_timestamp ' */
45 private static function filterOutRcTimestampCondition( $var ) {
46 return ( false === strpos( $var, 'rc_timestamp ' ) );
49 public function testRcNsFilter() {
50 $this->assertConditions(
51 array( # expected
52 'rc_bot' => 0,
53 0 => "rc_namespace = '0'",
55 array(
56 'namespace' => NS_MAIN,
58 "rc conditions with no options (aka default setting)"
62 public function testRcNsFilterInversion() {
63 $this->assertConditions(
64 array( # expected
65 'rc_bot' => 0,
66 0 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
68 array(
69 'namespace' => NS_MAIN,
70 'invert' => 1,
72 "rc conditions with namespace inverted"
76 /**
77 * @bug 2429
78 * @dataProvider provideNamespacesAssociations
80 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
81 $this->assertConditions(
82 array( # expected
83 'rc_bot' => 0,
84 0 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
86 array(
87 'namespace' => $ns1,
88 'associated' => 1,
90 "rc conditions with namespace inverted"
94 /**
95 * @bug 2429
96 * @dataProvider provideNamespacesAssociations
98 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
99 $this->assertConditions(
100 array( # expected
101 'rc_bot' => 0,
102 0 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
104 array(
105 'namespace' => $ns1,
106 'associated' => 1,
107 'invert' => 1,
109 "rc conditions with namespace inverted"
114 * Provides associated namespaces to test recent changes
115 * namespaces association filtering.
117 public static function provideNamespacesAssociations() {
118 return array( # (NS => Associated_NS)
119 array( NS_MAIN, NS_TALK ),
120 array( NS_TALK, NS_MAIN ),