A number of tests have hardcoded expections that pass only in WMF CI where Quibble has LocalSettings.php with $wgScript and $wgArticlePath set a certain way. We could fix these by adding setMwGlobals() in their tests, as we often do, but these are so often forgotten that I'd rather we just add them to TestSetup.php so that it is simply impossible to write a test that that passes locally for you (if you have the same config) but not for someone else. There is a larger project in there somewhere about expanding this slowly such that we basically only pluck DB-settings and extension enablement from LocalSettings and otherwise run the tests with the default settings in PHPUnit. Pretty much by definition, any (other) setting you have in LocalSettings is irrelevant because it either: 1. has no effect on the test (majority, harmless either way), 2. has a custom default via TestSetup.php (which has precedence over LocalSettings.php), 3. is relevant to the code being tested and the test case correctly calls setMwGlobals() to ensure a consistent value during test. 4. is relevant to the tested code but has no override, thus only passes if you happen to have the "right" value set for it (undesirable). Case 4 is already categorically impossible for the most common config settings that influence random code because we give them a value in TestSetup.php. This patch expands that to include $wgScript and $wgArticlePath. Perhaps in the future we can think about a way to do this automatically by either re-applying MainConfigSchema (sans db settings) or by only selectively applying LocalSettings.php in the first place. This patch follows-up I072ddf89562fe, which added a test case in WikitextContentHandlerIntegrationTest.php that assumed "/index.php" as the value of $wgScript. This passes in WMF CI since Quibble uses that value, but the tests failed in most local development installs since those tend to use "/w" instead. Rather than one-off fixing that one test with overrideConfigValues(), switch to a more general fixture, since the precise values don't matter for this test. Bug: T349087 Bug: T277470 Change-Id: If4304b7ca4a838bd892d4516a0b5c6dfbc30986e
73 lines
3.9 KiB
PHP
73 lines
3.9 KiB
PHP
<?php
|
|
|
|
use MediaWiki\MainConfigNames;
|
|
use MediaWiki\Navigation\PagerNavigationBuilder;
|
|
use MediaWiki\Page\PageReferenceValue;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Navigation\PagerNavigationBuilder
|
|
*/
|
|
class PagerNavigationBuilderTest extends MediaWikiIntegrationTestCase {
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->overrideConfigValues( [
|
|
MainConfigNames::ScriptPath => '/w',
|
|
MainConfigNames::Script => '/w/index.php',
|
|
] );
|
|
}
|
|
|
|
private const EXPECTED_BASIC = '<div class="mw-pager-navigation-bar">(viewprevnext: <span class="mw-prevlink">(prevn: 50)</span>, <span class="mw-nextlink">(nextn: 50)</span>, <a href="/w/index.php?title=A&limit=20" class="mw-numlink">20</a>(pipe-separator)<span class="mw-numlink">50</span>(pipe-separator)<a href="/w/index.php?title=A&limit=100" class="mw-numlink">100</a>(pipe-separator)<a href="/w/index.php?title=A&limit=250" class="mw-numlink">250</a>(pipe-separator)<a href="/w/index.php?title=A&limit=500" class="mw-numlink">500</a>)</div>';
|
|
private const EXPECTED_OVERRIDES = '<div class="mw-pager-navigation-bar">(parentheses: <a href="/w/index.php?title=A&a=a&d=d" title="(m)" class="mw-firstlink">(i)</a>(pipe-separator)<a href="/w/index.php?title=A&a=a&e=e" title="(n)" class="mw-lastlink">(j)</a>) (viewprevnext: <a href="/w/index.php?title=A&a=a&b=b" rel="prev" title="(k: 1)" class="mw-prevlink">(g: 1)</a>, <a href="/w/index.php?title=A&a=a&c=c" rel="next" title="(l: 1)" class="mw-nextlink">(h: 1)</a>, <span class="mw-numlink">1</span>(pipe-separator)<a href="/w/index.php?title=A&a=a&f=2" title="(o: 2)" class="mw-numlink">2</a>)</div>';
|
|
private const EXPECTED_NULL_LINK_QUERY = '<div class="mw-pager-navigation-bar">(parentheses: <a href="/wiki/A" class="mw-firstlink">(i)</a>(pipe-separator)<a href="/w/index.php?title=A&dir=prev" class="mw-lastlink">(j)</a>) (viewprevnext: <a href="/w/index.php?title=A&dir=prev&offset=1" rel="prev" class="mw-prevlink">(prevn: 1)</a>, <a href="/w/index.php?title=A&dir=next&offset=2" rel="next" class="mw-nextlink">(nextn: 1)</a>, <span class="mw-numlink">1</span>)</div>';
|
|
|
|
public function testBasic() {
|
|
$navBuilder = new PagerNavigationBuilder( new MockMessageLocalizer() );
|
|
$navBuilder->setPage( PageReferenceValue::localReference( NS_MAIN, 'A' ) );
|
|
$this->assertEquals( self::EXPECTED_BASIC, $navBuilder->getHtml() );
|
|
}
|
|
|
|
public function testOverrides() {
|
|
$navBuilder = new PagerNavigationBuilder( new MockMessageLocalizer() );
|
|
$navBuilder
|
|
->setPage( PageReferenceValue::localReference( NS_MAIN, 'A' ) )
|
|
->setLinkQuery( [ 'a' => 'a' ] )
|
|
->setPrevLinkQuery( [ 'b' => 'b' ] )
|
|
->setNextLinkQuery( [ 'c' => 'c' ] )
|
|
->setFirstLinkQuery( [ 'd' => 'd' ] )
|
|
->setLastLinkQuery( [ 'e' => 'e' ] )
|
|
->setLimitLinkQueryParam( 'f' )
|
|
->setPrevMsg( 'g' )
|
|
->setNextMsg( 'h' )
|
|
->setFirstMsg( 'i' )
|
|
->setLastMsg( 'j' )
|
|
->setPrevTooltipMsg( 'k' )
|
|
->setNextTooltipMsg( 'l' )
|
|
->setFirstTooltipMsg( 'm' )
|
|
->setLastTooltipMsg( 'n' )
|
|
->setLimitTooltipMsg( 'o' )
|
|
->setCurrentLimit( 1 )
|
|
->setLimits( [ 1, 2 ] );
|
|
$this->assertEquals( self::EXPECTED_OVERRIDES, $navBuilder->getHtml() );
|
|
}
|
|
|
|
public function testNullLinkQuery() {
|
|
$navBuilder = new PagerNavigationBuilder( new MockMessageLocalizer() );
|
|
$navBuilder
|
|
->setPage( PageReferenceValue::localReference( NS_MAIN, 'A' ) )
|
|
->setFirstMsg( 'i' )
|
|
->setLastMsg( 'j' )
|
|
->setCurrentLimit( 1 )
|
|
->setLimits( [ 1 ] )
|
|
// null is allowed here, and it establishes the order of parameters for the output
|
|
->setLinkQuery( [ 'dir' => null, 'offset' => '1' ] )
|
|
->setPrevLinkQuery( [ 'dir' => 'prev' ] )
|
|
->setNextLinkQuery( [ 'offset' => '2', 'dir' => 'next' ] )
|
|
// null is allowed here, and it overrides defaults from setLinkQuery()
|
|
->setFirstLinkQuery( [ 'offset' => null ] )
|
|
->setLastLinkQuery( [ 'offset' => null, 'dir' => 'prev' ] );
|
|
$this->assertEquals( self::EXPECTED_NULL_LINK_QUERY, $navBuilder->getHtml() );
|
|
}
|
|
|
|
}
|