test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / specials / SpecialRecentchangesTest.php
blob436eb2e2b568c5dc8b4df03682104e43a7ccfe81
1 <?php
2 /**
3 * Test class for SpecialRecentchanges class
5 * Copyright © 2011, Antoine Musso
7 * @author Antoine Musso
8 * @group Database
9 */
10 class SpecialRecentchangesTest extends MediaWikiTestCase {
12 /**
13 * @var SpecialRecentChanges
15 protected $rc;
17 /** helper to test SpecialRecentchanges::buildMainQueryConds() */
18 private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
19 $context = new RequestContext;
20 $context->setRequest( new FauxRequest( $requestOptions ) );
22 # setup the rc object
23 $this->rc = new SpecialRecentChanges();
24 $this->rc->setContext( $context );
25 $formOptions = $this->rc->setup( null );
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'
35 $this->assertEquals(
36 $expected,
37 $queryConditions,
38 $message
42 /** return false if condition begin with 'rc_timestamp ' */
43 private static function filterOutRcTimestampCondition( $var ) {
44 return ( false === strpos( $var, 'rc_timestamp ' ) );
47 public function testRcNsFilter() {
48 $this->assertConditions(
49 array( # expected
50 'rc_bot' => 0,
51 #0 => "rc_timestamp >= '20110223000000'",
52 1 => "rc_namespace = '0'",
54 array(
55 'namespace' => NS_MAIN,
57 "rc conditions with no options (aka default setting)"
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 ),
68 array(
69 'namespace' => NS_MAIN,
70 'invert' => 1,
72 "rc conditions with namespace inverted"
76 /**
77 * @bug 2429
78 * @dataProvider provideNamespacesAssociations
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 ),
87 array(
88 'namespace' => $ns1,
89 'associated' => 1,
91 "rc conditions with namespace inverted"
95 /**
96 * @bug 2429
97 * @dataProvider provideNamespacesAssociations
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 ),
106 array(
107 'namespace' => $ns1,
108 'associated' => 1,
109 'invert' => 1,
111 "rc conditions with namespace inverted"
116 * Provides associated namespaces to test recent changes
117 * namespaces association filtering.
119 public static function provideNamespacesAssociations() {
120 return array( # (NS => Associated_NS)
121 array( NS_MAIN, NS_TALK ),
122 array( NS_TALK, NS_MAIN ),