3 use Wikimedia\TestingAccessWrapper
;
4 use MediaWiki\Navigation\PrevNextNavigationRenderer
;
7 * @covers \MediaWiki\Navigation\PrevNextNavigationRenderer
9 class PrevNextNavigationRendererTest
extends MediaWikiTestCase
{
11 public function provideBuildPrevNextNavigation() {
12 yield
[ 0, 20, false, false ];
13 yield
[ 17, 20, false, false ];
14 yield
[ 0, 17, false, false ];
15 yield
[ 0, 20, true, 'Foo' ];
16 yield
[ 17, 20, true, 'Föö_Bär' ];
20 * @dataProvider provideBuildPrevNextNavigation
22 public function testBuildPrevNextNavigation( $offset, $limit, $atEnd, $subPage ) {
23 $this->setUserLang( Language
::factory( 'qqx' ) ); // disable i18n
25 $prevNext = new PrevNextNavigationRenderer( RequestContext
::getMain() );
26 $prevNext = TestingAccessWrapper
::newFromObject( $prevNext );
28 $html = $prevNext->buildPrevNextNavigation(
29 SpecialPage
::getTitleFor( 'Watchlist', $subPage ),
36 $this->assertStringStartsWith( '(viewprevnext:', $html );
38 preg_match_all( '!<a.*?</a>!', $html, $m, PREG_PATTERN_ORDER
);
41 foreach ( $links as $a ) {
43 $this->assertContains( 'Special:Watchlist/' . wfUrlencode( $subPage ), $a );
45 $this->assertContains( 'Special:Watchlist', $a );
46 $this->assertNotContains( 'Special:Watchlist/', $a );
48 $this->assertContains( 'x=25', $a );
54 $this->assertContains(
55 'limit=' . $limit . '&offset=' . max( 0, $offset - $limit ) . '&',
58 $this->assertContains( 'title="(prevn-title: ' . $limit . ')"', $links[$i] );
59 $this->assertContains( 'class="mw-prevlink"', $links[$i] );
60 $this->assertContains( '>(prevn: ' . $limit . ')<', $links[$i] );
65 $this->assertContains(
66 'limit=' . $limit . '&offset=' . ( $offset +
$limit ) . '&',
69 $this->assertContains( 'title="(nextn-title: ' . $limit . ')"', $links[$i] );
70 $this->assertContains( 'class="mw-nextlink"', $links[$i] );
71 $this->assertContains( '>(nextn: ' . $limit . ')<', $links[$i] );
75 $this->assertCount( 5 +
$i, $links );
77 $this->assertContains( 'limit=20&offset=' . $offset, $links[$i] );
78 $this->assertContains( 'title="(shown-title: 20)"', $links[$i] );
79 $this->assertContains( 'class="mw-numlink"', $links[$i] );
80 $this->assertContains( '>20<', $links[$i] );
83 $this->assertContains( 'limit=500&offset=' . $offset, $links[$i] );
84 $this->assertContains( 'title="(shown-title: 500)"', $links[$i] );
85 $this->assertContains( 'class="mw-numlink"', $links[$i] );
86 $this->assertContains( '>500<', $links[$i] );