3 class SideBarTest
extends MediaWikiLangTestCase
{
5 /** A skin template, reinitialized before each test */
7 /** Local cache for sidebar messages */
10 function __construct() {
11 parent
::__construct();
14 /** Build $this->messages array */
15 private function initMessagesHref() {
16 # List of default messages for the sidebar:
17 $URL_messages = array(
26 foreach( $URL_messages as $m ) {
27 $titleName = MessageCache
::singleton()->get($m);
28 $title = Title
::newFromText( $titleName );
29 $this->messages
[$m]['href'] = $title->getLocalURL();
35 $this->initMessagesHref();
36 $this->skin
= new SkinTemplate();
44 * Internal helper to test the sidebar
47 * @param $message (Default: '')
49 private function assertSideBar( $expected, $text, $message = '' ) {
51 $this->skin
->addToSidebarPlain( $bar, $text );
52 $this->assertEquals( $expected, $bar, $message );
55 function testSidebarWithOnlyTwoTitles() {
67 function testExpandMessages() {
69 array( 'Title' => array(
72 'href' => $this->messages
['helppage']['href'],
83 function testExternalUrlsRequireADescription() {
85 array( 'Title' => array(
86 # ** http://www.mediawiki.org/| Home
89 'href' => 'http://www.mediawiki.org/',
94 # ** http://valid.no.desc.org/
95 # ... skipped since it is missing a pipe with a description
98 ** http://www.mediawiki.org/| Home
99 ** http://valid.no.desc.org/
107 #### Attributes for external links ##########################
108 private function getAttribs( ) {
109 # Sidebar text we will use everytime
111 ** http://www.mediawiki.org/| Home';
114 $this->skin
->addToSideBarPlain( $bar, $text );
116 return $bar['Title'][0];
120 * Simple test to verify our helper assertAttribs() is functional
121 * Please note this assume MediaWiki default settings:
122 * $wgNoFollowLinks = true
123 * $wgExternalLinkTarget = false
125 function testTestAttributesAssertionHelper() {
126 $attribs = $this->getAttribs();
128 $this->assertArrayHasKey( 'rel', $attribs );
129 $this->assertEquals( 'nofollow', $attribs['rel'] );
131 $this->assertArrayNotHasKey( 'target', $attribs );
135 * Test wgNoFollowLinks in sidebar
137 function testRespectWgnofollowlinks() {
138 global $wgNoFollowLinks;
139 $saved = $wgNoFollowLinks;
140 $wgNoFollowLinks = false;
142 $attribs = $this->getAttribs();
143 $this->assertArrayNotHasKey( 'rel', $attribs,
144 'External URL in sidebar do not have rel=nofollow when wgNoFollowLinks = false'
148 $wgNoFollowLinks = $saved;
152 * Test wgExternaLinkTarget in sidebar
154 function testRespectExternallinktarget() {
155 global $wgExternalLinkTarget;
156 $saved = $wgExternalLinkTarget;
158 $wgExternalLinkTarget = '_blank';
159 $attribs = $this->getAttribs();
160 $this->assertArrayHasKey( 'target', $attribs );
161 $this->assertEquals( $attribs['target'], '_blank' );
163 $wgExternalLinkTarget = '_self';
164 $attribs = $this->getAttribs();
165 $this->assertArrayHasKey( 'target', $attribs );
166 $this->assertEquals( $attribs['target'], '_self' );
169 $wgExternalLinkTarget = $saved;