6 class SideBarTest
extends MediaWikiLangTestCase
{
8 /** A skin template, reinitialized before each test */
10 /** Local cache for sidebar messages */
13 /** Build $this->messages array */
14 private function initMessagesHref() {
15 # List of default messages for the sidebar:
16 $URL_messages = array(
25 foreach ( $URL_messages as $m ) {
26 $titleName = MessageCache
::singleton()->get( $m );
27 $title = Title
::newFromText( $titleName );
28 $this->messages
[$m]['href'] = $title->getLocalURL();
32 protected function setUp() {
34 $this->initMessagesHref();
35 $this->skin
= new SkinTemplate();
36 $this->skin
->getContext()->setLanguage( Language
::factory( 'en' ) );
39 protected function tearDown() {
45 * Internal helper to test the sidebar
48 * @param $message (Default: '')
50 private function assertSideBar( $expected, $text, $message = '' ) {
52 $this->skin
->addToSidebarPlain( $bar, $text );
53 $this->assertEquals( $expected, $bar, $message );
56 function testSidebarWithOnlyTwoTitles() {
68 function testExpandMessages() {
70 array( 'Title' => array(
73 'href' => $this->messages
['helppage']['href'],
84 function testExternalUrlsRequireADescription() {
86 array( 'Title' => array(
87 # ** http://www.mediawiki.org/| Home
90 'href' => 'http://www.mediawiki.org/',
95 # ** http://valid.no.desc.org/
96 # ... skipped since it is missing a pipe with a description
99 ** http://www.mediawiki.org/| Home
100 ** http://valid.no.desc.org/
107 * bug 33321 - Make sure there's a | after transforming.
110 function testTrickyPipe() {
111 $this->assertSidebar(
112 array( 'Title' => array(
113 # The first 2 are skipped
114 # Doesn't really test the url properly
115 # because it will vary with $wgArticlePath et al.
119 'href' => Title
::newFromText( 'Baz' )->getLocalUrl(),
124 'text' => 'title-to-display',
125 'href' => Title
::newFromText( 'page-to-go-to' )->getLocalUrl(),
126 'id' => 'n-title-to-display',
134 ** {{PLURAL:1|page-to-go-to{{int:pipe-separator/en}}title-to-display|branch not taken}}
140 #### Attributes for external links ##########################
141 private function getAttribs() {
142 # Sidebar text we will use everytime
144 ** http://www.mediawiki.org/| Home';
147 $this->skin
->addToSideBarPlain( $bar, $text );
149 return $bar['Title'][0];
153 * Simple test to verify our helper assertAttribs() is functional
154 * Please note this assume MediaWiki default settings:
155 * $wgNoFollowLinks = true
156 * $wgExternalLinkTarget = false
158 function testTestAttributesAssertionHelper() {
159 $attribs = $this->getAttribs();
161 $this->assertArrayHasKey( 'rel', $attribs );
162 $this->assertEquals( 'nofollow', $attribs['rel'] );
164 $this->assertArrayNotHasKey( 'target', $attribs );
168 * Test $wgNoFollowLinks in sidebar
170 function testRespectWgnofollowlinks() {
171 global $wgNoFollowLinks;
172 $saved = $wgNoFollowLinks;
173 $wgNoFollowLinks = false;
175 $attribs = $this->getAttribs();
176 $this->assertArrayNotHasKey( 'rel', $attribs,
177 'External URL in sidebar do not have rel=nofollow when $wgNoFollowLinks = false'
181 $wgNoFollowLinks = $saved;
185 * Test $wgExternaLinkTarget in sidebar
187 function testRespectExternallinktarget() {
188 global $wgExternalLinkTarget;
189 $saved = $wgExternalLinkTarget;
191 $wgExternalLinkTarget = '_blank';
192 $attribs = $this->getAttribs();
193 $this->assertArrayHasKey( 'target', $attribs );
194 $this->assertEquals( $attribs['target'], '_blank' );
196 $wgExternalLinkTarget = '_self';
197 $attribs = $this->getAttribs();
198 $this->assertArrayHasKey( 'target', $attribs );
199 $this->assertEquals( $attribs['target'], '_self' );
202 $wgExternalLinkTarget = $saved;