47182a711a642019c4eb49f16558bab2d6eacf7a
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();
47 * Internal helper to test the sidebar
50 * @param $message (Default: '')
52 private function assertSideBar( $expected, $text, $message = '' ) {
54 $this->skin
->addToSidebarPlain( $bar, $text );
55 $this->assertEquals( $expected, $bar, $message );
58 function testSidebarWithOnlyTwoTitles() {
70 function testExpandMessages() {
72 array( 'Title' => array(
75 'href' => $this->messages
['helppage']['href'],
86 function testExternalUrlsRequireADescription() {
88 array( 'Title' => array(
89 # ** http://www.mediawiki.org/| Home
92 'href' => 'http://www.mediawiki.org/',
97 # ** http://valid.no.desc.org/
98 # ... skipped since it is missing a pipe with a description
101 ** http://www.mediawiki.org/| Home
102 ** http://valid.no.desc.org/
110 #### Attributes for external links ##########################
111 private function getAttribs( ) {
112 # Sidebar text we will use everytime
114 ** http://www.mediawiki.org/| Home';
117 $this->skin
->addToSideBarPlain( $bar, $text );
119 return $bar['Title'][0];
123 * Simple test to verify our helper assertAttribs() is functional
124 * Please note this assume MediaWiki default settings:
125 * $wgNoFollowLinks = true
126 * $wgExternalLinkTarget = false
128 function testTestAttributesAssertionHelper() {
129 $attribs = $this->getAttribs();
131 $this->assertArrayHasKey( 'rel', $attribs );
132 $this->assertEquals( 'nofollow', $attribs['rel'] );
134 $this->assertArrayNotHasKey( 'target', $attribs );
138 * Test wgNoFollowLinks in sidebar
140 function testRespectWgnofollowlinks() {
141 global $wgNoFollowLinks;
142 $saved = $wgNoFollowLinks;
143 $wgNoFollowLinks = false;
145 $attribs = $this->getAttribs();
146 $this->assertArrayNotHasKey( 'rel', $attribs,
147 'External URL in sidebar do not have rel=nofollow when wgNoFollowLinks = false'
151 $wgNoFollowLinks = $saved;
155 * Test wgExternaLinkTarget in sidebar
157 function testRespectExternallinktarget() {
158 global $wgExternalLinkTarget;
159 $saved = $wgExternalLinkTarget;
161 $wgExternalLinkTarget = '_blank';
162 $attribs = $this->getAttribs();
163 $this->assertArrayHasKey( 'target', $attribs );
164 $this->assertEquals( $attribs['target'], '_blank' );
166 $wgExternalLinkTarget = '_self';
167 $attribs = $this->getAttribs();
168 $this->assertArrayHasKey( 'target', $attribs );
169 $this->assertEquals( $attribs['target'], '_self' );
172 $wgExternalLinkTarget = $saved;