Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / tests / phpunit / includes / Navigation / PrevNextNavigationRendererTest.php
1 <?php
2
3 use Wikimedia\TestingAccessWrapper;
4 use MediaWiki\Navigation\PrevNextNavigationRenderer;
5
6 /**
7 * @covers \MediaWiki\Navigation\PrevNextNavigationRenderer
8 */
9 class PrevNextNavigationRendererTest extends MediaWikiTestCase {
10
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' ];
17 }
18
19 /**
20 * @dataProvider provideBuildPrevNextNavigation
21 */
22 public function testBuildPrevNextNavigation( $offset, $limit, $atEnd, $subPage ) {
23 $this->setUserLang( Language::factory( 'qqx' ) ); // disable i18n
24
25 $prevNext = new PrevNextNavigationRenderer( RequestContext::getMain() );
26 $prevNext = TestingAccessWrapper::newFromObject( $prevNext );
27
28 $html = $prevNext->buildPrevNextNavigation(
29 SpecialPage::getTitleFor( 'Watchlist', $subPage ),
30 $offset,
31 $limit,
32 [ 'x' => 25 ],
33 $atEnd
34 );
35
36 $this->assertStringStartsWith( '(viewprevnext:', $html );
37
38 preg_match_all( '!<a.*?</a>!', $html, $m, PREG_PATTERN_ORDER );
39 $links = $m[0];
40
41 foreach ( $links as $a ) {
42 if ( $subPage ) {
43 $this->assertContains( 'Special:Watchlist/' . wfUrlencode( $subPage ), $a );
44 } else {
45 $this->assertContains( 'Special:Watchlist', $a );
46 $this->assertNotContains( 'Special:Watchlist/', $a );
47 }
48 $this->assertContains( 'x=25', $a );
49 }
50
51 $i = 0;
52
53 if ( $offset > 0 ) {
54 $this->assertContains(
55 'limit=' . $limit . '&amp;offset=' . max( 0, $offset - $limit ) . '&amp;',
56 $links[ $i ]
57 );
58 $this->assertContains( 'title="(prevn-title: ' . $limit . ')"', $links[$i] );
59 $this->assertContains( 'class="mw-prevlink"', $links[$i] );
60 $this->assertContains( '>(prevn: ' . $limit . ')<', $links[$i] );
61 $i += 1;
62 }
63
64 if ( !$atEnd ) {
65 $this->assertContains(
66 'limit=' . $limit . '&amp;offset=' . ( $offset + $limit ) . '&amp;',
67 $links[ $i ]
68 );
69 $this->assertContains( 'title="(nextn-title: ' . $limit . ')"', $links[$i] );
70 $this->assertContains( 'class="mw-nextlink"', $links[$i] );
71 $this->assertContains( '>(nextn: ' . $limit . ')<', $links[$i] );
72 $i += 1;
73 }
74
75 $this->assertCount( 5 + $i, $links );
76
77 $this->assertContains( 'limit=20&amp;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] );
81 $i += 4;
82
83 $this->assertContains( 'limit=500&amp;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] );
87 }
88 }