441302a549c29bcf6efacc4706f41a608435ba71
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/
111 #### Attributes for external links ##########################
112 private function getAttribs( ) {
113 # Sidebar text we will use everytime
115 ** http://www.mediawiki.org/| Home';
118 $this->skin
->addToSideBarPlain( $bar, $text );
120 return $bar['Title'][0];
124 * Simple test to verify our helper assertAttribs() is functional
125 * Please note this assume MediaWiki default settings:
126 * $wgNoFollowLinks = true
127 * $wgExternalLinkTarget = false
129 function testTestAttributesAssertionHelper() {
130 $attribs = $this->getAttribs();
132 $this->assertArrayHasKey( 'rel', $attribs );
133 $this->assertEquals( 'nofollow', $attribs['rel'] );
135 $this->assertArrayNotHasKey( 'target', $attribs );
139 * Test wgNoFollowLinks in sidebar
141 function testRespectWgnofollowlinks() {
142 global $wgNoFollowLinks;
143 $saved = $wgNoFollowLinks;
144 $wgNoFollowLinks = false;
146 $attribs = $this->getAttribs();
147 $this->assertArrayNotHasKey( 'rel', $attribs,
148 'External URL in sidebar do not have rel=nofollow when wgNoFollowLinks = false'
152 $wgNoFollowLinks = $saved;
156 * Test wgExternaLinkTarget in sidebar
158 function testRespectExternallinktarget() {
159 global $wgExternalLinkTarget;
160 $saved = $wgExternalLinkTarget;
162 $wgExternalLinkTarget = '_blank';
163 $attribs = $this->getAttribs();
164 $this->assertArrayHasKey( 'target', $attribs );
165 $this->assertEquals( $attribs['target'], '_blank' );
167 $wgExternalLinkTarget = '_self';
168 $attribs = $this->getAttribs();
169 $this->assertArrayHasKey( 'target', $attribs );
170 $this->assertEquals( $attribs['target'], '_self' );
173 $wgExternalLinkTarget = $saved;