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. The sidebar doesn't care at
19 # all whether they are full URLs, interwiki links or local titles.
20 $URL_messages = array(
29 # We're assuming that isValidURI works as advertised: it's also
30 # tested separately, in tests/phpunit/includes/HttpTest.php.
31 foreach ( $URL_messages as $m ) {
32 $titleName = MessageCache
::singleton()->get( $m );
33 if ( Http
::isValidURI( $titleName ) ) {
34 $this->messages
[$m]['href'] = $titleName;
36 $title = Title
::newFromText( $titleName );
37 $this->messages
[$m]['href'] = $title->getLocalURL();
42 protected function setUp() {
44 $this->initMessagesHref();
45 $this->skin
= new SkinTemplate();
46 $this->skin
->getContext()->setLanguage( Language
::factory( 'en' ) );
50 * Internal helper to test the sidebar
51 * @param array $expected
53 * @param string $message (Default: '')
54 * @todo this assert method to should be converted to a test using a dataprovider..
56 private function assertSideBar( $expected, $text, $message = '' ) {
58 $this->skin
->addToSidebarPlain( $bar, $text );
59 $this->assertEquals( $expected, $bar, $message );
63 * @covers SkinTemplate::addToSidebarPlain
65 public function testSidebarWithOnlyTwoTitles() {
78 * @covers SkinTemplate::addToSidebarPlain
80 public function testExpandMessages() {
82 array( 'Title' => array(
85 'href' => $this->messages
['helppage']['href'],
97 * @covers SkinTemplate::addToSidebarPlain
99 public function testExternalUrlsRequireADescription() {
100 $this->setMwGlobals( array(
101 'wgNoFollowLinks' => true,
102 'wgNoFollowDomainExceptions' => array(),
103 'wgNoFollowNsExceptions' => array(),
105 $this->assertSidebar(
106 array( 'Title' => array(
107 # ** http://www.mediawiki.org/| Home
110 'href' => 'http://www.mediawiki.org/',
115 # ** http://valid.no.desc.org/
116 # ... skipped since it is missing a pipe with a description
119 ** http://www.mediawiki.org/| Home
120 ** http://valid.no.desc.org/
126 * bug 33321 - Make sure there's a | after transforming.
128 * @covers SkinTemplate::addToSidebarPlain
130 public function testTrickyPipe() {
131 $this->assertSidebar(
132 array( 'Title' => array(
133 # The first 2 are skipped
134 # Doesn't really test the url properly
135 # because it will vary with $wgArticlePath et al.
139 'href' => Title
::newFromText( 'Baz' )->getLocalURL(),
144 'text' => 'title-to-display',
145 'href' => Title
::newFromText( 'page-to-go-to' )->getLocalURL(),
146 'id' => 'n-title-to-display',
154 ** {{PLURAL:1|page-to-go-to{{int:pipe-separator/en}}title-to-display|branch not taken}}
159 #### Attributes for external links ##########################
160 private function getAttribs() {
161 # Sidebar text we will use everytime
163 ** http://www.mediawiki.org/| Home';
166 $this->skin
->addToSideBarPlain( $bar, $text );
168 return $bar['Title'][0];
172 * Simple test to verify our helper assertAttribs() is functional
174 public function testTestAttributesAssertionHelper() {
175 $this->setMwGlobals( array(
176 'wgNoFollowLinks' => true,
177 'wgNoFollowDomainExceptions' => array(),
178 'wgNoFollowNsExceptions' => array(),
179 'wgExternalLinkTarget' => false,
181 $attribs = $this->getAttribs();
183 $this->assertArrayHasKey( 'rel', $attribs );
184 $this->assertEquals( 'nofollow', $attribs['rel'] );
186 $this->assertArrayNotHasKey( 'target', $attribs );
190 * Test $wgNoFollowLinks in sidebar
192 public function testRespectWgnofollowlinks() {
193 $this->setMwGlobals( 'wgNoFollowLinks', false );
195 $attribs = $this->getAttribs();
196 $this->assertArrayNotHasKey( 'rel', $attribs,
197 'External URL in sidebar do not have rel=nofollow when $wgNoFollowLinks = false'
202 * Test $wgExternaLinkTarget in sidebar
203 * @dataProvider dataRespectExternallinktarget
205 public function testRespectExternallinktarget( $externalLinkTarget ) {
206 $this->setMwGlobals( 'wgExternalLinkTarget', $externalLinkTarget );
208 $attribs = $this->getAttribs();
209 $this->assertArrayHasKey( 'target', $attribs );
210 $this->assertEquals( $attribs['target'], $externalLinkTarget );
213 public static function dataRespectExternallinktarget() {