48e31f3abc1e5434dd4609314164ab6df35ba2be
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / SpecialRecentchanges.php
1 <?php
2 /**
3 * Test class for SpecialRecentchanges class
4 *
5 * Copyright © 2011, Ashar Voultoiz
6 *
7 * @author Ashar Voultoiz
8 */
9 class SpecialRecentchangesTest extends MediaWikiTestCase {
10
11 /**
12 * @var SpecialRecentChanges
13 */
14 protected $rc;
15
16 function setUp() {
17 }
18
19 /** helper to test SpecialRecentchanges::buildMainQueryConds() */
20 private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
21 global $wgRequest;
22 $savedGlobal = $wgRequest;
23
24 # Initialize a WebRequest object ...
25 $wgRequest = new FauxRequest( $requestOptions );
26 # ... then setup the rc object (which use wgRequest internally)
27 $this->rc = new SpecialRecentChanges();
28 $formOptions = $this->rc->setup( null );
29
30 # Filter out rc_timestamp conditions which depends on the test runtime
31 # This condition is not needed as of march 2, 2011 -- hashar
32 # FIXME: find a way to generate the correct rc_timestamp
33 $queryConditions = array_filter(
34 $this->rc->buildMainQueryConds( $formOptions ),
35 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
36 );
37
38 $this->assertEquals(
39 $expected,
40 $queryConditions,
41 $message
42 );
43
44 $wgRequest = $savedGlobal;
45 }
46
47 /** return false if condition begin with 'rc_timestamp ' */
48 private static function filterOutRcTimestampCondition( $var ) {
49 return (false === strpos( $var, 'rc_timestamp ' ));
50
51 }
52
53 public function testRcNsFilter() {
54 $this->assertConditions(
55 array( # expected
56 'rc_bot' => 0,
57 #0 => "rc_timestamp >= '20110223000000'",
58 1 => "rc_namespace = '0'",
59 ),
60 array(
61 'namespace' => NS_MAIN,
62 ),
63 "rc conditions with no options (aka default setting)"
64 );
65 }
66
67 public function testRcNsFilterInversion() {
68 $this->assertConditions(
69 array( # expected
70 #0 => "rc_timestamp >= '20110223000000'",
71 'rc_bot' => 0,
72 1 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
73 ),
74 array(
75 'namespace' => NS_MAIN,
76 'invert' => 1,
77 ),
78 "rc conditions with namespace inverted"
79 );
80 }
81
82 /**
83 * @bug 2429
84 * @dataProvider provideNamespacesAssociations
85 */
86 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
87 $this->assertConditions(
88 array( # expected
89 #0 => "rc_timestamp >= '20110223000000'",
90 'rc_bot' => 0,
91 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
92 ),
93 array(
94 'namespace' => $ns1,
95 'associated' => 1,
96 ),
97 "rc conditions with namespace inverted"
98 );
99 }
100
101 /**
102 * @bug 2429
103 * @dataProvider provideNamespacesAssociations
104 */
105 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
106 $this->assertConditions(
107 array( # expected
108 #0 => "rc_timestamp >= '20110223000000'",
109 'rc_bot' => 0,
110 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
111 ),
112 array(
113 'namespace' => $ns1,
114 'associated' => 1,
115 'invert' => 1,
116 ),
117 "rc conditions with namespace inverted"
118 );
119 }
120
121 /**
122 * Provides associated namespaces to test recent changes
123 * namespaces association filtering.
124 */
125 public function provideNamespacesAssociations() {
126 return array( # (NS => Associated_NS)
127 array( NS_MAIN, NS_TALK),
128 array( NS_TALK, NS_MAIN),
129 );
130 }
131
132 }
133
134