r97830 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97829‎ | r97830 | r97831 >
Date:17:39, 22 September 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Copy SideBarTest from trunk for bug 3110
Modified paths:
  • /branches/REL1_18/phase3/tests/phpunit/skins/SideBarTest.php (added) (history)

Diff [purge]

Index: branches/REL1_18/phase3/tests/phpunit/skins/SideBarTest.php
@@ -0,0 +1,175 @@
 2+<?php
 3+
 4+/**
 5+ * @group Skin
 6+ */
 7+class SideBarTest extends MediaWikiLangTestCase {
 8+
 9+ /** A skin template, reinitialized before each test */
 10+ private $skin;
 11+ /** Local cache for sidebar messages */
 12+ private $messages;
 13+
 14+ function __construct() {
 15+ parent::__construct();
 16+ }
 17+
 18+ /** Build $this->messages array */
 19+ private function initMessagesHref() {
 20+ # List of default messages for the sidebar:
 21+ $URL_messages = array(
 22+ 'mainpage',
 23+ 'portal-url',
 24+ 'currentevents-url',
 25+ 'recentchanges-url',
 26+ 'randompage-url',
 27+ 'helppage',
 28+ );
 29+
 30+ foreach( $URL_messages as $m ) {
 31+ $titleName = MessageCache::singleton()->get($m);
 32+ $title = Title::newFromText( $titleName );
 33+ $this->messages[$m]['href'] = $title->getLocalURL();
 34+ }
 35+ }
 36+
 37+ function setUp() {
 38+ parent::setUp();
 39+ $this->initMessagesHref();
 40+ $this->skin = new SkinTemplate();
 41+ }
 42+ function tearDown() {
 43+ parent::tearDown();
 44+ $this->skin = null;
 45+ }
 46+
 47+ /**
 48+ * Internal helper to test the sidebar
 49+ * @param $expected
 50+ * @param $text
 51+ * @param $message (Default: '')
 52+ */
 53+ private function assertSideBar( $expected, $text, $message = '' ) {
 54+ $bar = array();
 55+ $this->skin->addToSidebarPlain( $bar, $text );
 56+ $this->assertEquals( $expected, $bar, $message );
 57+ }
 58+
 59+ function testSidebarWithOnlyTwoTitles() {
 60+ $this->assertSideBar(
 61+ array(
 62+ 'Title1' => array(),
 63+ 'Title2' => array(),
 64+ ),
 65+'* Title1
 66+* Title2
 67+'
 68+ );
 69+ }
 70+
 71+ function testExpandMessages() {
 72+ $this->assertSidebar(
 73+ array( 'Title' => array(
 74+ array(
 75+ 'text' => 'Help',
 76+ 'href' => $this->messages['helppage']['href'],
 77+ 'id' => 'n-help',
 78+ 'active' => null
 79+ )
 80+ )),
 81+'* Title
 82+** helppage|help
 83+'
 84+ );
 85+ }
 86+
 87+ function testExternalUrlsRequireADescription() {
 88+ $this->assertSidebar(
 89+ array( 'Title' => array(
 90+ # ** http://www.mediawiki.org/| Home
 91+ array(
 92+ 'text' => 'Home',
 93+ 'href' => 'http://www.mediawiki.org/',
 94+ 'id' => 'n-Home',
 95+ 'active' => null,
 96+ 'rel' => 'nofollow',
 97+ ),
 98+ # ** http://valid.no.desc.org/
 99+ # ... skipped since it is missing a pipe with a description
 100+ )),
 101+'* Title
 102+** http://www.mediawiki.org/| Home
 103+** http://valid.no.desc.org/
 104+'
 105+
 106+ );
 107+
 108+ }
 109+
 110+
 111+ #### Attributes for external links ##########################
 112+ private function getAttribs( ) {
 113+ # Sidebar text we will use everytime
 114+ $text = '* Title
 115+** http://www.mediawiki.org/| Home';
 116+
 117+ $bar = array();
 118+ $this->skin->addToSideBarPlain( $bar, $text );
 119+
 120+ return $bar['Title'][0];
 121+ }
 122+
 123+ /**
 124+ * Simple test to verify our helper assertAttribs() is functional
 125+ * Please note this assume MediaWiki default settings:
 126+ * $wgNoFollowLinks = true
 127+ * $wgExternalLinkTarget = false
 128+ */
 129+ function testTestAttributesAssertionHelper() {
 130+ $attribs = $this->getAttribs();
 131+
 132+ $this->assertArrayHasKey( 'rel', $attribs );
 133+ $this->assertEquals( 'nofollow', $attribs['rel'] );
 134+
 135+ $this->assertArrayNotHasKey( 'target', $attribs );
 136+ }
 137+
 138+ /**
 139+ * Test wgNoFollowLinks in sidebar
 140+ */
 141+ function testRespectWgnofollowlinks() {
 142+ global $wgNoFollowLinks;
 143+ $saved = $wgNoFollowLinks;
 144+ $wgNoFollowLinks = false;
 145+
 146+ $attribs = $this->getAttribs();
 147+ $this->assertArrayNotHasKey( 'rel', $attribs,
 148+ 'External URL in sidebar do not have rel=nofollow when wgNoFollowLinks = false'
 149+ );
 150+
 151+ // Restore global
 152+ $wgNoFollowLinks = $saved;
 153+ }
 154+
 155+ /**
 156+ * Test wgExternaLinkTarget in sidebar
 157+ */
 158+ function testRespectExternallinktarget() {
 159+ global $wgExternalLinkTarget;
 160+ $saved = $wgExternalLinkTarget;
 161+
 162+ $wgExternalLinkTarget = '_blank';
 163+ $attribs = $this->getAttribs();
 164+ $this->assertArrayHasKey( 'target', $attribs );
 165+ $this->assertEquals( $attribs['target'], '_blank' );
 166+
 167+ $wgExternalLinkTarget = '_self';
 168+ $attribs = $this->getAttribs();
 169+ $this->assertArrayHasKey( 'target', $attribs );
 170+ $this->assertEquals( $attribs['target'], '_self' );
 171+
 172+ // Restore global
 173+ $wgExternalLinkTarget = $saved;
 174+ }
 175+
 176+}
Property changes on: branches/REL1_18/phase3/tests/phpunit/skins/SideBarTest.php
___________________________________________________________________
Added: svn:eol-style
1177 + native

Comments

#Comment by Aaron Schulz (talk | contribs)   17:40, 22 September 2011

Wrong bug number?

#Comment by Reedy (talk | contribs)   17:41, 22 September 2011

Yup, bug 31100

reedy@ubuntu64-esxi:~/mediawiki/branches/REL1_18/phase3/tests/phpunit$ php phpunit.php skins/SideBarTest.php
PHPUnit 3.5.15 by Sebastian Bergmann.

......

Time: 0 seconds, Memory: 29.50Mb

OK (6 tests, 11 assertions)

Status & tagging log