Partial revert r97035, followup r96930: make recentchanges tests pass again
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / SpecialRecentchangesTest.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 $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
50 public function testRcNsFilter() {
51 $this->assertConditions(
52 array( # expected
53 'rc_bot' => 0,
54 #0 => "rc_timestamp >= '20110223000000'",
55 1 => "rc_namespace = '0'",
56 ),
57 array(
58 'namespace' => NS_MAIN,
59 ),
60 "rc conditions with no options (aka default setting)"
61 );
62 }
63
64 public function testRcNsFilterInversion() {
65 $this->assertConditions(
66 array( # expected
67 #0 => "rc_timestamp >= '20110223000000'",
68 'rc_bot' => 0,
69 1 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
70 ),
71 array(
72 'namespace' => NS_MAIN,
73 'invert' => 1,
74 ),
75 "rc conditions with namespace inverted"
76 );
77 }
78
79 /**
80 * @bug 2429
81 * @dataProvider provideNamespacesAssociations
82 */
83 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
84 $this->assertConditions(
85 array( # expected
86 #0 => "rc_timestamp >= '20110223000000'",
87 'rc_bot' => 0,
88 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
89 ),
90 array(
91 'namespace' => $ns1,
92 'associated' => 1,
93 ),
94 "rc conditions with namespace inverted"
95 );
96 }
97
98 /**
99 * @bug 2429
100 * @dataProvider provideNamespacesAssociations
101 */
102 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
103 $this->assertConditions(
104 array( # expected
105 #0 => "rc_timestamp >= '20110223000000'",
106 'rc_bot' => 0,
107 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
108 ),
109 array(
110 'namespace' => $ns1,
111 'associated' => 1,
112 'invert' => 1,
113 ),
114 "rc conditions with namespace inverted"
115 );
116 }
117
118 /**
119 * Provides associated namespaces to test recent changes
120 * namespaces association filtering.
121 */
122 public function provideNamespacesAssociations() {
123 return array( # (NS => Associated_NS)
124 array( NS_MAIN, NS_TALK),
125 array( NS_TALK, NS_MAIN),
126 );
127 }
128
129 }
130
131