Compress images
[mediawiki.git] / tests / phpunit / includes / specials / SpecialRecentchangesTest.php
blob2e4f4b09b8357590af366c7213edeab0001d395f
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 function setUp() {
20 /** helper to test SpecialRecentchanges::buildMainQueryConds() */
21 private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
22 $context = new RequestContext;
23 $context->setRequest( new FauxRequest( $requestOptions ) );
25 # setup the rc object
26 $this->rc = new SpecialRecentChanges();
27 $this->rc->setContext( $context );
28 $formOptions = $this->rc->setup( null );
30 # Filter out rc_timestamp conditions which depends on the test runtime
31 # This condition is not needed as of march 2, 2011 -- hashar
32 # @todo FIXME: Find a way to generate the correct rc_timestamp
33 $queryConditions = array_filter(
34 $this->rc->buildMainQueryConds( $formOptions ),
35 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
38 $this->assertEquals(
39 $expected,
40 $queryConditions,
41 $message
45 /** return false if condition begin with 'rc_timestamp ' */
46 private static function filterOutRcTimestampCondition( $var ) {
47 return (false === strpos( $var, 'rc_timestamp ' ));
51 public function testRcNsFilter() {
52 $this->assertConditions(
53 array( # expected
54 'rc_bot' => 0,
55 #0 => "rc_timestamp >= '20110223000000'",
56 1 => "rc_namespace = '0'",
58 array(
59 'namespace' => NS_MAIN,
61 "rc conditions with no options (aka default setting)"
65 public function testRcNsFilterInversion() {
66 $this->assertConditions(
67 array( # expected
68 #0 => "rc_timestamp >= '20110223000000'",
69 'rc_bot' => 0,
70 1 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
72 array(
73 'namespace' => NS_MAIN,
74 'invert' => 1,
76 "rc conditions with namespace inverted"
80 /**
81 * @bug 2429
82 * @dataProvider provideNamespacesAssociations
84 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
85 $this->assertConditions(
86 array( # expected
87 #0 => "rc_timestamp >= '20110223000000'",
88 'rc_bot' => 0,
89 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
91 array(
92 'namespace' => $ns1,
93 'associated' => 1,
95 "rc conditions with namespace inverted"
99 /**
100 * @bug 2429
101 * @dataProvider provideNamespacesAssociations
103 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
104 $this->assertConditions(
105 array( # expected
106 #0 => "rc_timestamp >= '20110223000000'",
107 'rc_bot' => 0,
108 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
110 array(
111 'namespace' => $ns1,
112 'associated' => 1,
113 'invert' => 1,
115 "rc conditions with namespace inverted"
120 * Provides associated namespaces to test recent changes
121 * namespaces association filtering.
123 public function provideNamespacesAssociations() {
124 return array( # (NS => Associated_NS)
125 array( NS_MAIN, NS_TALK),
126 array( NS_TALK, NS_MAIN),