Merge "Include additional analytics in Special:Search"
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / SpecialRecentchangesTest.php
1 <?php
2 /**
3 * Test class for SpecialRecentchanges class
4 *
5 * Copyright © 2011, Antoine Musso
6 *
7 * @author Antoine Musso
8 * @group Database
9 *
10 * @covers SpecialRecentChanges
11 */
12 class SpecialRecentchangesTest extends MediaWikiTestCase {
13
14 /**
15 * @var SpecialRecentChanges
16 */
17 protected $rc;
18
19 /** helper to test SpecialRecentchanges::buildMainQueryConds() */
20 private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
21 $context = new RequestContext;
22 $context->setRequest( new FauxRequest( $requestOptions ) );
23
24 # setup the rc object
25 $this->rc = new SpecialRecentChanges();
26 $this->rc->setContext( $context );
27 $formOptions = $this->rc->setup( null );
28
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'
35 );
36
37 $this->assertEquals(
38 $expected,
39 $queryConditions,
40 $message
41 );
42 }
43
44 /** return false if condition begin with 'rc_timestamp ' */
45 private static function filterOutRcTimestampCondition( $var ) {
46 return ( false === strpos( $var, 'rc_timestamp ' ) );
47 }
48
49 public function testRcNsFilter() {
50 $this->assertConditions(
51 array( # expected
52 'rc_bot' => 0,
53 0 => "rc_namespace = '0'",
54 ),
55 array(
56 'namespace' => NS_MAIN,
57 ),
58 "rc conditions with no options (aka default setting)"
59 );
60 }
61
62 public function testRcNsFilterInversion() {
63 $this->assertConditions(
64 array( # expected
65 'rc_bot' => 0,
66 0 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
67 ),
68 array(
69 'namespace' => NS_MAIN,
70 'invert' => 1,
71 ),
72 "rc conditions with namespace inverted"
73 );
74 }
75
76 /**
77 * @bug 2429
78 * @dataProvider provideNamespacesAssociations
79 */
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 ),
85 ),
86 array(
87 'namespace' => $ns1,
88 'associated' => 1,
89 ),
90 "rc conditions with namespace inverted"
91 );
92 }
93
94 /**
95 * @bug 2429
96 * @dataProvider provideNamespacesAssociations
97 */
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 ),
103 ),
104 array(
105 'namespace' => $ns1,
106 'associated' => 1,
107 'invert' => 1,
108 ),
109 "rc conditions with namespace inverted"
110 );
111 }
112
113 /**
114 * Provides associated namespaces to test recent changes
115 * namespaces association filtering.
116 */
117 public static function provideNamespacesAssociations() {
118 return array( # (NS => Associated_NS)
119 array( NS_MAIN, NS_TALK ),
120 array( NS_TALK, NS_MAIN ),
121 );
122 }
123 }