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() {
93 $this->setMwGlobals( array(
94 'wgNoFollowLinks' => true,
95 'wgNoFollowDomainExceptions' => array(),
96 'wgNoFollowNsExceptions' => array(),
99 array( 'Title' => array(
100 # ** http://www.mediawiki.org/| Home
103 'href' => 'http://www.mediawiki.org/',
108 # ** http://valid.no.desc.org/
109 # ... skipped since it is missing a pipe with a description
112 ** http://www.mediawiki.org/| Home
113 ** http://valid.no.desc.org/
119 * bug 33321 - Make sure there's a | after transforming.
121 * @covers SkinTemplate::addToSidebarPlain
123 public function testTrickyPipe() {
124 $this->assertSidebar(
125 array( 'Title' => array(
126 # The first 2 are skipped
127 # Doesn't really test the url properly
128 # because it will vary with $wgArticlePath et al.
132 'href' => Title
::newFromText( 'Baz' )->getLocalURL(),
137 'text' => 'title-to-display',
138 'href' => Title
::newFromText( 'page-to-go-to' )->getLocalURL(),
139 'id' => 'n-title-to-display',
147 ** {{PLURAL:1|page-to-go-to{{int:pipe-separator/en}}title-to-display|branch not taken}}
152 #### Attributes for external links ##########################
153 private function getAttribs() {
154 # Sidebar text we will use everytime
156 ** http://www.mediawiki.org/| Home';
159 $this->skin
->addToSideBarPlain( $bar, $text );
161 return $bar['Title'][0];
165 * Simple test to verify our helper assertAttribs() is functional
167 public function testTestAttributesAssertionHelper() {
168 $this->setMwGlobals( array(
169 'wgNoFollowLinks' => true,
170 'wgNoFollowDomainExceptions' => array(),
171 'wgNoFollowNsExceptions' => array(),
172 'wgExternalLinkTarget' => false,
174 $attribs = $this->getAttribs();
176 $this->assertArrayHasKey( 'rel', $attribs );
177 $this->assertEquals( 'nofollow', $attribs['rel'] );
179 $this->assertArrayNotHasKey( 'target', $attribs );
183 * Test $wgNoFollowLinks in sidebar
185 public function testRespectWgnofollowlinks() {
186 $this->setMwGlobals( 'wgNoFollowLinks', false );
188 $attribs = $this->getAttribs();
189 $this->assertArrayNotHasKey( 'rel', $attribs,
190 'External URL in sidebar do not have rel=nofollow when $wgNoFollowLinks = false'
195 * Test $wgExternaLinkTarget in sidebar
196 * @dataProvider dataRespectExternallinktarget
198 public function testRespectExternallinktarget( $externalLinkTarget ) {
199 $this->setMwGlobals( 'wgExternalLinkTarget', $externalLinkTarget );
201 $attribs = $this->getAttribs();
202 $this->assertArrayHasKey( 'target', $attribs );
203 $this->assertEquals( $attribs['target'], $externalLinkTarget );
206 public static function dataRespectExternallinktarget() {