MediaWiki REL1_28
SpecialRecentchangesTest.php
Go to the documentation of this file.
1<?php
13
14 protected function setUp() {
15 parent::setUp();
16 $this->setMwGlobals( 'wgRCWatchCategoryMembership', true );
17 }
18
22 protected $rc;
23
25 private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
27 $context->setRequest( new FauxRequest( $requestOptions ) );
28
29 # setup the rc object
30 $this->rc = new SpecialRecentChanges();
31 $this->rc->setContext( $context );
32 $formOptions = $this->rc->setup( null );
33
34 #  Filter out rc_timestamp conditions which depends on the test runtime
35 # This condition is not needed as of march 2, 2011 -- hashar
36 # @todo FIXME: Find a way to generate the correct rc_timestamp
37 $queryConditions = array_filter(
38 $this->rc->buildMainQueryConds( $formOptions ),
39 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
40 );
41
42 $this->assertEquals(
43 $expected,
44 $queryConditions,
45 $message
46 );
47 }
48
50 private static function filterOutRcTimestampCondition( $var ) {
51 return ( false === strpos( $var, 'rc_timestamp ' ) );
52 }
53
54 public function testRcNsFilter() {
55 $this->assertConditions(
56 [ # expected
57 'rc_bot' => 0,
58 0 => "rc_type != '6'",
59 1 => "rc_namespace = '0'",
60 ],
61 [
62 'namespace' => NS_MAIN,
63 ],
64 "rc conditions with no options (aka default setting)"
65 );
66 }
67
68 public function testRcNsFilterInversion() {
69 $this->assertConditions(
70 [ # expected
71 'rc_bot' => 0,
72 0 => "rc_type != '6'",
73 1 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
74 ],
75 [
76 'namespace' => NS_MAIN,
77 'invert' => 1,
78 ],
79 "rc conditions with namespace inverted"
80 );
81 }
82
87 public function testRcNsFilterAssociation( $ns1, $ns2 ) {
88 $this->assertConditions(
89 [ # expected
90 'rc_bot' => 0,
91 0 => "rc_type != '6'",
92 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
93 ],
94 [
95 'namespace' => $ns1,
96 'associated' => 1,
97 ],
98 "rc conditions with namespace inverted"
99 );
100 }
101
106 public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
107 $this->assertConditions(
108 [ # expected
109 'rc_bot' => 0,
110 0 => "rc_type != '6'",
111 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
112 ],
113 [
114 'namespace' => $ns1,
115 'associated' => 1,
116 'invert' => 1,
117 ],
118 "rc conditions with namespace inverted"
119 );
120 }
121
126 public static function provideNamespacesAssociations() {
127 return [ # (NS => Associated_NS)
128 [ NS_MAIN, NS_TALK ],
129 [ NS_TALK, NS_MAIN ],
130 ];
131 }
132}
WebRequest clone which takes values from a provided array.
setMwGlobals( $pairs, $value=null)
Group all the pieces relevant to the context of a request into one instance.
setRequest(WebRequest $r)
Set the WebRequest object.
A special page that lists last changes made to the wiki.
Test class for SpecialRecentchanges class.
static filterOutRcTimestampCondition( $var)
return false if condition begin with 'rc_timestamp '
assertConditions( $expected, $requestOptions=null, $message='')
helper to test SpecialRecentchanges::buildMainQueryConds()
static provideNamespacesAssociations()
Provides associated namespaces to test recent changes namespaces association filtering.
const NS_MAIN
Definition Defines.php:56
const NS_TALK
Definition Defines.php:57
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
$context
Definition load.php:50