6 class SideBarTest
extends MediaWikiLangTestCase
{
9 * A skin template, reinitialized before each test
13 /** Local cache for sidebar messages */
16 /** Build $this->messages array */
17 private function initMessagesHref() {
18 # List of default messages for the sidebar:
19 $URL_messages = array(
28 foreach ( $URL_messages as $m ) {
29 $titleName = MessageCache
::singleton()->get( $m );
30 $title = Title
::newFromText( $titleName );
31 $this->messages
[$m]['href'] = $title->getLocalURL();
35 protected function setUp() {
37 $this->initMessagesHref();
38 $this->skin
= new SkinTemplate();
39 $this->skin
->getContext()->setLanguage( Language
::factory( 'en' ) );
43 * Internal helper to test the sidebar
46 * @param $message (Default: '')
47 * @todo this assert method to should be converted to a test using a dataprovider..
49 private function assertSideBar( $expected, $text, $message = '' ) {
51 $this->skin
->addToSidebarPlain( $bar, $text );
52 $this->assertEquals( $expected, $bar, $message );
56 * @covers SkinTemplate::addToSidebarPlain
58 public function testSidebarWithOnlyTwoTitles() {
71 * @covers SkinTemplate::addToSidebarPlain
73 public function testExpandMessages() {
75 array( 'Title' => array(
78 'href' => $this->messages
['helppage']['href'],
90 * @covers SkinTemplate::addToSidebarPlain
92 public function testExternalUrlsRequireADescription() {
94 array( 'Title' => array(
95 # ** http://www.mediawiki.org/| Home
98 'href' => 'http://www.mediawiki.org/',
103 # ** http://valid.no.desc.org/
104 # ... skipped since it is missing a pipe with a description
107 ** http://www.mediawiki.org/| Home
108 ** http://valid.no.desc.org/
114 * bug 33321 - Make sure there's a | after transforming.
116 * @covers SkinTemplate::addToSidebarPlain
118 public function testTrickyPipe() {
119 $this->assertSidebar(
120 array( 'Title' => array(
121 # The first 2 are skipped
122 # Doesn't really test the url properly
123 # because it will vary with $wgArticlePath et al.
127 'href' => Title
::newFromText( 'Baz' )->getLocalURL(),
132 'text' => 'title-to-display',
133 'href' => Title
::newFromText( 'page-to-go-to' )->getLocalURL(),
134 'id' => 'n-title-to-display',
142 ** {{PLURAL:1|page-to-go-to{{int:pipe-separator/en}}title-to-display|branch not taken}}
147 #### Attributes for external links ##########################
148 private function getAttribs() {
149 # Sidebar text we will use everytime
151 ** http://www.mediawiki.org/| Home';
154 $this->skin
->addToSideBarPlain( $bar, $text );
156 return $bar['Title'][0];
160 * Simple test to verify our helper assertAttribs() is functional
162 public function testTestAttributesAssertionHelper() {
163 $this->setMwGlobals( array(
164 'wgNoFollowLinks' => true,
165 'wgExternalLinkTarget' => false,
167 $attribs = $this->getAttribs();
169 $this->assertArrayHasKey( 'rel', $attribs );
170 $this->assertEquals( 'nofollow', $attribs['rel'] );
172 $this->assertArrayNotHasKey( 'target', $attribs );
176 * Test $wgNoFollowLinks in sidebar
178 public function testRespectWgnofollowlinks() {
179 $this->setMwGlobals( 'wgNoFollowLinks', false );
181 $attribs = $this->getAttribs();
182 $this->assertArrayNotHasKey( 'rel', $attribs,
183 'External URL in sidebar do not have rel=nofollow when $wgNoFollowLinks = false'
188 * Test $wgExternaLinkTarget in sidebar
189 * @dataProvider dataRespectExternallinktarget
191 public function testRespectExternallinktarget( $externalLinkTarget ) {
192 $this->setMwGlobals( 'wgExternalLinkTarget', $externalLinkTarget );
194 $attribs = $this->getAttribs();
195 $this->assertArrayHasKey( 'target', $attribs );
196 $this->assertEquals( $attribs['target'], $externalLinkTarget );
199 public static function dataRespectExternallinktarget() {