Merge "Slight improvements to FormSpecialPage behavior."
[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 public function testRcNsFilter() {
48 $this->assertConditions(
49 array( # expected
50 'rc_bot' => 0,
51 #0 => "rc_timestamp >= '20110223000000'",
52 1 => "rc_namespace = '0'",
53 ),
54 array(
55 'namespace' => NS_MAIN,
56 ),
57 "rc conditions with no options (aka default setting)"
58 );
59 }
60
61 public function testRcNsFilterInversion() {
62 $this->assertConditions(
63 array( # expected
64 #0 => "rc_timestamp >= '20110223000000'",
65 'rc_bot' => 0,
66 1 => 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 #0 => "rc_timestamp >= '20110223000000'",
84 'rc_bot' => 0,
85 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
86 ),
87 array(
88 'namespace' => $ns1,
89 'associated' => 1,
90 ),
91 "rc conditions with namespace inverted"
92 );
93 }
94
95 /**
96 * @bug 2429
97 * @dataProvider provideNamespacesAssociations
98 */
99 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
100 $this->assertConditions(
101 array( # expected
102 #0 => "rc_timestamp >= '20110223000000'",
103 'rc_bot' => 0,
104 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
105 ),
106 array(
107 'namespace' => $ns1,
108 'associated' => 1,
109 'invert' => 1,
110 ),
111 "rc conditions with namespace inverted"
112 );
113 }
114
115 /**
116 * Provides associated namespaces to test recent changes
117 * namespaces association filtering.
118 */
119 public static function provideNamespacesAssociations() {
120 return array( # (NS => Associated_NS)
121 array( NS_MAIN, NS_TALK ),
122 array( NS_TALK, NS_MAIN ),
123 );
124 }
125 }