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()->setLanguage( 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
* bug 33321 - Make sure there's a | after transforming.
113
function testTrickyPipe() {
114
$this->assertSidebar(
115
array( 'Title' => array(
116
# The first 2 are skipped
117
# Doesn't really test the url properly
118
# because it will vary with $wgArticlePath et al.
122
'href' => Title::newFromText( 'Baz' )->getLocalUrl(),
127
'text' => 'title-to-display',
128
'href' => Title::newFromText( 'page-to-go-to' )->getLocalUrl(),
129
'id' => 'n-title-to-display',
137
** {{PLURAL:1|page-to-go-to{{int:pipe-separator/en}}title-to-display|branch not taken}}
144
#### Attributes for external links ##########################
145
private function getAttribs( ) {
146
# Sidebar text we will use everytime
148
** http://www.mediawiki.org/| Home';
151
$this->skin->addToSideBarPlain( $bar, $text );
153
return $bar['Title'][0];
157
* Simple test to verify our helper assertAttribs() is functional
158
* Please note this assume MediaWiki default settings:
159
* $wgNoFollowLinks = true
160
* $wgExternalLinkTarget = false
162
function testTestAttributesAssertionHelper() {
163
$attribs = $this->getAttribs();
165
$this->assertArrayHasKey( 'rel', $attribs );
166
$this->assertEquals( 'nofollow', $attribs['rel'] );
168
$this->assertArrayNotHasKey( 'target', $attribs );
172
* Test $wgNoFollowLinks in sidebar
174
function testRespectWgnofollowlinks() {
175
global $wgNoFollowLinks;
176
$saved = $wgNoFollowLinks;
177
$wgNoFollowLinks = false;
179
$attribs = $this->getAttribs();
180
$this->assertArrayNotHasKey( 'rel', $attribs,
181
'External URL in sidebar do not have rel=nofollow when $wgNoFollowLinks = false'
185
$wgNoFollowLinks = $saved;
189
* Test $wgExternaLinkTarget in sidebar
191
function testRespectExternallinktarget() {
192
global $wgExternalLinkTarget;
193
$saved = $wgExternalLinkTarget;
195
$wgExternalLinkTarget = '_blank';
196
$attribs = $this->getAttribs();
197
$this->assertArrayHasKey( 'target', $attribs );
198
$this->assertEquals( $attribs['target'], '_blank' );
200
$wgExternalLinkTarget = '_self';
201
$attribs = $this->getAttribs();
202
$this->assertArrayHasKey( 'target', $attribs );
203
$this->assertEquals( $attribs['target'], '_self' );
206
$wgExternalLinkTarget = $saved;