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