r33134 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r33133‎ | r33134 | r33135 >
Date:15:56, 11 April 2008
Author:ialex
Status:old
Tags:
Comment:
* Ported tests from test/ branch to t/ branch
* Added maint option to Makefile, only does maintenance tests
* Added .htaccess file in t/ to disallow acces from the web
Modified paths:
  • /trunk/phase3/Makefile (modified) (history)
  • /trunk/phase3/t/.htaccess (added) (history)
  • /trunk/phase3/t/Search.inc (added) (history)
  • /trunk/phase3/t/inc/Database.t (added) (history)
  • /trunk/phase3/t/inc/Global.t (added) (history)
  • /trunk/phase3/t/inc/ImageFunctions.t (added) (history)
  • /trunk/phase3/t/inc/LocalFile.t (added) (history)
  • /trunk/phase3/t/inc/Revision.t (added) (history)
  • /trunk/phase3/t/inc/Search.t (added) (history)

Diff [purge]

Index: trunk/phase3/Makefile
@@ -21,5 +21,8 @@
2222 fast: t/Test.php
2323 $(PROVE_BIN) $(FAST_TESTS)
2424
 25+maint:
 26+ $(PROVE_BIN) $(MAINTENANCE_TESTS)
 27+
2528 verbose: t/Test.php
2629 $(PROVE_BIN) -v $(ALL_TESTS) | egrep -v '^ok'
Index: trunk/phase3/t/inc/Revision.t
@@ -0,0 +1,79 @@
 2+#!/usr/bin/env php
 3+<?php
 4+
 5+define( 'MEDIAWIKI', true );
 6+require 't/Test.php';
 7+
 8+plan( 19 );
 9+
 10+require_ok( 'includes/Defines.php' );
 11+require_ok( 'includes/ProfilerStub.php' );
 12+require_ok( 'includes/GlobalFunctions.php' );
 13+require_ok( 'languages/Language.php' );
 14+require_ok( 'includes/Revision.php' );
 15+
 16+$wgContLang = Language::factory( 'en' );
 17+$wgLegacyEncoding = false;
 18+$wgCompressRevisions = false;
 19+$wgInputEncoding = 'utf-8';
 20+$wgOutputEncoding = 'utf-8';
 21+
 22+$row = new stdClass;
 23+$row->old_flags = '';
 24+$row->old_text = 'This is a bunch of revision text.';
 25+cmp_ok( Revision::getRevisionText( $row ), '==',
 26+ 'This is a bunch of revision text.', 'Get revision text' );
 27+
 28+$row = new stdClass;
 29+$row->old_flags = 'gzip';
 30+$row->old_text = gzdeflate( 'This is a bunch of revision text.' );
 31+cmp_ok( Revision::getRevisionText( $row ), '==',
 32+ 'This is a bunch of revision text.', 'Get revision text with gzip compression' );
 33+
 34+$wgLegacyEncoding = 'iso-8859-1';
 35+
 36+$row = new stdClass;
 37+$row->old_flags = 'utf-8';
 38+$row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
 39+cmp_ok( Revision::getRevisionText( $row ), '==',
 40+ "Wiki est l'\xc3\xa9cole superieur !", 'Get revision text utf-8 native' );
 41+
 42+$row = new stdClass;
 43+$row->old_flags = '';
 44+$row->old_text = "Wiki est l'\xe9cole superieur !";
 45+cmp_ok( Revision::getRevisionText( $row ), '==',
 46+ "Wiki est l'\xc3\xa9cole superieur !", 'Get revision text utf-8 legacy' );
 47+
 48+$row = new stdClass;
 49+$row->old_flags = 'gzip,utf-8';
 50+$row->old_text = gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" );
 51+cmp_ok( Revision::getRevisionText( $row ), '==',
 52+ "Wiki est l'\xc3\xa9cole superieur !", 'Get revision text utf-8 native and gzip' );
 53+
 54+$row = new stdClass;
 55+$row->old_flags = 'gzip';
 56+$row->old_text = gzdeflate( "Wiki est l'\xe9cole superieur !" );
 57+cmp_ok( Revision::getRevisionText( $row ), '==',
 58+ "Wiki est l'\xc3\xa9cole superieur !", 'Get revision text utf-8 native and gzip' );
 59+
 60+$row = new stdClass;
 61+$row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
 62+$row->old_flags = Revision::compressRevisionText( $row->old_text );
 63+like( $row->old_flags, '/utf-8/', "Flags should contain 'utf-8'" );
 64+unlike( $row->old_flags, '/gzip/', "Flags should not contain 'gzip'" );
 65+cmp_ok( $row->old_text, '==',
 66+ "Wiki est l'\xc3\xa9cole superieur !", "Direct check" );
 67+cmp_ok( Revision::getRevisionText( $row ), '==',
 68+ "Wiki est l'\xc3\xa9cole superieur !", "getRevisionText" );
 69+
 70+$wgCompressRevisions = true;
 71+
 72+$row = new stdClass;
 73+$row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
 74+$row->old_flags = Revision::compressRevisionText( $row->old_text );
 75+like( $row->old_flags, '/utf-8/', "Flags should contain 'utf-8'" );
 76+like( $row->old_flags, '/gzip/', "Flags should contain 'gzip'" );
 77+cmp_ok( gzinflate( $row->old_text ), '==',
 78+ "Wiki est l'\xc3\xa9cole superieur !", "Direct check" );
 79+cmp_ok( Revision::getRevisionText( $row ), '==',
 80+ "Wiki est l'\xc3\xa9cole superieur !", "getRevisionText" );
Property changes on: trunk/phase3/t/inc/Revision.t
___________________________________________________________________
Added: svn:eol-style
181 + native
Index: trunk/phase3/t/inc/Global.t
@@ -0,0 +1,154 @@
 2+#!/usr/bin/env php
 3+<?php
 4+
 5+define( 'MEDIAWIKI', true );
 6+require 't/Test.php';
 7+
 8+require 'includes/Defines.php';
 9+require 'LocalSettings.php';
 10+
 11+plan( 48 );
 12+
 13+require_ok( 'includes/ProfilerStub.php' );
 14+require_ok( 'includes/GlobalFunctions.php' );
 15+
 16+$wgReadOnly = null;
 17+$wgReadOnlyFile = tempnam(wfTempDir(), "mwtest_readonly");
 18+unlink( $wgReadOnlyFile );
 19+
 20+isnt( wfRandom(), wfRandom(), "Two differents random" );
 21+
 22+is( wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ),
 23+ "%E7%89%B9%E5%88%A5:Contributions/Foobar", 'Urlencode' );
 24+
 25+is( wfReadOnly(), false, 'Empty read only' );
 26+
 27+is( wfReadOnly(), false, 'Empty read only, second time' );
 28+
 29+$f = fopen( $wgReadOnlyFile, "wt" );
 30+fwrite( $f, 'Message' );
 31+fclose( $f );
 32+$wgReadOnly = null;
 33+
 34+is( wfReadOnly(), true, 'Read only file set' );
 35+
 36+is( wfReadOnly(), true, 'Read only file set, second time' );
 37+
 38+unlink( $wgReadOnlyFile );
 39+$wgReadOnly = null;
 40+
 41+is( wfReadOnly(), false, 'Read only reset' );
 42+
 43+is( wfReadOnly(), false, 'Read only reset, second time' );
 44+
 45+
 46+is( wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ),
 47+ "=?UTF-8?Q?=C4=88u=20legebla=3F?=", 'Quoted printable' );
 48+
 49+$start = wfTime();
 50+is( gettype( $start ), 'float', 'Time (type)' );
 51+$end = wfTime();
 52+cmp_ok( $end, '>', $start, 'Time' );
 53+
 54+$arr = wfArrayToCGI(
 55+ array( 'baz' => 'AT&T', 'ignore' => '' ),
 56+ array( 'foo' => 'bar', 'baz' => 'overridden value' ) );
 57+is( $arr, "baz=AT%26T&foo=bar", 'Array to CGI' );
 58+
 59+$mime = mimeTypeMatch( 'text/html', array(
 60+ 'application/xhtml+xml' => 1.0,
 61+ 'text/html' => 0.7,
 62+ 'text/plain' => 0.3
 63+) );
 64+is( $mime, 'text/html', 'Mime (1)' );
 65+
 66+$mime = mimeTypeMatch( 'text/html', array(
 67+ 'image/*' => 1.0,
 68+ 'text/*' => 0.5
 69+) );
 70+is( $mime, 'text/*', 'Mime (2)' );
 71+
 72+$mime = mimeTypeMatch( 'text/html', array( '*/*' => 1.0 ) );
 73+is( $mime, '*/*', 'Mime (3)' );
 74+
 75+$mime = mimeTypeMatch( 'text/html', array(
 76+ 'image/png' => 1.0,
 77+ 'image/svg+xml' => 0.5
 78+) );
 79+is( $mime, null, 'Mime (4)' );
 80+
 81+$mime = wfNegotiateType(
 82+ array( 'application/xhtml+xml' => 1.0,
 83+ 'text/html' => 0.7,
 84+ 'text/plain' => 0.5,
 85+ 'text/*' => 0.2 ),
 86+ array( 'text/html' => 1.0 ) );
 87+is( $mime, 'text/html', 'Negotiate Mime (1)' );
 88+
 89+$mime = wfNegotiateType(
 90+ array( 'application/xhtml+xml' => 1.0,
 91+ 'text/html' => 0.7,
 92+ 'text/plain' => 0.5,
 93+ 'text/*' => 0.2 ),
 94+ array( 'application/xhtml+xml' => 1.0,
 95+ 'text/html' => 0.5 ) );
 96+is( $mime, 'application/xhtml+xml', 'Negotiate Mime (2)' );
 97+
 98+$mime = wfNegotiateType(
 99+ array( 'text/html' => 1.0,
 100+ 'text/plain' => 0.5,
 101+ 'text/*' => 0.5,
 102+ 'application/xhtml+xml' => 0.2 ),
 103+ array( 'application/xhtml+xml' => 1.0,
 104+ 'text/html' => 0.5 ) );
 105+is( $mime, 'text/html', 'Negotiate Mime (3)' );
 106+
 107+$mime = wfNegotiateType(
 108+ array( 'text/*' => 1.0,
 109+ 'image/*' => 0.7,
 110+ '*/*' => 0.3 ),
 111+ array( 'application/xhtml+xml' => 1.0,
 112+ 'text/html' => 0.5 ) );
 113+is( $mime, 'text/html', 'Negotiate Mime (4)' );
 114+
 115+$mime = wfNegotiateType(
 116+ array( 'text/*' => 1.0 ),
 117+ array( 'application/xhtml+xml' => 1.0 ) );
 118+is( $mime, null, 'Negotiate Mime (5)' );
 119+
 120+$t = gmmktime( 12, 34, 56, 1, 15, 2001 );
 121+is( wfTimestamp( TS_MW, $t ), '20010115123456', 'TS_UNIX to TS_MW' );
 122+is( wfTimestamp( TS_UNIX, $t ), 979562096, 'TS_UNIX to TS_UNIX' );
 123+is( wfTimestamp( TS_DB, $t ), '2001-01-15 12:34:56', 'TS_UNIX to TS_DB' );
 124+$t = '20010115123456';
 125+is( wfTimestamp( TS_MW, $t ), '20010115123456', 'TS_MW to TS_MW' );
 126+is( wfTimestamp( TS_UNIX, $t ), 979562096, 'TS_MW to TS_UNIX' );
 127+is( wfTimestamp( TS_DB, $t ), '2001-01-15 12:34:56', 'TS_MW to TS_DB' );
 128+$t = '2001-01-15 12:34:56';
 129+is( wfTimestamp( TS_MW, $t ), '20010115123456', 'TS_DB to TS_MW' );
 130+is( wfTimestamp( TS_UNIX, $t ), 979562096, 'TS_DB to TS_UNIX' );
 131+is( wfTimestamp( TS_DB, $t ), '2001-01-15 12:34:56', 'TS_DB to TS_DB' );
 132+
 133+$sets = array(
 134+ '' => '',
 135+ '/' => '',
 136+ '\\' => '',
 137+ '//' => '',
 138+ '\\\\' => '',
 139+ 'a' => 'a',
 140+ 'aaaa' => 'aaaa',
 141+ '/a' => 'a',
 142+ '\\a' => 'a',
 143+ '/aaaa' => 'aaaa',
 144+ '\\aaaa' => 'aaaa',
 145+ '/aaaa/' => 'aaaa',
 146+ '\\aaaa\\' => 'aaaa',
 147+ '\\aaaa\\' => 'aaaa',
 148+ '/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',
 149+ 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
 150+ 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
 151+);
 152+foreach( $sets as $from => $to ) {
 153+ is( $to, wfBaseName( $from ),
 154+ "wfBaseName('$from') => '$to'");
 155+}
\ No newline at end of file
Property changes on: trunk/phase3/t/inc/Global.t
___________________________________________________________________
Added: svn:eol-style
1156 + native
Index: trunk/phase3/t/inc/Database.t
@@ -0,0 +1,55 @@
 2+#!/usr/bin/env php
 3+<?php
 4+
 5+define( 'MEDIAWIKI', true );
 6+require 't/Test.php';
 7+
 8+require 'includes/Defines.php';
 9+require 'LocalSettings.php';
 10+
 11+plan( 13 );
 12+
 13+require_ok( 'includes/ProfilerStub.php' );
 14+require_ok( 'includes/GlobalFunctions.php' );
 15+require_ok( 'includes/Exception.php' );
 16+require_ok( 'includes/Database.php' );
 17+
 18+$db = new Database( $wgDBserver, $wgDBuser, $wgDBpassword );
 19+
 20+cmp_ok( $db->addQuotes( NULL ), '==',
 21+ 'NULL', 'Add quotes to NULL' );
 22+
 23+cmp_ok( $db->addQuotes( 1234 ), '==',
 24+ "'1234'", 'Add quotes to int' );
 25+
 26+cmp_ok( $db->addQuotes( 1234.5678 ), '==',
 27+ "'1234.5678'", 'Add quotes to float' );
 28+
 29+cmp_ok( $db->addQuotes( 'string' ), '==',
 30+ "'string'", 'Add quotes to string' );
 31+
 32+cmp_ok( $db->addQuotes( "string's cause trouble" ), '==',
 33+ "'string\'s cause trouble'", 'Add quotes to quoted string' );
 34+
 35+$sql = $db->fillPrepared(
 36+ 'SELECT * FROM interwiki', array() );
 37+cmp_ok( $sql, '==',
 38+ 'SELECT * FROM interwiki', 'FillPrepared empty' );
 39+
 40+$sql = $db->fillPrepared(
 41+ 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
 42+ array( 4, "Snicker's_paradox" ) );
 43+cmp_ok( $sql, '==',
 44+ "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'", 'FillPrepared question' );
 45+
 46+$sql = $db->fillPrepared(
 47+ 'SELECT user_id FROM ! WHERE user_name=?',
 48+ array( '"user"', "Slash's Dot" ) );
 49+cmp_ok( $sql, '==',
 50+ "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'", 'FillPrepared quoted' );
 51+
 52+$sql = $db->fillPrepared(
 53+ "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
 54+ array( '"user"', "Slash's Dot" ) );
 55+cmp_ok( $sql, '==',
 56+ "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'", 'FillPrepared raw' );
Property changes on: trunk/phase3/t/inc/Database.t
___________________________________________________________________
Added: svn:eol-style
157 + native
Index: trunk/phase3/t/inc/Search.t
@@ -0,0 +1,14 @@
 2+#!/usr/bin/env php
 3+<?php
 4+
 5+require 't/Search.inc';
 6+
 7+$db = buildTestDatabase( array( 'page', 'revision', 'text', 'searchindex' ) );
 8+if( is_null( $db ) ){
 9+ fail( 'no db' );
 10+ exit();
 11+}
 12+$t = new SearchEngineTest( new SearchMySQL( $db ) );
 13+$t->run();
 14+
 15+/* vim: set filetype=php: */
Property changes on: trunk/phase3/t/inc/Search.t
___________________________________________________________________
Added: svn:eol-style
116 + native
Index: trunk/phase3/t/inc/LocalFile.t
@@ -0,0 +1,77 @@
 2+#!/usr/bin/env php
 3+<?php
 4+
 5+define( 'MEDIAWIKI', true );
 6+require 't/Test.php';
 7+
 8+require 'includes/Defines.php';
 9+require 'includes/ProfilerStub.php';
 10+require 'LocalSettings.php';
 11+require 'includes/Setup.php';
 12+
 13+/**
 14+ * These tests should work regardless of $wgCapitalLinks
 15+ */
 16+
 17+$info = array(
 18+ 'name' => 'test',
 19+ 'directory' => '/testdir',
 20+ 'url' => '/testurl',
 21+ 'hashLevels' => 2,
 22+ 'transformVia404' => false,
 23+);
 24+
 25+plan( 35 );
 26+
 27+$repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
 28+$repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
 29+$repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
 30+
 31+$file_hl0 = $repo_hl0->newFile( 'test!' );
 32+$file_hl2 = $repo_hl2->newFile( 'test!' );
 33+$file_lc = $repo_lc->newFile( 'test!' );
 34+
 35+is( $file_hl0->getHashPath(), '', 'Get hash path, hasLev 0' );
 36+is( $file_hl2->getHashPath(), 'a/a2/', 'Get hash path, hasLev 2' );
 37+is( $file_lc->getHashPath(), 'c/c4/', 'Get hash path, lc first' );
 38+
 39+is( $file_hl0->getRel(), 'Test!', 'Get rel path, hasLev 0' );
 40+is( $file_hl2->getRel(), 'a/a2/Test!', 'Get rel path, hasLev 2' );
 41+is( $file_lc->getRel(), 'c/c4/test!', 'Get rel path, lc first' );
 42+
 43+is( $file_hl0->getUrlRel(), 'Test%21', 'Get rel url, hasLev 0' );
 44+is( $file_hl2->getUrlRel(), 'a/a2/Test%21', 'Get rel url, hasLev 2' );
 45+is( $file_lc->getUrlRel(), 'c/c4/test%21', 'Get rel url, lc first' );
 46+
 47+is( $file_hl0->getArchivePath(), '/testdir/archive', 'Get archive path, hasLev 0' );
 48+is( $file_hl2->getArchivePath(), '/testdir/archive/a/a2', 'Get archive path, hasLev 2' );
 49+is( $file_hl0->getArchivePath( '!' ), '/testdir/archive/!', 'Get archive path, hasLev 0' );
 50+is( $file_hl2->getArchivePath( '!' ), '/testdir/archive/a/a2/!', 'Get archive path, hasLev 2' );
 51+
 52+is( $file_hl0->getThumbPath(), '/testdir/thumb/Test!', 'Get thumb path, hasLev 0' );
 53+is( $file_hl2->getThumbPath(), '/testdir/thumb/a/a2/Test!', 'Get thumb path, hasLev 2' );
 54+is( $file_hl0->getThumbPath( 'x' ), '/testdir/thumb/Test!/x', 'Get thumb path, hasLev 0' );
 55+is( $file_hl2->getThumbPath( 'x' ), '/testdir/thumb/a/a2/Test!/x', 'Get thumb path, hasLev 2' );
 56+
 57+is( $file_hl0->getArchiveUrl(), '/testurl/archive', 'Get archive url, hasLev 0' );
 58+is( $file_hl2->getArchiveUrl(), '/testurl/archive/a/a2', 'Get archive url, hasLev 2' );
 59+is( $file_hl0->getArchiveUrl( '!' ), '/testurl/archive/%21', 'Get archive url, hasLev 0' );
 60+is( $file_hl2->getArchiveUrl( '!' ), '/testurl/archive/a/a2/%21', 'Get archive url, hasLev 2' );
 61+
 62+is( $file_hl0->getThumbUrl(), '/testurl/thumb/Test%21', 'Get thumb url, hasLev 0' );
 63+is( $file_hl2->getThumbUrl(), '/testurl/thumb/a/a2/Test%21', 'Get thumb url, hasLev 2' );
 64+is( $file_hl0->getThumbUrl( 'x' ), '/testurl/thumb/Test%21/x', 'Get thumb url, hasLev 0' );
 65+is( $file_hl2->getThumbUrl( 'x' ), '/testurl/thumb/a/a2/Test%21/x', 'Get thumb url, hasLev 2' );
 66+
 67+is( $file_hl0->getArchiveVirtualUrl(), 'mwrepo://test/public/archive', 'Get archive virtual url, hasLev 0' );
 68+is( $file_hl2->getArchiveVirtualUrl(), 'mwrepo://test/public/archive/a/a2', 'Get archive virtual url, hasLev 2' );
 69+is( $file_hl0->getArchiveVirtualUrl( '!' ), 'mwrepo://test/public/archive/%21', 'Get archive virtual url, hasLev 0' );
 70+is( $file_hl2->getArchiveVirtualUrl( '!' ), 'mwrepo://test/public/archive/a/a2/%21', 'Get archive virtual url, hasLev 2' );
 71+
 72+is( $file_hl0->getThumbVirtualUrl(), 'mwrepo://test/public/thumb/Test%21', 'Get thumb virtual url, hasLev 0' );
 73+is( $file_hl2->getThumbVirtualUrl(), 'mwrepo://test/public/thumb/a/a2/Test%21', 'Get thumb virtual url, hasLev 2' );
 74+is( $file_hl0->getThumbVirtualUrl( '!' ), 'mwrepo://test/public/thumb/Test%21/%21', 'Get thumb virtual url, hasLev 0' );
 75+is( $file_hl2->getThumbVirtualUrl( '!' ), 'mwrepo://test/public/thumb/a/a2/Test%21/%21', 'Get thumb virtual url, hasLev 2' );
 76+
 77+is( $file_hl0->getUrl(), '/testurl/Test%21', 'Get url, hasLev 0' );
 78+is( $file_hl2->getUrl(), '/testurl/a/a2/Test%21', 'Get url, hasLev 2' );
Property changes on: trunk/phase3/t/inc/LocalFile.t
___________________________________________________________________
Added: svn:eol-style
179 + native
Index: trunk/phase3/t/inc/ImageFunctions.t
@@ -0,0 +1,56 @@
 2+#!/usr/bin/env php
 3+<?php
 4+
 5+define( 'MEDIAWIKI', true );
 6+require 't/Test.php';
 7+
 8+require 'includes/Defines.php';
 9+
 10+$vals = array(
 11+ array(
 12+ 'width' => 50,
 13+ 'height' => 50,
 14+ 'tests' => array(
 15+ 50 => 50,
 16+ 17 => 17,
 17+ 18 => 18 ) ),
 18+ array(
 19+ 'width' => 366,
 20+ 'height' => 300,
 21+ 'tests' => array(
 22+ 50 => 61,
 23+ 17 => 21,
 24+ 18 => 22 ) ),
 25+ array(
 26+ 'width' => 300,
 27+ 'height' => 366,
 28+ 'tests' => array(
 29+ 50 => 41,
 30+ 17 => 14,
 31+ 18 => 15 ) ),
 32+ array(
 33+ 'width' => 100,
 34+ 'height' => 400,
 35+ 'tests' => array(
 36+ 50 => 12,
 37+ 17 => 4,
 38+ 18 => 4 ) )
 39+);
 40+
 41+plan( 3 + 3 * count( $vals ) );
 42+
 43+require_ok( 'includes/ProfilerStub.php' );
 44+require_ok( 'includes/GlobalFunctions.php' );
 45+require_ok( 'includes/ImageFunctions.php' );
 46+
 47+foreach( $vals as $row ) {
 48+ extract( $row );
 49+ foreach( $tests as $max => $expected ) {
 50+ $y = round( $expected * $height / $width );
 51+ $result = wfFitBoxWidth( $width, $height, $max );
 52+ $y2 = round( $result * $height / $width );
 53+ is( $result, $expected,
 54+ "($width, $height, $max) wanted: {$expected}x{$y}, got: {$result}x{$y2}" );
 55+ }
 56+}
 57+
Property changes on: trunk/phase3/t/inc/ImageFunctions.t
___________________________________________________________________
Added: svn:eol-style
158 + native
Index: trunk/phase3/t/.htaccess
@@ -0,0 +1 @@
 2+Deny from all
Property changes on: trunk/phase3/t/.htaccess
___________________________________________________________________
Added: svn:eol-style
13 + native
Index: trunk/phase3/t/Search.inc
@@ -0,0 +1,165 @@
 2+<?php
 3+
 4+$wgCommandLineMode = true;
 5+$self = 'Search.t';
 6+define( 'MEDIAWIKI', true );
 7+require 't/Test.php';
 8+require 'includes/Defines.php';
 9+require 'includes/ProfilerStub.php';
 10+require 'LocalSettings.php';
 11+require 'AdminSettings.php';
 12+require 'includes/Setup.php';
 13+
 14+function buildTestDatabase( $tables ) {
 15+ global $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname, $wgDBtype;
 16+ $oldPrefix = $wgDBprefix;
 17+ $wgDBprefix = 'parsertest';
 18+ $class = 'Database' . ucfirst( $wgDBtype );
 19+ $db = new $class (
 20+ $wgDBserver,
 21+ $wgDBadminuser,
 22+ $wgDBadminpassword,
 23+ $wgDBname );
 24+ if( $db->isOpen() ) {
 25+ if ( !( stristr( $db->getSoftwareLink(), 'MySQL') && version_compare( $db->getServerVersion(), '4.1', '<' ) ) ) {
 26+ # Database that supports CREATE TABLE ... LIKE
 27+ foreach ($tables as $tbl) {
 28+ $newTableName = $db->tableName( $tbl );
 29+ #$tableName = $oldPrefix . $tbl;
 30+ $tableName = $tbl;
 31+ $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)");
 32+ }
 33+ } else {
 34+ # Hack for MySQL versions < 4.1, which don't support
 35+ # "CREATE TABLE ... LIKE". Note that
 36+ # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
 37+ # would not create the indexes we need....
 38+ foreach ($tables as $tbl) {
 39+ $res = $db->query("SHOW CREATE TABLE $tbl");
 40+ $row = $db->fetchRow($res);
 41+ $create = $row[1];
 42+ $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
 43+ . $wgDBprefix . '\\1`', $create);
 44+ if ($create === $create_tmp) {
 45+ # Couldn't do replacement
 46+ wfDie( "could not create temporary table $tbl" );
 47+ }
 48+ $db->query($create_tmp);
 49+ }
 50+
 51+ }
 52+ return $db;
 53+ } else {
 54+ // Something amiss
 55+ return null;
 56+ }
 57+}
 58+
 59+class SearchEngineTest {
 60+ var $db, $search;
 61+
 62+ function __construct( SearchEngine $search ){
 63+ $this->search = $search;
 64+ $this->db = $this->search->db;
 65+ }
 66+
 67+ function insertSearchData() {
 68+ $this->db->safeQuery( <<<END
 69+ INSERT INTO ! (page_id,page_namespace,page_title,page_latest)
 70+ VALUES (1, 0, 'Main_Page', 1),
 71+ (2, 1, 'Main_Page', 2),
 72+ (3, 0, 'Smithee', 3),
 73+ (4, 1, 'Smithee', 4),
 74+ (5, 0, 'Unrelated_page', 5),
 75+ (6, 0, 'Another_page', 6),
 76+ (7, 4, 'Help', 7),
 77+ (8, 0, 'Thppt', 8),
 78+ (9, 0, 'Alan_Smithee', 9),
 79+ (10, 0, 'Pages', 10)
 80+END
 81+ , $this->db->tableName( 'page' ) );
 82+ $this->db->safeQuery( <<<END
 83+ INSERT INTO ! (rev_id,rev_page)
 84+ VALUES (1, 1),
 85+ (2, 2),
 86+ (3, 3),
 87+ (4, 4),
 88+ (5, 5),
 89+ (6, 6),
 90+ (7, 7),
 91+ (8, 8),
 92+ (9, 9),
 93+ (10, 10)
 94+END
 95+ , $this->db->tableName( 'revision' ) );
 96+ $this->db->safeQuery( <<<END
 97+ INSERT INTO ! (old_id,old_text)
 98+ VALUES (1, 'This is a main page'),
 99+ (2, 'This is a talk page to the main page, see [[smithee]]'),
 100+ (3, 'A smithee is one who smiths. See also [[Alan Smithee]]'),
 101+ (4, 'This article sucks.'),
 102+ (5, 'Nothing in this page is about the S word.'),
 103+ (6, 'This page also is unrelated.'),
 104+ (7, 'Help me!'),
 105+ (8, 'Blah blah'),
 106+ (9, 'yum'),
 107+ (10,'are food')
 108+END
 109+ , $this->db->tableName( 'text' ) );
 110+ $this->db->safeQuery( <<<END
 111+ INSERT INTO ! (si_page,si_title,si_text)
 112+ VALUES (1, 'main page', 'this is a main page'),
 113+ (2, 'main page', 'this is a talk page to the main page, see smithee'),
 114+ (3, 'smithee', 'a smithee is one who smiths see also alan smithee'),
 115+ (4, 'smithee', 'this article sucks'),
 116+ (5, 'unrelated page', 'nothing in this page is about the s word'),
 117+ (6, 'another page', 'this page also is unrelated'),
 118+ (7, 'help', 'help me'),
 119+ (8, 'thppt', 'blah blah'),
 120+ (9, 'alan smithee', 'yum'),
 121+ (10, 'pages', 'are food')
 122+END
 123+ , $this->db->tableName( 'searchindex' ) );
 124+ }
 125+
 126+ function fetchIds( $results ) {
 127+ $matches = array();
 128+ while( $row = $results->next() ) {
 129+ $matches[] = $row->getTitle()->getPrefixedText();
 130+ }
 131+ $results->free();
 132+ # Search is not guaranteed to return results in a certain order;
 133+ # sort them numerically so we will compare simply that we received
 134+ # the expected matches.
 135+ sort( $matches );
 136+ return $matches;
 137+ }
 138+
 139+ function run(){
 140+ if( is_null( $this->db ) ){
 141+ fail( "Can't find a database to test with." );
 142+ return;
 143+ }
 144+
 145+ $this->insertSearchData();
 146+ plan( 4 );
 147+
 148+ $exp = array( 'Smithee' );
 149+ $got = $this->fetchIds( $this->search->searchText( 'smithee' ) );
 150+ is( $got, $exp, "Plain search" );
 151+
 152+ $exp = array( 'Alan Smithee', 'Smithee' );
 153+ $got = $this->fetchIds( $this->search->searchTitle( 'smithee' ) );
 154+ is( $got, $exp, "Title search" );
 155+
 156+ $this->search->setNamespaces( array( 0, 1, 4 ) );
 157+
 158+ $exp = array( 'Smithee', 'Talk:Main Page', );
 159+ $got = $this->fetchIds( $this->search->searchText( 'smithee' ) );
 160+ is( $got, $exp, "Power search" );
 161+
 162+ $exp = array( 'Alan Smithee', 'Smithee', 'Talk:Smithee', );
 163+ $got = $this->fetchIds( $this->search->searchTitle( 'smithee' ) );
 164+ is( $got, $exp, "Title power search" );
 165+ }
 166+}
\ No newline at end of file
Property changes on: trunk/phase3/t/Search.inc
___________________________________________________________________
Added: svn:eol-style
1167 + native

Status & tagging log