wiki.techinc.nl/tests/phpunit/includes/specials/SpecialRecentchangesTest.php

124 lines
2.9 KiB
PHP
Raw Normal View History

<?php
/**
* Test class for SpecialRecentchanges class
*
* Copyright © 2011, Antoine Musso
*
* @author Antoine Musso
* @group Database
*
* @covers SpecialRecentChanges
*/
class SpecialRecentchangesTest extends MediaWikiTestCase {
/**
* @var SpecialRecentChanges
*/
protected $rc;
/** helper to test SpecialRecentchanges::buildMainQueryConds() */
private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
2011-08-11 14:13:03 +00:00
$context = new RequestContext;
$context->setRequest( new FauxRequest( $requestOptions ) );
2011-08-11 14:13:03 +00:00
# setup the rc object
$this->rc = new SpecialRecentChanges();
2011-08-11 14:13:03 +00:00
$this->rc->setContext( $context );
$formOptions = $this->rc->setup( null );
#  Filter out rc_timestamp conditions which depends on the test runtime
# This condition is not needed as of march 2, 2011 -- hashar
# @todo FIXME: Find a way to generate the correct rc_timestamp
$queryConditions = array_filter(
$this->rc->buildMainQueryConds( $formOptions ),
'SpecialRecentchangesTest::filterOutRcTimestampCondition'
);
$this->assertEquals(
$expected,
$queryConditions,
$message
);
}
/** return false if condition begin with 'rc_timestamp ' */
private static function filterOutRcTimestampCondition( $var ) {
return ( false === strpos( $var, 'rc_timestamp ' ) );
}
public function testRcNsFilter() {
$this->assertConditions(
array( # expected
'rc_bot' => 0,
0 => "rc_namespace = '0'",
),
array(
'namespace' => NS_MAIN,
),
"rc conditions with no options (aka default setting)"
);
}
public function testRcNsFilterInversion() {
$this->assertConditions(
array( # expected
'rc_bot' => 0,
0 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
),
array(
'namespace' => NS_MAIN,
'invert' => 1,
),
"rc conditions with namespace inverted"
);
}
/**
* @bug 2429
* @dataProvider provideNamespacesAssociations
*/
public function testRcNsFilterAssociation( $ns1, $ns2 ) {
$this->assertConditions(
array( # expected
'rc_bot' => 0,
0 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ),
),
array(
'namespace' => $ns1,
'associated' => 1,
),
"rc conditions with namespace inverted"
);
}
/**
* @bug 2429
* @dataProvider provideNamespacesAssociations
*/
public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
$this->assertConditions(
array( # expected
'rc_bot' => 0,
0 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ),
),
array(
'namespace' => $ns1,
'associated' => 1,
'invert' => 1,
),
"rc conditions with namespace inverted"
);
}
/**
* Provides associated namespaces to test recent changes
* namespaces association filtering.
*/
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
public static function provideNamespacesAssociations() {
return array( # (NS => Associated_NS)
array( NS_MAIN, NS_TALK ),
array( NS_TALK, NS_MAIN ),
);
}
}