tests: always call parent setUp
[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 class SpecialRecentchangesTest extends MediaWikiTestCase {
11
12 /**
13 * @var SpecialRecentChanges
14 */
15 protected $rc;
16
17 /** helper to test SpecialRecentchanges::buildMainQueryConds() */
18 private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
19 $context = new RequestContext;
20 $context->setRequest( new FauxRequest( $requestOptions ) );
21
22 # setup the rc object
23 $this->rc = new SpecialRecentChanges();
24 $this->rc->setContext( $context );
25 $formOptions = $this->rc->setup( null );
26
27 # Filter out rc_timestamp conditions which depends on the test runtime
28 # This condition is not needed as of march 2, 2011 -- hashar
29 # @todo FIXME: Find a way to generate the correct rc_timestamp
30 $queryConditions = array_filter(
31 $this->rc->buildMainQueryConds( $formOptions ),
32 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
33 );
34
35 $this->assertEquals(
36 $expected,
37 $queryConditions,
38 $message
39 );
40 }
41
42 /** return false if condition begin with 'rc_timestamp ' */
43 private static function filterOutRcTimestampCondition( $var ) {
44 return (false === strpos( $var, 'rc_timestamp ' ));
45
46 }
47
48 public function testRcNsFilter() {
49 $this->assertConditions(
50 array( # expected
51 'rc_bot' => 0,
52 #0 => "rc_timestamp >= '20110223000000'",
53 1 => "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 #0 => "rc_timestamp >= '20110223000000'",
66 'rc_bot' => 0,
67 1 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
68 ),
69 array(
70 'namespace' => NS_MAIN,
71 'invert' => 1,
72 ),
73 "rc conditions with namespace inverted"
74 );
75 }
76
77 /**
78 * @bug 2429
79 * @dataProvider provideNamespacesAssociations
80 */
81 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
82 $this->assertConditions(
83 array( # expected
84 #0 => "rc_timestamp >= '20110223000000'",
85 'rc_bot' => 0,
86 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
87 ),
88 array(
89 'namespace' => $ns1,
90 'associated' => 1,
91 ),
92 "rc conditions with namespace inverted"
93 );
94 }
95
96 /**
97 * @bug 2429
98 * @dataProvider provideNamespacesAssociations
99 */
100 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
101 $this->assertConditions(
102 array( # expected
103 #0 => "rc_timestamp >= '20110223000000'",
104 'rc_bot' => 0,
105 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
106 ),
107 array(
108 'namespace' => $ns1,
109 'associated' => 1,
110 'invert' => 1,
111 ),
112 "rc conditions with namespace inverted"
113 );
114 }
115
116 /**
117 * Provides associated namespaces to test recent changes
118 * namespaces association filtering.
119 */
120 public static function provideNamespacesAssociations() {
121 return array( # (NS => Associated_NS)
122 array( NS_MAIN, NS_TALK),
123 array( NS_TALK, NS_MAIN),
124 );
125 }
126
127 }
128
129