r61945 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61944‎ | r61945 | r61946 >
Date:19:21, 3 February 2010
Author:maxsem
Status:ok (Comments)
Tags:
Comment:
Moved tests to maintenance - one directory less to care about when configuring access.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/maintenance/tests (added) (history)
  • /trunk/phase3/maintenance/tests/.htaccess (deleted) (history)
  • /trunk/phase3/maintenance/tests/bootstrap.php (modified) (history)
  • /trunk/phase3/tests (deleted) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/LocalFileTest.php
@@ -0,0 +1,99 @@
 2+<?php
 3+
 4+/**
 5+ * These tests should work regardless of $wgCapitalLinks
 6+ */
 7+
 8+require_once( 'Namespace.php' );
 9+
 10+class LocalFileTest extends PHPUnit_Framework_TestCase {
 11+ function setUp() {
 12+ global $wgContLang;
 13+ $wgContLang = new Language;
 14+ $info = array(
 15+ 'name' => 'test',
 16+ 'directory' => '/testdir',
 17+ 'url' => '/testurl',
 18+ 'hashLevels' => 2,
 19+ 'transformVia404' => false,
 20+ );
 21+ $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
 22+ $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
 23+ $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
 24+ $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
 25+ $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
 26+ $this->file_lc = $this->repo_lc->newFile( 'test!' );
 27+ }
 28+
 29+ function tearDown() {
 30+ global $wgContLang;
 31+ unset($wgContLang);
 32+ }
 33+
 34+ function testGetHashPath() {
 35+ $this->assertEquals( '', $this->file_hl0->getHashPath() );
 36+ $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
 37+ $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
 38+ }
 39+
 40+ function testGetRel() {
 41+ $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
 42+ $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
 43+ $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
 44+ }
 45+
 46+ function testGetUrlRel() {
 47+ $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
 48+ $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
 49+ $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
 50+ }
 51+
 52+ function testGetArchivePath() {
 53+ $this->assertEquals( '/testdir/archive', $this->file_hl0->getArchivePath() );
 54+ $this->assertEquals( '/testdir/archive/a/a2', $this->file_hl2->getArchivePath() );
 55+ $this->assertEquals( '/testdir/archive/!', $this->file_hl0->getArchivePath( '!' ) );
 56+ $this->assertEquals( '/testdir/archive/a/a2/!', $this->file_hl2->getArchivePath( '!' ) );
 57+ }
 58+
 59+ function testGetThumbPath() {
 60+ $this->assertEquals( '/testdir/thumb/Test!', $this->file_hl0->getThumbPath() );
 61+ $this->assertEquals( '/testdir/thumb/a/a2/Test!', $this->file_hl2->getThumbPath() );
 62+ $this->assertEquals( '/testdir/thumb/Test!/x', $this->file_hl0->getThumbPath( 'x' ) );
 63+ $this->assertEquals( '/testdir/thumb/a/a2/Test!/x', $this->file_hl2->getThumbPath( 'x' ) );
 64+ }
 65+
 66+ function testGetArchiveUrl() {
 67+ $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
 68+ $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
 69+ $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
 70+ $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
 71+ }
 72+
 73+ function testGetThumbUrl() {
 74+ $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
 75+ $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
 76+ $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
 77+ $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
 78+ }
 79+
 80+ function testGetArchiveVirtualUrl() {
 81+ $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
 82+ $this->assertEquals( 'mwrepo://test/public/archive/a/a2', $this->file_hl2->getArchiveVirtualUrl() );
 83+ $this->assertEquals( 'mwrepo://test/public/archive/%21', $this->file_hl0->getArchiveVirtualUrl( '!' ) );
 84+ $this->assertEquals( 'mwrepo://test/public/archive/a/a2/%21', $this->file_hl2->getArchiveVirtualUrl( '!' ) );
 85+ }
 86+
 87+ function testGetThumbVirtualUrl() {
 88+ $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
 89+ $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
 90+ $this->assertEquals( 'mwrepo://test/thumb/Test%21/%21', $this->file_hl0->getThumbVirtualUrl( '!' ) );
 91+ $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21/%21', $this->file_hl2->getThumbVirtualUrl( '!' ) );
 92+ }
 93+
 94+ function testGetUrl() {
 95+ $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
 96+ $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
 97+ }
 98+}
 99+
 100+
Property changes on: trunk/phase3/maintenance/tests/LocalFileTest.php
___________________________________________________________________
Name: svn:eol-style
1101 + native
Index: trunk/phase3/maintenance/tests/SearchEngineTest.php
@@ -0,0 +1,138 @@
 2+<?php
 3+
 4+require_once( 'MediaWiki_TestCase.php' );
 5+
 6+/** @todo document
 7+ */
 8+
 9+class SearchEngineTest extends MediaWiki_TestCase {
 10+ var $db, $search;
 11+
 12+ function insertSearchData() {
 13+ $this->db->safeQuery( <<<SQL
 14+ INSERT INTO ! (page_id,page_namespace,page_title,page_latest)
 15+ VALUES (1, 0, 'Main_Page', 1),
 16+ (2, 1, 'Main_Page', 2),
 17+ (3, 0, 'Smithee', 3),
 18+ (4, 1, 'Smithee', 4),
 19+ (5, 0, 'Unrelated_page', 5),
 20+ (6, 0, 'Another_page', 6),
 21+ (7, 4, 'Help', 7),
 22+ (8, 0, 'Thppt', 8),
 23+ (9, 0, 'Alan_Smithee', 9),
 24+ (10, 0, 'Pages', 10)
 25+SQL
 26+ , $this->db->tableName( 'page' ) );
 27+ $this->db->safeQuery( <<<SQL
 28+ INSERT INTO ! (rev_id,rev_page)
 29+ VALUES (1, 1),
 30+ (2, 2),
 31+ (3, 3),
 32+ (4, 4),
 33+ (5, 5),
 34+ (6, 6),
 35+ (7, 7),
 36+ (8, 8),
 37+ (9, 9),
 38+ (10, 10)
 39+SQL
 40+ , $this->db->tableName( 'revision' ) );
 41+ $this->db->safeQuery( <<<SQL
 42+ INSERT INTO ! (old_id,old_text)
 43+ VALUES (1, 'This is a main page'),
 44+ (2, 'This is a talk page to the main page, see [[smithee]]'),
 45+ (3, 'A smithee is one who smiths. See also [[Alan Smithee]]'),
 46+ (4, 'This article sucks.'),
 47+ (5, 'Nothing in this page is about the S word.'),
 48+ (6, 'This page also is unrelated.'),
 49+ (7, 'Help me!'),
 50+ (8, 'Blah blah'),
 51+ (9, 'yum'),
 52+ (10,'are food')
 53+SQL
 54+ , $this->db->tableName( 'text' ) );
 55+ $this->db->safeQuery( <<<SQL
 56+ INSERT INTO ! (si_page,si_title,si_text)
 57+ VALUES (1, 'main page', 'this is a main page'),
 58+ (2, 'main page', 'this is a talk page to the main page, see smithee'),
 59+ (3, 'smithee', 'a smithee is one who smiths see also alan smithee'),
 60+ (4, 'smithee', 'this article sucks'),
 61+ (5, 'unrelated page', 'nothing in this page is about the s word'),
 62+ (6, 'another page', 'this page also is unrelated'),
 63+ (7, 'help', 'help me'),
 64+ (8, 'thppt', 'blah blah'),
 65+ (9, 'alan smithee', 'yum'),
 66+ (10, 'pages', 'are food')
 67+SQL
 68+ , $this->db->tableName( 'searchindex' ) );
 69+ }
 70+
 71+ function fetchIds( $results ) {
 72+ $matches = array();
 73+ while( $row = $results->next() ) {
 74+ $matches[] = $row->getTitle()->getPrefixedText();
 75+ }
 76+ $results->free();
 77+ # Search is not guaranteed to return results in a certain order;
 78+ # sort them numerically so we will compare simply that we received
 79+ # the expected matches.
 80+ sort( $matches );
 81+ return $matches;
 82+ }
 83+
 84+ function testTextSearch() {
 85+ if( is_null( $this->db ) ) {
 86+ $this->markTestIncomplete( "Can't find a database to test with." );
 87+ }
 88+ $this->assertEquals(
 89+ array( 'Smithee' ),
 90+ $this->fetchIds( $this->search->searchText( 'smithee' ) ),
 91+ "Plain search failed" );
 92+ }
 93+
 94+ function testTextPowerSearch() {
 95+ if( is_null( $this->db ) ) {
 96+ $this->markTestIncomplete( "Can't find a database to test with." );
 97+ }
 98+ $this->search->setNamespaces( array( 0, 1, 4 ) );
 99+ $this->assertEquals(
 100+ array(
 101+ 'Smithee',
 102+ 'Talk:Main Page',
 103+ ),
 104+ $this->fetchIds( $this->search->searchText( 'smithee' ) ),
 105+ "Power search failed" );
 106+ }
 107+
 108+ function testTitleSearch() {
 109+ if( is_null( $this->db ) ) {
 110+ $this->markTestIncomplete( "Can't find a database to test with." );
 111+ }
 112+ $this->assertEquals(
 113+ array(
 114+ 'Alan Smithee',
 115+ 'Smithee',
 116+ ),
 117+ $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
 118+ "Title search failed" );
 119+ }
 120+
 121+ function testTextTitlePowerSearch() {
 122+ if( is_null( $this->db ) ) {
 123+ $this->markTestIncomplete( "Can't find a database to test with." );
 124+ }
 125+ $this->search->setNamespaces( array( 0, 1, 4 ) );
 126+ $this->assertEquals(
 127+ array(
 128+ 'Alan Smithee',
 129+ 'Smithee',
 130+ 'Talk:Smithee',
 131+ ),
 132+ $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
 133+ "Title power search failed" );
 134+ }
 135+
 136+}
 137+
 138+
 139+
Property changes on: trunk/phase3/maintenance/tests/SearchEngineTest.php
___________________________________________________________________
Name: svn:keywords
1140 + Author Date Id Revision
Name: svn:eol-style
2141 + native
Index: trunk/phase3/maintenance/tests/SiteConfigurationTest.php
@@ -0,0 +1,311 @@
 2+<?php
 3+
 4+function getSiteParams( $conf, $wiki ) {
 5+ $site = null;
 6+ $lang = null;
 7+ foreach( $conf->suffixes as $suffix ) {
 8+ if ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
 9+ $site = $suffix;
 10+ $lang = substr( $wiki, 0, -strlen( $suffix ) );
 11+ break;
 12+ }
 13+ }
 14+ return array(
 15+ 'suffix' => $site,
 16+ 'lang' => $lang,
 17+ 'params' => array(
 18+ 'lang' => $lang,
 19+ 'site' => $site,
 20+ 'wiki' => $wiki,
 21+ ),
 22+ 'tags' => array( 'tag' ),
 23+ );
 24+}
 25+
 26+class SiteConfigurationTest extends PHPUnit_Framework_TestCase {
 27+ var $mConf;
 28+
 29+ function setUp() {
 30+ $this->mConf = new SiteConfiguration;
 31+
 32+ $this->mConf->suffixes = array( 'wiki' );
 33+ $this->mConf->wikis = array( 'enwiki', 'dewiki', 'frwiki' );
 34+ $this->mConf->settings = array(
 35+ 'simple' => array(
 36+ 'wiki' => 'wiki',
 37+ 'tag' => 'tag',
 38+ 'enwiki' => 'enwiki',
 39+ 'dewiki' => 'dewiki',
 40+ 'frwiki' => 'frwiki',
 41+ ),
 42+
 43+ 'fallback' => array(
 44+ 'default' => 'default',
 45+ 'wiki' => 'wiki',
 46+ 'tag' => 'tag',
 47+ ),
 48+
 49+ 'params' => array(
 50+ 'default' => '$lang $site $wiki',
 51+ ),
 52+
 53+ '+global' => array(
 54+ 'wiki' => array(
 55+ 'wiki' => 'wiki',
 56+ ),
 57+ 'tag' => array(
 58+ 'tag' => 'tag',
 59+ ),
 60+ 'enwiki' => array(
 61+ 'enwiki' => 'enwiki',
 62+ ),
 63+ 'dewiki' => array(
 64+ 'dewiki' => 'dewiki',
 65+ ),
 66+ 'frwiki' => array(
 67+ 'frwiki' => 'frwiki',
 68+ ),
 69+ ),
 70+
 71+ 'merge' => array(
 72+ '+wiki' => array(
 73+ 'wiki' => 'wiki',
 74+ ),
 75+ '+tag' => array(
 76+ 'tag' => 'tag',
 77+ ),
 78+ 'default' => array(
 79+ 'default' => 'default',
 80+ ),
 81+ '+enwiki' => array(
 82+ 'enwiki' => 'enwiki',
 83+ ),
 84+ '+dewiki' => array(
 85+ 'dewiki' => 'dewiki',
 86+ ),
 87+ '+frwiki' => array(
 88+ 'frwiki' => 'frwiki',
 89+ ),
 90+ ),
 91+ );
 92+
 93+ $GLOBALS['global'] = array( 'global' => 'global' );
 94+ }
 95+
 96+
 97+ function testSiteFromDB() {
 98+ $this->assertEquals(
 99+ array( 'wikipedia', 'en' ),
 100+ $this->mConf->siteFromDB( 'enwiki' ),
 101+ 'siteFromDB()'
 102+ );
 103+ $this->assertEquals(
 104+ array( 'wikipedia', '' ),
 105+ $this->mConf->siteFromDB( 'wiki' ),
 106+ 'siteFromDB() on a suffix'
 107+ );
 108+ $this->assertEquals(
 109+ array( null, null ),
 110+ $this->mConf->siteFromDB( 'wikien' ),
 111+ 'siteFromDB() on a non-existing wiki'
 112+ );
 113+
 114+ $this->mConf->suffixes = array( 'wiki', '' );
 115+ $this->assertEquals(
 116+ array( '', 'wikien' ),
 117+ $this->mConf->siteFromDB( 'wikien' ),
 118+ 'siteFromDB() on a non-existing wiki (2)'
 119+ );
 120+ }
 121+
 122+ function testGetLocalDatabases() {
 123+ $this->assertEquals(
 124+ array( 'enwiki', 'dewiki', 'frwiki' ),
 125+ $this->mConf->getLocalDatabases(),
 126+ 'getLocalDatabases()'
 127+ );
 128+ }
 129+
 130+ function testGet() {
 131+ $this->assertEquals(
 132+ 'enwiki',
 133+ $this->mConf->get( 'simple', 'enwiki', 'wiki' ),
 134+ 'get(): simple setting on an existing wiki'
 135+ );
 136+ $this->assertEquals(
 137+ 'dewiki',
 138+ $this->mConf->get( 'simple', 'dewiki', 'wiki' ),
 139+ 'get(): simple setting on an existing wiki (2)'
 140+ );
 141+ $this->assertEquals(
 142+ 'frwiki',
 143+ $this->mConf->get( 'simple', 'frwiki', 'wiki' ),
 144+ 'get(): simple setting on an existing wiki (3)'
 145+ );
 146+ $this->assertEquals(
 147+ 'wiki',
 148+ $this->mConf->get( 'simple', 'wiki', 'wiki' ),
 149+ 'get(): simple setting on an suffix'
 150+ );
 151+ $this->assertEquals(
 152+ 'wiki',
 153+ $this->mConf->get( 'simple', 'eswiki', 'wiki' ),
 154+ 'get(): simple setting on an non-existing wiki'
 155+ );
 156+
 157+ $this->assertEquals(
 158+ 'wiki',
 159+ $this->mConf->get( 'fallback', 'enwiki', 'wiki' ),
 160+ 'get(): fallback setting on an existing wiki'
 161+ );
 162+ $this->assertEquals(
 163+ 'tag',
 164+ $this->mConf->get( 'fallback', 'dewiki', 'wiki', array(), array( 'tag' ) ),
 165+ 'get(): fallback setting on an existing wiki (with wiki tag)'
 166+ );
 167+ $this->assertEquals(
 168+ 'wiki',
 169+ $this->mConf->get( 'fallback', 'wiki', 'wiki' ),
 170+ 'get(): fallback setting on an suffix'
 171+ );
 172+ $this->assertEquals(
 173+ 'wiki',
 174+ $this->mConf->get( 'fallback', 'wiki', 'wiki', array(), array( 'tag' ) ),
 175+ 'get(): fallback setting on an suffix (with wiki tag)'
 176+ );
 177+ $this->assertEquals(
 178+ 'wiki',
 179+ $this->mConf->get( 'fallback', 'eswiki', 'wiki' ),
 180+ 'get(): fallback setting on an non-existing wiki'
 181+ );
 182+ $this->assertEquals(
 183+ 'tag',
 184+ $this->mConf->get( 'fallback', 'eswiki', 'wiki', array(), array( 'tag' ) ),
 185+ 'get(): fallback setting on an non-existing wiki (with wiki tag)'
 186+ );
 187+
 188+ $common = array( 'wiki' => 'wiki', 'default' => 'default' );
 189+ $commonTag = array( 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' );
 190+ $this->assertEquals(
 191+ array( 'enwiki' => 'enwiki' ) + $common,
 192+ $this->mConf->get( 'merge', 'enwiki', 'wiki' ),
 193+ 'get(): merging setting on an existing wiki'
 194+ );
 195+ $this->assertEquals(
 196+ array( 'enwiki' => 'enwiki' ) + $commonTag,
 197+ $this->mConf->get( 'merge', 'enwiki', 'wiki', array(), array( 'tag' ) ),
 198+ 'get(): merging setting on an existing wiki (with tag)'
 199+ );
 200+ $this->assertEquals(
 201+ array( 'dewiki' => 'dewiki' ) + $common,
 202+ $this->mConf->get( 'merge', 'dewiki', 'wiki' ),
 203+ 'get(): merging setting on an existing wiki (2)'
 204+ );
 205+ $this->assertEquals(
 206+ array( 'dewiki' => 'dewiki' ) + $commonTag,
 207+ $this->mConf->get( 'merge', 'dewiki', 'wiki', array(), array( 'tag' ) ),
 208+ 'get(): merging setting on an existing wiki (2) (with tag)'
 209+ );
 210+ $this->assertEquals(
 211+ array( 'frwiki' => 'frwiki' ) + $common,
 212+ $this->mConf->get( 'merge', 'frwiki', 'wiki' ),
 213+ 'get(): merging setting on an existing wiki (3)'
 214+ );
 215+ $this->assertEquals(
 216+ array( 'frwiki' => 'frwiki' ) + $commonTag,
 217+ $this->mConf->get( 'merge', 'frwiki', 'wiki', array(), array( 'tag' ) ),
 218+ 'get(): merging setting on an existing wiki (3) (with tag)'
 219+ );
 220+ $this->assertEquals(
 221+ array( 'wiki' => 'wiki' ) + $common,
 222+ $this->mConf->get( 'merge', 'wiki', 'wiki' ),
 223+ 'get(): merging setting on an suffix'
 224+ );
 225+ $this->assertEquals(
 226+ array( 'wiki' => 'wiki' ) + $commonTag,
 227+ $this->mConf->get( 'merge', 'wiki', 'wiki', array(), array( 'tag' ) ),
 228+ 'get(): merging setting on an suffix (with tag)'
 229+ );
 230+ $this->assertEquals(
 231+ $common,
 232+ $this->mConf->get( 'merge', 'eswiki', 'wiki' ),
 233+ 'get(): merging setting on an non-existing wiki'
 234+ );
 235+ $this->assertEquals(
 236+ $commonTag,
 237+ $this->mConf->get( 'merge', 'eswiki', 'wiki', array(), array( 'tag' ) ),
 238+ 'get(): merging setting on an non-existing wiki (with tag)'
 239+ );
 240+ }
 241+
 242+ function testSiteFromDBWithCallback() {
 243+ $this->mConf->siteParamsCallback = 'getSiteParams';
 244+
 245+ $this->assertEquals(
 246+ array( 'wiki', 'en' ),
 247+ $this->mConf->siteFromDB( 'enwiki' ),
 248+ 'siteFromDB() with callback'
 249+ );
 250+ $this->assertEquals(
 251+ array( 'wiki', '' ),
 252+ $this->mConf->siteFromDB( 'wiki' ),
 253+ 'siteFromDB() with callback on a suffix'
 254+ );
 255+ $this->assertEquals(
 256+ array( null, null ),
 257+ $this->mConf->siteFromDB( 'wikien' ),
 258+ 'siteFromDB() with callback on a non-existing wiki'
 259+ );
 260+ }
 261+
 262+ function testParamReplacement() {
 263+ $this->mConf->siteParamsCallback = 'getSiteParams';
 264+
 265+ $this->assertEquals(
 266+ 'en wiki enwiki',
 267+ $this->mConf->get( 'params', 'enwiki', 'wiki' ),
 268+ 'get(): parameter replacement on an existing wiki'
 269+ );
 270+ $this->assertEquals(
 271+ 'de wiki dewiki',
 272+ $this->mConf->get( 'params', 'dewiki', 'wiki' ),
 273+ 'get(): parameter replacement on an existing wiki (2)'
 274+ );
 275+ $this->assertEquals(
 276+ 'fr wiki frwiki',
 277+ $this->mConf->get( 'params', 'frwiki', 'wiki' ),
 278+ 'get(): parameter replacement on an existing wiki (3)'
 279+ );
 280+ $this->assertEquals(
 281+ ' wiki wiki',
 282+ $this->mConf->get( 'params', 'wiki', 'wiki' ),
 283+ 'get(): parameter replacement on an suffix'
 284+ );
 285+ $this->assertEquals(
 286+ 'es wiki eswiki',
 287+ $this->mConf->get( 'params', 'eswiki', 'wiki' ),
 288+ 'get(): parameter replacement on an non-existing wiki'
 289+ );
 290+ }
 291+
 292+ function testGetAll() {
 293+ $this->mConf->siteParamsCallback = 'getSiteParams';
 294+
 295+ $getall = array(
 296+ 'simple' => 'enwiki',
 297+ 'fallback' => 'tag',
 298+ 'params' => 'en wiki enwiki',
 299+ 'global' => array( 'enwiki' => 'enwiki' ) + $GLOBALS['global'],
 300+ 'merge' => array( 'enwiki' => 'enwiki', 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' ),
 301+ );
 302+ $this->assertEquals( $getall, $this->mConf->getAll( 'enwiki' ), 'getAll()' );
 303+
 304+ $this->mConf->extractAllGlobals( 'enwiki', 'wiki' );
 305+
 306+ $this->assertEquals( $getall['simple'], $GLOBALS['simple'], 'extractAllGlobals(): simple setting' );
 307+ $this->assertEquals( $getall['fallback'], $GLOBALS['fallback'], 'extractAllGlobals(): fallback setting' );
 308+ $this->assertEquals( $getall['params'], $GLOBALS['params'], 'extractAllGlobals(): parameter replacement' );
 309+ $this->assertEquals( $getall['global'], $GLOBALS['global'], 'extractAllGlobals(): merging with global' );
 310+ $this->assertEquals( $getall['merge'], $GLOBALS['merge'], 'extractAllGlobals(): merging setting' );
 311+ }
 312+}
Property changes on: trunk/phase3/maintenance/tests/SiteConfigurationTest.php
___________________________________________________________________
Name: svn:eol-style
1313 + native
Index: trunk/phase3/maintenance/tests/MediaWikiAPITest.php
@@ -0,0 +1,74 @@
 2+<?php
 3+
 4+require_once( "MediaWikiAPI_TestCase.php" );
 5+
 6+class MediaWikiAPITest extends MediaWikiAPI_TestCase {
 7+
 8+ function setup() {
 9+ parent::setup();
 10+ }
 11+
 12+ function testApi() {
 13+ /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */
 14+ $resp = Http::get( self::$apiUrl . "?format=xml" );
 15+
 16+ libxml_use_internal_errors( true );
 17+ $sxe = simplexml_load_string( $resp );
 18+ $this->assertNotType( "bool", $sxe );
 19+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
 20+ }
 21+
 22+ function testApiLoginNoName() {
 23+ $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
 24+ array( "postData" => array(
 25+ "lgname" => "",
 26+ "lgpassword" => self::$passWord ) ) );
 27+ libxml_use_internal_errors( true );
 28+ $sxe = simplexml_load_string( $resp );
 29+ $this->assertNotType( "bool", $sxe );
 30+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
 31+ $a = $sxe->login[0]->attributes()->result;
 32+ $this->assertEquals( ' result="NoName"', $a->asXML() );
 33+ }
 34+
 35+ function testApiLoginBadPass() {
 36+ $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
 37+ array( "postData" => array(
 38+ "lgname" => self::$userName,
 39+ "lgpassword" => "bad" ) ) );
 40+ libxml_use_internal_errors( true );
 41+ $sxe = simplexml_load_string( $resp );
 42+ $this->assertNotType( "bool", $sxe );
 43+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
 44+ $a = $sxe->login[0]->attributes()->result;
 45+ $this->assertEquals( ' result="WrongPass"', $a->asXML() );
 46+ }
 47+
 48+ function testApiLoginGoodPass() {
 49+ $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
 50+ array( "postData" => array(
 51+ "lgname" => self::$userName,
 52+ "lgpassword" => self::$passWord ) ) );
 53+ libxml_use_internal_errors( true );
 54+ $sxe = simplexml_load_string( $resp );
 55+ $this->assertNotType( "bool", $sxe );
 56+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
 57+ $a = $sxe->login[0]->attributes()->result;
 58+ $this->assertEquals( ' result="Success"', $a->asXML() );
 59+ }
 60+
 61+ function testApiGotCookie() {
 62+ global $wgScriptPath, $wgServerName;
 63+
 64+ $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml",
 65+ array( "method" => "POST",
 66+ "postData" => array(
 67+ "lgname" => self::$userName,
 68+ "lgpassword" => self::$passWord ) ) );
 69+ $req->execute();
 70+ $cj = $req->getCookieJar();
 71+
 72+ $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/',
 73+ $cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ) );
 74+ }
 75+}
Property changes on: trunk/phase3/maintenance/tests/MediaWikiAPITest.php
___________________________________________________________________
Name: svn:eol-syle
176 + native
Index: trunk/phase3/maintenance/tests/MediaWiki_TestCase.php
@@ -0,0 +1,53 @@
 2+<?php
 3+
 4+abstract class MediaWiki_TestCase extends PHPUnit_Framework_TestCase {
 5+ /**
 6+ * @param string $serverType
 7+ * @param array $tables
 8+ */
 9+ protected function buildTestDatabase( $tables ) {
 10+ global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
 11+ $this->markTestIncomplete("This test requires DB admin user credentials.");
 12+ $wgDBprefix = 'parsertest_';
 13+
 14+ $db = new DatabaseMysql(
 15+ $wgDBserver,
 16+ $wgDBadminuser,
 17+ $wgDBadminpassword,
 18+ $wgDBname );
 19+ if( $db->isOpen() ) {
 20+ if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
 21+ # Database that supports CREATE TABLE ... LIKE
 22+ foreach ($tables as $tbl) {
 23+ $newTableName = $db->tableName( $tbl );
 24+ #$tableName = $this->oldTableNames[$tbl];
 25+ $tableName = $tbl;
 26+ $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)");
 27+ }
 28+ } else {
 29+ # Hack for MySQL versions < 4.1, which don't support
 30+ # "CREATE TABLE ... LIKE". Note that
 31+ # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
 32+ # would not create the indexes we need....
 33+ foreach ($tables as $tbl) {
 34+ $res = $db->query("SHOW CREATE TABLE $tbl");
 35+ $row = $db->fetchRow($res);
 36+ $create = $row[1];
 37+ $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
 38+ . $wgDBprefix . '\\1`', $create);
 39+ if ($create === $create_tmp) {
 40+ # Couldn't do replacement
 41+ wfDie( "could not create temporary table $tbl" );
 42+ }
 43+ $db->query($create_tmp);
 44+ }
 45+
 46+ }
 47+ return $db;
 48+ } else {
 49+ // Something amiss
 50+ return null;
 51+ }
 52+ }
 53+}
 54+
Property changes on: trunk/phase3/maintenance/tests/MediaWiki_TestCase.php
___________________________________________________________________
Name: svn:eol-style
155 + native
Index: trunk/phase3/maintenance/tests/test-prefetch-previous.xml
@@ -0,0 +1,57 @@
 2+<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="en">
 3+<siteinfo>
 4+ <sitename>DemoWiki</sitename>
 5+ <base>http://example.com/wiki/Main_Page</base>
 6+ <generator>MediaWiki 1.5.0</generator>
 7+ <case>first-letter</case>
 8+ <namespaces>
 9+ <namespace key="-2">Media</namespace>
 10+ <namespace key="-1">Special</namespace>
 11+ <namespace key="0"></namespace>
 12+ <namespace key="1">Talk</namespace>
 13+ <namespace key="2">User</namespace>
 14+ <namespace key="3">User talk</namespace>
 15+ <namespace key="4">DemoWiki</namespace>
 16+ <namespace key="5">DemoWIki talk</namespace>
 17+ <namespace key="6">Image</namespace>
 18+ <namespace key="7">Image talk</namespace>
 19+ <namespace key="8">MediaWiki</namespace>
 20+ <namespace key="9">MediaWiki talk</namespace>
 21+ <namespace key="10">Template</namespace>
 22+ <namespace key="11">Template talk</namespace>
 23+ <namespace key="12">Help</namespace>
 24+ <namespace key="13">Help talk</namespace>
 25+ <namespace key="14">Category</namespace>
 26+ <namespace key="15">Category talk</namespace>
 27+ </namespaces>
 28+</siteinfo>
 29+<page>
 30+ <title>First page</title>
 31+ <id>1</id>
 32+ <revision>
 33+ <id>1</id>
 34+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 35+ <contributor><ip>10.0.0.1</ip></contributor>
 36+ <comment>page 1, rev 1</comment>
 37+ <text>page 1, rev 1</text>
 38+ </revision>
 39+ <revision>
 40+ <id>2</id>
 41+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 42+ <contributor><ip>10.0.0.1</ip></contributor>
 43+ <comment>page 1, rev 2</comment>
 44+ <text>page 1, rev 2</text>
 45+ </revision>
 46+</page>
 47+<page>
 48+ <title>Second page</title>
 49+ <id>2</id>
 50+ <revision>
 51+ <id>3</id>
 52+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 53+ <contributor><ip>10.0.0.1</ip></contributor>
 54+ <comment>page 2, rev 3</comment>
 55+ <text>page 2, rev 3</text>
 56+ </revision>
 57+</page>
 58+</mediawiki>
Property changes on: trunk/phase3/maintenance/tests/test-prefetch-previous.xml
___________________________________________________________________
Name: svn:keywords
159 + Author Date Id Revision
Name: svn:eol-style
260 + native
Index: trunk/phase3/maintenance/tests/phpunit.xml
@@ -0,0 +1,16 @@
 2+<!-- See http://www.phpunit.de/manual/3.3/en/appendixes.configuration.html -->
 3+<phpunit bootstrap="./bootstrap.php"
 4+ colors="false"
 5+ stopOnFailure="false">
 6+ <!-- convertErrorsToExceptions="true" -->
 7+ <!-- convertNoticesToExceptions="true" -->
 8+ <!-- convertWarningsToExceptions="true" -->
 9+ <testsuite name="MediaWiki Test Suite">
 10+ <directory>.</directory>
 11+ </testsuite>
 12+ <groups>
 13+ <exclude>
 14+ <group>Broken</group>
 15+ </exclude>
 16+ </groups>
 17+</phpunit>
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/tests/phpunit.xml
___________________________________________________________________
Name: svn:eol-style
118 + native
Name: svn:eol-syle
219 + native
Index: trunk/phase3/maintenance/tests/XmlTest.php
@@ -0,0 +1,115 @@
 2+<?php
 3+
 4+class XmlTest extends PHPUnit_Framework_TestCase {
 5+
 6+ function testElementOpen() {
 7+ $this->assertEquals(
 8+ '<element>',
 9+ Xml::element( 'element', null, null ),
 10+ 'Opening element with no attributes'
 11+ );
 12+ }
 13+
 14+ function testElementEmpty() {
 15+ $this->assertEquals(
 16+ '<element />',
 17+ Xml::element( 'element', null, '' ),
 18+ 'Terminated empty element'
 19+ );
 20+ }
 21+
 22+ function testElementEscaping() {
 23+ $this->assertEquals(
 24+ '<element>hello &lt;there&gt; you &amp; you</element>',
 25+ Xml::element( 'element', null, 'hello <there> you & you' ),
 26+ 'Element with no attributes and content that needs escaping'
 27+ );
 28+ }
 29+
 30+ function testElementAttributes() {
 31+ $this->assertEquals(
 32+ '<element key="value" <>="&lt;&gt;">',
 33+ Xml::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ),
 34+ 'Element attributes, keys are not escaped'
 35+ );
 36+ }
 37+
 38+ function testOpenElement() {
 39+ $this->assertEquals(
 40+ '<element k="v">',
 41+ Xml::openElement( 'element', array( 'k' => 'v' ) ),
 42+ 'openElement() shortcut'
 43+ );
 44+ }
 45+
 46+ function testCloseElement() {
 47+ $this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' );
 48+ }
 49+
 50+ #
 51+ # textarea
 52+ #
 53+ function testTextareaNoContent() {
 54+ $this->assertEquals(
 55+ '<textarea name="name" id="name" cols="40" rows="5"></textarea>',
 56+ Xml::textarea( 'name', '' ),
 57+ 'textarea() with not content'
 58+ );
 59+ }
 60+
 61+ function testTextareaAttribs() {
 62+ $this->assertEquals(
 63+ '<textarea name="name" id="name" cols="20" rows="10">&lt;txt&gt;</textarea>',
 64+ Xml::textarea( 'name', '<txt>', 20, 10 ),
 65+ 'textarea() with custom attribs'
 66+ );
 67+ }
 68+
 69+ #
 70+ # JS
 71+ #
 72+ function testEscapeJsStringSpecialChars() {
 73+ $this->assertEquals(
 74+ '\\\\\r\n',
 75+ Xml::escapeJsString( "\\\r\n" ),
 76+ 'escapeJsString() with special characters'
 77+ );
 78+ }
 79+
 80+ function testEncodeJsVarBoolean() {
 81+ $this->assertEquals(
 82+ 'true',
 83+ Xml::encodeJsVar( true ),
 84+ 'encodeJsVar() with boolean'
 85+ );
 86+ }
 87+
 88+ function testEncodeJsVarNull() {
 89+ $this->assertEquals(
 90+ 'null',
 91+ Xml::encodeJsVar( null ),
 92+ 'encodeJsVar() with null'
 93+ );
 94+ }
 95+
 96+ function testEncodeJsVarArray() {
 97+ $this->assertEquals(
 98+ '["a", 1]',
 99+ Xml::encodeJsVar( array( 'a', 1 ) ),
 100+ 'encodeJsVar() with array'
 101+ );
 102+ $this->assertEquals(
 103+ '{"a": "a", "b": 1}',
 104+ Xml::encodeJsVar( array( 'a' => 'a', 'b' => 1 ) ),
 105+ 'encodeJsVar() with associative array'
 106+ );
 107+ }
 108+
 109+ function testEncodeJsVarObject() {
 110+ $this->assertEquals(
 111+ '{"a": "a", "b": 1}',
 112+ Xml::encodeJsVar( (object)array( 'a' => 'a', 'b' => 1 ) ),
 113+ 'encodeJsVar() with object'
 114+ );
 115+ }
 116+}
Property changes on: trunk/phase3/maintenance/tests/XmlTest.php
___________________________________________________________________
Name: svn:eol-style
1117 + native
Index: trunk/phase3/maintenance/tests/GlobalTest.php
@@ -0,0 +1,212 @@
 2+<?php
 3+
 4+class GlobalTest extends PHPUnit_Framework_TestCase {
 5+ function setUp() {
 6+ global $wgReadOnlyFile;
 7+ $this->originals['wgReadOnlyFile'] = $wgReadOnlyFile;
 8+ $wgReadOnlyFile = tempnam(wfTempDir(), "mwtest_readonly");
 9+ unlink( $wgReadOnlyFile );
 10+ }
 11+
 12+ function tearDown() {
 13+ global $wgReadOnlyFile;
 14+ if( file_exists( $wgReadOnlyFile ) ) {
 15+ unlink( $wgReadOnlyFile );
 16+ }
 17+ $wgReadOnlyFile = $this->originals['wgReadOnlyFile'];
 18+ }
 19+
 20+ function testRandom() {
 21+ # This could hypothetically fail, but it shouldn't ;)
 22+ $this->assertFalse(
 23+ wfRandom() == wfRandom() );
 24+ }
 25+
 26+ function testUrlencode() {
 27+ $this->assertEquals(
 28+ "%E7%89%B9%E5%88%A5:Contributions/Foobar",
 29+ wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
 30+ }
 31+
 32+ function testReadOnlyEmpty() {
 33+ global $wgReadOnly;
 34+ $wgReadOnly = null;
 35+
 36+ $this->assertFalse( wfReadOnly() );
 37+ $this->assertFalse( wfReadOnly() );
 38+ }
 39+
 40+ function testReadOnlySet() {
 41+ global $wgReadOnly, $wgReadOnlyFile;
 42+
 43+ $f = fopen( $wgReadOnlyFile, "wt" );
 44+ fwrite( $f, 'Message' );
 45+ fclose( $f );
 46+ $wgReadOnly = null;
 47+
 48+ $this->assertTrue( wfReadOnly() );
 49+ $this->assertTrue( wfReadOnly() );
 50+
 51+ unlink( $wgReadOnlyFile );
 52+ $wgReadOnly = null;
 53+
 54+ $this->assertFalse( wfReadOnly() );
 55+ $this->assertFalse( wfReadOnly() );
 56+ }
 57+
 58+ function testQuotedPrintable() {
 59+ $this->assertEquals(
 60+ "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
 61+ wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
 62+ }
 63+
 64+ function testTime() {
 65+ $start = wfTime();
 66+ $this->assertType( 'float', $start );
 67+ $end = wfTime();
 68+ $this->assertTrue( $end > $start, "Time is running backwards!" );
 69+ }
 70+
 71+ function testArrayToCGI() {
 72+ $this->assertEquals(
 73+ "baz=AT%26T&foo=bar",
 74+ wfArrayToCGI(
 75+ array( 'baz' => 'AT&T', 'ignore' => '' ),
 76+ array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
 77+ }
 78+
 79+ function testMimeTypeMatch() {
 80+ $this->assertEquals(
 81+ 'text/html',
 82+ mimeTypeMatch( 'text/html',
 83+ array( 'application/xhtml+xml' => 1.0,
 84+ 'text/html' => 0.7,
 85+ 'text/plain' => 0.3 ) ) );
 86+ $this->assertEquals(
 87+ 'text/*',
 88+ mimeTypeMatch( 'text/html',
 89+ array( 'image/*' => 1.0,
 90+ 'text/*' => 0.5 ) ) );
 91+ $this->assertEquals(
 92+ '*/*',
 93+ mimeTypeMatch( 'text/html',
 94+ array( '*/*' => 1.0 ) ) );
 95+ $this->assertNull(
 96+ mimeTypeMatch( 'text/html',
 97+ array( 'image/png' => 1.0,
 98+ 'image/svg+xml' => 0.5 ) ) );
 99+ }
 100+
 101+ function testNegotiateType() {
 102+ $this->assertEquals(
 103+ 'text/html',
 104+ wfNegotiateType(
 105+ array( 'application/xhtml+xml' => 1.0,
 106+ 'text/html' => 0.7,
 107+ 'text/plain' => 0.5,
 108+ 'text/*' => 0.2 ),
 109+ array( 'text/html' => 1.0 ) ) );
 110+ $this->assertEquals(
 111+ 'application/xhtml+xml',
 112+ wfNegotiateType(
 113+ array( 'application/xhtml+xml' => 1.0,
 114+ 'text/html' => 0.7,
 115+ 'text/plain' => 0.5,
 116+ 'text/*' => 0.2 ),
 117+ array( 'application/xhtml+xml' => 1.0,
 118+ 'text/html' => 0.5 ) ) );
 119+ $this->assertEquals(
 120+ 'text/html',
 121+ wfNegotiateType(
 122+ array( 'text/html' => 1.0,
 123+ 'text/plain' => 0.5,
 124+ 'text/*' => 0.5,
 125+ 'application/xhtml+xml' => 0.2 ),
 126+ array( 'application/xhtml+xml' => 1.0,
 127+ 'text/html' => 0.5 ) ) );
 128+ $this->assertEquals(
 129+ 'text/html',
 130+ wfNegotiateType(
 131+ array( 'text/*' => 1.0,
 132+ 'image/*' => 0.7,
 133+ '*/*' => 0.3 ),
 134+ array( 'application/xhtml+xml' => 1.0,
 135+ 'text/html' => 0.5 ) ) );
 136+ $this->assertNull(
 137+ wfNegotiateType(
 138+ array( 'text/*' => 1.0 ),
 139+ array( 'application/xhtml+xml' => 1.0 ) ) );
 140+ }
 141+
 142+ function testTimestamp() {
 143+ $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
 144+ $this->assertEquals(
 145+ '20010115123456',
 146+ wfTimestamp( TS_MW, $t ),
 147+ 'TS_UNIX to TS_MW' );
 148+ $this->assertEquals(
 149+ 979562096,
 150+ wfTimestamp( TS_UNIX, $t ),
 151+ 'TS_UNIX to TS_UNIX' );
 152+ $this->assertEquals(
 153+ '2001-01-15 12:34:56',
 154+ wfTimestamp( TS_DB, $t ),
 155+ 'TS_UNIX to TS_DB' );
 156+
 157+ $this->assertEquals(
 158+ '20010115123456',
 159+ wfTimestamp( TS_MW, '20010115123456' ),
 160+ 'TS_MW to TS_MW' );
 161+ $this->assertEquals(
 162+ 979562096,
 163+ wfTimestamp( TS_UNIX, '20010115123456' ),
 164+ 'TS_MW to TS_UNIX' );
 165+ $this->assertEquals(
 166+ '2001-01-15 12:34:56',
 167+ wfTimestamp( TS_DB, '20010115123456' ),
 168+ 'TS_MW to TS_DB' );
 169+
 170+ $this->assertEquals(
 171+ '20010115123456',
 172+ wfTimestamp( TS_MW, '2001-01-15 12:34:56' ),
 173+ 'TS_DB to TS_MW' );
 174+ $this->assertEquals(
 175+ 979562096,
 176+ wfTimestamp( TS_UNIX, '2001-01-15 12:34:56' ),
 177+ 'TS_DB to TS_UNIX' );
 178+ $this->assertEquals(
 179+ '2001-01-15 12:34:56',
 180+ wfTimestamp( TS_DB, '2001-01-15 12:34:56' ),
 181+ 'TS_DB to TS_DB' );
 182+ }
 183+
 184+ function testBasename() {
 185+ $sets = array(
 186+ '' => '',
 187+ '/' => '',
 188+ '\\' => '',
 189+ '//' => '',
 190+ '\\\\' => '',
 191+ 'a' => 'a',
 192+ 'aaaa' => 'aaaa',
 193+ '/a' => 'a',
 194+ '\\a' => 'a',
 195+ '/aaaa' => 'aaaa',
 196+ '\\aaaa' => 'aaaa',
 197+ '/aaaa/' => 'aaaa',
 198+ '\\aaaa\\' => 'aaaa',
 199+ '\\aaaa\\' => 'aaaa',
 200+ '/mnt/upload3/wikipedia/en/thumb/8/8b/Zork_Grand_Inquisitor_box_cover.jpg/93px-Zork_Grand_Inquisitor_box_cover.jpg' => '93px-Zork_Grand_Inquisitor_box_cover.jpg',
 201+ 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
 202+ 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
 203+ );
 204+ foreach( $sets as $from => $to ) {
 205+ $this->assertEquals( $to, wfBaseName( $from ),
 206+ "wfBaseName('$from') => '$to'");
 207+ }
 208+ }
 209+
 210+ /* TODO: many more! */
 211+}
 212+
 213+
Property changes on: trunk/phase3/maintenance/tests/GlobalTest.php
___________________________________________________________________
Name: svn:keywords
1214 + Author Date Id Revision
Name: svn:eol-style
2215 + native
Index: trunk/phase3/maintenance/tests/test-prefetch-stub.xml
@@ -0,0 +1,75 @@
 2+<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="en">
 3+<siteinfo>
 4+ <sitename>DemoWiki</sitename>
 5+ <base>http://example.com/wiki/Main_Page</base>
 6+ <generator>MediaWiki 1.5.0</generator>
 7+ <case>first-letter</case>
 8+ <namespaces>
 9+ <namespace key="-2">Media</namespace>
 10+ <namespace key="-1">Special</namespace>
 11+ <namespace key="0"></namespace>
 12+ <namespace key="1">Talk</namespace>
 13+ <namespace key="2">User</namespace>
 14+ <namespace key="3">User talk</namespace>
 15+ <namespace key="4">DemoWiki</namespace>
 16+ <namespace key="5">DemoWIki talk</namespace>
 17+ <namespace key="6">Image</namespace>
 18+ <namespace key="7">Image talk</namespace>
 19+ <namespace key="8">MediaWiki</namespace>
 20+ <namespace key="9">MediaWiki talk</namespace>
 21+ <namespace key="10">Template</namespace>
 22+ <namespace key="11">Template talk</namespace>
 23+ <namespace key="12">Help</namespace>
 24+ <namespace key="13">Help talk</namespace>
 25+ <namespace key="14">Category</namespace>
 26+ <namespace key="15">Category talk</namespace>
 27+ </namespaces>
 28+</siteinfo>
 29+<page>
 30+ <title>First page</title>
 31+ <id>1</id>
 32+ <revision>
 33+ <id>1</id>
 34+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 35+ <contributor><ip>10.0.0.1</ip></contributor>
 36+ <comment>page 1, rev 1</comment>
 37+ <text id="1" />
 38+ </revision>
 39+ <revision>
 40+ <id>2</id>
 41+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 42+ <contributor><ip>10.0.0.1</ip></contributor>
 43+ <comment>page 1, rev 2</comment>
 44+ <text id="2" />
 45+ </revision>
 46+ <revision>
 47+ <id>4</id>
 48+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 49+ <contributor><ip>10.0.0.1</ip></contributor>
 50+ <comment>page 1, rev 4</comment>
 51+ <text id="4" />
 52+ </revision>
 53+</page>
 54+<page>
 55+ <title>Second page</title>
 56+ <id>2</id>
 57+ <revision>
 58+ <id>3</id>
 59+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 60+ <contributor><ip>10.0.0.1</ip></contributor>
 61+ <comment>page 2, rev 3</comment>
 62+ <text id="3" />
 63+ </revision>
 64+</page>
 65+<page>
 66+ <title>Third page</title>
 67+ <id>3</id>
 68+ <revision>
 69+ <id>5</id>
 70+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 71+ <contributor><ip>10.0.0.1</ip></contributor>
 72+ <comment>page 3, rev 5</comment>
 73+ <text id="5" />
 74+ </revision>
 75+</page>
 76+</mediawiki>
Property changes on: trunk/phase3/maintenance/tests/test-prefetch-stub.xml
___________________________________________________________________
Name: svn:keywords
177 + Author Date Id Revision
Name: svn:eol-style
278 + native
Index: trunk/phase3/maintenance/tests/.svnignore
@@ -0,0 +1,6 @@
 2+LocalTestSettings.php
 3+*~
 4+bin
 5+.classpath
 6+.project
 7+project.index
Property changes on: trunk/phase3/maintenance/tests/.svnignore
___________________________________________________________________
Name: svn:eol-style
18 + native
Index: trunk/phase3/maintenance/tests/DatabaseTest.php
@@ -0,0 +1,92 @@
 2+<?php
 3+
 4+class DatabaseTest extends PHPUnit_Framework_TestCase {
 5+ var $db;
 6+
 7+ function setUp() {
 8+ $this->db = wfGetDB( DB_SLAVE );
 9+ }
 10+
 11+ function testAddQuotesNull() {
 12+ $check = "NULL";
 13+ if ( $this->db->getType() === 'sqlite' ) {
 14+ $check = "''";
 15+ }
 16+ $this->assertEquals( $check, $this->db->addQuotes( null ) );
 17+ }
 18+
 19+ function testAddQuotesInt() {
 20+ # returning just "1234" should be ok too, though...
 21+ # maybe
 22+ $this->assertEquals(
 23+ "'1234'",
 24+ $this->db->addQuotes( 1234 ) );
 25+ }
 26+
 27+ function testAddQuotesFloat() {
 28+ # returning just "1234.5678" would be ok too, though
 29+ $this->assertEquals(
 30+ "'1234.5678'",
 31+ $this->db->addQuotes( 1234.5678 ) );
 32+ }
 33+
 34+ function testAddQuotesString() {
 35+ $this->assertEquals(
 36+ "'string'",
 37+ $this->db->addQuotes( 'string' ) );
 38+ }
 39+
 40+ function testAddQuotesStringQuote() {
 41+ $check = "'string''s cause trouble'";
 42+ if ( $this->db->getType() === 'mysql' ) {
 43+ $check = "'string\'s cause trouble'";
 44+ }
 45+ $this->assertEquals(
 46+ $check,
 47+ $this->db->addQuotes( "string's cause trouble" ) );
 48+ }
 49+
 50+ function testFillPreparedEmpty() {
 51+ $sql = $this->db->fillPrepared(
 52+ 'SELECT * FROM interwiki', array() );
 53+ $this->assertEquals(
 54+ "SELECT * FROM interwiki",
 55+ $sql);
 56+ }
 57+
 58+ function testFillPreparedQuestion() {
 59+ $sql = $this->db->fillPrepared(
 60+ 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
 61+ array( 4, "Snicker's_paradox" ) );
 62+
 63+ $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker''s_paradox'";
 64+ if ( $this->db->getType() === 'mysql' ) {
 65+ $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'";
 66+ }
 67+ $this->assertEquals( $check, $sql );
 68+ }
 69+
 70+ function testFillPreparedBang() {
 71+ $sql = $this->db->fillPrepared(
 72+ 'SELECT user_id FROM ! WHERE user_name=?',
 73+ array( '"user"', "Slash's Dot" ) );
 74+
 75+ $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash''s Dot'";
 76+ if ( $this->db->getType() === 'mysql' ) {
 77+ $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'";
 78+ }
 79+ $this->assertEquals( $check, $sql );
 80+ }
 81+
 82+ function testFillPreparedRaw() {
 83+ $sql = $this->db->fillPrepared(
 84+ "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
 85+ array( '"user"', "Slash's Dot" ) );
 86+ $this->assertEquals(
 87+ "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",
 88+ $sql);
 89+ }
 90+
 91+}
 92+
 93+
Property changes on: trunk/phase3/maintenance/tests/DatabaseTest.php
___________________________________________________________________
Name: svn:keywords
194 + Author Date Id Revision
Name: svn:eol-style
295 + native
Index: trunk/phase3/maintenance/tests/LicensesTest.php
@@ -0,0 +1,17 @@
 2+<?php
 3+
 4+/**
 5+ * @group Broken
 6+ */
 7+class LicensesTest extends PHPUnit_Framework_TestCase {
 8+
 9+ function testLicenses() {
 10+ $str = "
 11+* Free licenses:
 12+** GFLD|Debian disagrees
 13+";
 14+
 15+ $lc = new Licenses( $str );
 16+ $this->assertTrue( is_a( $lc, 'Licenses' ), 'Correct class' );
 17+ }
 18+}
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/tests/LicensesTest.php
___________________________________________________________________
Name: svn:eol-style
119 + native
Index: trunk/phase3/maintenance/tests/test-prefetch-current.xml
@@ -0,0 +1,75 @@
 2+<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="en">
 3+<siteinfo>
 4+ <sitename>DemoWiki</sitename>
 5+ <base>http://example.com/wiki/Main_Page</base>
 6+ <generator>MediaWiki 1.5.0</generator>
 7+ <case>first-letter</case>
 8+ <namespaces>
 9+ <namespace key="-2">Media</namespace>
 10+ <namespace key="-1">Special</namespace>
 11+ <namespace key="0"></namespace>
 12+ <namespace key="1">Talk</namespace>
 13+ <namespace key="2">User</namespace>
 14+ <namespace key="3">User talk</namespace>
 15+ <namespace key="4">DemoWiki</namespace>
 16+ <namespace key="5">DemoWIki talk</namespace>
 17+ <namespace key="6">Image</namespace>
 18+ <namespace key="7">Image talk</namespace>
 19+ <namespace key="8">MediaWiki</namespace>
 20+ <namespace key="9">MediaWiki talk</namespace>
 21+ <namespace key="10">Template</namespace>
 22+ <namespace key="11">Template talk</namespace>
 23+ <namespace key="12">Help</namespace>
 24+ <namespace key="13">Help talk</namespace>
 25+ <namespace key="14">Category</namespace>
 26+ <namespace key="15">Category talk</namespace>
 27+ </namespaces>
 28+</siteinfo>
 29+<page>
 30+ <title>First page</title>
 31+ <id>1</id>
 32+ <revision>
 33+ <id>1</id>
 34+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 35+ <contributor><ip>10.0.0.1</ip></contributor>
 36+ <comment>page 1, rev 1</comment>
 37+ <text>page 1, rev 1</text>
 38+ </revision>
 39+ <revision>
 40+ <id>2</id>
 41+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 42+ <contributor><ip>10.0.0.1</ip></contributor>
 43+ <comment>page 1, rev 2</comment>
 44+ <text>page 1, rev 2</text>
 45+ </revision>
 46+ <revision>
 47+ <id>4</id>
 48+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 49+ <contributor><ip>10.0.0.1</ip></contributor>
 50+ <comment>page 1, rev 4</comment>
 51+ <text>page 1, rev 4</text>
 52+ </revision>
 53+</page>
 54+<page>
 55+ <title>Second page</title>
 56+ <id>2</id>
 57+ <revision>
 58+ <id>3</id>
 59+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 60+ <contributor><ip>10.0.0.1</ip></contributor>
 61+ <comment>page 2, rev 3</comment>
 62+ <text>page 2, rev 3</text>
 63+ </revision>
 64+</page>
 65+<page>
 66+ <title>Third page</title>
 67+ <id>3</id>
 68+ <revision>
 69+ <id>5</id>
 70+ <timestamp>2001-01-15T12:00:00Z</timestamp>
 71+ <contributor><ip>10.0.0.1</ip></contributor>
 72+ <comment>page 3, rev 5</comment>
 73+ <text>page 3, rev 5</text>
 74+ </revision>
 75+</page>
 76+</mediawiki>
Property changes on: trunk/phase3/maintenance/tests/test-prefetch-current.xml
___________________________________________________________________
Name: svn:keywords
177 + Author Date Id Revision
Name: svn:eol-style
278 + native
Index: trunk/phase3/maintenance/tests/README
@@ -0,0 +1,24 @@
 2+Some quickie unit tests done with the PHPUnit testing framework. To run the
 3+test suite, run 'make test' in this dir. This directly invokes 'phpunit.'
 4+
 5+PHPUnit is no longer maintained by PEAR. To get the current version of
 6+PHPUnit, first uninstall any old version of PHPUnit or PHPUnit2 from PEAR,
 7+then install the current version from phpunit.de like this:
 8+
 9+# pear channel-discover pear.phpunit.de
 10+# pear install phpunit/PHPUnit
 11+
 12+You also may wish to install this via your normal package mechanism:
 13+
 14+# aptitude install phpunit
 15+ - or -
 16+# yum install phpunit
 17+
 18+Notes:
 19+- Label currently broken tests in the group Broken and they will not
 20+ be run by phpunit. You can add them to the group by putting the
 21+ following comment at the top of the file:
 22+ /**
 23+ * @group Broken
 24+ */
 25+- Need to fix some broken tests
Property changes on: trunk/phase3/maintenance/tests/README
___________________________________________________________________
Name: svn:keywords
126 + Author Date Id Revision
Name: svn:eol-style
227 + native
Index: trunk/phase3/maintenance/tests/IPTest.php
@@ -0,0 +1,52 @@
 2+<?php
 3+/*
 4+ * Tests for IP validity functions. Ported from /t/inc/IP.t by avar.
 5+ */
 6+
 7+class IPTest extends PHPUnit_Framework_TestCase {
 8+
 9+ public function testValidIPs() {
 10+ foreach ( range( 0, 255 ) as $i ) {
 11+ $a = sprintf( "%03d", $i );
 12+ $b = sprintf( "%02d", $i );
 13+ $c = sprintf( "%01d", $i );
 14+ foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
 15+ $ip = "$f.$f.$f.$f";
 16+ $this->assertTrue( IP::isValid( $ip ) , "$ip is a valid IPv4 address" );
 17+ }
 18+ }
 19+ }
 20+
 21+ public function testInvalidIPs() {
 22+ foreach ( range( 256, 999 ) as $i ) {
 23+ $a = sprintf( "%03d", $i );
 24+ $b = sprintf( "%02d", $i );
 25+ $c = sprintf( "%01d", $i );
 26+ foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
 27+ $ip = "$f.$f.$f.$f";
 28+ $this->assertFalse( IP::isValid( $ip ), "$ip is not a valid IPv4 address" );
 29+ }
 30+ }
 31+ }
 32+
 33+ public function testBogusIPs() {
 34+ $invalid = array(
 35+ 'www.xn--var-xla.net',
 36+ '216.17.184.G',
 37+ '216.17.184.1.',
 38+ '216.17.184',
 39+ '216.17.184.',
 40+ '256.17.184.1'
 41+ );
 42+ foreach ( $invalid as $i ) {
 43+ $this->assertFalse( IP::isValid( $i ), "$i is an invalid IPv4 address" );
 44+ }
 45+ }
 46+
 47+ public function testPrivateIPs() {
 48+ $private = array( '10.0.0.1', '172.16.0.1', '192.168.0.1' );
 49+ foreach ( $private as $p ) {
 50+ $this->assertFalse( IP::isPublic( $p ), "$p is not a public IP address" );
 51+ }
 52+ }
 53+}
Index: trunk/phase3/maintenance/tests/SanitizerTest.php
@@ -0,0 +1,71 @@
 2+<?php
 3+
 4+global $IP;
 5+require_once( "$IP/includes/Sanitizer.php" );
 6+
 7+class SanitizerTest extends PHPUnit_Framework_TestCase {
 8+
 9+ function testDecodeNamedEntities() {
 10+ $this->assertEquals(
 11+ "\xc3\xa9cole",
 12+ Sanitizer::decodeCharReferences( '&eacute;cole' ),
 13+ 'decode named entities'
 14+ );
 15+ }
 16+
 17+ function testDecodeNumericEntities() {
 18+ $this->assertEquals(
 19+ "\xc4\x88io bonas dans l'\xc3\xa9cole!",
 20+ Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&#233;cole!" ),
 21+ 'decode numeric entities'
 22+ );
 23+ }
 24+
 25+ function testDecodeMixedEntities() {
 26+ $this->assertEquals(
 27+ "\xc4\x88io bonas dans l'\xc3\xa9cole!",
 28+ Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&eacute;cole!" ),
 29+ 'decode mixed numeric/named entities'
 30+ );
 31+ }
 32+
 33+ function testDecodeMixedComplexEntities() {
 34+ $this->assertEquals(
 35+ "\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas &#x108;io dans l'&eacute;cole)",
 36+ Sanitizer::decodeCharReferences(
 37+ "&#x108;io bonas dans l'&eacute;cole! (mais pas &amp;#x108;io dans l'&#38;eacute;cole)"
 38+ ),
 39+ 'decode mixed complex entities'
 40+ );
 41+ }
 42+
 43+ function testInvalidAmpersand() {
 44+ $this->assertEquals(
 45+ 'a & b',
 46+ Sanitizer::decodeCharReferences( 'a & b' ),
 47+ 'Invalid ampersand'
 48+ );
 49+ }
 50+
 51+ function testInvalidEntities() {
 52+ $this->assertEquals(
 53+ '&foo;',
 54+ Sanitizer::decodeCharReferences( '&foo;' ),
 55+ 'Invalid named entity'
 56+ );
 57+ }
 58+
 59+ function testInvalidNumberedEntities() {
 60+ $this->assertEquals( UTF8_REPLACEMENT, Sanitizer::decodeCharReferences( "&#88888888888888;" ), 'Invalid numbered entity' );
 61+ }
 62+
 63+ function testSelfClosingTag() {
 64+ $GLOBALS['wgUseTidy'] = false;
 65+ $this->assertEquals(
 66+ '<div>Hello world</div>',
 67+ Sanitizer::removeHTMLtags( '<div>Hello world</div />' ),
 68+ 'Self-closing closing div'
 69+ );
 70+ }
 71+}
 72+
Property changes on: trunk/phase3/maintenance/tests/SanitizerTest.php
___________________________________________________________________
Name: svn:eol-style
173 + native
Index: trunk/phase3/maintenance/tests/SearchUpdateTest.php
@@ -0,0 +1,103 @@
 2+<?php
 3+
 4+class DatabaseMock extends DatabaseBase {
 5+ function __construct( $server = false, $user = false, $password = false, $dbName = false,
 6+ $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
 7+ {
 8+ $this->mConn = true;
 9+ $this->mOpened = true;
 10+ }
 11+
 12+ function open( $server, $user, $password, $dbName ) { return true; }
 13+ function doQuery( $sql ) {}
 14+ function fetchObject( $res ) {}
 15+ function fetchRow( $res ) {}
 16+ function numRows( $res ) {}
 17+ function numFields( $res ) {}
 18+ function fieldName( $res, $n ) {}
 19+ function insertId() {}
 20+ function dataSeek( $res, $row ) {}
 21+ function lastErrno() { return 0; }
 22+ function lastError() { return ''; }
 23+ function affectedRows() {}
 24+ function fieldInfo( $table, $field ) {}
 25+ function strencode( $s ) {}
 26+ function getSoftwareLink() {}
 27+ function getServerVersion() {}
 28+ function getType() {}
 29+}
 30+
 31+class MockSearch extends SearchEngine {
 32+ public static $id;
 33+ public static $title;
 34+ public static $text;
 35+
 36+ public function __construct( $db ) {
 37+ }
 38+
 39+ public function update( $id, $title, $text ) {
 40+ self::$id = $id;
 41+ self::$title = $title;
 42+ self::$text = $text;
 43+ }
 44+}
 45+
 46+class SearchUpdateTest extends PHPUnit_Framework_TestCase {
 47+
 48+ function update( $text, $title = 'Test', $id = 1 ) {
 49+ $u = new SearchUpdate( $id, $title, $text );
 50+ $u->doUpdate();
 51+ return array( MockSearch::$title, MockSearch::$text );
 52+ }
 53+
 54+ function updateText( $text ) {
 55+ list( $title, $resultText ) = $this->update( $text );
 56+ $resultText = trim( $resultText ); // abstract from some implementation details
 57+ return $resultText;
 58+ }
 59+
 60+ function setUp() {
 61+ global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers;
 62+ $wgSearchType = 'MockSearch';
 63+ $wgDBtype = 'mock';
 64+ $wgLBFactoryConf['class'] = 'LBFactory_Simple';
 65+ $wgDBservers = null;
 66+ LBFactory::destroyInstance();
 67+ }
 68+
 69+ function tearDown() {
 70+ LBFactory::destroyInstance();
 71+ }
 72+
 73+ function testUpdateText() {
 74+ $this->assertEquals(
 75+ 'test',
 76+ $this->updateText( '<div>TeSt</div>' ),
 77+ 'HTML stripped, text lowercased'
 78+ );
 79+
 80+ $this->assertEquals(
 81+ 'foo bar boz quux',
 82+ $this->updateText( <<<EOT
 83+<table style="color:red; font-size:100px">
 84+ <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
 85+ <tr><td>boz</td><tr>quux</td></tr>
 86+</table>
 87+EOT
 88+ ), 'Stripping HTML tables' );
 89+
 90+ $this->assertEquals(
 91+ 'a b',
 92+ $this->updateText( 'a > b' ),
 93+ 'Handle unclosed tags'
 94+ );
 95+
 96+ $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
 97+
 98+ $this->assertNotEquals(
 99+ '',
 100+ $this->updateText( $text ),
 101+ 'Bug 18609'
 102+ );
 103+ }
 104+}
Property changes on: trunk/phase3/maintenance/tests/SearchUpdateTest.php
___________________________________________________________________
Name: svn:eol-style
1105 + native
Index: trunk/phase3/maintenance/tests/TimeAdjustTest.php
@@ -0,0 +1,40 @@
 2+<?php
 3+
 4+class TimeAdjustTest extends PHPUnit_Framework_TestCase {
 5+
 6+ public function setUp() {
 7+ $this->iniSet( 'precision', 15 );
 8+ }
 9+
 10+ # Test offset usage for a given language::userAdjust
 11+ function testUserAdjust() {
 12+ global $wgLocalTZoffset, $wgContLang, $wgUser;
 13+
 14+ $wgContLang = $en = Language::factory( 'en' );
 15+
 16+ # Collection of parameters for Language_t_Offset.
 17+ # Format: date to be formatted, localTZoffset value, expected date
 18+ $userAdjust_tests = array(
 19+ array( 20061231235959, 0, 20061231235959 ),
 20+ array( 20061231235959, 5, 20070101000459 ),
 21+ array( 20061231235959, 15, 20070101001459 ),
 22+ array( 20061231235959, 60, 20070101005959 ),
 23+ array( 20061231235959, 90, 20070101012959 ),
 24+ array( 20061231235959, 120, 20070101015959 ),
 25+ array( 20061231235959, 540, 20070101085959 ),
 26+ array( 20061231235959, -5, 20061231235459 ),
 27+ array( 20061231235959, -30, 20061231232959 ),
 28+ array( 20061231235959, -60, 20061231225959 ),
 29+ );
 30+
 31+ foreach( $userAdjust_tests as $data ) {
 32+ $wgLocalTZoffset = $data[1];
 33+
 34+ $this->assertEquals(
 35+ strval( $data[2] ),
 36+ strval( $en->userAdjust( $data[0], '' ) ),
 37+ "User adjust {$data[0]} by {$data[1]} minutes should give {$data[2]}"
 38+ );
 39+ }
 40+ }
 41+}
Property changes on: trunk/phase3/maintenance/tests/TimeAdjustTest.php
___________________________________________________________________
Name: svn:eol-style
142 + native
Index: trunk/phase3/maintenance/tests/LanguageConverterTest.php
@@ -0,0 +1,150 @@
 2+<?php
 3+
 4+require_once( 'ProxyTools.php' );
 5+
 6+class LanguageConverterTest extends PHPUnit_Framework_TestCase {
 7+ protected $lang = null;
 8+ protected $lc = null;
 9+
 10+ function setUp() {
 11+ global $wgMemc, $wgRequest, $wgUser, $wgContLang;
 12+
 13+ $wgUser = new User;
 14+ $wgRequest = new FauxRequest(array());
 15+ $wgMemc = new FakeMemCachedClient;
 16+ $wgContLang = Language::factory( 'tg' );
 17+ $this->lang = new LanguageTest();
 18+ $this->lc = new TestConverter( $this->lang, 'tg',
 19+ array( 'tg', 'tg-latn' ) );
 20+ }
 21+
 22+ function tearDown() {
 23+ global $wgMemc;
 24+ unset($wgMemc);
 25+ unset($this->lc);
 26+ unset($this->lang);
 27+ }
 28+
 29+ function testGetPreferredVariantDefaults() {
 30+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
 31+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
 32+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
 33+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
 34+ }
 35+
 36+ function testGetPreferredVariantHeaders() {
 37+ global $wgRequest;
 38+ $wgRequest->setHeader('Accept-Language', 'tg-latn');
 39+
 40+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
 41+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
 42+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
 43+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
 44+ }
 45+
 46+ function testGetPreferredVariantHeaderWeight() {
 47+ global $wgRequest;
 48+ $wgRequest->setHeader('Accept-Language', 'tg;q=1');
 49+
 50+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
 51+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
 52+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
 53+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
 54+ }
 55+
 56+ function testGetPreferredVariantHeaderWeight2() {
 57+ global $wgRequest;
 58+ $wgRequest->setHeader('Accept-Language', 'tg-latn;q=1');
 59+
 60+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
 61+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
 62+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
 63+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
 64+ }
 65+
 66+ function testGetPreferredVariantHeaderMulti() {
 67+ global $wgRequest;
 68+ $wgRequest->setHeader('Accept-Language', 'en, tg-latn;q=1');
 69+
 70+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
 71+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
 72+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
 73+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
 74+ }
 75+
 76+ function testGetPreferredVariantUserOption() {
 77+ global $wgUser;
 78+
 79+ $wgUser = new User;
 80+ $wgUser->setId(1);
 81+ $wgUser->setOption('variant', 'tg-latn');
 82+
 83+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
 84+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
 85+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
 86+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
 87+ }
 88+
 89+ function testGetPreferredVariantHeaderUserVsUrl() {
 90+ global $wgRequest, $wgUser, $wgContLang;
 91+
 92+ $wgContLang = Language::factory( 'tg-latn' );
 93+ $wgRequest->setVal('variant', 'tg');
 94+ $wgUser = User::newFromId("admin");
 95+ $wgUser->setId(1);
 96+ $wgUser->setOption('variant', 'tg-latn'); // The user's data is ignored
 97+ // because the variant is set in the URL.
 98+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
 99+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
 100+ }
 101+
 102+
 103+ function testGetPreferredVariantDefaultLanguageVariant() {
 104+ global $wgDefaultLanguageVariant;
 105+
 106+ $wgDefaultLanguageVariant = 'tg-latn';
 107+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, false));
 108+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
 109+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
 110+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
 111+ }
 112+
 113+ function testGetPreferredVariantDefaultLanguageVsUrlVariant() {
 114+ global $wgDefaultLanguageVariant, $wgRequest, $wgContLang;
 115+
 116+ $wgContLang = Language::factory( 'tg-latn' );
 117+ $wgDefaultLanguageVariant = 'tg';
 118+ $wgRequest->setVal('variant', null);
 119+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
 120+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
 121+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
 122+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
 123+ }
 124+}
 125+
 126+/**
 127+ * Test converter (from Tajiki to latin orthography)
 128+ */
 129+class TestConverter extends LanguageConverter {
 130+ private $table = array(
 131+ 'б' => 'b',
 132+ 'в' => 'v',
 133+ 'г' => 'g',
 134+ );
 135+
 136+ function loadDefaultTables() {
 137+ $this->mTables = array(
 138+ 'tg-latn' => new ReplacementArray( $this->table ),
 139+ 'tg' => new ReplacementArray()
 140+ );
 141+ }
 142+
 143+}
 144+
 145+class LanguageTest extends Language {
 146+ function __construct() {
 147+ parent::__construct();
 148+ $variants = array( 'tg', 'tg-latn' );
 149+ $this->mConverter = new TestConverter( $this, 'tg', $variants );
 150+ }
 151+}
Property changes on: trunk/phase3/maintenance/tests/LanguageConverterTest.php
___________________________________________________________________
Name: svn:eol-style
1152 + native
Name: svn:eol-syle
2153 + native
Index: trunk/phase3/maintenance/tests/ImageFunctionsTest.php
@@ -0,0 +1,50 @@
 2+<?php
 3+
 4+require_once( 'ImageFunctions.php' );
 5+
 6+class ImageFunctionsTest extends PHPUnit_Framework_TestCase {
 7+ function testFitBoxWidth() {
 8+ $vals = array(
 9+ array(
 10+ 'width' => 50,
 11+ 'height' => 50,
 12+ 'tests' => array(
 13+ 50 => 50,
 14+ 17 => 17,
 15+ 18 => 18 ) ),
 16+ array(
 17+ 'width' => 366,
 18+ 'height' => 300,
 19+ 'tests' => array(
 20+ 50 => 61,
 21+ 17 => 21,
 22+ 18 => 22 ) ),
 23+ array(
 24+ 'width' => 300,
 25+ 'height' => 366,
 26+ 'tests' => array(
 27+ 50 => 41,
 28+ 17 => 14,
 29+ 18 => 15 ) ),
 30+ array(
 31+ 'width' => 100,
 32+ 'height' => 400,
 33+ 'tests' => array(
 34+ 50 => 12,
 35+ 17 => 4,
 36+ 18 => 4 ) ) );
 37+ foreach( $vals as $row ) {
 38+ extract( $row );
 39+ foreach( $tests as $max => $expected ) {
 40+ $y = round( $expected * $height / $width );
 41+ $result = wfFitBoxWidth( $width, $height, $max );
 42+ $y2 = round( $result * $height / $width );
 43+ $this->assertEquals( $expected,
 44+ $result,
 45+ "($width, $height, $max) wanted: {$expected}x$y, got: {$result}x$y2" );
 46+ }
 47+ }
 48+ }
 49+}
 50+
 51+
Property changes on: trunk/phase3/maintenance/tests/ImageFunctionsTest.php
___________________________________________________________________
Name: svn:keywords
152 + Author Date Id Revision
Name: svn:eol-style
253 + native
Index: trunk/phase3/maintenance/tests/bootstrap.php
@@ -0,0 +1,26 @@
 2+<?php
 3+
 4+/**
 5+ * Set up the MediaWiki environment when running tests with "phpunit" command
 6+ *
 7+ * Warning: this file is not included from global scope!
 8+ * @file
 9+ */
 10+
 11+global $wgCommandLineMode, $IP;
 12+$wgCommandLineMode = true;
 13+$IP = dirname( dirname( dirname( __FILE__ ) ) );
 14+
 15+define( 'MEDIAWIKI', true );
 16+define( 'MW_PHPUNIT_TEST', true );
 17+
 18+require_once( "$IP/includes/Defines.php" );
 19+require_once( "$IP/includes/AutoLoader.php" );
 20+require_once( "$IP/LocalSettings.php" );
 21+require_once( "$IP/includes/ProfilerStub.php" );
 22+require_once( "$IP/includes/GlobalFunctions.php" );
 23+require_once( "$IP/includes/Hooks.php" );
 24+$self = __FILE__;
 25+require_once( "$IP/includes/Setup.php" );
 26+
 27+
Property changes on: trunk/phase3/maintenance/tests/bootstrap.php
___________________________________________________________________
Name: svn:eol-style
128 + native
Name: svn:eol-syle
229 + native
Index: trunk/phase3/maintenance/tests/HttpTest.php
@@ -0,0 +1,499 @@
 2+<?php
 3+
 4+class MockCookie extends Cookie {
 5+ public function canServeDomain($arg) { return parent::canServeDomain($arg); }
 6+ public function canServePath($arg) { return parent::canServePath($arg); }
 7+ public function isUnExpired() { return parent::isUnExpired(); }
 8+}
 9+
 10+class HttpTest extends PhpUnit_Framework_TestCase {
 11+ static $content;
 12+ static $headers;
 13+ static $has_curl;
 14+ static $has_fopen;
 15+ static $has_proxy = false;
 16+ static $proxy = "http://hulk:8080/";
 17+ var $test_geturl = array(
 18+ "http://www.example.com/",
 19+ "http://pecl.php.net/feeds/pkg_apc.rss",
 20+ "http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id=3",
 21+ "http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw",
 22+ "http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&format=php",
 23+ );
 24+ var $test_requesturl = array( "http://en.wikipedia.org/wiki/Special:Export/User:MarkAHershberger" );
 25+
 26+ var $test_posturl = array( "http://www.comp.leeds.ac.uk/cgi-bin/Perl/environment-example" => "review=test" );
 27+
 28+ function setup() {
 29+ putenv("http_proxy"); /* Remove any proxy env var, so curl doesn't get confused */
 30+ if ( is_array( self::$content ) ) {
 31+ return;
 32+ }
 33+ self::$has_curl = function_exists( 'curl_init' );
 34+ self::$has_fopen = wfIniGetBool( 'allow_url_fopen' );
 35+
 36+ if ( !file_exists("/usr/bin/curl") ) {
 37+ $this->markTestIncomplete("This test requires the curl binary at /usr/bin/curl. If you have curl, please file a bug on this test, or, better yet, provide a patch.");
 38+ }
 39+
 40+ $content = tempnam( wfTempDir(), "" );
 41+ $headers = tempnam( wfTempDir(), "" );
 42+ if ( !$content && !$headers ) {
 43+ die( "Couldn't create temp file!" );
 44+ }
 45+
 46+ // This probably isn't the best test for a proxy, but it works on my system!
 47+ system("curl -0 -o $content -s ".self::$proxy);
 48+ $out = file_get_contents( $content );
 49+ if( $out ) {
 50+ self::$has_proxy = true;
 51+ }
 52+
 53+ /* Maybe use wget instead of curl here ... just to use a different codebase? */
 54+ foreach ( $this->test_geturl as $u ) {
 55+ system( "curl -0 -s -D $headers '$u' -o $content" );
 56+ self::$content["GET $u"] = file_get_contents( $content );
 57+ self::$headers["GET $u"] = file_get_contents( $headers );
 58+ }
 59+ foreach ( $this->test_requesturl as $u ) {
 60+ system( "curl -0 -s -X POST -H 'Content-Length: 0' -D $headers '$u' -o $content" );
 61+ self::$content["POST $u"] = file_get_contents( $content );
 62+ self::$headers["POST $u"] = file_get_contents( $headers );
 63+ }
 64+ foreach ( $this->test_posturl as $u => $postData ) {
 65+ system( "curl -0 -s -X POST -d '$postData' -D $headers '$u' -o $content" );
 66+ self::$content["POST $u => $postData"] = file_get_contents( $content );
 67+ self::$headers["POST $u => $postData"] = file_get_contents( $headers );
 68+ }
 69+ unlink( $content );
 70+ unlink( $headers );
 71+ }
 72+
 73+
 74+ function testInstantiation() {
 75+ Http::$httpEngine = false;
 76+
 77+ $r = HttpRequest::factory("http://www.example.com/");
 78+ if ( self::$has_curl ) {
 79+ $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' ));
 80+ } else {
 81+ $this->assertThat($r, $this->isInstanceOf( 'PhpHttpRequest' ));
 82+ }
 83+ unset($r);
 84+
 85+ if( !self::$has_fopen ) {
 86+ $this->setExpectedException( 'MWException' );
 87+ }
 88+ Http::$httpEngine = 'php';
 89+ $r = HttpRequest::factory("http://www.example.com/");
 90+ $this->assertThat($r, $this->isInstanceOf( 'PhpHttpRequest' ));
 91+ unset($r);
 92+
 93+ if( !self::$has_curl ) {
 94+ $this->setExpectedException( 'MWException' );
 95+ }
 96+ Http::$httpEngine = 'curl';
 97+ $r = HttpRequest::factory("http://www.example.com/");
 98+ if( self::$has_curl ) {
 99+ $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' ));
 100+ }
 101+ }
 102+
 103+ function runHTTPFailureChecks() {
 104+ // Each of the following requests should result in a failure.
 105+
 106+ $timeout = 1;
 107+ $start_time = time();
 108+ $r = HTTP::get( "http://www.example.com:1/", $timeout);
 109+ $end_time = time();
 110+ $this->assertLessThan($timeout+2, $end_time - $start_time,
 111+ "Request took less than {$timeout}s via ".Http::$httpEngine);
 112+ $this->assertEquals($r, false, "false -- what we get on error from Http::get()");
 113+ }
 114+
 115+ function testFailureDefault() {
 116+ Http::$httpEngine = false;
 117+ self::runHTTPFailureChecks();
 118+ }
 119+
 120+ function testFailurePhp() {
 121+ if ( !self::$has_fopen ) {
 122+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
 123+ }
 124+
 125+ Http::$httpEngine = "php";
 126+ self::runHTTPFailureChecks();
 127+ }
 128+
 129+ function testFailureCurl() {
 130+ if ( !self::$has_curl ) {
 131+ $this->markTestIncomplete( "This test requires curl." );
 132+ }
 133+
 134+ Http::$httpEngine = "curl";
 135+ self::runHTTPFailureChecks();
 136+ }
 137+
 138+ /* ./phase3/includes/Import.php:1108: $data = Http::request( $method, $url ); */
 139+ /* ./includes/Import.php:1124: $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */
 140+ /* ./includes/Import.php:1134: return ImportStreamSource::newFromURL( $url, "POST" ); */
 141+ function runHTTPRequests($proxy=null) {
 142+ $opt = array();
 143+
 144+ if($proxy) {
 145+ $opt['proxy'] = $proxy;
 146+ } elseif( $proxy === false ) {
 147+ $opt['noProxy'] = true;
 148+ }
 149+
 150+ /* no postData here because the only request I could find in code so far didn't have any */
 151+ foreach ( $this->test_requesturl as $u ) {
 152+ $r = Http::request( "POST", $u, $opt );
 153+ $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with ".Http::$httpEngine );
 154+ }
 155+ }
 156+
 157+ function testRequestDefault() {
 158+ Http::$httpEngine = false;
 159+ self::runHTTPRequests();
 160+ }
 161+
 162+ function testRequestPhp() {
 163+ if ( !self::$has_fopen ) {
 164+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
 165+ }
 166+
 167+ Http::$httpEngine = "php";
 168+ self::runHTTPRequests();
 169+ }
 170+
 171+ function testRequestCurl() {
 172+ if ( !self::$has_curl ) {
 173+ $this->markTestIncomplete( "This test requires curl." );
 174+ }
 175+
 176+ Http::$httpEngine = "curl";
 177+ self::runHTTPRequests();
 178+ }
 179+
 180+ /* ./extensions/SpamBlacklist/SpamBlacklist_body.php:164: $httpText = Http::get( $fileName ); */
 181+ /* ./extensions/ApiSVGProxy/ApiSVGProxy.body.php:44: $contents = Http::get( $file->getFullUrl() ); */
 182+ /* ./extensions/BookInformation/drivers/IsbnDb.php:24: if( ( $xml = Http::get( $uri ) ) !== false ) { */
 183+ /* ./extensions/BookInformation/drivers/Amazon.php:23: if( ( $xml = Http::get( $uri ) ) !== false ) { */
 184+ /* ./extensions/TitleBlacklist/TitleBlacklist.list.php:217: $result = Http::get( $url ); */
 185+ /* ./extensions/TSPoll/TSPoll.php:68: $get_server = Http::get( 'http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id='.$id ); */
 186+ /* ./extensions/TSPoll/TSPoll.php:70: $get_server = Http::get( 'http://toolserver.org/~jan/poll/main.php?page=wiki_output&id='.$id ); */
 187+ /* ./extensions/DoubleWiki/DoubleWiki.php:56: $translation = Http::get( $url.$sep.'action=render' ); */
 188+ /* ./extensions/ExternalPages/ExternalPages_body.php:177: $serializedText = Http::get( $this->mPageURL ); */
 189+ /* ./extensions/Translate/utils/TranslationHelpers.php:143: $suggestions = Http::get( $url, $timeout ); */
 190+ /* ./extensions/Translate/SpecialImportTranslations.php:169: $filedata = Http::get( $url ); ; */
 191+ /* ./extensions/Translate/TranslateEditAddons.php:338: $suggestions = Http::get( $url, $timeout ); */
 192+ /* ./extensions/SecurePoll/includes/user/Auth.php:283: $value = Http::get( $url, 20, $curlParams ); */
 193+ /* ./extensions/DumpHTML/dumpHTML.inc:778: $contents = Http::get( $url ); */
 194+ /* ./extensions/DumpHTML/dumpHTML.inc:1298: $contents = Http::get( $sourceUrl ); */
 195+ /* ./extensions/DumpHTML/dumpHTML.inc:1373: $contents = Http::get( $sourceUrl ); */
 196+ /* ./phase3/maintenance/rebuildInterwiki.inc:101: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
 197+ /* ./phase3/maintenance/findhooks.php:98: $allhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php' ); */
 198+ /* ./phase3/maintenance/findhooks.php:109: $oldhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Removed_hooks&cmlimit=500&format=php' ); */
 199+ /* ./phase3/maintenance/dumpInterwiki.inc:95: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
 200+ /* ./phase3/includes/parser/Parser.php:3204: $text = Http::get($url); */
 201+ /* ./phase3/includes/filerepo/ForeignAPIRepo.php:131: $data = Http::get( $url ); */
 202+ /* ./phase3/includes/filerepo/ForeignAPIRepo.php:205: $thumb = Http::get( $foreignUrl ); */
 203+ /* ./phase3/includes/filerepo/File.php:1105: $res = Http::get( $renderUrl ); */
 204+ /* ./phase3/includes/GlobalFunctions.php:2760: * @deprecated Use Http::get() instead */
 205+ /* ./phase3/includes/GlobalFunctions.php:2764: return Http::get( $url ); */
 206+ /* ./phase3/includes/ExternalStoreHttp.php:18: $ret = Http::get( $url ); */
 207+ /* ./phase3/includes/Import.php:357: $data = Http::get( $src ); */
 208+ /* ./extensions/ExternalData/ED_Utils.php:291: return Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
 209+ /* ./extensions/ExternalData/ED_Utils.php:293: return Http::get( $url ); */
 210+ /* ./extensions/ExternalData/ED_Utils.php:306: $page = Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
 211+ /* ./extensions/ExternalData/ED_Utils.php:308: $page = Http::get( $url ); */
 212+ /* ./extensions/CodeReview/backend/Subversion.php:320: $blob = Http::get( $target, $this->mTimeout ); */
 213+ /* ./extensions/AmazonPlus/AmazonPlus.php:214: $this->response = Http::get( $urlstr ); */
 214+ /* ./extensions/StaticWiki/StaticWiki.php:24: $text = Http::get( $url ) ; */
 215+ /* ./extensions/StaticWiki/StaticWiki.php:64: $history = Http::get ( $wgStaticWikiExternalSite . "index.php?title=" . urlencode ( $url_title ) . "&action=history" ) ; */
 216+ /* ./extensions/Configure/scripts/findSettings.php:126: $cont = Http::get( "http://www.mediawiki.org/w/index.php?title={$page}&action=raw" ); */
 217+ /* ./extensions/TorBlock/TorBlock.class.php:148: $data = Http::get( $url ); */
 218+ /* ./extensions/HoneypotIntegration/HoneypotIntegration.class.php:60: $data = Http::get( $wgHoneypotURLSource, 'default', */
 219+ /* ./extensions/SemanticForms/includes/SF_Utils.inc:378: $page_contents = Http::get($url); */
 220+ /* ./extensions/LocalisationUpdate/LocalisationUpdate.class.php:172: $basefilecontents = Http::get( $basefile ); */
 221+ /* ./extensions/APC/SpecialAPC.php:245: $rss = Http::get( 'http://pecl.php.net/feeds/pkg_apc.rss' ); */
 222+ /* ./extensions/Interlanguage/Interlanguage.php:56: $a = Http::get( $url ); */
 223+ /* ./extensions/MWSearch/MWSearch_body.php:492: $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts); */
 224+ function runHTTPGets($proxy=null) {
 225+ $opt = array();
 226+
 227+ if($proxy) {
 228+ $opt['proxy'] = $proxy;
 229+ } elseif( $proxy === false ) {
 230+ $opt['noProxy'] = true;
 231+ }
 232+
 233+ foreach ( $this->test_geturl as $u ) {
 234+ $r = Http::get( $u, 30, $opt ); /* timeout of 30s */
 235+ $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with ".Http::$httpEngine );
 236+ }
 237+ }
 238+
 239+ function testGetDefault() {
 240+ Http::$httpEngine = false;
 241+ self::runHTTPGets();
 242+ }
 243+
 244+ function testGetPhp() {
 245+ if ( !self::$has_fopen ) {
 246+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
 247+ }
 248+
 249+ Http::$httpEngine = "php";
 250+ self::runHTTPGets();
 251+ }
 252+
 253+ function testGetCurl() {
 254+ if ( !self::$has_curl ) {
 255+ $this->markTestIncomplete( "This test requires curl." );
 256+ }
 257+
 258+ Http::$httpEngine = "curl";
 259+ self::runHTTPGets();
 260+ }
 261+
 262+ /* ./phase3/maintenance/parserTests.inc:1618: return Http::post( $url, array( 'postData' => wfArrayToCGI( $data ) ) ); */
 263+ function runHTTPPosts($proxy=null) {
 264+ $opt = array();
 265+
 266+ if($proxy) {
 267+ $opt['proxy'] = $proxy;
 268+ } elseif( $proxy === false ) {
 269+ $opt['noProxy'] = true;
 270+ }
 271+
 272+ foreach ( $this->test_posturl as $u => $postData ) {
 273+ $opt['postData'] = $postData;
 274+ $r = Http::post( $u, $opt );
 275+ $this->assertEquals( self::$content["POST $u => $postData"], "$r",
 276+ "POST $u (postData=$postData) with ".Http::$httpEngine );
 277+ }
 278+ }
 279+
 280+ function testPostDefault() {
 281+ Http::$httpEngine = false;
 282+ self::runHTTPPosts();
 283+ }
 284+
 285+ function testPostPhp() {
 286+ if ( !self::$has_fopen ) {
 287+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
 288+ }
 289+
 290+ Http::$httpEngine = "php";
 291+ self::runHTTPPosts();
 292+ }
 293+
 294+ function testPostCurl() {
 295+ if ( !self::$has_curl ) {
 296+ $this->markTestIncomplete( "This test requires curl." );
 297+ }
 298+
 299+ Http::$httpEngine = "curl";
 300+ self::runHTTPPosts();
 301+ }
 302+
 303+ function runProxyRequests() {
 304+ if(!self::$has_proxy) {
 305+ $this->markTestIncomplete( "This test requires a proxy." );
 306+ }
 307+ self::runHTTPGets(self::$proxy);
 308+ self::runHTTPPosts(self::$proxy);
 309+ self::runHTTPRequests(self::$proxy);
 310+
 311+ // Set false here to do noProxy
 312+ self::runHTTPGets(false);
 313+ self::runHTTPPosts(false);
 314+ self::runHTTPRequests(false);
 315+ }
 316+
 317+ function testProxyDefault() {
 318+ Http::$httpEngine = false;
 319+ self::runProxyRequests();
 320+ }
 321+
 322+ function testProxyPhp() {
 323+ if ( !self::$has_fopen ) {
 324+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
 325+ }
 326+
 327+ Http::$httpEngine = 'php';
 328+ self::runProxyRequests();
 329+ }
 330+
 331+ function testProxyCurl() {
 332+ if ( !self::$has_curl ) {
 333+ $this->markTestIncomplete( "This test requires curl." );
 334+ }
 335+
 336+ Http::$httpEngine = 'curl';
 337+ self::runProxyRequests();
 338+ }
 339+
 340+ function testIsLocalUrl() {
 341+ }
 342+
 343+ /* ./extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php:559: $user_agent = Http::userAgent(); */
 344+ function testUserAgent() {
 345+ }
 346+
 347+ function testIsValidUrl() {
 348+ }
 349+
 350+ function testSetCookie() {
 351+ $c = new MockCookie( "name", "value",
 352+ array(
 353+ "domain" => ".example.com",
 354+ "path" => "/path/",
 355+ ) );
 356+
 357+ $this->assertFalse($c->canServeDomain("example.com"));
 358+ $this->assertFalse($c->canServeDomain("www.example.net"));
 359+ $this->assertTrue($c->canServeDomain("www.example.com"));
 360+
 361+ $this->assertFalse($c->canServePath("/"));
 362+ $this->assertFalse($c->canServePath("/bogus/path/"));
 363+ $this->assertFalse($c->canServePath("/path"));
 364+ $this->assertTrue($c->canServePath("/path/"));
 365+
 366+ $this->assertTrue($c->isUnExpired());
 367+
 368+ $this->assertEquals("", $c->serializeToHttpRequest("/path/", "www.example.net"));
 369+ $this->assertEquals("", $c->serializeToHttpRequest("/", "www.example.com"));
 370+ $this->assertEquals("name=value", $c->serializeToHttpRequest("/path/", "www.example.com"));
 371+
 372+ $c = new MockCookie( "name", "value",
 373+ array(
 374+ "domain" => ".example.com",
 375+ "path" => "/path/",
 376+ "expires" => "January 1, 1990",
 377+ ) );
 378+ $this->assertFalse($c->isUnExpired());
 379+ $this->assertEquals("", $c->serializeToHttpRequest("/path/", "www.example.com"));
 380+
 381+ $c = new MockCookie( "name", "value",
 382+ array(
 383+ "domain" => ".example.com",
 384+ "path" => "/path/",
 385+ "expires" => "January 1, 2999",
 386+ ) );
 387+ $this->assertTrue($c->isUnExpired());
 388+ $this->assertEquals("name=value", $c->serializeToHttpRequest("/path/", "www.example.com"));
 389+
 390+
 391+ }
 392+
 393+ function testCookieJarSetCookie() {
 394+ $cj = new CookieJar;
 395+ $cj->setCookie( "name", "value",
 396+ array(
 397+ "domain" => ".example.com",
 398+ "path" => "/path/",
 399+ ) );
 400+ $cj->setCookie( "name2", "value",
 401+ array(
 402+ "domain" => ".example.com",
 403+ "path" => "/path/sub",
 404+ ) );
 405+ $cj->setCookie( "name3", "value",
 406+ array(
 407+ "domain" => ".example.com",
 408+ "path" => "/",
 409+ ) );
 410+ $cj->setCookie( "name4", "value",
 411+ array(
 412+ "domain" => ".example.net",
 413+ "path" => "/path/",
 414+ ) );
 415+ $cj->setCookie( "name5", "value",
 416+ array(
 417+ "domain" => ".example.net",
 418+ "path" => "/path/",
 419+ "expires" => "January 1, 1999",
 420+ ) );
 421+
 422+ $this->assertEquals("name4=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
 423+ $this->assertEquals("name3=value", $cj->serializeToHttpRequest("/", "www.example.com"));
 424+ $this->assertEquals("name=value; name3=value", $cj->serializeToHttpRequest("/path/", "www.example.com"));
 425+
 426+ $cj->setCookie( "name5", "value",
 427+ array(
 428+ "domain" => ".example.net",
 429+ "path" => "/path/",
 430+ "expires" => "January 1, 2999",
 431+ ) );
 432+ $this->assertEquals("name4=value; name5=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
 433+
 434+ $cj->setCookie( "name4", "value",
 435+ array(
 436+ "domain" => ".example.net",
 437+ "path" => "/path/",
 438+ "expires" => "January 1, 1999",
 439+ ) );
 440+ $this->assertEquals("name5=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
 441+ }
 442+
 443+ function testParseResponseHeader() {
 444+ $cj = new CookieJar;
 445+
 446+ $h[] = "Set-Cookie: name4=value; domain=.example.com; path=/; expires=Mon, 09-Dec-2999 13:46:00 GMT";
 447+ $cj->parseCookieResponseHeader( $h[0] );
 448+ $this->assertEquals("name4=value", $cj->serializeToHttpRequest("/", "www.example.com"));
 449+
 450+ $h[] = "name4=value2; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2999 13:46:00 GMT";
 451+ $cj->parseCookieResponseHeader( $h[1] );
 452+ $this->assertEquals("", $cj->serializeToHttpRequest("/", "www.example.com"));
 453+ $this->assertEquals("name4=value2", $cj->serializeToHttpRequest("/path/", "www.example.com"));
 454+
 455+ $h[] = "name5=value3; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2999 13:46:00 GMT";
 456+ $cj->parseCookieResponseHeader( $h[2] );
 457+ $this->assertEquals("name4=value2; name5=value3", $cj->serializeToHttpRequest("/path/", "www.example.com"));
 458+
 459+ $h[] = "name6=value3; domain=.example.net; path=/path/; expires=Mon, 09-Dec-1999 13:46:00 GMT";
 460+ $cj->parseCookieResponseHeader( $h[3] );
 461+ $this->assertEquals("", $cj->serializeToHttpRequest("/path/", "www.example.net"));
 462+
 463+ $h[] = "name6=value4; domain=.example.net; path=/path/; expires=Mon, 09-Dec-2999 13:46:00 GMT";
 464+ $cj->parseCookieResponseHeader( $h[4] );
 465+ $this->assertEquals("name6=value4", $cj->serializeToHttpRequest("/path/", "www.example.net"));
 466+ }
 467+
 468+ function runCookieRequests() {
 469+ $r = HttpRequest::factory( "http://www.php.net/manual" );
 470+ $r->execute();
 471+
 472+ $jar = $r->getCookieJar();
 473+
 474+ $this->assertThat( $jar, $this->isInstanceOf( 'CookieJar' ) );
 475+ $this->assertRegExp( '/^COUNTRY=.*; LAST_LANG=.*$/', $jar->serializeToHttpRequest( "/search?q=test", "www.php.net" ) );
 476+ $this->assertEquals( '', $jar->serializeToHttpRequest( "/search?q=test", "www.php.com" ) );
 477+ }
 478+
 479+ function testCookieRequestDefault() {
 480+ Http::$httpEngine = false;
 481+ self::runCookieRequests();
 482+ }
 483+ function testCookieRequestPhp() {
 484+ if ( !self::$has_fopen ) {
 485+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
 486+ }
 487+
 488+ Http::$httpEngine = 'php';
 489+ self::runCookieRequests();
 490+ }
 491+ function testCookieRequestCurl() {
 492+ if ( !self::$has_curl ) {
 493+ $this->markTestIncomplete( "This test requires curl." );
 494+ }
 495+
 496+ Http::$httpEngine = 'curl';
 497+ self::runCookieRequests();
 498+ }
 499+
 500+}
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/tests/HttpTest.php
___________________________________________________________________
Name: svn:eol-style
1501 + native
Name: svn:eol-syle
2502 + native
Index: trunk/phase3/maintenance/tests/SearchMySQL4Test.php
@@ -0,0 +1,27 @@
 2+<?php
 3+require_once( 'SearchEngineTest.php' );
 4+
 5+class SearchMySQL4Test extends SearchEngineTest {
 6+ var $db;
 7+
 8+ function setUp() {
 9+ $GLOBALS['wgContLang'] = new Language;
 10+ $this->db = $this->buildTestDatabase(
 11+ array( 'page', 'revision', 'text', 'searchindex' ) );
 12+ if( $this->db ) {
 13+ $this->insertSearchData();
 14+ }
 15+ $this->search = new SearchMySQL4( $this->db );
 16+ }
 17+
 18+ function tearDown() {
 19+ if( !is_null( $this->db ) ) {
 20+ $this->db->close();
 21+ }
 22+ unset( $this->db );
 23+ unset( $this->search );
 24+ }
 25+
 26+}
 27+
 28+
Property changes on: trunk/phase3/maintenance/tests/SearchMySQL4Test.php
___________________________________________________________________
Name: svn:keywords
129 + Author Date Id Revision
Name: svn:eol-style
230 + native
Index: trunk/phase3/maintenance/tests/MediaWikiParserTest.php
@@ -0,0 +1,219 @@
 2+<?php
 3+
 4+global $IP;
 5+define( "NO_COMMAND_LINE", 1 );
 6+require_once( "$IP/maintenance/parserTests.inc" );
 7+require_once( "ImageFunctions.php" );
 8+require_once( "ProxyTools.php" );
 9+require_once( "ObjectCache.php" );
 10+
 11+class PTShell extends ParserTest {
 12+
 13+ private $cb;
 14+
 15+ function setCallback( $cb ) {
 16+ $this->cb = $cb;
 17+ }
 18+
 19+ function showTesting( $desc ) {
 20+ }
 21+
 22+ function showRunFile( $path ) {
 23+ }
 24+
 25+ function showSuccess( $desc ) {
 26+ $this->cb->assertTrue( true, $desc );
 27+ echo "PASSED: $desc\n";
 28+ return true;
 29+ }
 30+
 31+ function showFailure( $desc, $expected, $got ) {
 32+ /* $this->cb->assertEquals( $expected, $got, $desc ); */
 33+ echo "FAILED: $desc\n";
 34+ echo "got: $got\n";
 35+ echo "expected: $expected\n";
 36+ }
 37+}
 38+
 39+class MediaWikiParserTest extends PHPUnit_Framework_TestCase {
 40+ private $parserTester;
 41+ private $db;
 42+ private $uploadDir;
 43+ private $keepUploads;
 44+
 45+ /**
 46+ * Remove the dummy uploads directory
 47+ */
 48+ private function teardownUploadDir( $dir ) {
 49+ if ( $this->keepUploads ) {
 50+ return;
 51+ }
 52+
 53+ // delete the files first, then the dirs.
 54+ self::deleteFiles(
 55+ array (
 56+ "$dir/3/3a/Foobar.jpg",
 57+ "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
 58+ "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
 59+ "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
 60+ "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
 61+
 62+ "$dir/0/09/Bad.jpg",
 63+ )
 64+ );
 65+
 66+ self::deleteDirs(
 67+ array (
 68+ "$dir/3/3a",
 69+ "$dir/3",
 70+ "$dir/thumb/6/65",
 71+ "$dir/thumb/6",
 72+ "$dir/thumb/3/3a/Foobar.jpg",
 73+ "$dir/thumb/3/3a",
 74+ "$dir/thumb/3",
 75+
 76+ "$dir/0/09/",
 77+ "$dir/0/",
 78+
 79+ "$dir/thumb",
 80+ "$dir",
 81+ )
 82+ );
 83+ }
 84+
 85+ /**
 86+ * Delete the specified files, if they exist.
 87+ * @param array $files full paths to files to delete.
 88+ */
 89+ private static function deleteFiles( $files ) {
 90+ foreach( $files as $file ) {
 91+ if( file_exists( $file ) ) {
 92+ unlink( $file );
 93+ }
 94+ }
 95+ }
 96+ /**
 97+ * Delete the specified directories, if they exist. Must be empty.
 98+ * @param array $dirs full paths to directories to delete.
 99+ */
 100+ private static function deleteDirs( $dirs ) {
 101+ foreach( $dirs as $dir ) {
 102+ if( is_dir( $dir ) ) {
 103+ rmdir( $dir );
 104+ }
 105+ }
 106+ }
 107+
 108+ /**
 109+ * Create a dummy uploads directory which will contain a couple
 110+ * of files in order to pass existence tests.
 111+ * @return string The directory
 112+ */
 113+ private function setupUploadDir() {
 114+ global $IP;
 115+ if ( $this->keepUploads ) {
 116+ $dir = wfTempDir() . '/mwParser-images';
 117+ if ( is_dir( $dir ) ) {
 118+ return $dir;
 119+ }
 120+ } else {
 121+ $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
 122+ }
 123+
 124+ wfDebug( "Creating upload directory $dir\n" );
 125+ if ( file_exists( $dir ) ) {
 126+ wfDebug( "Already exists!\n" );
 127+ return $dir;
 128+ }
 129+ wfMkdirParents( $dir . '/3/3a' );
 130+ copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
 131+
 132+ wfMkdirParents( $dir . '/0/09' );
 133+ copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
 134+ return $dir;
 135+ }
 136+
 137+ function setUp() {
 138+ global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
 139+ $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgMessageCache,
 140+ $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc, $wgNamespaceAliases, $wgNamespaceProtection,
 141+ $wgLocalFileRepo, $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath,
 142+ $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
 143+
 144+ $wgScript = '/index.php';
 145+ $wgScriptPath = '/';
 146+ $wgArticlePath = '/wiki/$1';
 147+ $wgStyleSheetPath = '/skins';
 148+ $wgStylePath = '/skins';
 149+ $wgThumbnailScriptPath = false;
 150+ $this->uploadDir = $this->setupUploadDir();
 151+ $wgLocalFileRepo = array(
 152+ 'class' => 'LocalRepo',
 153+ 'name' => 'local',
 154+ 'directory' => $this->uploadDir,
 155+ 'url' => 'http://example.com/images',
 156+ 'hashLevels' => 2,
 157+ 'transformVia404' => false,
 158+ );
 159+ //$wgNamespacesWithSubpages = array( 0 => isset( $opts['subpage'] ) );
 160+ $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
 161+ $wgNamespaceAliases['Image'] = NS_FILE;
 162+ $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
 163+
 164+
 165+ $wgEnableParserCache = false;
 166+ $wgDeferredUpdateList = array();
 167+ $wgMemc =& wfGetMainCache();
 168+ $messageMemc =& wfGetMessageCacheStorage();
 169+ $parserMemc =& wfGetParserCacheStorage();
 170+
 171+ $wgContLang = new StubContLang;
 172+ $wgUser = new StubUser;
 173+ $wgLang = new StubUserLang;
 174+ $wgOut = new StubObject( 'wgOut', 'OutputPage' );
 175+ $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
 176+ $wgRequest = new WebRequest;
 177+
 178+ $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
 179+ array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
 180+ if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
 181+
 182+ $this->parserTester = new PTShell();
 183+ $this->parserTester->setCallback( $this );
 184+
 185+ /* global $wgDBtype, $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBport, $wgDBmwschema, $wgDBts2chema; */
 186+ /* $this->db['type'] = $wgDBtype; */
 187+ /* $this->db['server'] = $wgDBserver; */
 188+ /* $this->db['name'] = $wgDBname; */
 189+ /* $this->db['user'] = $wgDBuser; */
 190+ /* $this->db['password'] = $wgDBpassword; */
 191+ /* $this->db['port'] = $wgDBport; */
 192+ /* $this->db['mwschema'] = $wgDBmwschema; */
 193+ /* $this->db['ts2schema'] = $wgDBts2chema; */
 194+ }
 195+
 196+ function tearDown() {
 197+ $this->teardownUploadDir($this->uploadDir);
 198+ /* $db = wfGetDB( DB_MASTER ); */
 199+ /* $db->close(); */
 200+ /* global $wgDBtype, $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBport, $wgDBmwschema, $wgDBts2chema; */
 201+
 202+ /* $wgDBtype = $this->db['type']; */
 203+ /* $wgDBserver = $this->db['server']; */
 204+ /* $wgDBname = $this->db['name']; */
 205+ /* $wgDBuser = $this->db['user']; */
 206+ /* $wgDBpassword = $this->db['password']; */
 207+ /* $wgDBport = $this->db['port']; */
 208+ /* $wgDBmwschema = $this->db['mwschema']; */
 209+ /* $wgDBts2chema = $this->db['ts2schema']; */
 210+
 211+ }
 212+
 213+
 214+ function testParser() {
 215+ global $IP;
 216+
 217+ $this->parserTester->runTestsFromFiles( array( "$IP/maintenance/parserTests.txt" ) );
 218+ }
 219+}
 220+
Property changes on: trunk/phase3/maintenance/tests/MediaWikiParserTest.php
___________________________________________________________________
Name: svn:eol-style
1221 + native
Name: svn:eol-syle
2222 + native
Index: trunk/phase3/maintenance/tests/TitleTest.php
@@ -0,0 +1,17 @@
 2+<?php
 3+
 4+class TitleTest extends PHPUnit_Framework_TestCase {
 5+
 6+ function testLegalChars() {
 7+ $titlechars = Title::legalChars();
 8+
 9+ foreach ( range( 1, 255 ) as $num ) {
 10+ $chr = chr( $num );
 11+ if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
 12+ $this->assertFalse( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid titlechar" );
 13+ } else {
 14+ $this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" );
 15+ }
 16+ }
 17+ }
 18+}
Property changes on: trunk/phase3/maintenance/tests/TitleTest.php
___________________________________________________________________
Name: svn:eol-style
119 + native
Index: trunk/phase3/maintenance/tests/ArticleTest.php
@@ -0,0 +1,114 @@
 2+<?php
 3+
 4+class ArticleTest extends PHPUnit_Framework_TestCase {
 5+ var $saveGlobals = array();
 6+
 7+ function setUp() {
 8+ global $wgContLang;
 9+ $wgContLang = Language::factory( 'en' );
 10+ $globalSet = array(
 11+ 'wgLegacyEncoding' => false,
 12+ 'wgCompressRevisions' => false,
 13+ 'wgInputEncoding' => 'utf-8',
 14+ 'wgOutputEncoding' => 'utf-8' );
 15+ foreach( $globalSet as $var => $data ) {
 16+ $this->saveGlobals[$var] = $GLOBALS[$var];
 17+ $GLOBALS[$var] = $data;
 18+ }
 19+ }
 20+
 21+ function tearDown() {
 22+ foreach( $this->saveGlobals as $var => $data ) {
 23+ $GLOBALS[$var] = $data;
 24+ }
 25+ }
 26+
 27+ function testGetRevisionText() {
 28+ $row = new stdClass;
 29+ $row->old_flags = '';
 30+ $row->old_text = 'This is a bunch of revision text.';
 31+ $this->assertEquals(
 32+ 'This is a bunch of revision text.',
 33+ Revision::getRevisionText( $row ) );
 34+ }
 35+
 36+ function testGetRevisionTextGzip() {
 37+ $row = new stdClass;
 38+ $row->old_flags = 'gzip';
 39+ $row->old_text = gzdeflate( 'This is a bunch of revision text.' );
 40+ $this->assertEquals(
 41+ 'This is a bunch of revision text.',
 42+ Revision::getRevisionText( $row ) );
 43+ }
 44+
 45+ function testGetRevisionTextUtf8Native() {
 46+ $row = new stdClass;
 47+ $row->old_flags = 'utf-8';
 48+ $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
 49+ $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
 50+ $this->assertEquals(
 51+ "Wiki est l'\xc3\xa9cole superieur !",
 52+ Revision::getRevisionText( $row ) );
 53+ }
 54+
 55+ function testGetRevisionTextUtf8Legacy() {
 56+ $row = new stdClass;
 57+ $row->old_flags = '';
 58+ $row->old_text = "Wiki est l'\xe9cole superieur !";
 59+ $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
 60+ $this->assertEquals(
 61+ "Wiki est l'\xc3\xa9cole superieur !",
 62+ Revision::getRevisionText( $row ) );
 63+ }
 64+
 65+ function testGetRevisionTextUtf8NativeGzip() {
 66+ $row = new stdClass;
 67+ $row->old_flags = 'gzip,utf-8';
 68+ $row->old_text = gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" );
 69+ $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
 70+ $this->assertEquals(
 71+ "Wiki est l'\xc3\xa9cole superieur !",
 72+ Revision::getRevisionText( $row ) );
 73+ }
 74+
 75+ function testGetRevisionTextUtf8LegacyGzip() {
 76+ $row = new stdClass;
 77+ $row->old_flags = 'gzip';
 78+ $row->old_text = gzdeflate( "Wiki est l'\xe9cole superieur !" );
 79+ $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
 80+ $this->assertEquals(
 81+ "Wiki est l'\xc3\xa9cole superieur !",
 82+ Revision::getRevisionText( $row ) );
 83+ }
 84+
 85+ function testCompressRevisionTextUtf8() {
 86+ $row = new stdClass;
 87+ $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
 88+ $row->old_flags = Revision::compressRevisionText( $row->old_text );
 89+ $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
 90+ "Flags should contain 'utf-8'" );
 91+ $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ),
 92+ "Flags should not contain 'gzip'" );
 93+ $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
 94+ $row->old_text, "Direct check" );
 95+ $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
 96+ Revision::getRevisionText( $row ), "getRevisionText" );
 97+ }
 98+
 99+ function testCompressRevisionTextUtf8Gzip() {
 100+ $GLOBALS['wgCompressRevisions'] = true;
 101+ $row = new stdClass;
 102+ $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
 103+ $row->old_flags = Revision::compressRevisionText( $row->old_text );
 104+ $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
 105+ "Flags should contain 'utf-8'" );
 106+ $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ),
 107+ "Flags should contain 'gzip'" );
 108+ $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
 109+ gzinflate( $row->old_text ), "Direct check" );
 110+ $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
 111+ Revision::getRevisionText( $row ), "getRevisionText" );
 112+ }
 113+}
 114+
 115+
Property changes on: trunk/phase3/maintenance/tests/ArticleTest.php
___________________________________________________________________
Name: svn:keywords
1116 + Author Date Id Revision
Name: svn:eol-style
2117 + native
Index: trunk/phase3/maintenance/tests/Makefile
@@ -0,0 +1,11 @@
 2+.PHONY: help test
 3+all test:
 4+ phpunit
 5+install:
 6+ pear channel-discover pear.phpunit.de
 7+ pear install phpunit/PHPUnit
 8+help:
 9+ # Options:
 10+ # test (default) Run the unit tests
 11+ # install Install PHPUnit from phpunit.de
 12+ # help You're looking at it!
Property changes on: trunk/phase3/maintenance/tests/Makefile
___________________________________________________________________
Name: svn:keywords
113 + Author Date Id Revision
Name: svn:eol-style
214 + native
Index: trunk/phase3/maintenance/tests/MediaWikiAPI_TestCase.php
@@ -0,0 +1,42 @@
 2+<?php
 3+
 4+abstract class MediaWikiAPI_TestCase extends PHPUnit_Framework_TestCase {
 5+ protected static $userName;
 6+ protected static $passWord;
 7+ protected static $user;
 8+ protected static $apiUrl;
 9+
 10+ function setup() {
 11+ global $wgServerName, $wgServer, $wgContLang, $wgAuth, $wgScriptPath,
 12+ $wgScriptExtension, $wgMemc;
 13+
 14+ if($wgServerName == "localhost" || $wgServer == "http://localhost") {
 15+ $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
 16+ 'be set in LocalSettings.php');
 17+ }
 18+ self::$apiUrl = $wgServer.$wgScriptPath."/api".$wgScriptExtension;
 19+
 20+ $wgMemc = new FakeMemCachedClient;
 21+ $wgContLang = Language::factory( 'en' );
 22+ $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
 23+ self::setupUser();
 24+ }
 25+
 26+ static function setupUser() {
 27+ if ( self::$user == NULL ) {
 28+ self::$userName = "Useruser";
 29+ self::$passWord = User::randomPassword();
 30+
 31+ self::$user = User::newFromName(self::$userName);
 32+ if ( !self::$user->getID() ) {
 33+ self::$user = User::createNew(self::$userName, array(
 34+ "password" => self::$passWord,
 35+ "email" => "test@example.com",
 36+ "real_name" => "Test User"));
 37+ } else {
 38+ self::$user->setPassword(self::$passWord);
 39+ }
 40+ self::$user->saveSettings();
 41+ }
 42+ }
 43+}
Property changes on: trunk/phase3/maintenance/tests/MediaWikiAPI_TestCase.php
___________________________________________________________________
Name: svn:eol-syle
144 + native
Property changes on: trunk/phase3/maintenance/tests
___________________________________________________________________
Name: svn:ignore
245 + LocalTestSettings.php
*~
bin
.classpath
.project
project.index
Index: trunk/phase3/RELEASE-NOTES
@@ -316,6 +316,8 @@
317317 article
318318 * (bug 22315) SpecialRecentChangesQuery hook now pass $query_options and checks
319319 the return value
 320+* Separate unit test suites under t/ and tests/ were merged and moved to
 321+ maintenance/tests/.
320322
321323 === Bug fixes in 1.16 ===
322324

Comments

Status & tagging log