6 class SideBarTest
extends MediaWikiLangTestCase
{
8 /** A skin template, reinitialized before each test */
10 /** Local cache for sidebar messages */
13 function __construct() {
14 parent
::__construct();
17 /** Build $this->messages array */
18 private function initMessagesHref() {
19 # List of default messages for the sidebar:
20 $URL_messages = array(
29 foreach( $URL_messages as $m ) {
30 $titleName = MessageCache
::singleton()->get($m);
31 $title = Title
::newFromText( $titleName );
32 $this->messages
[$m]['href'] = $title->getLocalURL();
38 $this->initMessagesHref();
39 $this->skin
= new SkinTemplate();
40 $this->skin
->getContext()->setLang( Language
::factory( 'en' ) );
48 * Internal helper to test the sidebar
51 * @param $message (Default: '')
53 private function assertSideBar( $expected, $text, $message = '' ) {
55 $this->skin
->addToSidebarPlain( $bar, $text );
56 $this->assertEquals( $expected, $bar, $message );
59 function testSidebarWithOnlyTwoTitles() {
71 function testExpandMessages() {
73 array( 'Title' => array(
76 'href' => $this->messages
['helppage']['href'],
87 function testExternalUrlsRequireADescription() {
89 array( 'Title' => array(
90 # ** http://www.mediawiki.org/| Home
93 'href' => 'http://www.mediawiki.org/',
98 # ** http://valid.no.desc.org/
99 # ... skipped since it is missing a pipe with a description
102 ** http://www.mediawiki.org/| Home
103 ** http://valid.no.desc.org/
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}}
141 #### Attributes for external links ##########################
142 private function getAttribs( ) {
143 # Sidebar text we will use everytime
145 ** http://www.mediawiki.org/| Home';
148 $this->skin
->addToSideBarPlain( $bar, $text );
150 return $bar['Title'][0];
154 * Simple test to verify our helper assertAttribs() is functional
155 * Please note this assume MediaWiki default settings:
156 * $wgNoFollowLinks = true
157 * $wgExternalLinkTarget = false
159 function testTestAttributesAssertionHelper() {
160 $attribs = $this->getAttribs();
162 $this->assertArrayHasKey( 'rel', $attribs );
163 $this->assertEquals( 'nofollow', $attribs['rel'] );
165 $this->assertArrayNotHasKey( 'target', $attribs );
169 * Test $wgNoFollowLinks in sidebar
171 function testRespectWgnofollowlinks() {
172 global $wgNoFollowLinks;
173 $saved = $wgNoFollowLinks;
174 $wgNoFollowLinks = false;
176 $attribs = $this->getAttribs();
177 $this->assertArrayNotHasKey( 'rel', $attribs,
178 'External URL in sidebar do not have rel=nofollow when $wgNoFollowLinks = false'
182 $wgNoFollowLinks = $saved;
186 * Test $wgExternaLinkTarget in sidebar
188 function testRespectExternallinktarget() {
189 global $wgExternalLinkTarget;
190 $saved = $wgExternalLinkTarget;
192 $wgExternalLinkTarget = '_blank';
193 $attribs = $this->getAttribs();
194 $this->assertArrayHasKey( 'target', $attribs );
195 $this->assertEquals( $attribs['target'], '_blank' );
197 $wgExternalLinkTarget = '_self';
198 $attribs = $this->getAttribs();
199 $this->assertArrayHasKey( 'target', $attribs );
200 $this->assertEquals( $attribs['target'], '_self' );
203 $wgExternalLinkTarget = $saved;