MediaWiki  1.23.2
SpecialRecentchangesTest.php
Go to the documentation of this file.
1 <?php
13 
17  protected $rc;
18 
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 
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_namespace = '0'",
54  ),
55  array(
56  'namespace' => NS_MAIN,
57  ),
58  "rc conditions with no options (aka default setting)"
59  );
60  }
61 
62  public function testRcNsFilterInversion() {
63  $this->assertConditions(
64  array( # expected
65  'rc_bot' => 0,
66  0 => 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 
80  public function testRcNsFilterAssociation( $ns1, $ns2 ) {
81  $this->assertConditions(
82  array( # expected
83  'rc_bot' => 0,
84  0 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
85  ),
86  array(
87  'namespace' => $ns1,
88  'associated' => 1,
89  ),
90  "rc conditions with namespace inverted"
91  );
92  }
93 
98  public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
99  $this->assertConditions(
100  array( # expected
101  'rc_bot' => 0,
102  0 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
103  ),
104  array(
105  'namespace' => $ns1,
106  'associated' => 1,
107  'invert' => 1,
108  ),
109  "rc conditions with namespace inverted"
110  );
111  }
112 
117  public static function provideNamespacesAssociations() {
118  return array( # (NS => Associated_NS)
119  array( NS_MAIN, NS_TALK ),
120  array( NS_TALK, NS_MAIN ),
121  );
122  }
123 }
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: WebRequest.php:1275
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
SpecialRecentchangesTest\testRcNsFilter
testRcNsFilter()
Definition: SpecialRecentchangesTest.php:48
NS_MAIN
const NS_MAIN
Definition: Defines.php:79
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
SpecialRecentchangesTest\testRcNsFilterInversion
testRcNsFilterInversion()
Definition: SpecialRecentchangesTest.php:61
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:30
SpecialRecentchangesTest\testRcNsFilterAssociationWithInversion
testRcNsFilterAssociationWithInversion( $ns1, $ns2)
Definition: SpecialRecentchangesTest.php:97
SpecialRecentchangesTest\provideNamespacesAssociations
static provideNamespacesAssociations()
Provides associated namespaces to test recent changes namespaces association filtering.
Definition: SpecialRecentchangesTest.php:116
SpecialRecentchangesTest\filterOutRcTimestampCondition
static filterOutRcTimestampCondition( $var)
return false if condition begin with 'rc_timestamp '
Definition: SpecialRecentchangesTest.php:44
SpecialRecentchangesTest\assertConditions
assertConditions( $expected, $requestOptions=null, $message='')
helper to test SpecialRecentchanges::buildMainQueryConds()
Definition: SpecialRecentchangesTest.php:19
SpecialRecentchangesTest
Test class for SpecialRecentchanges class.
Definition: SpecialRecentchangesTest.php:12
SpecialRecentChanges
A special page that lists last changes made to the wiki.
Definition: SpecialRecentchanges.php:29
SpecialRecentchangesTest\$rc
SpecialRecentChanges $rc
Definition: SpecialRecentchangesTest.php:16
NS_TALK
const NS_TALK
Definition: Defines.php:80
SpecialRecentchangesTest\testRcNsFilterAssociation
testRcNsFilterAssociation( $ns1, $ns2)
Definition: SpecialRecentchangesTest.php:79
RequestContext\setRequest
setRequest(WebRequest $r)
Set the WebRequest object.
Definition: RequestContext.php:92