article
* (bug 22315) SpecialRecentChangesQuery hook now pass $query_options and checks
the return value
+* Separate unit test suites under t/ and tests/ were merged and moved to
+ maintenance/tests/.
=== Bug fixes in 1.16 ===
--- /dev/null
+LocalTestSettings.php
+*~
+bin
+.classpath
+.project
+project.index
--- /dev/null
+<?php
+
+class ArticleTest extends PHPUnit_Framework_TestCase {
+ var $saveGlobals = array();
+
+ function setUp() {
+ global $wgContLang;
+ $wgContLang = Language::factory( 'en' );
+ $globalSet = array(
+ 'wgLegacyEncoding' => false,
+ 'wgCompressRevisions' => false,
+ 'wgInputEncoding' => 'utf-8',
+ 'wgOutputEncoding' => 'utf-8' );
+ foreach( $globalSet as $var => $data ) {
+ $this->saveGlobals[$var] = $GLOBALS[$var];
+ $GLOBALS[$var] = $data;
+ }
+ }
+
+ function tearDown() {
+ foreach( $this->saveGlobals as $var => $data ) {
+ $GLOBALS[$var] = $data;
+ }
+ }
+
+ function testGetRevisionText() {
+ $row = new stdClass;
+ $row->old_flags = '';
+ $row->old_text = 'This is a bunch of revision text.';
+ $this->assertEquals(
+ 'This is a bunch of revision text.',
+ Revision::getRevisionText( $row ) );
+ }
+
+ function testGetRevisionTextGzip() {
+ $row = new stdClass;
+ $row->old_flags = 'gzip';
+ $row->old_text = gzdeflate( 'This is a bunch of revision text.' );
+ $this->assertEquals(
+ 'This is a bunch of revision text.',
+ Revision::getRevisionText( $row ) );
+ }
+
+ function testGetRevisionTextUtf8Native() {
+ $row = new stdClass;
+ $row->old_flags = 'utf-8';
+ $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
+ $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
+ $this->assertEquals(
+ "Wiki est l'\xc3\xa9cole superieur !",
+ Revision::getRevisionText( $row ) );
+ }
+
+ function testGetRevisionTextUtf8Legacy() {
+ $row = new stdClass;
+ $row->old_flags = '';
+ $row->old_text = "Wiki est l'\xe9cole superieur !";
+ $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
+ $this->assertEquals(
+ "Wiki est l'\xc3\xa9cole superieur !",
+ Revision::getRevisionText( $row ) );
+ }
+
+ function testGetRevisionTextUtf8NativeGzip() {
+ $row = new stdClass;
+ $row->old_flags = 'gzip,utf-8';
+ $row->old_text = gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" );
+ $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
+ $this->assertEquals(
+ "Wiki est l'\xc3\xa9cole superieur !",
+ Revision::getRevisionText( $row ) );
+ }
+
+ function testGetRevisionTextUtf8LegacyGzip() {
+ $row = new stdClass;
+ $row->old_flags = 'gzip';
+ $row->old_text = gzdeflate( "Wiki est l'\xe9cole superieur !" );
+ $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
+ $this->assertEquals(
+ "Wiki est l'\xc3\xa9cole superieur !",
+ Revision::getRevisionText( $row ) );
+ }
+
+ function testCompressRevisionTextUtf8() {
+ $row = new stdClass;
+ $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
+ $row->old_flags = Revision::compressRevisionText( $row->old_text );
+ $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
+ "Flags should contain 'utf-8'" );
+ $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ),
+ "Flags should not contain 'gzip'" );
+ $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
+ $row->old_text, "Direct check" );
+ $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
+ Revision::getRevisionText( $row ), "getRevisionText" );
+ }
+
+ function testCompressRevisionTextUtf8Gzip() {
+ $GLOBALS['wgCompressRevisions'] = true;
+ $row = new stdClass;
+ $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
+ $row->old_flags = Revision::compressRevisionText( $row->old_text );
+ $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
+ "Flags should contain 'utf-8'" );
+ $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ),
+ "Flags should contain 'gzip'" );
+ $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
+ gzinflate( $row->old_text ), "Direct check" );
+ $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
+ Revision::getRevisionText( $row ), "getRevisionText" );
+ }
+}
+
+
--- /dev/null
+<?php
+
+class DatabaseTest extends PHPUnit_Framework_TestCase {
+ var $db;
+
+ function setUp() {
+ $this->db = wfGetDB( DB_SLAVE );
+ }
+
+ function testAddQuotesNull() {
+ $check = "NULL";
+ if ( $this->db->getType() === 'sqlite' ) {
+ $check = "''";
+ }
+ $this->assertEquals( $check, $this->db->addQuotes( null ) );
+ }
+
+ function testAddQuotesInt() {
+ # returning just "1234" should be ok too, though...
+ # maybe
+ $this->assertEquals(
+ "'1234'",
+ $this->db->addQuotes( 1234 ) );
+ }
+
+ function testAddQuotesFloat() {
+ # returning just "1234.5678" would be ok too, though
+ $this->assertEquals(
+ "'1234.5678'",
+ $this->db->addQuotes( 1234.5678 ) );
+ }
+
+ function testAddQuotesString() {
+ $this->assertEquals(
+ "'string'",
+ $this->db->addQuotes( 'string' ) );
+ }
+
+ function testAddQuotesStringQuote() {
+ $check = "'string''s cause trouble'";
+ if ( $this->db->getType() === 'mysql' ) {
+ $check = "'string\'s cause trouble'";
+ }
+ $this->assertEquals(
+ $check,
+ $this->db->addQuotes( "string's cause trouble" ) );
+ }
+
+ function testFillPreparedEmpty() {
+ $sql = $this->db->fillPrepared(
+ 'SELECT * FROM interwiki', array() );
+ $this->assertEquals(
+ "SELECT * FROM interwiki",
+ $sql);
+ }
+
+ function testFillPreparedQuestion() {
+ $sql = $this->db->fillPrepared(
+ 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
+ array( 4, "Snicker's_paradox" ) );
+
+ $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker''s_paradox'";
+ if ( $this->db->getType() === 'mysql' ) {
+ $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'";
+ }
+ $this->assertEquals( $check, $sql );
+ }
+
+ function testFillPreparedBang() {
+ $sql = $this->db->fillPrepared(
+ 'SELECT user_id FROM ! WHERE user_name=?',
+ array( '"user"', "Slash's Dot" ) );
+
+ $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash''s Dot'";
+ if ( $this->db->getType() === 'mysql' ) {
+ $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'";
+ }
+ $this->assertEquals( $check, $sql );
+ }
+
+ function testFillPreparedRaw() {
+ $sql = $this->db->fillPrepared(
+ "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
+ array( '"user"', "Slash's Dot" ) );
+ $this->assertEquals(
+ "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",
+ $sql);
+ }
+
+}
+
+
--- /dev/null
+<?php
+
+class GlobalTest extends PHPUnit_Framework_TestCase {
+ function setUp() {
+ global $wgReadOnlyFile;
+ $this->originals['wgReadOnlyFile'] = $wgReadOnlyFile;
+ $wgReadOnlyFile = tempnam(wfTempDir(), "mwtest_readonly");
+ unlink( $wgReadOnlyFile );
+ }
+
+ function tearDown() {
+ global $wgReadOnlyFile;
+ if( file_exists( $wgReadOnlyFile ) ) {
+ unlink( $wgReadOnlyFile );
+ }
+ $wgReadOnlyFile = $this->originals['wgReadOnlyFile'];
+ }
+
+ function testRandom() {
+ # This could hypothetically fail, but it shouldn't ;)
+ $this->assertFalse(
+ wfRandom() == wfRandom() );
+ }
+
+ function testUrlencode() {
+ $this->assertEquals(
+ "%E7%89%B9%E5%88%A5:Contributions/Foobar",
+ wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
+ }
+
+ function testReadOnlyEmpty() {
+ global $wgReadOnly;
+ $wgReadOnly = null;
+
+ $this->assertFalse( wfReadOnly() );
+ $this->assertFalse( wfReadOnly() );
+ }
+
+ function testReadOnlySet() {
+ global $wgReadOnly, $wgReadOnlyFile;
+
+ $f = fopen( $wgReadOnlyFile, "wt" );
+ fwrite( $f, 'Message' );
+ fclose( $f );
+ $wgReadOnly = null;
+
+ $this->assertTrue( wfReadOnly() );
+ $this->assertTrue( wfReadOnly() );
+
+ unlink( $wgReadOnlyFile );
+ $wgReadOnly = null;
+
+ $this->assertFalse( wfReadOnly() );
+ $this->assertFalse( wfReadOnly() );
+ }
+
+ function testQuotedPrintable() {
+ $this->assertEquals(
+ "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
+ wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
+ }
+
+ function testTime() {
+ $start = wfTime();
+ $this->assertType( 'float', $start );
+ $end = wfTime();
+ $this->assertTrue( $end > $start, "Time is running backwards!" );
+ }
+
+ function testArrayToCGI() {
+ $this->assertEquals(
+ "baz=AT%26T&foo=bar",
+ wfArrayToCGI(
+ array( 'baz' => 'AT&T', 'ignore' => '' ),
+ array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
+ }
+
+ function testMimeTypeMatch() {
+ $this->assertEquals(
+ 'text/html',
+ mimeTypeMatch( 'text/html',
+ array( 'application/xhtml+xml' => 1.0,
+ 'text/html' => 0.7,
+ 'text/plain' => 0.3 ) ) );
+ $this->assertEquals(
+ 'text/*',
+ mimeTypeMatch( 'text/html',
+ array( 'image/*' => 1.0,
+ 'text/*' => 0.5 ) ) );
+ $this->assertEquals(
+ '*/*',
+ mimeTypeMatch( 'text/html',
+ array( '*/*' => 1.0 ) ) );
+ $this->assertNull(
+ mimeTypeMatch( 'text/html',
+ array( 'image/png' => 1.0,
+ 'image/svg+xml' => 0.5 ) ) );
+ }
+
+ function testNegotiateType() {
+ $this->assertEquals(
+ 'text/html',
+ wfNegotiateType(
+ array( 'application/xhtml+xml' => 1.0,
+ 'text/html' => 0.7,
+ 'text/plain' => 0.5,
+ 'text/*' => 0.2 ),
+ array( 'text/html' => 1.0 ) ) );
+ $this->assertEquals(
+ 'application/xhtml+xml',
+ wfNegotiateType(
+ array( 'application/xhtml+xml' => 1.0,
+ 'text/html' => 0.7,
+ 'text/plain' => 0.5,
+ 'text/*' => 0.2 ),
+ array( 'application/xhtml+xml' => 1.0,
+ 'text/html' => 0.5 ) ) );
+ $this->assertEquals(
+ 'text/html',
+ wfNegotiateType(
+ array( 'text/html' => 1.0,
+ 'text/plain' => 0.5,
+ 'text/*' => 0.5,
+ 'application/xhtml+xml' => 0.2 ),
+ array( 'application/xhtml+xml' => 1.0,
+ 'text/html' => 0.5 ) ) );
+ $this->assertEquals(
+ 'text/html',
+ wfNegotiateType(
+ array( 'text/*' => 1.0,
+ 'image/*' => 0.7,
+ '*/*' => 0.3 ),
+ array( 'application/xhtml+xml' => 1.0,
+ 'text/html' => 0.5 ) ) );
+ $this->assertNull(
+ wfNegotiateType(
+ array( 'text/*' => 1.0 ),
+ array( 'application/xhtml+xml' => 1.0 ) ) );
+ }
+
+ function testTimestamp() {
+ $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
+ $this->assertEquals(
+ '20010115123456',
+ wfTimestamp( TS_MW, $t ),
+ 'TS_UNIX to TS_MW' );
+ $this->assertEquals(
+ 979562096,
+ wfTimestamp( TS_UNIX, $t ),
+ 'TS_UNIX to TS_UNIX' );
+ $this->assertEquals(
+ '2001-01-15 12:34:56',
+ wfTimestamp( TS_DB, $t ),
+ 'TS_UNIX to TS_DB' );
+
+ $this->assertEquals(
+ '20010115123456',
+ wfTimestamp( TS_MW, '20010115123456' ),
+ 'TS_MW to TS_MW' );
+ $this->assertEquals(
+ 979562096,
+ wfTimestamp( TS_UNIX, '20010115123456' ),
+ 'TS_MW to TS_UNIX' );
+ $this->assertEquals(
+ '2001-01-15 12:34:56',
+ wfTimestamp( TS_DB, '20010115123456' ),
+ 'TS_MW to TS_DB' );
+
+ $this->assertEquals(
+ '20010115123456',
+ wfTimestamp( TS_MW, '2001-01-15 12:34:56' ),
+ 'TS_DB to TS_MW' );
+ $this->assertEquals(
+ 979562096,
+ wfTimestamp( TS_UNIX, '2001-01-15 12:34:56' ),
+ 'TS_DB to TS_UNIX' );
+ $this->assertEquals(
+ '2001-01-15 12:34:56',
+ wfTimestamp( TS_DB, '2001-01-15 12:34:56' ),
+ 'TS_DB to TS_DB' );
+ }
+
+ function testBasename() {
+ $sets = array(
+ '' => '',
+ '/' => '',
+ '\\' => '',
+ '//' => '',
+ '\\\\' => '',
+ 'a' => 'a',
+ 'aaaa' => 'aaaa',
+ '/a' => 'a',
+ '\\a' => 'a',
+ '/aaaa' => 'aaaa',
+ '\\aaaa' => 'aaaa',
+ '/aaaa/' => 'aaaa',
+ '\\aaaa\\' => 'aaaa',
+ '\\aaaa\\' => 'aaaa',
+ '/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',
+ 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
+ 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
+ );
+ foreach( $sets as $from => $to ) {
+ $this->assertEquals( $to, wfBaseName( $from ),
+ "wfBaseName('$from') => '$to'");
+ }
+ }
+
+ /* TODO: many more! */
+}
+
+
--- /dev/null
+<?php
+
+class MockCookie extends Cookie {
+ public function canServeDomain($arg) { return parent::canServeDomain($arg); }
+ public function canServePath($arg) { return parent::canServePath($arg); }
+ public function isUnExpired() { return parent::isUnExpired(); }
+}
+
+class HttpTest extends PhpUnit_Framework_TestCase {
+ static $content;
+ static $headers;
+ static $has_curl;
+ static $has_fopen;
+ static $has_proxy = false;
+ static $proxy = "http://hulk:8080/";
+ var $test_geturl = array(
+ "http://www.example.com/",
+ "http://pecl.php.net/feeds/pkg_apc.rss",
+ "http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id=3",
+ "http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw",
+ "http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&format=php",
+ );
+ var $test_requesturl = array( "http://en.wikipedia.org/wiki/Special:Export/User:MarkAHershberger" );
+
+ var $test_posturl = array( "http://www.comp.leeds.ac.uk/cgi-bin/Perl/environment-example" => "review=test" );
+
+ function setup() {
+ putenv("http_proxy"); /* Remove any proxy env var, so curl doesn't get confused */
+ if ( is_array( self::$content ) ) {
+ return;
+ }
+ self::$has_curl = function_exists( 'curl_init' );
+ self::$has_fopen = wfIniGetBool( 'allow_url_fopen' );
+
+ if ( !file_exists("/usr/bin/curl") ) {
+ $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.");
+ }
+
+ $content = tempnam( wfTempDir(), "" );
+ $headers = tempnam( wfTempDir(), "" );
+ if ( !$content && !$headers ) {
+ die( "Couldn't create temp file!" );
+ }
+
+ // This probably isn't the best test for a proxy, but it works on my system!
+ system("curl -0 -o $content -s ".self::$proxy);
+ $out = file_get_contents( $content );
+ if( $out ) {
+ self::$has_proxy = true;
+ }
+
+ /* Maybe use wget instead of curl here ... just to use a different codebase? */
+ foreach ( $this->test_geturl as $u ) {
+ system( "curl -0 -s -D $headers '$u' -o $content" );
+ self::$content["GET $u"] = file_get_contents( $content );
+ self::$headers["GET $u"] = file_get_contents( $headers );
+ }
+ foreach ( $this->test_requesturl as $u ) {
+ system( "curl -0 -s -X POST -H 'Content-Length: 0' -D $headers '$u' -o $content" );
+ self::$content["POST $u"] = file_get_contents( $content );
+ self::$headers["POST $u"] = file_get_contents( $headers );
+ }
+ foreach ( $this->test_posturl as $u => $postData ) {
+ system( "curl -0 -s -X POST -d '$postData' -D $headers '$u' -o $content" );
+ self::$content["POST $u => $postData"] = file_get_contents( $content );
+ self::$headers["POST $u => $postData"] = file_get_contents( $headers );
+ }
+ unlink( $content );
+ unlink( $headers );
+ }
+
+
+ function testInstantiation() {
+ Http::$httpEngine = false;
+
+ $r = HttpRequest::factory("http://www.example.com/");
+ if ( self::$has_curl ) {
+ $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' ));
+ } else {
+ $this->assertThat($r, $this->isInstanceOf( 'PhpHttpRequest' ));
+ }
+ unset($r);
+
+ if( !self::$has_fopen ) {
+ $this->setExpectedException( 'MWException' );
+ }
+ Http::$httpEngine = 'php';
+ $r = HttpRequest::factory("http://www.example.com/");
+ $this->assertThat($r, $this->isInstanceOf( 'PhpHttpRequest' ));
+ unset($r);
+
+ if( !self::$has_curl ) {
+ $this->setExpectedException( 'MWException' );
+ }
+ Http::$httpEngine = 'curl';
+ $r = HttpRequest::factory("http://www.example.com/");
+ if( self::$has_curl ) {
+ $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' ));
+ }
+ }
+
+ function runHTTPFailureChecks() {
+ // Each of the following requests should result in a failure.
+
+ $timeout = 1;
+ $start_time = time();
+ $r = HTTP::get( "http://www.example.com:1/", $timeout);
+ $end_time = time();
+ $this->assertLessThan($timeout+2, $end_time - $start_time,
+ "Request took less than {$timeout}s via ".Http::$httpEngine);
+ $this->assertEquals($r, false, "false -- what we get on error from Http::get()");
+ }
+
+ function testFailureDefault() {
+ Http::$httpEngine = false;
+ self::runHTTPFailureChecks();
+ }
+
+ function testFailurePhp() {
+ if ( !self::$has_fopen ) {
+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
+ }
+
+ Http::$httpEngine = "php";
+ self::runHTTPFailureChecks();
+ }
+
+ function testFailureCurl() {
+ if ( !self::$has_curl ) {
+ $this->markTestIncomplete( "This test requires curl." );
+ }
+
+ Http::$httpEngine = "curl";
+ self::runHTTPFailureChecks();
+ }
+
+ /* ./phase3/includes/Import.php:1108: $data = Http::request( $method, $url ); */
+ /* ./includes/Import.php:1124: $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */
+ /* ./includes/Import.php:1134: return ImportStreamSource::newFromURL( $url, "POST" ); */
+ function runHTTPRequests($proxy=null) {
+ $opt = array();
+
+ if($proxy) {
+ $opt['proxy'] = $proxy;
+ } elseif( $proxy === false ) {
+ $opt['noProxy'] = true;
+ }
+
+ /* no postData here because the only request I could find in code so far didn't have any */
+ foreach ( $this->test_requesturl as $u ) {
+ $r = Http::request( "POST", $u, $opt );
+ $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with ".Http::$httpEngine );
+ }
+ }
+
+ function testRequestDefault() {
+ Http::$httpEngine = false;
+ self::runHTTPRequests();
+ }
+
+ function testRequestPhp() {
+ if ( !self::$has_fopen ) {
+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
+ }
+
+ Http::$httpEngine = "php";
+ self::runHTTPRequests();
+ }
+
+ function testRequestCurl() {
+ if ( !self::$has_curl ) {
+ $this->markTestIncomplete( "This test requires curl." );
+ }
+
+ Http::$httpEngine = "curl";
+ self::runHTTPRequests();
+ }
+
+ /* ./extensions/SpamBlacklist/SpamBlacklist_body.php:164: $httpText = Http::get( $fileName ); */
+ /* ./extensions/ApiSVGProxy/ApiSVGProxy.body.php:44: $contents = Http::get( $file->getFullUrl() ); */
+ /* ./extensions/BookInformation/drivers/IsbnDb.php:24: if( ( $xml = Http::get( $uri ) ) !== false ) { */
+ /* ./extensions/BookInformation/drivers/Amazon.php:23: if( ( $xml = Http::get( $uri ) ) !== false ) { */
+ /* ./extensions/TitleBlacklist/TitleBlacklist.list.php:217: $result = Http::get( $url ); */
+ /* ./extensions/TSPoll/TSPoll.php:68: $get_server = Http::get( 'http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id='.$id ); */
+ /* ./extensions/TSPoll/TSPoll.php:70: $get_server = Http::get( 'http://toolserver.org/~jan/poll/main.php?page=wiki_output&id='.$id ); */
+ /* ./extensions/DoubleWiki/DoubleWiki.php:56: $translation = Http::get( $url.$sep.'action=render' ); */
+ /* ./extensions/ExternalPages/ExternalPages_body.php:177: $serializedText = Http::get( $this->mPageURL ); */
+ /* ./extensions/Translate/utils/TranslationHelpers.php:143: $suggestions = Http::get( $url, $timeout ); */
+ /* ./extensions/Translate/SpecialImportTranslations.php:169: $filedata = Http::get( $url ); ; */
+ /* ./extensions/Translate/TranslateEditAddons.php:338: $suggestions = Http::get( $url, $timeout ); */
+ /* ./extensions/SecurePoll/includes/user/Auth.php:283: $value = Http::get( $url, 20, $curlParams ); */
+ /* ./extensions/DumpHTML/dumpHTML.inc:778: $contents = Http::get( $url ); */
+ /* ./extensions/DumpHTML/dumpHTML.inc:1298: $contents = Http::get( $sourceUrl ); */
+ /* ./extensions/DumpHTML/dumpHTML.inc:1373: $contents = Http::get( $sourceUrl ); */
+ /* ./phase3/maintenance/rebuildInterwiki.inc:101: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
+ /* ./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' ); */
+ /* ./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' ); */
+ /* ./phase3/maintenance/dumpInterwiki.inc:95: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
+ /* ./phase3/includes/parser/Parser.php:3204: $text = Http::get($url); */
+ /* ./phase3/includes/filerepo/ForeignAPIRepo.php:131: $data = Http::get( $url ); */
+ /* ./phase3/includes/filerepo/ForeignAPIRepo.php:205: $thumb = Http::get( $foreignUrl ); */
+ /* ./phase3/includes/filerepo/File.php:1105: $res = Http::get( $renderUrl ); */
+ /* ./phase3/includes/GlobalFunctions.php:2760: * @deprecated Use Http::get() instead */
+ /* ./phase3/includes/GlobalFunctions.php:2764: return Http::get( $url ); */
+ /* ./phase3/includes/ExternalStoreHttp.php:18: $ret = Http::get( $url ); */
+ /* ./phase3/includes/Import.php:357: $data = Http::get( $src ); */
+ /* ./extensions/ExternalData/ED_Utils.php:291: return Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
+ /* ./extensions/ExternalData/ED_Utils.php:293: return Http::get( $url ); */
+ /* ./extensions/ExternalData/ED_Utils.php:306: $page = Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
+ /* ./extensions/ExternalData/ED_Utils.php:308: $page = Http::get( $url ); */
+ /* ./extensions/CodeReview/backend/Subversion.php:320: $blob = Http::get( $target, $this->mTimeout ); */
+ /* ./extensions/AmazonPlus/AmazonPlus.php:214: $this->response = Http::get( $urlstr ); */
+ /* ./extensions/StaticWiki/StaticWiki.php:24: $text = Http::get( $url ) ; */
+ /* ./extensions/StaticWiki/StaticWiki.php:64: $history = Http::get ( $wgStaticWikiExternalSite . "index.php?title=" . urlencode ( $url_title ) . "&action=history" ) ; */
+ /* ./extensions/Configure/scripts/findSettings.php:126: $cont = Http::get( "http://www.mediawiki.org/w/index.php?title={$page}&action=raw" ); */
+ /* ./extensions/TorBlock/TorBlock.class.php:148: $data = Http::get( $url ); */
+ /* ./extensions/HoneypotIntegration/HoneypotIntegration.class.php:60: $data = Http::get( $wgHoneypotURLSource, 'default', */
+ /* ./extensions/SemanticForms/includes/SF_Utils.inc:378: $page_contents = Http::get($url); */
+ /* ./extensions/LocalisationUpdate/LocalisationUpdate.class.php:172: $basefilecontents = Http::get( $basefile ); */
+ /* ./extensions/APC/SpecialAPC.php:245: $rss = Http::get( 'http://pecl.php.net/feeds/pkg_apc.rss' ); */
+ /* ./extensions/Interlanguage/Interlanguage.php:56: $a = Http::get( $url ); */
+ /* ./extensions/MWSearch/MWSearch_body.php:492: $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts); */
+ function runHTTPGets($proxy=null) {
+ $opt = array();
+
+ if($proxy) {
+ $opt['proxy'] = $proxy;
+ } elseif( $proxy === false ) {
+ $opt['noProxy'] = true;
+ }
+
+ foreach ( $this->test_geturl as $u ) {
+ $r = Http::get( $u, 30, $opt ); /* timeout of 30s */
+ $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with ".Http::$httpEngine );
+ }
+ }
+
+ function testGetDefault() {
+ Http::$httpEngine = false;
+ self::runHTTPGets();
+ }
+
+ function testGetPhp() {
+ if ( !self::$has_fopen ) {
+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
+ }
+
+ Http::$httpEngine = "php";
+ self::runHTTPGets();
+ }
+
+ function testGetCurl() {
+ if ( !self::$has_curl ) {
+ $this->markTestIncomplete( "This test requires curl." );
+ }
+
+ Http::$httpEngine = "curl";
+ self::runHTTPGets();
+ }
+
+ /* ./phase3/maintenance/parserTests.inc:1618: return Http::post( $url, array( 'postData' => wfArrayToCGI( $data ) ) ); */
+ function runHTTPPosts($proxy=null) {
+ $opt = array();
+
+ if($proxy) {
+ $opt['proxy'] = $proxy;
+ } elseif( $proxy === false ) {
+ $opt['noProxy'] = true;
+ }
+
+ foreach ( $this->test_posturl as $u => $postData ) {
+ $opt['postData'] = $postData;
+ $r = Http::post( $u, $opt );
+ $this->assertEquals( self::$content["POST $u => $postData"], "$r",
+ "POST $u (postData=$postData) with ".Http::$httpEngine );
+ }
+ }
+
+ function testPostDefault() {
+ Http::$httpEngine = false;
+ self::runHTTPPosts();
+ }
+
+ function testPostPhp() {
+ if ( !self::$has_fopen ) {
+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
+ }
+
+ Http::$httpEngine = "php";
+ self::runHTTPPosts();
+ }
+
+ function testPostCurl() {
+ if ( !self::$has_curl ) {
+ $this->markTestIncomplete( "This test requires curl." );
+ }
+
+ Http::$httpEngine = "curl";
+ self::runHTTPPosts();
+ }
+
+ function runProxyRequests() {
+ if(!self::$has_proxy) {
+ $this->markTestIncomplete( "This test requires a proxy." );
+ }
+ self::runHTTPGets(self::$proxy);
+ self::runHTTPPosts(self::$proxy);
+ self::runHTTPRequests(self::$proxy);
+
+ // Set false here to do noProxy
+ self::runHTTPGets(false);
+ self::runHTTPPosts(false);
+ self::runHTTPRequests(false);
+ }
+
+ function testProxyDefault() {
+ Http::$httpEngine = false;
+ self::runProxyRequests();
+ }
+
+ function testProxyPhp() {
+ if ( !self::$has_fopen ) {
+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
+ }
+
+ Http::$httpEngine = 'php';
+ self::runProxyRequests();
+ }
+
+ function testProxyCurl() {
+ if ( !self::$has_curl ) {
+ $this->markTestIncomplete( "This test requires curl." );
+ }
+
+ Http::$httpEngine = 'curl';
+ self::runProxyRequests();
+ }
+
+ function testIsLocalUrl() {
+ }
+
+ /* ./extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php:559: $user_agent = Http::userAgent(); */
+ function testUserAgent() {
+ }
+
+ function testIsValidUrl() {
+ }
+
+ function testSetCookie() {
+ $c = new MockCookie( "name", "value",
+ array(
+ "domain" => ".example.com",
+ "path" => "/path/",
+ ) );
+
+ $this->assertFalse($c->canServeDomain("example.com"));
+ $this->assertFalse($c->canServeDomain("www.example.net"));
+ $this->assertTrue($c->canServeDomain("www.example.com"));
+
+ $this->assertFalse($c->canServePath("/"));
+ $this->assertFalse($c->canServePath("/bogus/path/"));
+ $this->assertFalse($c->canServePath("/path"));
+ $this->assertTrue($c->canServePath("/path/"));
+
+ $this->assertTrue($c->isUnExpired());
+
+ $this->assertEquals("", $c->serializeToHttpRequest("/path/", "www.example.net"));
+ $this->assertEquals("", $c->serializeToHttpRequest("/", "www.example.com"));
+ $this->assertEquals("name=value", $c->serializeToHttpRequest("/path/", "www.example.com"));
+
+ $c = new MockCookie( "name", "value",
+ array(
+ "domain" => ".example.com",
+ "path" => "/path/",
+ "expires" => "January 1, 1990",
+ ) );
+ $this->assertFalse($c->isUnExpired());
+ $this->assertEquals("", $c->serializeToHttpRequest("/path/", "www.example.com"));
+
+ $c = new MockCookie( "name", "value",
+ array(
+ "domain" => ".example.com",
+ "path" => "/path/",
+ "expires" => "January 1, 2999",
+ ) );
+ $this->assertTrue($c->isUnExpired());
+ $this->assertEquals("name=value", $c->serializeToHttpRequest("/path/", "www.example.com"));
+
+
+ }
+
+ function testCookieJarSetCookie() {
+ $cj = new CookieJar;
+ $cj->setCookie( "name", "value",
+ array(
+ "domain" => ".example.com",
+ "path" => "/path/",
+ ) );
+ $cj->setCookie( "name2", "value",
+ array(
+ "domain" => ".example.com",
+ "path" => "/path/sub",
+ ) );
+ $cj->setCookie( "name3", "value",
+ array(
+ "domain" => ".example.com",
+ "path" => "/",
+ ) );
+ $cj->setCookie( "name4", "value",
+ array(
+ "domain" => ".example.net",
+ "path" => "/path/",
+ ) );
+ $cj->setCookie( "name5", "value",
+ array(
+ "domain" => ".example.net",
+ "path" => "/path/",
+ "expires" => "January 1, 1999",
+ ) );
+
+ $this->assertEquals("name4=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
+ $this->assertEquals("name3=value", $cj->serializeToHttpRequest("/", "www.example.com"));
+ $this->assertEquals("name=value; name3=value", $cj->serializeToHttpRequest("/path/", "www.example.com"));
+
+ $cj->setCookie( "name5", "value",
+ array(
+ "domain" => ".example.net",
+ "path" => "/path/",
+ "expires" => "January 1, 2999",
+ ) );
+ $this->assertEquals("name4=value; name5=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
+
+ $cj->setCookie( "name4", "value",
+ array(
+ "domain" => ".example.net",
+ "path" => "/path/",
+ "expires" => "January 1, 1999",
+ ) );
+ $this->assertEquals("name5=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
+ }
+
+ function testParseResponseHeader() {
+ $cj = new CookieJar;
+
+ $h[] = "Set-Cookie: name4=value; domain=.example.com; path=/; expires=Mon, 09-Dec-2999 13:46:00 GMT";
+ $cj->parseCookieResponseHeader( $h[0] );
+ $this->assertEquals("name4=value", $cj->serializeToHttpRequest("/", "www.example.com"));
+
+ $h[] = "name4=value2; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2999 13:46:00 GMT";
+ $cj->parseCookieResponseHeader( $h[1] );
+ $this->assertEquals("", $cj->serializeToHttpRequest("/", "www.example.com"));
+ $this->assertEquals("name4=value2", $cj->serializeToHttpRequest("/path/", "www.example.com"));
+
+ $h[] = "name5=value3; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2999 13:46:00 GMT";
+ $cj->parseCookieResponseHeader( $h[2] );
+ $this->assertEquals("name4=value2; name5=value3", $cj->serializeToHttpRequest("/path/", "www.example.com"));
+
+ $h[] = "name6=value3; domain=.example.net; path=/path/; expires=Mon, 09-Dec-1999 13:46:00 GMT";
+ $cj->parseCookieResponseHeader( $h[3] );
+ $this->assertEquals("", $cj->serializeToHttpRequest("/path/", "www.example.net"));
+
+ $h[] = "name6=value4; domain=.example.net; path=/path/; expires=Mon, 09-Dec-2999 13:46:00 GMT";
+ $cj->parseCookieResponseHeader( $h[4] );
+ $this->assertEquals("name6=value4", $cj->serializeToHttpRequest("/path/", "www.example.net"));
+ }
+
+ function runCookieRequests() {
+ $r = HttpRequest::factory( "http://www.php.net/manual" );
+ $r->execute();
+
+ $jar = $r->getCookieJar();
+
+ $this->assertThat( $jar, $this->isInstanceOf( 'CookieJar' ) );
+ $this->assertRegExp( '/^COUNTRY=.*; LAST_LANG=.*$/', $jar->serializeToHttpRequest( "/search?q=test", "www.php.net" ) );
+ $this->assertEquals( '', $jar->serializeToHttpRequest( "/search?q=test", "www.php.com" ) );
+ }
+
+ function testCookieRequestDefault() {
+ Http::$httpEngine = false;
+ self::runCookieRequests();
+ }
+ function testCookieRequestPhp() {
+ if ( !self::$has_fopen ) {
+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
+ }
+
+ Http::$httpEngine = 'php';
+ self::runCookieRequests();
+ }
+ function testCookieRequestCurl() {
+ if ( !self::$has_curl ) {
+ $this->markTestIncomplete( "This test requires curl." );
+ }
+
+ Http::$httpEngine = 'curl';
+ self::runCookieRequests();
+ }
+
+}
\ No newline at end of file
--- /dev/null
+<?php
+/*
+ * Tests for IP validity functions. Ported from /t/inc/IP.t by avar.
+ */
+
+class IPTest extends PHPUnit_Framework_TestCase {
+
+ public function testValidIPs() {
+ foreach ( range( 0, 255 ) as $i ) {
+ $a = sprintf( "%03d", $i );
+ $b = sprintf( "%02d", $i );
+ $c = sprintf( "%01d", $i );
+ foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
+ $ip = "$f.$f.$f.$f";
+ $this->assertTrue( IP::isValid( $ip ) , "$ip is a valid IPv4 address" );
+ }
+ }
+ }
+
+ public function testInvalidIPs() {
+ foreach ( range( 256, 999 ) as $i ) {
+ $a = sprintf( "%03d", $i );
+ $b = sprintf( "%02d", $i );
+ $c = sprintf( "%01d", $i );
+ foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
+ $ip = "$f.$f.$f.$f";
+ $this->assertFalse( IP::isValid( $ip ), "$ip is not a valid IPv4 address" );
+ }
+ }
+ }
+
+ public function testBogusIPs() {
+ $invalid = array(
+ 'www.xn--var-xla.net',
+ '216.17.184.G',
+ '216.17.184.1.',
+ '216.17.184',
+ '216.17.184.',
+ '256.17.184.1'
+ );
+ foreach ( $invalid as $i ) {
+ $this->assertFalse( IP::isValid( $i ), "$i is an invalid IPv4 address" );
+ }
+ }
+
+ public function testPrivateIPs() {
+ $private = array( '10.0.0.1', '172.16.0.1', '192.168.0.1' );
+ foreach ( $private as $p ) {
+ $this->assertFalse( IP::isPublic( $p ), "$p is not a public IP address" );
+ }
+ }
+}
--- /dev/null
+<?php
+
+require_once( 'ImageFunctions.php' );
+
+class ImageFunctionsTest extends PHPUnit_Framework_TestCase {
+ function testFitBoxWidth() {
+ $vals = array(
+ array(
+ 'width' => 50,
+ 'height' => 50,
+ 'tests' => array(
+ 50 => 50,
+ 17 => 17,
+ 18 => 18 ) ),
+ array(
+ 'width' => 366,
+ 'height' => 300,
+ 'tests' => array(
+ 50 => 61,
+ 17 => 21,
+ 18 => 22 ) ),
+ array(
+ 'width' => 300,
+ 'height' => 366,
+ 'tests' => array(
+ 50 => 41,
+ 17 => 14,
+ 18 => 15 ) ),
+ array(
+ 'width' => 100,
+ 'height' => 400,
+ 'tests' => array(
+ 50 => 12,
+ 17 => 4,
+ 18 => 4 ) ) );
+ foreach( $vals as $row ) {
+ extract( $row );
+ foreach( $tests as $max => $expected ) {
+ $y = round( $expected * $height / $width );
+ $result = wfFitBoxWidth( $width, $height, $max );
+ $y2 = round( $result * $height / $width );
+ $this->assertEquals( $expected,
+ $result,
+ "($width, $height, $max) wanted: {$expected}x$y, got: {$result}x$y2" );
+ }
+ }
+ }
+}
+
+
--- /dev/null
+<?php
+
+require_once( 'ProxyTools.php' );
+
+class LanguageConverterTest extends PHPUnit_Framework_TestCase {
+ protected $lang = null;
+ protected $lc = null;
+
+ function setUp() {
+ global $wgMemc, $wgRequest, $wgUser, $wgContLang;
+
+ $wgUser = new User;
+ $wgRequest = new FauxRequest(array());
+ $wgMemc = new FakeMemCachedClient;
+ $wgContLang = Language::factory( 'tg' );
+ $this->lang = new LanguageTest();
+ $this->lc = new TestConverter( $this->lang, 'tg',
+ array( 'tg', 'tg-latn' ) );
+ }
+
+ function tearDown() {
+ global $wgMemc;
+ unset($wgMemc);
+ unset($this->lc);
+ unset($this->lang);
+ }
+
+ function testGetPreferredVariantDefaults() {
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
+ }
+
+ function testGetPreferredVariantHeaders() {
+ global $wgRequest;
+ $wgRequest->setHeader('Accept-Language', 'tg-latn');
+
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
+ }
+
+ function testGetPreferredVariantHeaderWeight() {
+ global $wgRequest;
+ $wgRequest->setHeader('Accept-Language', 'tg;q=1');
+
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
+ }
+
+ function testGetPreferredVariantHeaderWeight2() {
+ global $wgRequest;
+ $wgRequest->setHeader('Accept-Language', 'tg-latn;q=1');
+
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
+ }
+
+ function testGetPreferredVariantHeaderMulti() {
+ global $wgRequest;
+ $wgRequest->setHeader('Accept-Language', 'en, tg-latn;q=1');
+
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
+ }
+
+ function testGetPreferredVariantUserOption() {
+ global $wgUser;
+
+ $wgUser = new User;
+ $wgUser->setId(1);
+ $wgUser->setOption('variant', 'tg-latn');
+
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
+ }
+
+ function testGetPreferredVariantHeaderUserVsUrl() {
+ global $wgRequest, $wgUser, $wgContLang;
+
+ $wgContLang = Language::factory( 'tg-latn' );
+ $wgRequest->setVal('variant', 'tg');
+ $wgUser = User::newFromId("admin");
+ $wgUser->setId(1);
+ $wgUser->setOption('variant', 'tg-latn'); // The user's data is ignored
+ // because the variant is set in the URL.
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
+ }
+
+
+ function testGetPreferredVariantDefaultLanguageVariant() {
+ global $wgDefaultLanguageVariant;
+
+ $wgDefaultLanguageVariant = 'tg-latn';
+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, false));
+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
+ }
+
+ function testGetPreferredVariantDefaultLanguageVsUrlVariant() {
+ global $wgDefaultLanguageVariant, $wgRequest, $wgContLang;
+
+ $wgContLang = Language::factory( 'tg-latn' );
+ $wgDefaultLanguageVariant = 'tg';
+ $wgRequest->setVal('variant', null);
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
+ $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
+ $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
+ }
+}
+
+/**
+ * Test converter (from Tajiki to latin orthography)
+ */
+class TestConverter extends LanguageConverter {
+ private $table = array(
+ 'б' => 'b',
+ 'в' => 'v',
+ 'г' => 'g',
+ );
+
+ function loadDefaultTables() {
+ $this->mTables = array(
+ 'tg-latn' => new ReplacementArray( $this->table ),
+ 'tg' => new ReplacementArray()
+ );
+ }
+
+}
+
+class LanguageTest extends Language {
+ function __construct() {
+ parent::__construct();
+ $variants = array( 'tg', 'tg-latn' );
+ $this->mConverter = new TestConverter( $this, 'tg', $variants );
+ }
+}
--- /dev/null
+<?php
+
+/**
+ * @group Broken
+ */
+class LicensesTest extends PHPUnit_Framework_TestCase {
+
+ function testLicenses() {
+ $str = "
+* Free licenses:
+** GFLD|Debian disagrees
+";
+
+ $lc = new Licenses( $str );
+ $this->assertTrue( is_a( $lc, 'Licenses' ), 'Correct class' );
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+/**
+ * These tests should work regardless of $wgCapitalLinks
+ */
+
+require_once( 'Namespace.php' );
+
+class LocalFileTest extends PHPUnit_Framework_TestCase {
+ function setUp() {
+ global $wgContLang;
+ $wgContLang = new Language;
+ $info = array(
+ 'name' => 'test',
+ 'directory' => '/testdir',
+ 'url' => '/testurl',
+ 'hashLevels' => 2,
+ 'transformVia404' => false,
+ );
+ $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
+ $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
+ $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
+ $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
+ $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
+ $this->file_lc = $this->repo_lc->newFile( 'test!' );
+ }
+
+ function tearDown() {
+ global $wgContLang;
+ unset($wgContLang);
+ }
+
+ function testGetHashPath() {
+ $this->assertEquals( '', $this->file_hl0->getHashPath() );
+ $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
+ $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
+ }
+
+ function testGetRel() {
+ $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
+ $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
+ $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
+ }
+
+ function testGetUrlRel() {
+ $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
+ $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
+ $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
+ }
+
+ function testGetArchivePath() {
+ $this->assertEquals( '/testdir/archive', $this->file_hl0->getArchivePath() );
+ $this->assertEquals( '/testdir/archive/a/a2', $this->file_hl2->getArchivePath() );
+ $this->assertEquals( '/testdir/archive/!', $this->file_hl0->getArchivePath( '!' ) );
+ $this->assertEquals( '/testdir/archive/a/a2/!', $this->file_hl2->getArchivePath( '!' ) );
+ }
+
+ function testGetThumbPath() {
+ $this->assertEquals( '/testdir/thumb/Test!', $this->file_hl0->getThumbPath() );
+ $this->assertEquals( '/testdir/thumb/a/a2/Test!', $this->file_hl2->getThumbPath() );
+ $this->assertEquals( '/testdir/thumb/Test!/x', $this->file_hl0->getThumbPath( 'x' ) );
+ $this->assertEquals( '/testdir/thumb/a/a2/Test!/x', $this->file_hl2->getThumbPath( 'x' ) );
+ }
+
+ function testGetArchiveUrl() {
+ $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
+ $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
+ $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
+ $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
+ }
+
+ function testGetThumbUrl() {
+ $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
+ $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
+ $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
+ $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
+ }
+
+ function testGetArchiveVirtualUrl() {
+ $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
+ $this->assertEquals( 'mwrepo://test/public/archive/a/a2', $this->file_hl2->getArchiveVirtualUrl() );
+ $this->assertEquals( 'mwrepo://test/public/archive/%21', $this->file_hl0->getArchiveVirtualUrl( '!' ) );
+ $this->assertEquals( 'mwrepo://test/public/archive/a/a2/%21', $this->file_hl2->getArchiveVirtualUrl( '!' ) );
+ }
+
+ function testGetThumbVirtualUrl() {
+ $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
+ $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
+ $this->assertEquals( 'mwrepo://test/thumb/Test%21/%21', $this->file_hl0->getThumbVirtualUrl( '!' ) );
+ $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21/%21', $this->file_hl2->getThumbVirtualUrl( '!' ) );
+ }
+
+ function testGetUrl() {
+ $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
+ $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
+ }
+}
+
+
--- /dev/null
+.PHONY: help test
+all test:
+ phpunit
+install:
+ pear channel-discover pear.phpunit.de
+ pear install phpunit/PHPUnit
+help:
+ # Options:
+ # test (default) Run the unit tests
+ # install Install PHPUnit from phpunit.de
+ # help You're looking at it!
--- /dev/null
+<?php
+
+require_once( "MediaWikiAPI_TestCase.php" );
+
+class MediaWikiAPITest extends MediaWikiAPI_TestCase {
+
+ function setup() {
+ parent::setup();
+ }
+
+ function testApi() {
+ /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */
+ $resp = Http::get( self::$apiUrl . "?format=xml" );
+
+ libxml_use_internal_errors( true );
+ $sxe = simplexml_load_string( $resp );
+ $this->assertNotType( "bool", $sxe );
+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
+ }
+
+ function testApiLoginNoName() {
+ $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
+ array( "postData" => array(
+ "lgname" => "",
+ "lgpassword" => self::$passWord ) ) );
+ libxml_use_internal_errors( true );
+ $sxe = simplexml_load_string( $resp );
+ $this->assertNotType( "bool", $sxe );
+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
+ $a = $sxe->login[0]->attributes()->result;
+ $this->assertEquals( ' result="NoName"', $a->asXML() );
+ }
+
+ function testApiLoginBadPass() {
+ $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
+ array( "postData" => array(
+ "lgname" => self::$userName,
+ "lgpassword" => "bad" ) ) );
+ libxml_use_internal_errors( true );
+ $sxe = simplexml_load_string( $resp );
+ $this->assertNotType( "bool", $sxe );
+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
+ $a = $sxe->login[0]->attributes()->result;
+ $this->assertEquals( ' result="WrongPass"', $a->asXML() );
+ }
+
+ function testApiLoginGoodPass() {
+ $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
+ array( "postData" => array(
+ "lgname" => self::$userName,
+ "lgpassword" => self::$passWord ) ) );
+ libxml_use_internal_errors( true );
+ $sxe = simplexml_load_string( $resp );
+ $this->assertNotType( "bool", $sxe );
+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
+ $a = $sxe->login[0]->attributes()->result;
+ $this->assertEquals( ' result="Success"', $a->asXML() );
+ }
+
+ function testApiGotCookie() {
+ global $wgScriptPath, $wgServerName;
+
+ $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml",
+ array( "method" => "POST",
+ "postData" => array(
+ "lgname" => self::$userName,
+ "lgpassword" => self::$passWord ) ) );
+ $req->execute();
+ $cj = $req->getCookieJar();
+
+ $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/',
+ $cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ) );
+ }
+}
--- /dev/null
+<?php
+
+abstract class MediaWikiAPI_TestCase extends PHPUnit_Framework_TestCase {
+ protected static $userName;
+ protected static $passWord;
+ protected static $user;
+ protected static $apiUrl;
+
+ function setup() {
+ global $wgServerName, $wgServer, $wgContLang, $wgAuth, $wgScriptPath,
+ $wgScriptExtension, $wgMemc;
+
+ if($wgServerName == "localhost" || $wgServer == "http://localhost") {
+ $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
+ 'be set in LocalSettings.php');
+ }
+ self::$apiUrl = $wgServer.$wgScriptPath."/api".$wgScriptExtension;
+
+ $wgMemc = new FakeMemCachedClient;
+ $wgContLang = Language::factory( 'en' );
+ $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
+ self::setupUser();
+ }
+
+ static function setupUser() {
+ if ( self::$user == NULL ) {
+ self::$userName = "Useruser";
+ self::$passWord = User::randomPassword();
+
+ self::$user = User::newFromName(self::$userName);
+ if ( !self::$user->getID() ) {
+ self::$user = User::createNew(self::$userName, array(
+ "password" => self::$passWord,
+ "email" => "test@example.com",
+ "real_name" => "Test User"));
+ } else {
+ self::$user->setPassword(self::$passWord);
+ }
+ self::$user->saveSettings();
+ }
+ }
+}
--- /dev/null
+<?php
+
+global $IP;
+define( "NO_COMMAND_LINE", 1 );
+require_once( "$IP/maintenance/parserTests.inc" );
+require_once( "ImageFunctions.php" );
+require_once( "ProxyTools.php" );
+require_once( "ObjectCache.php" );
+
+class PTShell extends ParserTest {
+
+ private $cb;
+
+ function setCallback( $cb ) {
+ $this->cb = $cb;
+ }
+
+ function showTesting( $desc ) {
+ }
+
+ function showRunFile( $path ) {
+ }
+
+ function showSuccess( $desc ) {
+ $this->cb->assertTrue( true, $desc );
+ echo "PASSED: $desc\n";
+ return true;
+ }
+
+ function showFailure( $desc, $expected, $got ) {
+ /* $this->cb->assertEquals( $expected, $got, $desc ); */
+ echo "FAILED: $desc\n";
+ echo "got: $got\n";
+ echo "expected: $expected\n";
+ }
+}
+
+class MediaWikiParserTest extends PHPUnit_Framework_TestCase {
+ private $parserTester;
+ private $db;
+ private $uploadDir;
+ private $keepUploads;
+
+ /**
+ * Remove the dummy uploads directory
+ */
+ private function teardownUploadDir( $dir ) {
+ if ( $this->keepUploads ) {
+ return;
+ }
+
+ // delete the files first, then the dirs.
+ self::deleteFiles(
+ array (
+ "$dir/3/3a/Foobar.jpg",
+ "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
+ "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
+ "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
+ "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
+
+ "$dir/0/09/Bad.jpg",
+ )
+ );
+
+ self::deleteDirs(
+ array (
+ "$dir/3/3a",
+ "$dir/3",
+ "$dir/thumb/6/65",
+ "$dir/thumb/6",
+ "$dir/thumb/3/3a/Foobar.jpg",
+ "$dir/thumb/3/3a",
+ "$dir/thumb/3",
+
+ "$dir/0/09/",
+ "$dir/0/",
+
+ "$dir/thumb",
+ "$dir",
+ )
+ );
+ }
+
+ /**
+ * Delete the specified files, if they exist.
+ * @param array $files full paths to files to delete.
+ */
+ private static function deleteFiles( $files ) {
+ foreach( $files as $file ) {
+ if( file_exists( $file ) ) {
+ unlink( $file );
+ }
+ }
+ }
+ /**
+ * Delete the specified directories, if they exist. Must be empty.
+ * @param array $dirs full paths to directories to delete.
+ */
+ private static function deleteDirs( $dirs ) {
+ foreach( $dirs as $dir ) {
+ if( is_dir( $dir ) ) {
+ rmdir( $dir );
+ }
+ }
+ }
+
+ /**
+ * Create a dummy uploads directory which will contain a couple
+ * of files in order to pass existence tests.
+ * @return string The directory
+ */
+ private function setupUploadDir() {
+ global $IP;
+ if ( $this->keepUploads ) {
+ $dir = wfTempDir() . '/mwParser-images';
+ if ( is_dir( $dir ) ) {
+ return $dir;
+ }
+ } else {
+ $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
+ }
+
+ wfDebug( "Creating upload directory $dir\n" );
+ if ( file_exists( $dir ) ) {
+ wfDebug( "Already exists!\n" );
+ return $dir;
+ }
+ wfMkdirParents( $dir . '/3/3a' );
+ copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
+
+ wfMkdirParents( $dir . '/0/09' );
+ copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
+ return $dir;
+ }
+
+ function setUp() {
+ global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
+ $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgMessageCache,
+ $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc, $wgNamespaceAliases, $wgNamespaceProtection,
+ $wgLocalFileRepo, $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath,
+ $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
+
+ $wgScript = '/index.php';
+ $wgScriptPath = '/';
+ $wgArticlePath = '/wiki/$1';
+ $wgStyleSheetPath = '/skins';
+ $wgStylePath = '/skins';
+ $wgThumbnailScriptPath = false;
+ $this->uploadDir = $this->setupUploadDir();
+ $wgLocalFileRepo = array(
+ 'class' => 'LocalRepo',
+ 'name' => 'local',
+ 'directory' => $this->uploadDir,
+ 'url' => 'http://example.com/images',
+ 'hashLevels' => 2,
+ 'transformVia404' => false,
+ );
+ //$wgNamespacesWithSubpages = array( 0 => isset( $opts['subpage'] ) );
+ $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
+ $wgNamespaceAliases['Image'] = NS_FILE;
+ $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
+
+
+ $wgEnableParserCache = false;
+ $wgDeferredUpdateList = array();
+ $wgMemc =& wfGetMainCache();
+ $messageMemc =& wfGetMessageCacheStorage();
+ $parserMemc =& wfGetParserCacheStorage();
+
+ $wgContLang = new StubContLang;
+ $wgUser = new StubUser;
+ $wgLang = new StubUserLang;
+ $wgOut = new StubObject( 'wgOut', 'OutputPage' );
+ $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
+ $wgRequest = new WebRequest;
+
+ $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
+ array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
+ if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
+
+ $this->parserTester = new PTShell();
+ $this->parserTester->setCallback( $this );
+
+ /* global $wgDBtype, $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBport, $wgDBmwschema, $wgDBts2chema; */
+ /* $this->db['type'] = $wgDBtype; */
+ /* $this->db['server'] = $wgDBserver; */
+ /* $this->db['name'] = $wgDBname; */
+ /* $this->db['user'] = $wgDBuser; */
+ /* $this->db['password'] = $wgDBpassword; */
+ /* $this->db['port'] = $wgDBport; */
+ /* $this->db['mwschema'] = $wgDBmwschema; */
+ /* $this->db['ts2schema'] = $wgDBts2chema; */
+ }
+
+ function tearDown() {
+ $this->teardownUploadDir($this->uploadDir);
+ /* $db = wfGetDB( DB_MASTER ); */
+ /* $db->close(); */
+ /* global $wgDBtype, $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBport, $wgDBmwschema, $wgDBts2chema; */
+
+ /* $wgDBtype = $this->db['type']; */
+ /* $wgDBserver = $this->db['server']; */
+ /* $wgDBname = $this->db['name']; */
+ /* $wgDBuser = $this->db['user']; */
+ /* $wgDBpassword = $this->db['password']; */
+ /* $wgDBport = $this->db['port']; */
+ /* $wgDBmwschema = $this->db['mwschema']; */
+ /* $wgDBts2chema = $this->db['ts2schema']; */
+
+ }
+
+
+ function testParser() {
+ global $IP;
+
+ $this->parserTester->runTestsFromFiles( array( "$IP/maintenance/parserTests.txt" ) );
+ }
+}
+
--- /dev/null
+<?php
+
+abstract class MediaWiki_TestCase extends PHPUnit_Framework_TestCase {
+ /**
+ * @param string $serverType
+ * @param array $tables
+ */
+ protected function buildTestDatabase( $tables ) {
+ global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
+ $this->markTestIncomplete("This test requires DB admin user credentials.");
+ $wgDBprefix = 'parsertest_';
+
+ $db = new DatabaseMysql(
+ $wgDBserver,
+ $wgDBadminuser,
+ $wgDBadminpassword,
+ $wgDBname );
+ if( $db->isOpen() ) {
+ if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
+ # Database that supports CREATE TABLE ... LIKE
+ foreach ($tables as $tbl) {
+ $newTableName = $db->tableName( $tbl );
+ #$tableName = $this->oldTableNames[$tbl];
+ $tableName = $tbl;
+ $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)");
+ }
+ } else {
+ # Hack for MySQL versions < 4.1, which don't support
+ # "CREATE TABLE ... LIKE". Note that
+ # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
+ # would not create the indexes we need....
+ foreach ($tables as $tbl) {
+ $res = $db->query("SHOW CREATE TABLE $tbl");
+ $row = $db->fetchRow($res);
+ $create = $row[1];
+ $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
+ . $wgDBprefix . '\\1`', $create);
+ if ($create === $create_tmp) {
+ # Couldn't do replacement
+ wfDie( "could not create temporary table $tbl" );
+ }
+ $db->query($create_tmp);
+ }
+
+ }
+ return $db;
+ } else {
+ // Something amiss
+ return null;
+ }
+ }
+}
+
--- /dev/null
+Some quickie unit tests done with the PHPUnit testing framework. To run the
+test suite, run 'make test' in this dir. This directly invokes 'phpunit.'
+
+PHPUnit is no longer maintained by PEAR. To get the current version of
+PHPUnit, first uninstall any old version of PHPUnit or PHPUnit2 from PEAR,
+then install the current version from phpunit.de like this:
+
+# pear channel-discover pear.phpunit.de
+# pear install phpunit/PHPUnit
+
+You also may wish to install this via your normal package mechanism:
+
+# aptitude install phpunit
+ - or -
+# yum install phpunit
+
+Notes:
+- Label currently broken tests in the group Broken and they will not
+ be run by phpunit. You can add them to the group by putting the
+ following comment at the top of the file:
+ /**
+ * @group Broken
+ */
+- Need to fix some broken tests
--- /dev/null
+<?php
+
+global $IP;
+require_once( "$IP/includes/Sanitizer.php" );
+
+class SanitizerTest extends PHPUnit_Framework_TestCase {
+
+ function testDecodeNamedEntities() {
+ $this->assertEquals(
+ "\xc3\xa9cole",
+ Sanitizer::decodeCharReferences( 'école' ),
+ 'decode named entities'
+ );
+ }
+
+ function testDecodeNumericEntities() {
+ $this->assertEquals(
+ "\xc4\x88io bonas dans l'\xc3\xa9cole!",
+ Sanitizer::decodeCharReferences( "Ĉio bonas dans l'école!" ),
+ 'decode numeric entities'
+ );
+ }
+
+ function testDecodeMixedEntities() {
+ $this->assertEquals(
+ "\xc4\x88io bonas dans l'\xc3\xa9cole!",
+ Sanitizer::decodeCharReferences( "Ĉio bonas dans l'école!" ),
+ 'decode mixed numeric/named entities'
+ );
+ }
+
+ function testDecodeMixedComplexEntities() {
+ $this->assertEquals(
+ "\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas Ĉio dans l'école)",
+ Sanitizer::decodeCharReferences(
+ "Ĉio bonas dans l'école! (mais pas &#x108;io dans l'&eacute;cole)"
+ ),
+ 'decode mixed complex entities'
+ );
+ }
+
+ function testInvalidAmpersand() {
+ $this->assertEquals(
+ 'a & b',
+ Sanitizer::decodeCharReferences( 'a & b' ),
+ 'Invalid ampersand'
+ );
+ }
+
+ function testInvalidEntities() {
+ $this->assertEquals(
+ '&foo;',
+ Sanitizer::decodeCharReferences( '&foo;' ),
+ 'Invalid named entity'
+ );
+ }
+
+ function testInvalidNumberedEntities() {
+ $this->assertEquals( UTF8_REPLACEMENT, Sanitizer::decodeCharReferences( "�" ), 'Invalid numbered entity' );
+ }
+
+ function testSelfClosingTag() {
+ $GLOBALS['wgUseTidy'] = false;
+ $this->assertEquals(
+ '<div>Hello world</div>',
+ Sanitizer::removeHTMLtags( '<div>Hello world</div />' ),
+ 'Self-closing closing div'
+ );
+ }
+}
+
--- /dev/null
+<?php
+
+require_once( 'MediaWiki_TestCase.php' );
+
+/** @todo document
+ */
+
+class SearchEngineTest extends MediaWiki_TestCase {
+ var $db, $search;
+
+ function insertSearchData() {
+ $this->db->safeQuery( <<<SQL
+ INSERT INTO ! (page_id,page_namespace,page_title,page_latest)
+ VALUES (1, 0, 'Main_Page', 1),
+ (2, 1, 'Main_Page', 2),
+ (3, 0, 'Smithee', 3),
+ (4, 1, 'Smithee', 4),
+ (5, 0, 'Unrelated_page', 5),
+ (6, 0, 'Another_page', 6),
+ (7, 4, 'Help', 7),
+ (8, 0, 'Thppt', 8),
+ (9, 0, 'Alan_Smithee', 9),
+ (10, 0, 'Pages', 10)
+SQL
+ , $this->db->tableName( 'page' ) );
+ $this->db->safeQuery( <<<SQL
+ INSERT INTO ! (rev_id,rev_page)
+ VALUES (1, 1),
+ (2, 2),
+ (3, 3),
+ (4, 4),
+ (5, 5),
+ (6, 6),
+ (7, 7),
+ (8, 8),
+ (9, 9),
+ (10, 10)
+SQL
+ , $this->db->tableName( 'revision' ) );
+ $this->db->safeQuery( <<<SQL
+ INSERT INTO ! (old_id,old_text)
+ VALUES (1, 'This is a main page'),
+ (2, 'This is a talk page to the main page, see [[smithee]]'),
+ (3, 'A smithee is one who smiths. See also [[Alan Smithee]]'),
+ (4, 'This article sucks.'),
+ (5, 'Nothing in this page is about the S word.'),
+ (6, 'This page also is unrelated.'),
+ (7, 'Help me!'),
+ (8, 'Blah blah'),
+ (9, 'yum'),
+ (10,'are food')
+SQL
+ , $this->db->tableName( 'text' ) );
+ $this->db->safeQuery( <<<SQL
+ INSERT INTO ! (si_page,si_title,si_text)
+ VALUES (1, 'main page', 'this is a main page'),
+ (2, 'main page', 'this is a talk page to the main page, see smithee'),
+ (3, 'smithee', 'a smithee is one who smiths see also alan smithee'),
+ (4, 'smithee', 'this article sucks'),
+ (5, 'unrelated page', 'nothing in this page is about the s word'),
+ (6, 'another page', 'this page also is unrelated'),
+ (7, 'help', 'help me'),
+ (8, 'thppt', 'blah blah'),
+ (9, 'alan smithee', 'yum'),
+ (10, 'pages', 'are food')
+SQL
+ , $this->db->tableName( 'searchindex' ) );
+ }
+
+ function fetchIds( $results ) {
+ $matches = array();
+ while( $row = $results->next() ) {
+ $matches[] = $row->getTitle()->getPrefixedText();
+ }
+ $results->free();
+ # Search is not guaranteed to return results in a certain order;
+ # sort them numerically so we will compare simply that we received
+ # the expected matches.
+ sort( $matches );
+ return $matches;
+ }
+
+ function testTextSearch() {
+ if( is_null( $this->db ) ) {
+ $this->markTestIncomplete( "Can't find a database to test with." );
+ }
+ $this->assertEquals(
+ array( 'Smithee' ),
+ $this->fetchIds( $this->search->searchText( 'smithee' ) ),
+ "Plain search failed" );
+ }
+
+ function testTextPowerSearch() {
+ if( is_null( $this->db ) ) {
+ $this->markTestIncomplete( "Can't find a database to test with." );
+ }
+ $this->search->setNamespaces( array( 0, 1, 4 ) );
+ $this->assertEquals(
+ array(
+ 'Smithee',
+ 'Talk:Main Page',
+ ),
+ $this->fetchIds( $this->search->searchText( 'smithee' ) ),
+ "Power search failed" );
+ }
+
+ function testTitleSearch() {
+ if( is_null( $this->db ) ) {
+ $this->markTestIncomplete( "Can't find a database to test with." );
+ }
+ $this->assertEquals(
+ array(
+ 'Alan Smithee',
+ 'Smithee',
+ ),
+ $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
+ "Title search failed" );
+ }
+
+ function testTextTitlePowerSearch() {
+ if( is_null( $this->db ) ) {
+ $this->markTestIncomplete( "Can't find a database to test with." );
+ }
+ $this->search->setNamespaces( array( 0, 1, 4 ) );
+ $this->assertEquals(
+ array(
+ 'Alan Smithee',
+ 'Smithee',
+ 'Talk:Smithee',
+ ),
+ $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
+ "Title power search failed" );
+ }
+
+}
+
+
+
--- /dev/null
+<?php
+require_once( 'SearchEngineTest.php' );
+
+class SearchMySQL4Test extends SearchEngineTest {
+ var $db;
+
+ function setUp() {
+ $GLOBALS['wgContLang'] = new Language;
+ $this->db = $this->buildTestDatabase(
+ array( 'page', 'revision', 'text', 'searchindex' ) );
+ if( $this->db ) {
+ $this->insertSearchData();
+ }
+ $this->search = new SearchMySQL4( $this->db );
+ }
+
+ function tearDown() {
+ if( !is_null( $this->db ) ) {
+ $this->db->close();
+ }
+ unset( $this->db );
+ unset( $this->search );
+ }
+
+}
+
+
--- /dev/null
+<?php
+
+class DatabaseMock extends DatabaseBase {
+ function __construct( $server = false, $user = false, $password = false, $dbName = false,
+ $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
+ {
+ $this->mConn = true;
+ $this->mOpened = true;
+ }
+
+ function open( $server, $user, $password, $dbName ) { return true; }
+ function doQuery( $sql ) {}
+ function fetchObject( $res ) {}
+ function fetchRow( $res ) {}
+ function numRows( $res ) {}
+ function numFields( $res ) {}
+ function fieldName( $res, $n ) {}
+ function insertId() {}
+ function dataSeek( $res, $row ) {}
+ function lastErrno() { return 0; }
+ function lastError() { return ''; }
+ function affectedRows() {}
+ function fieldInfo( $table, $field ) {}
+ function strencode( $s ) {}
+ function getSoftwareLink() {}
+ function getServerVersion() {}
+ function getType() {}
+}
+
+class MockSearch extends SearchEngine {
+ public static $id;
+ public static $title;
+ public static $text;
+
+ public function __construct( $db ) {
+ }
+
+ public function update( $id, $title, $text ) {
+ self::$id = $id;
+ self::$title = $title;
+ self::$text = $text;
+ }
+}
+
+class SearchUpdateTest extends PHPUnit_Framework_TestCase {
+
+ function update( $text, $title = 'Test', $id = 1 ) {
+ $u = new SearchUpdate( $id, $title, $text );
+ $u->doUpdate();
+ return array( MockSearch::$title, MockSearch::$text );
+ }
+
+ function updateText( $text ) {
+ list( $title, $resultText ) = $this->update( $text );
+ $resultText = trim( $resultText ); // abstract from some implementation details
+ return $resultText;
+ }
+
+ function setUp() {
+ global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers;
+ $wgSearchType = 'MockSearch';
+ $wgDBtype = 'mock';
+ $wgLBFactoryConf['class'] = 'LBFactory_Simple';
+ $wgDBservers = null;
+ LBFactory::destroyInstance();
+ }
+
+ function tearDown() {
+ LBFactory::destroyInstance();
+ }
+
+ function testUpdateText() {
+ $this->assertEquals(
+ 'test',
+ $this->updateText( '<div>TeSt</div>' ),
+ 'HTML stripped, text lowercased'
+ );
+
+ $this->assertEquals(
+ 'foo bar boz quux',
+ $this->updateText( <<<EOT
+<table style="color:red; font-size:100px">
+ <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
+ <tr><td>boz</td><tr>quux</td></tr>
+</table>
+EOT
+ ), 'Stripping HTML tables' );
+
+ $this->assertEquals(
+ 'a b',
+ $this->updateText( 'a > b' ),
+ 'Handle unclosed tags'
+ );
+
+ $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
+
+ $this->assertNotEquals(
+ '',
+ $this->updateText( $text ),
+ 'Bug 18609'
+ );
+ }
+}
--- /dev/null
+<?php
+
+function getSiteParams( $conf, $wiki ) {
+ $site = null;
+ $lang = null;
+ foreach( $conf->suffixes as $suffix ) {
+ if ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
+ $site = $suffix;
+ $lang = substr( $wiki, 0, -strlen( $suffix ) );
+ break;
+ }
+ }
+ return array(
+ 'suffix' => $site,
+ 'lang' => $lang,
+ 'params' => array(
+ 'lang' => $lang,
+ 'site' => $site,
+ 'wiki' => $wiki,
+ ),
+ 'tags' => array( 'tag' ),
+ );
+}
+
+class SiteConfigurationTest extends PHPUnit_Framework_TestCase {
+ var $mConf;
+
+ function setUp() {
+ $this->mConf = new SiteConfiguration;
+
+ $this->mConf->suffixes = array( 'wiki' );
+ $this->mConf->wikis = array( 'enwiki', 'dewiki', 'frwiki' );
+ $this->mConf->settings = array(
+ 'simple' => array(
+ 'wiki' => 'wiki',
+ 'tag' => 'tag',
+ 'enwiki' => 'enwiki',
+ 'dewiki' => 'dewiki',
+ 'frwiki' => 'frwiki',
+ ),
+
+ 'fallback' => array(
+ 'default' => 'default',
+ 'wiki' => 'wiki',
+ 'tag' => 'tag',
+ ),
+
+ 'params' => array(
+ 'default' => '$lang $site $wiki',
+ ),
+
+ '+global' => array(
+ 'wiki' => array(
+ 'wiki' => 'wiki',
+ ),
+ 'tag' => array(
+ 'tag' => 'tag',
+ ),
+ 'enwiki' => array(
+ 'enwiki' => 'enwiki',
+ ),
+ 'dewiki' => array(
+ 'dewiki' => 'dewiki',
+ ),
+ 'frwiki' => array(
+ 'frwiki' => 'frwiki',
+ ),
+ ),
+
+ 'merge' => array(
+ '+wiki' => array(
+ 'wiki' => 'wiki',
+ ),
+ '+tag' => array(
+ 'tag' => 'tag',
+ ),
+ 'default' => array(
+ 'default' => 'default',
+ ),
+ '+enwiki' => array(
+ 'enwiki' => 'enwiki',
+ ),
+ '+dewiki' => array(
+ 'dewiki' => 'dewiki',
+ ),
+ '+frwiki' => array(
+ 'frwiki' => 'frwiki',
+ ),
+ ),
+ );
+
+ $GLOBALS['global'] = array( 'global' => 'global' );
+ }
+
+
+ function testSiteFromDB() {
+ $this->assertEquals(
+ array( 'wikipedia', 'en' ),
+ $this->mConf->siteFromDB( 'enwiki' ),
+ 'siteFromDB()'
+ );
+ $this->assertEquals(
+ array( 'wikipedia', '' ),
+ $this->mConf->siteFromDB( 'wiki' ),
+ 'siteFromDB() on a suffix'
+ );
+ $this->assertEquals(
+ array( null, null ),
+ $this->mConf->siteFromDB( 'wikien' ),
+ 'siteFromDB() on a non-existing wiki'
+ );
+
+ $this->mConf->suffixes = array( 'wiki', '' );
+ $this->assertEquals(
+ array( '', 'wikien' ),
+ $this->mConf->siteFromDB( 'wikien' ),
+ 'siteFromDB() on a non-existing wiki (2)'
+ );
+ }
+
+ function testGetLocalDatabases() {
+ $this->assertEquals(
+ array( 'enwiki', 'dewiki', 'frwiki' ),
+ $this->mConf->getLocalDatabases(),
+ 'getLocalDatabases()'
+ );
+ }
+
+ function testGet() {
+ $this->assertEquals(
+ 'enwiki',
+ $this->mConf->get( 'simple', 'enwiki', 'wiki' ),
+ 'get(): simple setting on an existing wiki'
+ );
+ $this->assertEquals(
+ 'dewiki',
+ $this->mConf->get( 'simple', 'dewiki', 'wiki' ),
+ 'get(): simple setting on an existing wiki (2)'
+ );
+ $this->assertEquals(
+ 'frwiki',
+ $this->mConf->get( 'simple', 'frwiki', 'wiki' ),
+ 'get(): simple setting on an existing wiki (3)'
+ );
+ $this->assertEquals(
+ 'wiki',
+ $this->mConf->get( 'simple', 'wiki', 'wiki' ),
+ 'get(): simple setting on an suffix'
+ );
+ $this->assertEquals(
+ 'wiki',
+ $this->mConf->get( 'simple', 'eswiki', 'wiki' ),
+ 'get(): simple setting on an non-existing wiki'
+ );
+
+ $this->assertEquals(
+ 'wiki',
+ $this->mConf->get( 'fallback', 'enwiki', 'wiki' ),
+ 'get(): fallback setting on an existing wiki'
+ );
+ $this->assertEquals(
+ 'tag',
+ $this->mConf->get( 'fallback', 'dewiki', 'wiki', array(), array( 'tag' ) ),
+ 'get(): fallback setting on an existing wiki (with wiki tag)'
+ );
+ $this->assertEquals(
+ 'wiki',
+ $this->mConf->get( 'fallback', 'wiki', 'wiki' ),
+ 'get(): fallback setting on an suffix'
+ );
+ $this->assertEquals(
+ 'wiki',
+ $this->mConf->get( 'fallback', 'wiki', 'wiki', array(), array( 'tag' ) ),
+ 'get(): fallback setting on an suffix (with wiki tag)'
+ );
+ $this->assertEquals(
+ 'wiki',
+ $this->mConf->get( 'fallback', 'eswiki', 'wiki' ),
+ 'get(): fallback setting on an non-existing wiki'
+ );
+ $this->assertEquals(
+ 'tag',
+ $this->mConf->get( 'fallback', 'eswiki', 'wiki', array(), array( 'tag' ) ),
+ 'get(): fallback setting on an non-existing wiki (with wiki tag)'
+ );
+
+ $common = array( 'wiki' => 'wiki', 'default' => 'default' );
+ $commonTag = array( 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' );
+ $this->assertEquals(
+ array( 'enwiki' => 'enwiki' ) + $common,
+ $this->mConf->get( 'merge', 'enwiki', 'wiki' ),
+ 'get(): merging setting on an existing wiki'
+ );
+ $this->assertEquals(
+ array( 'enwiki' => 'enwiki' ) + $commonTag,
+ $this->mConf->get( 'merge', 'enwiki', 'wiki', array(), array( 'tag' ) ),
+ 'get(): merging setting on an existing wiki (with tag)'
+ );
+ $this->assertEquals(
+ array( 'dewiki' => 'dewiki' ) + $common,
+ $this->mConf->get( 'merge', 'dewiki', 'wiki' ),
+ 'get(): merging setting on an existing wiki (2)'
+ );
+ $this->assertEquals(
+ array( 'dewiki' => 'dewiki' ) + $commonTag,
+ $this->mConf->get( 'merge', 'dewiki', 'wiki', array(), array( 'tag' ) ),
+ 'get(): merging setting on an existing wiki (2) (with tag)'
+ );
+ $this->assertEquals(
+ array( 'frwiki' => 'frwiki' ) + $common,
+ $this->mConf->get( 'merge', 'frwiki', 'wiki' ),
+ 'get(): merging setting on an existing wiki (3)'
+ );
+ $this->assertEquals(
+ array( 'frwiki' => 'frwiki' ) + $commonTag,
+ $this->mConf->get( 'merge', 'frwiki', 'wiki', array(), array( 'tag' ) ),
+ 'get(): merging setting on an existing wiki (3) (with tag)'
+ );
+ $this->assertEquals(
+ array( 'wiki' => 'wiki' ) + $common,
+ $this->mConf->get( 'merge', 'wiki', 'wiki' ),
+ 'get(): merging setting on an suffix'
+ );
+ $this->assertEquals(
+ array( 'wiki' => 'wiki' ) + $commonTag,
+ $this->mConf->get( 'merge', 'wiki', 'wiki', array(), array( 'tag' ) ),
+ 'get(): merging setting on an suffix (with tag)'
+ );
+ $this->assertEquals(
+ $common,
+ $this->mConf->get( 'merge', 'eswiki', 'wiki' ),
+ 'get(): merging setting on an non-existing wiki'
+ );
+ $this->assertEquals(
+ $commonTag,
+ $this->mConf->get( 'merge', 'eswiki', 'wiki', array(), array( 'tag' ) ),
+ 'get(): merging setting on an non-existing wiki (with tag)'
+ );
+ }
+
+ function testSiteFromDBWithCallback() {
+ $this->mConf->siteParamsCallback = 'getSiteParams';
+
+ $this->assertEquals(
+ array( 'wiki', 'en' ),
+ $this->mConf->siteFromDB( 'enwiki' ),
+ 'siteFromDB() with callback'
+ );
+ $this->assertEquals(
+ array( 'wiki', '' ),
+ $this->mConf->siteFromDB( 'wiki' ),
+ 'siteFromDB() with callback on a suffix'
+ );
+ $this->assertEquals(
+ array( null, null ),
+ $this->mConf->siteFromDB( 'wikien' ),
+ 'siteFromDB() with callback on a non-existing wiki'
+ );
+ }
+
+ function testParamReplacement() {
+ $this->mConf->siteParamsCallback = 'getSiteParams';
+
+ $this->assertEquals(
+ 'en wiki enwiki',
+ $this->mConf->get( 'params', 'enwiki', 'wiki' ),
+ 'get(): parameter replacement on an existing wiki'
+ );
+ $this->assertEquals(
+ 'de wiki dewiki',
+ $this->mConf->get( 'params', 'dewiki', 'wiki' ),
+ 'get(): parameter replacement on an existing wiki (2)'
+ );
+ $this->assertEquals(
+ 'fr wiki frwiki',
+ $this->mConf->get( 'params', 'frwiki', 'wiki' ),
+ 'get(): parameter replacement on an existing wiki (3)'
+ );
+ $this->assertEquals(
+ ' wiki wiki',
+ $this->mConf->get( 'params', 'wiki', 'wiki' ),
+ 'get(): parameter replacement on an suffix'
+ );
+ $this->assertEquals(
+ 'es wiki eswiki',
+ $this->mConf->get( 'params', 'eswiki', 'wiki' ),
+ 'get(): parameter replacement on an non-existing wiki'
+ );
+ }
+
+ function testGetAll() {
+ $this->mConf->siteParamsCallback = 'getSiteParams';
+
+ $getall = array(
+ 'simple' => 'enwiki',
+ 'fallback' => 'tag',
+ 'params' => 'en wiki enwiki',
+ 'global' => array( 'enwiki' => 'enwiki' ) + $GLOBALS['global'],
+ 'merge' => array( 'enwiki' => 'enwiki', 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' ),
+ );
+ $this->assertEquals( $getall, $this->mConf->getAll( 'enwiki' ), 'getAll()' );
+
+ $this->mConf->extractAllGlobals( 'enwiki', 'wiki' );
+
+ $this->assertEquals( $getall['simple'], $GLOBALS['simple'], 'extractAllGlobals(): simple setting' );
+ $this->assertEquals( $getall['fallback'], $GLOBALS['fallback'], 'extractAllGlobals(): fallback setting' );
+ $this->assertEquals( $getall['params'], $GLOBALS['params'], 'extractAllGlobals(): parameter replacement' );
+ $this->assertEquals( $getall['global'], $GLOBALS['global'], 'extractAllGlobals(): merging with global' );
+ $this->assertEquals( $getall['merge'], $GLOBALS['merge'], 'extractAllGlobals(): merging setting' );
+ }
+}
--- /dev/null
+<?php
+
+class TimeAdjustTest extends PHPUnit_Framework_TestCase {
+
+ public function setUp() {
+ $this->iniSet( 'precision', 15 );
+ }
+
+ # Test offset usage for a given language::userAdjust
+ function testUserAdjust() {
+ global $wgLocalTZoffset, $wgContLang, $wgUser;
+
+ $wgContLang = $en = Language::factory( 'en' );
+
+ # Collection of parameters for Language_t_Offset.
+ # Format: date to be formatted, localTZoffset value, expected date
+ $userAdjust_tests = array(
+ array( 20061231235959, 0, 20061231235959 ),
+ array( 20061231235959, 5, 20070101000459 ),
+ array( 20061231235959, 15, 20070101001459 ),
+ array( 20061231235959, 60, 20070101005959 ),
+ array( 20061231235959, 90, 20070101012959 ),
+ array( 20061231235959, 120, 20070101015959 ),
+ array( 20061231235959, 540, 20070101085959 ),
+ array( 20061231235959, -5, 20061231235459 ),
+ array( 20061231235959, -30, 20061231232959 ),
+ array( 20061231235959, -60, 20061231225959 ),
+ );
+
+ foreach( $userAdjust_tests as $data ) {
+ $wgLocalTZoffset = $data[1];
+
+ $this->assertEquals(
+ strval( $data[2] ),
+ strval( $en->userAdjust( $data[0], '' ) ),
+ "User adjust {$data[0]} by {$data[1]} minutes should give {$data[2]}"
+ );
+ }
+ }
+}
--- /dev/null
+<?php
+
+class TitleTest extends PHPUnit_Framework_TestCase {
+
+ function testLegalChars() {
+ $titlechars = Title::legalChars();
+
+ foreach ( range( 1, 255 ) as $num ) {
+ $chr = chr( $num );
+ if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
+ $this->assertFalse( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid titlechar" );
+ } else {
+ $this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" );
+ }
+ }
+ }
+}
--- /dev/null
+<?php
+
+class XmlTest extends PHPUnit_Framework_TestCase {
+
+ function testElementOpen() {
+ $this->assertEquals(
+ '<element>',
+ Xml::element( 'element', null, null ),
+ 'Opening element with no attributes'
+ );
+ }
+
+ function testElementEmpty() {
+ $this->assertEquals(
+ '<element />',
+ Xml::element( 'element', null, '' ),
+ 'Terminated empty element'
+ );
+ }
+
+ function testElementEscaping() {
+ $this->assertEquals(
+ '<element>hello <there> you & you</element>',
+ Xml::element( 'element', null, 'hello <there> you & you' ),
+ 'Element with no attributes and content that needs escaping'
+ );
+ }
+
+ function testElementAttributes() {
+ $this->assertEquals(
+ '<element key="value" <>="<>">',
+ Xml::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ),
+ 'Element attributes, keys are not escaped'
+ );
+ }
+
+ function testOpenElement() {
+ $this->assertEquals(
+ '<element k="v">',
+ Xml::openElement( 'element', array( 'k' => 'v' ) ),
+ 'openElement() shortcut'
+ );
+ }
+
+ function testCloseElement() {
+ $this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' );
+ }
+
+ #
+ # textarea
+ #
+ function testTextareaNoContent() {
+ $this->assertEquals(
+ '<textarea name="name" id="name" cols="40" rows="5"></textarea>',
+ Xml::textarea( 'name', '' ),
+ 'textarea() with not content'
+ );
+ }
+
+ function testTextareaAttribs() {
+ $this->assertEquals(
+ '<textarea name="name" id="name" cols="20" rows="10"><txt></textarea>',
+ Xml::textarea( 'name', '<txt>', 20, 10 ),
+ 'textarea() with custom attribs'
+ );
+ }
+
+ #
+ # JS
+ #
+ function testEscapeJsStringSpecialChars() {
+ $this->assertEquals(
+ '\\\\\r\n',
+ Xml::escapeJsString( "\\\r\n" ),
+ 'escapeJsString() with special characters'
+ );
+ }
+
+ function testEncodeJsVarBoolean() {
+ $this->assertEquals(
+ 'true',
+ Xml::encodeJsVar( true ),
+ 'encodeJsVar() with boolean'
+ );
+ }
+
+ function testEncodeJsVarNull() {
+ $this->assertEquals(
+ 'null',
+ Xml::encodeJsVar( null ),
+ 'encodeJsVar() with null'
+ );
+ }
+
+ function testEncodeJsVarArray() {
+ $this->assertEquals(
+ '["a", 1]',
+ Xml::encodeJsVar( array( 'a', 1 ) ),
+ 'encodeJsVar() with array'
+ );
+ $this->assertEquals(
+ '{"a": "a", "b": 1}',
+ Xml::encodeJsVar( array( 'a' => 'a', 'b' => 1 ) ),
+ 'encodeJsVar() with associative array'
+ );
+ }
+
+ function testEncodeJsVarObject() {
+ $this->assertEquals(
+ '{"a": "a", "b": 1}',
+ Xml::encodeJsVar( (object)array( 'a' => 'a', 'b' => 1 ) ),
+ 'encodeJsVar() with object'
+ );
+ }
+}
--- /dev/null
+<?php
+
+/**
+ * Set up the MediaWiki environment when running tests with "phpunit" command
+ *
+ * Warning: this file is not included from global scope!
+ * @file
+ */
+
+global $wgCommandLineMode, $IP;
+$wgCommandLineMode = true;
+$IP = dirname( dirname( dirname( __FILE__ ) ) );
+
+define( 'MEDIAWIKI', true );
+define( 'MW_PHPUNIT_TEST', true );
+
+require_once( "$IP/includes/Defines.php" );
+require_once( "$IP/includes/AutoLoader.php" );
+require_once( "$IP/LocalSettings.php" );
+require_once( "$IP/includes/ProfilerStub.php" );
+require_once( "$IP/includes/GlobalFunctions.php" );
+require_once( "$IP/includes/Hooks.php" );
+$self = __FILE__;
+require_once( "$IP/includes/Setup.php" );
+
+
--- /dev/null
+<!-- See http://www.phpunit.de/manual/3.3/en/appendixes.configuration.html -->
+<phpunit bootstrap="./bootstrap.php"
+ colors="false"
+ stopOnFailure="false">
+ <!-- convertErrorsToExceptions="true" -->
+ <!-- convertNoticesToExceptions="true" -->
+ <!-- convertWarningsToExceptions="true" -->
+ <testsuite name="MediaWiki Test Suite">
+ <directory>.</directory>
+ </testsuite>
+ <groups>
+ <exclude>
+ <group>Broken</group>
+ </exclude>
+ </groups>
+</phpunit>
\ No newline at end of file
--- /dev/null
+<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">
+<siteinfo>
+ <sitename>DemoWiki</sitename>
+ <base>http://example.com/wiki/Main_Page</base>
+ <generator>MediaWiki 1.5.0</generator>
+ <case>first-letter</case>
+ <namespaces>
+ <namespace key="-2">Media</namespace>
+ <namespace key="-1">Special</namespace>
+ <namespace key="0"></namespace>
+ <namespace key="1">Talk</namespace>
+ <namespace key="2">User</namespace>
+ <namespace key="3">User talk</namespace>
+ <namespace key="4">DemoWiki</namespace>
+ <namespace key="5">DemoWIki talk</namespace>
+ <namespace key="6">Image</namespace>
+ <namespace key="7">Image talk</namespace>
+ <namespace key="8">MediaWiki</namespace>
+ <namespace key="9">MediaWiki talk</namespace>
+ <namespace key="10">Template</namespace>
+ <namespace key="11">Template talk</namespace>
+ <namespace key="12">Help</namespace>
+ <namespace key="13">Help talk</namespace>
+ <namespace key="14">Category</namespace>
+ <namespace key="15">Category talk</namespace>
+ </namespaces>
+</siteinfo>
+<page>
+ <title>First page</title>
+ <id>1</id>
+ <revision>
+ <id>1</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 1, rev 1</comment>
+ <text>page 1, rev 1</text>
+ </revision>
+ <revision>
+ <id>2</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 1, rev 2</comment>
+ <text>page 1, rev 2</text>
+ </revision>
+ <revision>
+ <id>4</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 1, rev 4</comment>
+ <text>page 1, rev 4</text>
+ </revision>
+</page>
+<page>
+ <title>Second page</title>
+ <id>2</id>
+ <revision>
+ <id>3</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 2, rev 3</comment>
+ <text>page 2, rev 3</text>
+ </revision>
+</page>
+<page>
+ <title>Third page</title>
+ <id>3</id>
+ <revision>
+ <id>5</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 3, rev 5</comment>
+ <text>page 3, rev 5</text>
+ </revision>
+</page>
+</mediawiki>
--- /dev/null
+<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">
+<siteinfo>
+ <sitename>DemoWiki</sitename>
+ <base>http://example.com/wiki/Main_Page</base>
+ <generator>MediaWiki 1.5.0</generator>
+ <case>first-letter</case>
+ <namespaces>
+ <namespace key="-2">Media</namespace>
+ <namespace key="-1">Special</namespace>
+ <namespace key="0"></namespace>
+ <namespace key="1">Talk</namespace>
+ <namespace key="2">User</namespace>
+ <namespace key="3">User talk</namespace>
+ <namespace key="4">DemoWiki</namespace>
+ <namespace key="5">DemoWIki talk</namespace>
+ <namespace key="6">Image</namespace>
+ <namespace key="7">Image talk</namespace>
+ <namespace key="8">MediaWiki</namespace>
+ <namespace key="9">MediaWiki talk</namespace>
+ <namespace key="10">Template</namespace>
+ <namespace key="11">Template talk</namespace>
+ <namespace key="12">Help</namespace>
+ <namespace key="13">Help talk</namespace>
+ <namespace key="14">Category</namespace>
+ <namespace key="15">Category talk</namespace>
+ </namespaces>
+</siteinfo>
+<page>
+ <title>First page</title>
+ <id>1</id>
+ <revision>
+ <id>1</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 1, rev 1</comment>
+ <text>page 1, rev 1</text>
+ </revision>
+ <revision>
+ <id>2</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 1, rev 2</comment>
+ <text>page 1, rev 2</text>
+ </revision>
+</page>
+<page>
+ <title>Second page</title>
+ <id>2</id>
+ <revision>
+ <id>3</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 2, rev 3</comment>
+ <text>page 2, rev 3</text>
+ </revision>
+</page>
+</mediawiki>
--- /dev/null
+<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">
+<siteinfo>
+ <sitename>DemoWiki</sitename>
+ <base>http://example.com/wiki/Main_Page</base>
+ <generator>MediaWiki 1.5.0</generator>
+ <case>first-letter</case>
+ <namespaces>
+ <namespace key="-2">Media</namespace>
+ <namespace key="-1">Special</namespace>
+ <namespace key="0"></namespace>
+ <namespace key="1">Talk</namespace>
+ <namespace key="2">User</namespace>
+ <namespace key="3">User talk</namespace>
+ <namespace key="4">DemoWiki</namespace>
+ <namespace key="5">DemoWIki talk</namespace>
+ <namespace key="6">Image</namespace>
+ <namespace key="7">Image talk</namespace>
+ <namespace key="8">MediaWiki</namespace>
+ <namespace key="9">MediaWiki talk</namespace>
+ <namespace key="10">Template</namespace>
+ <namespace key="11">Template talk</namespace>
+ <namespace key="12">Help</namespace>
+ <namespace key="13">Help talk</namespace>
+ <namespace key="14">Category</namespace>
+ <namespace key="15">Category talk</namespace>
+ </namespaces>
+</siteinfo>
+<page>
+ <title>First page</title>
+ <id>1</id>
+ <revision>
+ <id>1</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 1, rev 1</comment>
+ <text id="1" />
+ </revision>
+ <revision>
+ <id>2</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 1, rev 2</comment>
+ <text id="2" />
+ </revision>
+ <revision>
+ <id>4</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 1, rev 4</comment>
+ <text id="4" />
+ </revision>
+</page>
+<page>
+ <title>Second page</title>
+ <id>2</id>
+ <revision>
+ <id>3</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 2, rev 3</comment>
+ <text id="3" />
+ </revision>
+</page>
+<page>
+ <title>Third page</title>
+ <id>3</id>
+ <revision>
+ <id>5</id>
+ <timestamp>2001-01-15T12:00:00Z</timestamp>
+ <contributor><ip>10.0.0.1</ip></contributor>
+ <comment>page 3, rev 5</comment>
+ <text id="5" />
+ </revision>
+</page>
+</mediawiki>
+++ /dev/null
-Deny from all
+++ /dev/null
-LocalTestSettings.php
-*~
-bin
-.classpath
-.project
-project.index
+++ /dev/null
-<?php
-
-class ArticleTest extends PHPUnit_Framework_TestCase {
- var $saveGlobals = array();
-
- function setUp() {
- global $wgContLang;
- $wgContLang = Language::factory( 'en' );
- $globalSet = array(
- 'wgLegacyEncoding' => false,
- 'wgCompressRevisions' => false,
- 'wgInputEncoding' => 'utf-8',
- 'wgOutputEncoding' => 'utf-8' );
- foreach( $globalSet as $var => $data ) {
- $this->saveGlobals[$var] = $GLOBALS[$var];
- $GLOBALS[$var] = $data;
- }
- }
-
- function tearDown() {
- foreach( $this->saveGlobals as $var => $data ) {
- $GLOBALS[$var] = $data;
- }
- }
-
- function testGetRevisionText() {
- $row = new stdClass;
- $row->old_flags = '';
- $row->old_text = 'This is a bunch of revision text.';
- $this->assertEquals(
- 'This is a bunch of revision text.',
- Revision::getRevisionText( $row ) );
- }
-
- function testGetRevisionTextGzip() {
- $row = new stdClass;
- $row->old_flags = 'gzip';
- $row->old_text = gzdeflate( 'This is a bunch of revision text.' );
- $this->assertEquals(
- 'This is a bunch of revision text.',
- Revision::getRevisionText( $row ) );
- }
-
- function testGetRevisionTextUtf8Native() {
- $row = new stdClass;
- $row->old_flags = 'utf-8';
- $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
- $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
- $this->assertEquals(
- "Wiki est l'\xc3\xa9cole superieur !",
- Revision::getRevisionText( $row ) );
- }
-
- function testGetRevisionTextUtf8Legacy() {
- $row = new stdClass;
- $row->old_flags = '';
- $row->old_text = "Wiki est l'\xe9cole superieur !";
- $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
- $this->assertEquals(
- "Wiki est l'\xc3\xa9cole superieur !",
- Revision::getRevisionText( $row ) );
- }
-
- function testGetRevisionTextUtf8NativeGzip() {
- $row = new stdClass;
- $row->old_flags = 'gzip,utf-8';
- $row->old_text = gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" );
- $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
- $this->assertEquals(
- "Wiki est l'\xc3\xa9cole superieur !",
- Revision::getRevisionText( $row ) );
- }
-
- function testGetRevisionTextUtf8LegacyGzip() {
- $row = new stdClass;
- $row->old_flags = 'gzip';
- $row->old_text = gzdeflate( "Wiki est l'\xe9cole superieur !" );
- $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
- $this->assertEquals(
- "Wiki est l'\xc3\xa9cole superieur !",
- Revision::getRevisionText( $row ) );
- }
-
- function testCompressRevisionTextUtf8() {
- $row = new stdClass;
- $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
- $row->old_flags = Revision::compressRevisionText( $row->old_text );
- $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
- "Flags should contain 'utf-8'" );
- $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ),
- "Flags should not contain 'gzip'" );
- $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
- $row->old_text, "Direct check" );
- $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
- Revision::getRevisionText( $row ), "getRevisionText" );
- }
-
- function testCompressRevisionTextUtf8Gzip() {
- $GLOBALS['wgCompressRevisions'] = true;
- $row = new stdClass;
- $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
- $row->old_flags = Revision::compressRevisionText( $row->old_text );
- $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
- "Flags should contain 'utf-8'" );
- $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ),
- "Flags should contain 'gzip'" );
- $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
- gzinflate( $row->old_text ), "Direct check" );
- $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
- Revision::getRevisionText( $row ), "getRevisionText" );
- }
-}
-
-
+++ /dev/null
-<?php
-
-class DatabaseTest extends PHPUnit_Framework_TestCase {
- var $db;
-
- function setUp() {
- $this->db = wfGetDB( DB_SLAVE );
- }
-
- function testAddQuotesNull() {
- $check = "NULL";
- if ( $this->db->getType() === 'sqlite' ) {
- $check = "''";
- }
- $this->assertEquals( $check, $this->db->addQuotes( null ) );
- }
-
- function testAddQuotesInt() {
- # returning just "1234" should be ok too, though...
- # maybe
- $this->assertEquals(
- "'1234'",
- $this->db->addQuotes( 1234 ) );
- }
-
- function testAddQuotesFloat() {
- # returning just "1234.5678" would be ok too, though
- $this->assertEquals(
- "'1234.5678'",
- $this->db->addQuotes( 1234.5678 ) );
- }
-
- function testAddQuotesString() {
- $this->assertEquals(
- "'string'",
- $this->db->addQuotes( 'string' ) );
- }
-
- function testAddQuotesStringQuote() {
- $check = "'string''s cause trouble'";
- if ( $this->db->getType() === 'mysql' ) {
- $check = "'string\'s cause trouble'";
- }
- $this->assertEquals(
- $check,
- $this->db->addQuotes( "string's cause trouble" ) );
- }
-
- function testFillPreparedEmpty() {
- $sql = $this->db->fillPrepared(
- 'SELECT * FROM interwiki', array() );
- $this->assertEquals(
- "SELECT * FROM interwiki",
- $sql);
- }
-
- function testFillPreparedQuestion() {
- $sql = $this->db->fillPrepared(
- 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
- array( 4, "Snicker's_paradox" ) );
-
- $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker''s_paradox'";
- if ( $this->db->getType() === 'mysql' ) {
- $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'";
- }
- $this->assertEquals( $check, $sql );
- }
-
- function testFillPreparedBang() {
- $sql = $this->db->fillPrepared(
- 'SELECT user_id FROM ! WHERE user_name=?',
- array( '"user"', "Slash's Dot" ) );
-
- $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash''s Dot'";
- if ( $this->db->getType() === 'mysql' ) {
- $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'";
- }
- $this->assertEquals( $check, $sql );
- }
-
- function testFillPreparedRaw() {
- $sql = $this->db->fillPrepared(
- "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
- array( '"user"', "Slash's Dot" ) );
- $this->assertEquals(
- "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",
- $sql);
- }
-
-}
-
-
+++ /dev/null
-<?php
-
-class GlobalTest extends PHPUnit_Framework_TestCase {
- function setUp() {
- global $wgReadOnlyFile;
- $this->originals['wgReadOnlyFile'] = $wgReadOnlyFile;
- $wgReadOnlyFile = tempnam(wfTempDir(), "mwtest_readonly");
- unlink( $wgReadOnlyFile );
- }
-
- function tearDown() {
- global $wgReadOnlyFile;
- if( file_exists( $wgReadOnlyFile ) ) {
- unlink( $wgReadOnlyFile );
- }
- $wgReadOnlyFile = $this->originals['wgReadOnlyFile'];
- }
-
- function testRandom() {
- # This could hypothetically fail, but it shouldn't ;)
- $this->assertFalse(
- wfRandom() == wfRandom() );
- }
-
- function testUrlencode() {
- $this->assertEquals(
- "%E7%89%B9%E5%88%A5:Contributions/Foobar",
- wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
- }
-
- function testReadOnlyEmpty() {
- global $wgReadOnly;
- $wgReadOnly = null;
-
- $this->assertFalse( wfReadOnly() );
- $this->assertFalse( wfReadOnly() );
- }
-
- function testReadOnlySet() {
- global $wgReadOnly, $wgReadOnlyFile;
-
- $f = fopen( $wgReadOnlyFile, "wt" );
- fwrite( $f, 'Message' );
- fclose( $f );
- $wgReadOnly = null;
-
- $this->assertTrue( wfReadOnly() );
- $this->assertTrue( wfReadOnly() );
-
- unlink( $wgReadOnlyFile );
- $wgReadOnly = null;
-
- $this->assertFalse( wfReadOnly() );
- $this->assertFalse( wfReadOnly() );
- }
-
- function testQuotedPrintable() {
- $this->assertEquals(
- "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
- wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
- }
-
- function testTime() {
- $start = wfTime();
- $this->assertType( 'float', $start );
- $end = wfTime();
- $this->assertTrue( $end > $start, "Time is running backwards!" );
- }
-
- function testArrayToCGI() {
- $this->assertEquals(
- "baz=AT%26T&foo=bar",
- wfArrayToCGI(
- array( 'baz' => 'AT&T', 'ignore' => '' ),
- array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
- }
-
- function testMimeTypeMatch() {
- $this->assertEquals(
- 'text/html',
- mimeTypeMatch( 'text/html',
- array( 'application/xhtml+xml' => 1.0,
- 'text/html' => 0.7,
- 'text/plain' => 0.3 ) ) );
- $this->assertEquals(
- 'text/*',
- mimeTypeMatch( 'text/html',
- array( 'image/*' => 1.0,
- 'text/*' => 0.5 ) ) );
- $this->assertEquals(
- '*/*',
- mimeTypeMatch( 'text/html',
- array( '*/*' => 1.0 ) ) );
- $this->assertNull(
- mimeTypeMatch( 'text/html',
- array( 'image/png' => 1.0,
- 'image/svg+xml' => 0.5 ) ) );
- }
-
- function testNegotiateType() {
- $this->assertEquals(
- 'text/html',
- wfNegotiateType(
- array( 'application/xhtml+xml' => 1.0,
- 'text/html' => 0.7,
- 'text/plain' => 0.5,
- 'text/*' => 0.2 ),
- array( 'text/html' => 1.0 ) ) );
- $this->assertEquals(
- 'application/xhtml+xml',
- wfNegotiateType(
- array( 'application/xhtml+xml' => 1.0,
- 'text/html' => 0.7,
- 'text/plain' => 0.5,
- 'text/*' => 0.2 ),
- array( 'application/xhtml+xml' => 1.0,
- 'text/html' => 0.5 ) ) );
- $this->assertEquals(
- 'text/html',
- wfNegotiateType(
- array( 'text/html' => 1.0,
- 'text/plain' => 0.5,
- 'text/*' => 0.5,
- 'application/xhtml+xml' => 0.2 ),
- array( 'application/xhtml+xml' => 1.0,
- 'text/html' => 0.5 ) ) );
- $this->assertEquals(
- 'text/html',
- wfNegotiateType(
- array( 'text/*' => 1.0,
- 'image/*' => 0.7,
- '*/*' => 0.3 ),
- array( 'application/xhtml+xml' => 1.0,
- 'text/html' => 0.5 ) ) );
- $this->assertNull(
- wfNegotiateType(
- array( 'text/*' => 1.0 ),
- array( 'application/xhtml+xml' => 1.0 ) ) );
- }
-
- function testTimestamp() {
- $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
- $this->assertEquals(
- '20010115123456',
- wfTimestamp( TS_MW, $t ),
- 'TS_UNIX to TS_MW' );
- $this->assertEquals(
- 979562096,
- wfTimestamp( TS_UNIX, $t ),
- 'TS_UNIX to TS_UNIX' );
- $this->assertEquals(
- '2001-01-15 12:34:56',
- wfTimestamp( TS_DB, $t ),
- 'TS_UNIX to TS_DB' );
-
- $this->assertEquals(
- '20010115123456',
- wfTimestamp( TS_MW, '20010115123456' ),
- 'TS_MW to TS_MW' );
- $this->assertEquals(
- 979562096,
- wfTimestamp( TS_UNIX, '20010115123456' ),
- 'TS_MW to TS_UNIX' );
- $this->assertEquals(
- '2001-01-15 12:34:56',
- wfTimestamp( TS_DB, '20010115123456' ),
- 'TS_MW to TS_DB' );
-
- $this->assertEquals(
- '20010115123456',
- wfTimestamp( TS_MW, '2001-01-15 12:34:56' ),
- 'TS_DB to TS_MW' );
- $this->assertEquals(
- 979562096,
- wfTimestamp( TS_UNIX, '2001-01-15 12:34:56' ),
- 'TS_DB to TS_UNIX' );
- $this->assertEquals(
- '2001-01-15 12:34:56',
- wfTimestamp( TS_DB, '2001-01-15 12:34:56' ),
- 'TS_DB to TS_DB' );
- }
-
- function testBasename() {
- $sets = array(
- '' => '',
- '/' => '',
- '\\' => '',
- '//' => '',
- '\\\\' => '',
- 'a' => 'a',
- 'aaaa' => 'aaaa',
- '/a' => 'a',
- '\\a' => 'a',
- '/aaaa' => 'aaaa',
- '\\aaaa' => 'aaaa',
- '/aaaa/' => 'aaaa',
- '\\aaaa\\' => 'aaaa',
- '\\aaaa\\' => 'aaaa',
- '/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',
- 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
- 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
- );
- foreach( $sets as $from => $to ) {
- $this->assertEquals( $to, wfBaseName( $from ),
- "wfBaseName('$from') => '$to'");
- }
- }
-
- /* TODO: many more! */
-}
-
-
+++ /dev/null
-<?php
-
-class MockCookie extends Cookie {
- public function canServeDomain($arg) { return parent::canServeDomain($arg); }
- public function canServePath($arg) { return parent::canServePath($arg); }
- public function isUnExpired() { return parent::isUnExpired(); }
-}
-
-class HttpTest extends PhpUnit_Framework_TestCase {
- static $content;
- static $headers;
- static $has_curl;
- static $has_fopen;
- static $has_proxy = false;
- static $proxy = "http://hulk:8080/";
- var $test_geturl = array(
- "http://www.example.com/",
- "http://pecl.php.net/feeds/pkg_apc.rss",
- "http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id=3",
- "http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw",
- "http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&format=php",
- );
- var $test_requesturl = array( "http://en.wikipedia.org/wiki/Special:Export/User:MarkAHershberger" );
-
- var $test_posturl = array( "http://www.comp.leeds.ac.uk/cgi-bin/Perl/environment-example" => "review=test" );
-
- function setup() {
- putenv("http_proxy"); /* Remove any proxy env var, so curl doesn't get confused */
- if ( is_array( self::$content ) ) {
- return;
- }
- self::$has_curl = function_exists( 'curl_init' );
- self::$has_fopen = wfIniGetBool( 'allow_url_fopen' );
-
- if ( !file_exists("/usr/bin/curl") ) {
- $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.");
- }
-
- $content = tempnam( wfTempDir(), "" );
- $headers = tempnam( wfTempDir(), "" );
- if ( !$content && !$headers ) {
- die( "Couldn't create temp file!" );
- }
-
- // This probably isn't the best test for a proxy, but it works on my system!
- system("curl -0 -o $content -s ".self::$proxy);
- $out = file_get_contents( $content );
- if( $out ) {
- self::$has_proxy = true;
- }
-
- /* Maybe use wget instead of curl here ... just to use a different codebase? */
- foreach ( $this->test_geturl as $u ) {
- system( "curl -0 -s -D $headers '$u' -o $content" );
- self::$content["GET $u"] = file_get_contents( $content );
- self::$headers["GET $u"] = file_get_contents( $headers );
- }
- foreach ( $this->test_requesturl as $u ) {
- system( "curl -0 -s -X POST -H 'Content-Length: 0' -D $headers '$u' -o $content" );
- self::$content["POST $u"] = file_get_contents( $content );
- self::$headers["POST $u"] = file_get_contents( $headers );
- }
- foreach ( $this->test_posturl as $u => $postData ) {
- system( "curl -0 -s -X POST -d '$postData' -D $headers '$u' -o $content" );
- self::$content["POST $u => $postData"] = file_get_contents( $content );
- self::$headers["POST $u => $postData"] = file_get_contents( $headers );
- }
- unlink( $content );
- unlink( $headers );
- }
-
-
- function testInstantiation() {
- Http::$httpEngine = false;
-
- $r = HttpRequest::factory("http://www.example.com/");
- if ( self::$has_curl ) {
- $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' ));
- } else {
- $this->assertThat($r, $this->isInstanceOf( 'PhpHttpRequest' ));
- }
- unset($r);
-
- if( !self::$has_fopen ) {
- $this->setExpectedException( 'MWException' );
- }
- Http::$httpEngine = 'php';
- $r = HttpRequest::factory("http://www.example.com/");
- $this->assertThat($r, $this->isInstanceOf( 'PhpHttpRequest' ));
- unset($r);
-
- if( !self::$has_curl ) {
- $this->setExpectedException( 'MWException' );
- }
- Http::$httpEngine = 'curl';
- $r = HttpRequest::factory("http://www.example.com/");
- if( self::$has_curl ) {
- $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' ));
- }
- }
-
- function runHTTPFailureChecks() {
- // Each of the following requests should result in a failure.
-
- $timeout = 1;
- $start_time = time();
- $r = HTTP::get( "http://www.example.com:1/", $timeout);
- $end_time = time();
- $this->assertLessThan($timeout+2, $end_time - $start_time,
- "Request took less than {$timeout}s via ".Http::$httpEngine);
- $this->assertEquals($r, false, "false -- what we get on error from Http::get()");
- }
-
- function testFailureDefault() {
- Http::$httpEngine = false;
- self::runHTTPFailureChecks();
- }
-
- function testFailurePhp() {
- if ( !self::$has_fopen ) {
- $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
- }
-
- Http::$httpEngine = "php";
- self::runHTTPFailureChecks();
- }
-
- function testFailureCurl() {
- if ( !self::$has_curl ) {
- $this->markTestIncomplete( "This test requires curl." );
- }
-
- Http::$httpEngine = "curl";
- self::runHTTPFailureChecks();
- }
-
- /* ./phase3/includes/Import.php:1108: $data = Http::request( $method, $url ); */
- /* ./includes/Import.php:1124: $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */
- /* ./includes/Import.php:1134: return ImportStreamSource::newFromURL( $url, "POST" ); */
- function runHTTPRequests($proxy=null) {
- $opt = array();
-
- if($proxy) {
- $opt['proxy'] = $proxy;
- } elseif( $proxy === false ) {
- $opt['noProxy'] = true;
- }
-
- /* no postData here because the only request I could find in code so far didn't have any */
- foreach ( $this->test_requesturl as $u ) {
- $r = Http::request( "POST", $u, $opt );
- $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with ".Http::$httpEngine );
- }
- }
-
- function testRequestDefault() {
- Http::$httpEngine = false;
- self::runHTTPRequests();
- }
-
- function testRequestPhp() {
- if ( !self::$has_fopen ) {
- $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
- }
-
- Http::$httpEngine = "php";
- self::runHTTPRequests();
- }
-
- function testRequestCurl() {
- if ( !self::$has_curl ) {
- $this->markTestIncomplete( "This test requires curl." );
- }
-
- Http::$httpEngine = "curl";
- self::runHTTPRequests();
- }
-
- /* ./extensions/SpamBlacklist/SpamBlacklist_body.php:164: $httpText = Http::get( $fileName ); */
- /* ./extensions/ApiSVGProxy/ApiSVGProxy.body.php:44: $contents = Http::get( $file->getFullUrl() ); */
- /* ./extensions/BookInformation/drivers/IsbnDb.php:24: if( ( $xml = Http::get( $uri ) ) !== false ) { */
- /* ./extensions/BookInformation/drivers/Amazon.php:23: if( ( $xml = Http::get( $uri ) ) !== false ) { */
- /* ./extensions/TitleBlacklist/TitleBlacklist.list.php:217: $result = Http::get( $url ); */
- /* ./extensions/TSPoll/TSPoll.php:68: $get_server = Http::get( 'http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id='.$id ); */
- /* ./extensions/TSPoll/TSPoll.php:70: $get_server = Http::get( 'http://toolserver.org/~jan/poll/main.php?page=wiki_output&id='.$id ); */
- /* ./extensions/DoubleWiki/DoubleWiki.php:56: $translation = Http::get( $url.$sep.'action=render' ); */
- /* ./extensions/ExternalPages/ExternalPages_body.php:177: $serializedText = Http::get( $this->mPageURL ); */
- /* ./extensions/Translate/utils/TranslationHelpers.php:143: $suggestions = Http::get( $url, $timeout ); */
- /* ./extensions/Translate/SpecialImportTranslations.php:169: $filedata = Http::get( $url ); ; */
- /* ./extensions/Translate/TranslateEditAddons.php:338: $suggestions = Http::get( $url, $timeout ); */
- /* ./extensions/SecurePoll/includes/user/Auth.php:283: $value = Http::get( $url, 20, $curlParams ); */
- /* ./extensions/DumpHTML/dumpHTML.inc:778: $contents = Http::get( $url ); */
- /* ./extensions/DumpHTML/dumpHTML.inc:1298: $contents = Http::get( $sourceUrl ); */
- /* ./extensions/DumpHTML/dumpHTML.inc:1373: $contents = Http::get( $sourceUrl ); */
- /* ./phase3/maintenance/rebuildInterwiki.inc:101: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
- /* ./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' ); */
- /* ./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' ); */
- /* ./phase3/maintenance/dumpInterwiki.inc:95: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
- /* ./phase3/includes/parser/Parser.php:3204: $text = Http::get($url); */
- /* ./phase3/includes/filerepo/ForeignAPIRepo.php:131: $data = Http::get( $url ); */
- /* ./phase3/includes/filerepo/ForeignAPIRepo.php:205: $thumb = Http::get( $foreignUrl ); */
- /* ./phase3/includes/filerepo/File.php:1105: $res = Http::get( $renderUrl ); */
- /* ./phase3/includes/GlobalFunctions.php:2760: * @deprecated Use Http::get() instead */
- /* ./phase3/includes/GlobalFunctions.php:2764: return Http::get( $url ); */
- /* ./phase3/includes/ExternalStoreHttp.php:18: $ret = Http::get( $url ); */
- /* ./phase3/includes/Import.php:357: $data = Http::get( $src ); */
- /* ./extensions/ExternalData/ED_Utils.php:291: return Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
- /* ./extensions/ExternalData/ED_Utils.php:293: return Http::get( $url ); */
- /* ./extensions/ExternalData/ED_Utils.php:306: $page = Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
- /* ./extensions/ExternalData/ED_Utils.php:308: $page = Http::get( $url ); */
- /* ./extensions/CodeReview/backend/Subversion.php:320: $blob = Http::get( $target, $this->mTimeout ); */
- /* ./extensions/AmazonPlus/AmazonPlus.php:214: $this->response = Http::get( $urlstr ); */
- /* ./extensions/StaticWiki/StaticWiki.php:24: $text = Http::get( $url ) ; */
- /* ./extensions/StaticWiki/StaticWiki.php:64: $history = Http::get ( $wgStaticWikiExternalSite . "index.php?title=" . urlencode ( $url_title ) . "&action=history" ) ; */
- /* ./extensions/Configure/scripts/findSettings.php:126: $cont = Http::get( "http://www.mediawiki.org/w/index.php?title={$page}&action=raw" ); */
- /* ./extensions/TorBlock/TorBlock.class.php:148: $data = Http::get( $url ); */
- /* ./extensions/HoneypotIntegration/HoneypotIntegration.class.php:60: $data = Http::get( $wgHoneypotURLSource, 'default', */
- /* ./extensions/SemanticForms/includes/SF_Utils.inc:378: $page_contents = Http::get($url); */
- /* ./extensions/LocalisationUpdate/LocalisationUpdate.class.php:172: $basefilecontents = Http::get( $basefile ); */
- /* ./extensions/APC/SpecialAPC.php:245: $rss = Http::get( 'http://pecl.php.net/feeds/pkg_apc.rss' ); */
- /* ./extensions/Interlanguage/Interlanguage.php:56: $a = Http::get( $url ); */
- /* ./extensions/MWSearch/MWSearch_body.php:492: $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts); */
- function runHTTPGets($proxy=null) {
- $opt = array();
-
- if($proxy) {
- $opt['proxy'] = $proxy;
- } elseif( $proxy === false ) {
- $opt['noProxy'] = true;
- }
-
- foreach ( $this->test_geturl as $u ) {
- $r = Http::get( $u, 30, $opt ); /* timeout of 30s */
- $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with ".Http::$httpEngine );
- }
- }
-
- function testGetDefault() {
- Http::$httpEngine = false;
- self::runHTTPGets();
- }
-
- function testGetPhp() {
- if ( !self::$has_fopen ) {
- $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
- }
-
- Http::$httpEngine = "php";
- self::runHTTPGets();
- }
-
- function testGetCurl() {
- if ( !self::$has_curl ) {
- $this->markTestIncomplete( "This test requires curl." );
- }
-
- Http::$httpEngine = "curl";
- self::runHTTPGets();
- }
-
- /* ./phase3/maintenance/parserTests.inc:1618: return Http::post( $url, array( 'postData' => wfArrayToCGI( $data ) ) ); */
- function runHTTPPosts($proxy=null) {
- $opt = array();
-
- if($proxy) {
- $opt['proxy'] = $proxy;
- } elseif( $proxy === false ) {
- $opt['noProxy'] = true;
- }
-
- foreach ( $this->test_posturl as $u => $postData ) {
- $opt['postData'] = $postData;
- $r = Http::post( $u, $opt );
- $this->assertEquals( self::$content["POST $u => $postData"], "$r",
- "POST $u (postData=$postData) with ".Http::$httpEngine );
- }
- }
-
- function testPostDefault() {
- Http::$httpEngine = false;
- self::runHTTPPosts();
- }
-
- function testPostPhp() {
- if ( !self::$has_fopen ) {
- $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
- }
-
- Http::$httpEngine = "php";
- self::runHTTPPosts();
- }
-
- function testPostCurl() {
- if ( !self::$has_curl ) {
- $this->markTestIncomplete( "This test requires curl." );
- }
-
- Http::$httpEngine = "curl";
- self::runHTTPPosts();
- }
-
- function runProxyRequests() {
- if(!self::$has_proxy) {
- $this->markTestIncomplete( "This test requires a proxy." );
- }
- self::runHTTPGets(self::$proxy);
- self::runHTTPPosts(self::$proxy);
- self::runHTTPRequests(self::$proxy);
-
- // Set false here to do noProxy
- self::runHTTPGets(false);
- self::runHTTPPosts(false);
- self::runHTTPRequests(false);
- }
-
- function testProxyDefault() {
- Http::$httpEngine = false;
- self::runProxyRequests();
- }
-
- function testProxyPhp() {
- if ( !self::$has_fopen ) {
- $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
- }
-
- Http::$httpEngine = 'php';
- self::runProxyRequests();
- }
-
- function testProxyCurl() {
- if ( !self::$has_curl ) {
- $this->markTestIncomplete( "This test requires curl." );
- }
-
- Http::$httpEngine = 'curl';
- self::runProxyRequests();
- }
-
- function testIsLocalUrl() {
- }
-
- /* ./extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php:559: $user_agent = Http::userAgent(); */
- function testUserAgent() {
- }
-
- function testIsValidUrl() {
- }
-
- function testSetCookie() {
- $c = new MockCookie( "name", "value",
- array(
- "domain" => ".example.com",
- "path" => "/path/",
- ) );
-
- $this->assertFalse($c->canServeDomain("example.com"));
- $this->assertFalse($c->canServeDomain("www.example.net"));
- $this->assertTrue($c->canServeDomain("www.example.com"));
-
- $this->assertFalse($c->canServePath("/"));
- $this->assertFalse($c->canServePath("/bogus/path/"));
- $this->assertFalse($c->canServePath("/path"));
- $this->assertTrue($c->canServePath("/path/"));
-
- $this->assertTrue($c->isUnExpired());
-
- $this->assertEquals("", $c->serializeToHttpRequest("/path/", "www.example.net"));
- $this->assertEquals("", $c->serializeToHttpRequest("/", "www.example.com"));
- $this->assertEquals("name=value", $c->serializeToHttpRequest("/path/", "www.example.com"));
-
- $c = new MockCookie( "name", "value",
- array(
- "domain" => ".example.com",
- "path" => "/path/",
- "expires" => "January 1, 1990",
- ) );
- $this->assertFalse($c->isUnExpired());
- $this->assertEquals("", $c->serializeToHttpRequest("/path/", "www.example.com"));
-
- $c = new MockCookie( "name", "value",
- array(
- "domain" => ".example.com",
- "path" => "/path/",
- "expires" => "January 1, 2999",
- ) );
- $this->assertTrue($c->isUnExpired());
- $this->assertEquals("name=value", $c->serializeToHttpRequest("/path/", "www.example.com"));
-
-
- }
-
- function testCookieJarSetCookie() {
- $cj = new CookieJar;
- $cj->setCookie( "name", "value",
- array(
- "domain" => ".example.com",
- "path" => "/path/",
- ) );
- $cj->setCookie( "name2", "value",
- array(
- "domain" => ".example.com",
- "path" => "/path/sub",
- ) );
- $cj->setCookie( "name3", "value",
- array(
- "domain" => ".example.com",
- "path" => "/",
- ) );
- $cj->setCookie( "name4", "value",
- array(
- "domain" => ".example.net",
- "path" => "/path/",
- ) );
- $cj->setCookie( "name5", "value",
- array(
- "domain" => ".example.net",
- "path" => "/path/",
- "expires" => "January 1, 1999",
- ) );
-
- $this->assertEquals("name4=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
- $this->assertEquals("name3=value", $cj->serializeToHttpRequest("/", "www.example.com"));
- $this->assertEquals("name=value; name3=value", $cj->serializeToHttpRequest("/path/", "www.example.com"));
-
- $cj->setCookie( "name5", "value",
- array(
- "domain" => ".example.net",
- "path" => "/path/",
- "expires" => "January 1, 2999",
- ) );
- $this->assertEquals("name4=value; name5=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
-
- $cj->setCookie( "name4", "value",
- array(
- "domain" => ".example.net",
- "path" => "/path/",
- "expires" => "January 1, 1999",
- ) );
- $this->assertEquals("name5=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
- }
-
- function testParseResponseHeader() {
- $cj = new CookieJar;
-
- $h[] = "Set-Cookie: name4=value; domain=.example.com; path=/; expires=Mon, 09-Dec-2999 13:46:00 GMT";
- $cj->parseCookieResponseHeader( $h[0] );
- $this->assertEquals("name4=value", $cj->serializeToHttpRequest("/", "www.example.com"));
-
- $h[] = "name4=value2; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2999 13:46:00 GMT";
- $cj->parseCookieResponseHeader( $h[1] );
- $this->assertEquals("", $cj->serializeToHttpRequest("/", "www.example.com"));
- $this->assertEquals("name4=value2", $cj->serializeToHttpRequest("/path/", "www.example.com"));
-
- $h[] = "name5=value3; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2999 13:46:00 GMT";
- $cj->parseCookieResponseHeader( $h[2] );
- $this->assertEquals("name4=value2; name5=value3", $cj->serializeToHttpRequest("/path/", "www.example.com"));
-
- $h[] = "name6=value3; domain=.example.net; path=/path/; expires=Mon, 09-Dec-1999 13:46:00 GMT";
- $cj->parseCookieResponseHeader( $h[3] );
- $this->assertEquals("", $cj->serializeToHttpRequest("/path/", "www.example.net"));
-
- $h[] = "name6=value4; domain=.example.net; path=/path/; expires=Mon, 09-Dec-2999 13:46:00 GMT";
- $cj->parseCookieResponseHeader( $h[4] );
- $this->assertEquals("name6=value4", $cj->serializeToHttpRequest("/path/", "www.example.net"));
- }
-
- function runCookieRequests() {
- $r = HttpRequest::factory( "http://www.php.net/manual" );
- $r->execute();
-
- $jar = $r->getCookieJar();
-
- $this->assertThat( $jar, $this->isInstanceOf( 'CookieJar' ) );
- $this->assertRegExp( '/^COUNTRY=.*; LAST_LANG=.*$/', $jar->serializeToHttpRequest( "/search?q=test", "www.php.net" ) );
- $this->assertEquals( '', $jar->serializeToHttpRequest( "/search?q=test", "www.php.com" ) );
- }
-
- function testCookieRequestDefault() {
- Http::$httpEngine = false;
- self::runCookieRequests();
- }
- function testCookieRequestPhp() {
- if ( !self::$has_fopen ) {
- $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
- }
-
- Http::$httpEngine = 'php';
- self::runCookieRequests();
- }
- function testCookieRequestCurl() {
- if ( !self::$has_curl ) {
- $this->markTestIncomplete( "This test requires curl." );
- }
-
- Http::$httpEngine = 'curl';
- self::runCookieRequests();
- }
-
-}
\ No newline at end of file
+++ /dev/null
-<?php
-/*
- * Tests for IP validity functions. Ported from /t/inc/IP.t by avar.
- */
-
-class IPTest extends PHPUnit_Framework_TestCase {
-
- public function testValidIPs() {
- foreach ( range( 0, 255 ) as $i ) {
- $a = sprintf( "%03d", $i );
- $b = sprintf( "%02d", $i );
- $c = sprintf( "%01d", $i );
- foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
- $ip = "$f.$f.$f.$f";
- $this->assertTrue( IP::isValid( $ip ) , "$ip is a valid IPv4 address" );
- }
- }
- }
-
- public function testInvalidIPs() {
- foreach ( range( 256, 999 ) as $i ) {
- $a = sprintf( "%03d", $i );
- $b = sprintf( "%02d", $i );
- $c = sprintf( "%01d", $i );
- foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
- $ip = "$f.$f.$f.$f";
- $this->assertFalse( IP::isValid( $ip ), "$ip is not a valid IPv4 address" );
- }
- }
- }
-
- public function testBogusIPs() {
- $invalid = array(
- 'www.xn--var-xla.net',
- '216.17.184.G',
- '216.17.184.1.',
- '216.17.184',
- '216.17.184.',
- '256.17.184.1'
- );
- foreach ( $invalid as $i ) {
- $this->assertFalse( IP::isValid( $i ), "$i is an invalid IPv4 address" );
- }
- }
-
- public function testPrivateIPs() {
- $private = array( '10.0.0.1', '172.16.0.1', '192.168.0.1' );
- foreach ( $private as $p ) {
- $this->assertFalse( IP::isPublic( $p ), "$p is not a public IP address" );
- }
- }
-}
+++ /dev/null
-<?php
-
-require_once( 'ImageFunctions.php' );
-
-class ImageFunctionsTest extends PHPUnit_Framework_TestCase {
- function testFitBoxWidth() {
- $vals = array(
- array(
- 'width' => 50,
- 'height' => 50,
- 'tests' => array(
- 50 => 50,
- 17 => 17,
- 18 => 18 ) ),
- array(
- 'width' => 366,
- 'height' => 300,
- 'tests' => array(
- 50 => 61,
- 17 => 21,
- 18 => 22 ) ),
- array(
- 'width' => 300,
- 'height' => 366,
- 'tests' => array(
- 50 => 41,
- 17 => 14,
- 18 => 15 ) ),
- array(
- 'width' => 100,
- 'height' => 400,
- 'tests' => array(
- 50 => 12,
- 17 => 4,
- 18 => 4 ) ) );
- foreach( $vals as $row ) {
- extract( $row );
- foreach( $tests as $max => $expected ) {
- $y = round( $expected * $height / $width );
- $result = wfFitBoxWidth( $width, $height, $max );
- $y2 = round( $result * $height / $width );
- $this->assertEquals( $expected,
- $result,
- "($width, $height, $max) wanted: {$expected}x$y, got: {$result}x$y2" );
- }
- }
- }
-}
-
-
+++ /dev/null
-<?php
-
-require_once( 'ProxyTools.php' );
-
-class LanguageConverterTest extends PHPUnit_Framework_TestCase {
- protected $lang = null;
- protected $lc = null;
-
- function setUp() {
- global $wgMemc, $wgRequest, $wgUser, $wgContLang;
-
- $wgUser = new User;
- $wgRequest = new FauxRequest(array());
- $wgMemc = new FakeMemCachedClient;
- $wgContLang = Language::factory( 'tg' );
- $this->lang = new LanguageTest();
- $this->lc = new TestConverter( $this->lang, 'tg',
- array( 'tg', 'tg-latn' ) );
- }
-
- function tearDown() {
- global $wgMemc;
- unset($wgMemc);
- unset($this->lc);
- unset($this->lang);
- }
-
- function testGetPreferredVariantDefaults() {
- $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
- }
-
- function testGetPreferredVariantHeaders() {
- global $wgRequest;
- $wgRequest->setHeader('Accept-Language', 'tg-latn');
-
- $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
- $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
- }
-
- function testGetPreferredVariantHeaderWeight() {
- global $wgRequest;
- $wgRequest->setHeader('Accept-Language', 'tg;q=1');
-
- $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
- }
-
- function testGetPreferredVariantHeaderWeight2() {
- global $wgRequest;
- $wgRequest->setHeader('Accept-Language', 'tg-latn;q=1');
-
- $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
- $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
- }
-
- function testGetPreferredVariantHeaderMulti() {
- global $wgRequest;
- $wgRequest->setHeader('Accept-Language', 'en, tg-latn;q=1');
-
- $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
- $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
- }
-
- function testGetPreferredVariantUserOption() {
- global $wgUser;
-
- $wgUser = new User;
- $wgUser->setId(1);
- $wgUser->setOption('variant', 'tg-latn');
-
- $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
- $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
- $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
- }
-
- function testGetPreferredVariantHeaderUserVsUrl() {
- global $wgRequest, $wgUser, $wgContLang;
-
- $wgContLang = Language::factory( 'tg-latn' );
- $wgRequest->setVal('variant', 'tg');
- $wgUser = User::newFromId("admin");
- $wgUser->setId(1);
- $wgUser->setOption('variant', 'tg-latn'); // The user's data is ignored
- // because the variant is set in the URL.
- $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
- }
-
-
- function testGetPreferredVariantDefaultLanguageVariant() {
- global $wgDefaultLanguageVariant;
-
- $wgDefaultLanguageVariant = 'tg-latn';
- $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, false));
- $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
- $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
- $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
- }
-
- function testGetPreferredVariantDefaultLanguageVsUrlVariant() {
- global $wgDefaultLanguageVariant, $wgRequest, $wgContLang;
-
- $wgContLang = Language::factory( 'tg-latn' );
- $wgDefaultLanguageVariant = 'tg';
- $wgRequest->setVal('variant', null);
- $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
- $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
- $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
- $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
- }
-}
-
-/**
- * Test converter (from Tajiki to latin orthography)
- */
-class TestConverter extends LanguageConverter {
- private $table = array(
- 'б' => 'b',
- 'в' => 'v',
- 'г' => 'g',
- );
-
- function loadDefaultTables() {
- $this->mTables = array(
- 'tg-latn' => new ReplacementArray( $this->table ),
- 'tg' => new ReplacementArray()
- );
- }
-
-}
-
-class LanguageTest extends Language {
- function __construct() {
- parent::__construct();
- $variants = array( 'tg', 'tg-latn' );
- $this->mConverter = new TestConverter( $this, 'tg', $variants );
- }
-}
+++ /dev/null
-<?php
-
-/**
- * @group Broken
- */
-class LicensesTest extends PHPUnit_Framework_TestCase {
-
- function testLicenses() {
- $str = "
-* Free licenses:
-** GFLD|Debian disagrees
-";
-
- $lc = new Licenses( $str );
- $this->assertTrue( is_a( $lc, 'Licenses' ), 'Correct class' );
- }
-}
\ No newline at end of file
+++ /dev/null
-<?php
-
-/**
- * These tests should work regardless of $wgCapitalLinks
- */
-
-require_once( 'Namespace.php' );
-
-class LocalFileTest extends PHPUnit_Framework_TestCase {
- function setUp() {
- global $wgContLang;
- $wgContLang = new Language;
- $info = array(
- 'name' => 'test',
- 'directory' => '/testdir',
- 'url' => '/testurl',
- 'hashLevels' => 2,
- 'transformVia404' => false,
- );
- $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
- $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
- $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
- $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
- $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
- $this->file_lc = $this->repo_lc->newFile( 'test!' );
- }
-
- function tearDown() {
- global $wgContLang;
- unset($wgContLang);
- }
-
- function testGetHashPath() {
- $this->assertEquals( '', $this->file_hl0->getHashPath() );
- $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
- $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
- }
-
- function testGetRel() {
- $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
- $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
- $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
- }
-
- function testGetUrlRel() {
- $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
- $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
- $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
- }
-
- function testGetArchivePath() {
- $this->assertEquals( '/testdir/archive', $this->file_hl0->getArchivePath() );
- $this->assertEquals( '/testdir/archive/a/a2', $this->file_hl2->getArchivePath() );
- $this->assertEquals( '/testdir/archive/!', $this->file_hl0->getArchivePath( '!' ) );
- $this->assertEquals( '/testdir/archive/a/a2/!', $this->file_hl2->getArchivePath( '!' ) );
- }
-
- function testGetThumbPath() {
- $this->assertEquals( '/testdir/thumb/Test!', $this->file_hl0->getThumbPath() );
- $this->assertEquals( '/testdir/thumb/a/a2/Test!', $this->file_hl2->getThumbPath() );
- $this->assertEquals( '/testdir/thumb/Test!/x', $this->file_hl0->getThumbPath( 'x' ) );
- $this->assertEquals( '/testdir/thumb/a/a2/Test!/x', $this->file_hl2->getThumbPath( 'x' ) );
- }
-
- function testGetArchiveUrl() {
- $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
- $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
- $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
- $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
- }
-
- function testGetThumbUrl() {
- $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
- $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
- $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
- $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
- }
-
- function testGetArchiveVirtualUrl() {
- $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
- $this->assertEquals( 'mwrepo://test/public/archive/a/a2', $this->file_hl2->getArchiveVirtualUrl() );
- $this->assertEquals( 'mwrepo://test/public/archive/%21', $this->file_hl0->getArchiveVirtualUrl( '!' ) );
- $this->assertEquals( 'mwrepo://test/public/archive/a/a2/%21', $this->file_hl2->getArchiveVirtualUrl( '!' ) );
- }
-
- function testGetThumbVirtualUrl() {
- $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
- $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
- $this->assertEquals( 'mwrepo://test/thumb/Test%21/%21', $this->file_hl0->getThumbVirtualUrl( '!' ) );
- $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21/%21', $this->file_hl2->getThumbVirtualUrl( '!' ) );
- }
-
- function testGetUrl() {
- $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
- $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
- }
-}
-
-
+++ /dev/null
-.PHONY: help test
-all test:
- phpunit
-install:
- pear channel-discover pear.phpunit.de
- pear install phpunit/PHPUnit
-help:
- # Options:
- # test (default) Run the unit tests
- # install Install PHPUnit from phpunit.de
- # help You're looking at it!
+++ /dev/null
-<?php
-
-require_once( "MediaWikiAPI_TestCase.php" );
-
-class MediaWikiAPITest extends MediaWikiAPI_TestCase {
-
- function setup() {
- parent::setup();
- }
-
- function testApi() {
- /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */
- $resp = Http::get( self::$apiUrl . "?format=xml" );
-
- libxml_use_internal_errors( true );
- $sxe = simplexml_load_string( $resp );
- $this->assertNotType( "bool", $sxe );
- $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
- }
-
- function testApiLoginNoName() {
- $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
- array( "postData" => array(
- "lgname" => "",
- "lgpassword" => self::$passWord ) ) );
- libxml_use_internal_errors( true );
- $sxe = simplexml_load_string( $resp );
- $this->assertNotType( "bool", $sxe );
- $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
- $a = $sxe->login[0]->attributes()->result;
- $this->assertEquals( ' result="NoName"', $a->asXML() );
- }
-
- function testApiLoginBadPass() {
- $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
- array( "postData" => array(
- "lgname" => self::$userName,
- "lgpassword" => "bad" ) ) );
- libxml_use_internal_errors( true );
- $sxe = simplexml_load_string( $resp );
- $this->assertNotType( "bool", $sxe );
- $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
- $a = $sxe->login[0]->attributes()->result;
- $this->assertEquals( ' result="WrongPass"', $a->asXML() );
- }
-
- function testApiLoginGoodPass() {
- $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
- array( "postData" => array(
- "lgname" => self::$userName,
- "lgpassword" => self::$passWord ) ) );
- libxml_use_internal_errors( true );
- $sxe = simplexml_load_string( $resp );
- $this->assertNotType( "bool", $sxe );
- $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
- $a = $sxe->login[0]->attributes()->result;
- $this->assertEquals( ' result="Success"', $a->asXML() );
- }
-
- function testApiGotCookie() {
- global $wgScriptPath, $wgServerName;
-
- $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml",
- array( "method" => "POST",
- "postData" => array(
- "lgname" => self::$userName,
- "lgpassword" => self::$passWord ) ) );
- $req->execute();
- $cj = $req->getCookieJar();
-
- $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/',
- $cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ) );
- }
-}
+++ /dev/null
-<?php
-
-abstract class MediaWikiAPI_TestCase extends PHPUnit_Framework_TestCase {
- protected static $userName;
- protected static $passWord;
- protected static $user;
- protected static $apiUrl;
-
- function setup() {
- global $wgServerName, $wgServer, $wgContLang, $wgAuth, $wgScriptPath,
- $wgScriptExtension, $wgMemc;
-
- if($wgServerName == "localhost" || $wgServer == "http://localhost") {
- $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
- 'be set in LocalSettings.php');
- }
- self::$apiUrl = $wgServer.$wgScriptPath."/api".$wgScriptExtension;
-
- $wgMemc = new FakeMemCachedClient;
- $wgContLang = Language::factory( 'en' );
- $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
- self::setupUser();
- }
-
- static function setupUser() {
- if ( self::$user == NULL ) {
- self::$userName = "Useruser";
- self::$passWord = User::randomPassword();
-
- self::$user = User::newFromName(self::$userName);
- if ( !self::$user->getID() ) {
- self::$user = User::createNew(self::$userName, array(
- "password" => self::$passWord,
- "email" => "test@example.com",
- "real_name" => "Test User"));
- } else {
- self::$user->setPassword(self::$passWord);
- }
- self::$user->saveSettings();
- }
- }
-}
+++ /dev/null
-<?php
-
-global $IP;
-define( "NO_COMMAND_LINE", 1 );
-require_once( "$IP/maintenance/parserTests.inc" );
-require_once( "ImageFunctions.php" );
-require_once( "ProxyTools.php" );
-require_once( "ObjectCache.php" );
-
-class PTShell extends ParserTest {
-
- private $cb;
-
- function setCallback( $cb ) {
- $this->cb = $cb;
- }
-
- function showTesting( $desc ) {
- }
-
- function showRunFile( $path ) {
- }
-
- function showSuccess( $desc ) {
- $this->cb->assertTrue( true, $desc );
- echo "PASSED: $desc\n";
- return true;
- }
-
- function showFailure( $desc, $expected, $got ) {
- /* $this->cb->assertEquals( $expected, $got, $desc ); */
- echo "FAILED: $desc\n";
- echo "got: $got\n";
- echo "expected: $expected\n";
- }
-}
-
-class MediaWikiParserTest extends PHPUnit_Framework_TestCase {
- private $parserTester;
- private $db;
- private $uploadDir;
- private $keepUploads;
-
- /**
- * Remove the dummy uploads directory
- */
- private function teardownUploadDir( $dir ) {
- if ( $this->keepUploads ) {
- return;
- }
-
- // delete the files first, then the dirs.
- self::deleteFiles(
- array (
- "$dir/3/3a/Foobar.jpg",
- "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
- "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
- "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
- "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
-
- "$dir/0/09/Bad.jpg",
- )
- );
-
- self::deleteDirs(
- array (
- "$dir/3/3a",
- "$dir/3",
- "$dir/thumb/6/65",
- "$dir/thumb/6",
- "$dir/thumb/3/3a/Foobar.jpg",
- "$dir/thumb/3/3a",
- "$dir/thumb/3",
-
- "$dir/0/09/",
- "$dir/0/",
-
- "$dir/thumb",
- "$dir",
- )
- );
- }
-
- /**
- * Delete the specified files, if they exist.
- * @param array $files full paths to files to delete.
- */
- private static function deleteFiles( $files ) {
- foreach( $files as $file ) {
- if( file_exists( $file ) ) {
- unlink( $file );
- }
- }
- }
- /**
- * Delete the specified directories, if they exist. Must be empty.
- * @param array $dirs full paths to directories to delete.
- */
- private static function deleteDirs( $dirs ) {
- foreach( $dirs as $dir ) {
- if( is_dir( $dir ) ) {
- rmdir( $dir );
- }
- }
- }
-
- /**
- * Create a dummy uploads directory which will contain a couple
- * of files in order to pass existence tests.
- * @return string The directory
- */
- private function setupUploadDir() {
- global $IP;
- if ( $this->keepUploads ) {
- $dir = wfTempDir() . '/mwParser-images';
- if ( is_dir( $dir ) ) {
- return $dir;
- }
- } else {
- $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
- }
-
- wfDebug( "Creating upload directory $dir\n" );
- if ( file_exists( $dir ) ) {
- wfDebug( "Already exists!\n" );
- return $dir;
- }
- wfMkdirParents( $dir . '/3/3a' );
- copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
-
- wfMkdirParents( $dir . '/0/09' );
- copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
- return $dir;
- }
-
- function setUp() {
- global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
- $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgMessageCache,
- $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc, $wgNamespaceAliases, $wgNamespaceProtection,
- $wgLocalFileRepo, $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath,
- $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
-
- $wgScript = '/index.php';
- $wgScriptPath = '/';
- $wgArticlePath = '/wiki/$1';
- $wgStyleSheetPath = '/skins';
- $wgStylePath = '/skins';
- $wgThumbnailScriptPath = false;
- $this->uploadDir = $this->setupUploadDir();
- $wgLocalFileRepo = array(
- 'class' => 'LocalRepo',
- 'name' => 'local',
- 'directory' => $this->uploadDir,
- 'url' => 'http://example.com/images',
- 'hashLevels' => 2,
- 'transformVia404' => false,
- );
- //$wgNamespacesWithSubpages = array( 0 => isset( $opts['subpage'] ) );
- $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
- $wgNamespaceAliases['Image'] = NS_FILE;
- $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
-
-
- $wgEnableParserCache = false;
- $wgDeferredUpdateList = array();
- $wgMemc =& wfGetMainCache();
- $messageMemc =& wfGetMessageCacheStorage();
- $parserMemc =& wfGetParserCacheStorage();
-
- $wgContLang = new StubContLang;
- $wgUser = new StubUser;
- $wgLang = new StubUserLang;
- $wgOut = new StubObject( 'wgOut', 'OutputPage' );
- $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
- $wgRequest = new WebRequest;
-
- $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
- array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
- if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
-
- $this->parserTester = new PTShell();
- $this->parserTester->setCallback( $this );
-
- /* global $wgDBtype, $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBport, $wgDBmwschema, $wgDBts2chema; */
- /* $this->db['type'] = $wgDBtype; */
- /* $this->db['server'] = $wgDBserver; */
- /* $this->db['name'] = $wgDBname; */
- /* $this->db['user'] = $wgDBuser; */
- /* $this->db['password'] = $wgDBpassword; */
- /* $this->db['port'] = $wgDBport; */
- /* $this->db['mwschema'] = $wgDBmwschema; */
- /* $this->db['ts2schema'] = $wgDBts2chema; */
- }
-
- function tearDown() {
- $this->teardownUploadDir($this->uploadDir);
- /* $db = wfGetDB( DB_MASTER ); */
- /* $db->close(); */
- /* global $wgDBtype, $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBport, $wgDBmwschema, $wgDBts2chema; */
-
- /* $wgDBtype = $this->db['type']; */
- /* $wgDBserver = $this->db['server']; */
- /* $wgDBname = $this->db['name']; */
- /* $wgDBuser = $this->db['user']; */
- /* $wgDBpassword = $this->db['password']; */
- /* $wgDBport = $this->db['port']; */
- /* $wgDBmwschema = $this->db['mwschema']; */
- /* $wgDBts2chema = $this->db['ts2schema']; */
-
- }
-
-
- function testParser() {
- global $IP;
-
- $this->parserTester->runTestsFromFiles( array( "$IP/maintenance/parserTests.txt" ) );
- }
-}
-
+++ /dev/null
-<?php
-
-abstract class MediaWiki_TestCase extends PHPUnit_Framework_TestCase {
- /**
- * @param string $serverType
- * @param array $tables
- */
- protected function buildTestDatabase( $tables ) {
- global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
- $this->markTestIncomplete("This test requires DB admin user credentials.");
- $wgDBprefix = 'parsertest_';
-
- $db = new DatabaseMysql(
- $wgDBserver,
- $wgDBadminuser,
- $wgDBadminpassword,
- $wgDBname );
- if( $db->isOpen() ) {
- if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
- # Database that supports CREATE TABLE ... LIKE
- foreach ($tables as $tbl) {
- $newTableName = $db->tableName( $tbl );
- #$tableName = $this->oldTableNames[$tbl];
- $tableName = $tbl;
- $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)");
- }
- } else {
- # Hack for MySQL versions < 4.1, which don't support
- # "CREATE TABLE ... LIKE". Note that
- # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
- # would not create the indexes we need....
- foreach ($tables as $tbl) {
- $res = $db->query("SHOW CREATE TABLE $tbl");
- $row = $db->fetchRow($res);
- $create = $row[1];
- $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
- . $wgDBprefix . '\\1`', $create);
- if ($create === $create_tmp) {
- # Couldn't do replacement
- wfDie( "could not create temporary table $tbl" );
- }
- $db->query($create_tmp);
- }
-
- }
- return $db;
- } else {
- // Something amiss
- return null;
- }
- }
-}
-
+++ /dev/null
-Some quickie unit tests done with the PHPUnit testing framework. To run the
-test suite, run 'make test' in this dir. This directly invokes 'phpunit.'
-
-PHPUnit is no longer maintained by PEAR. To get the current version of
-PHPUnit, first uninstall any old version of PHPUnit or PHPUnit2 from PEAR,
-then install the current version from phpunit.de like this:
-
-# pear channel-discover pear.phpunit.de
-# pear install phpunit/PHPUnit
-
-You also may wish to install this via your normal package mechanism:
-
-# aptitude install phpunit
- - or -
-# yum install phpunit
-
-Notes:
-- Label currently broken tests in the group Broken and they will not
- be run by phpunit. You can add them to the group by putting the
- following comment at the top of the file:
- /**
- * @group Broken
- */
-- Need to fix some broken tests
+++ /dev/null
-<?php
-
-global $IP;
-require_once( "$IP/includes/Sanitizer.php" );
-
-class SanitizerTest extends PHPUnit_Framework_TestCase {
-
- function testDecodeNamedEntities() {
- $this->assertEquals(
- "\xc3\xa9cole",
- Sanitizer::decodeCharReferences( 'école' ),
- 'decode named entities'
- );
- }
-
- function testDecodeNumericEntities() {
- $this->assertEquals(
- "\xc4\x88io bonas dans l'\xc3\xa9cole!",
- Sanitizer::decodeCharReferences( "Ĉio bonas dans l'école!" ),
- 'decode numeric entities'
- );
- }
-
- function testDecodeMixedEntities() {
- $this->assertEquals(
- "\xc4\x88io bonas dans l'\xc3\xa9cole!",
- Sanitizer::decodeCharReferences( "Ĉio bonas dans l'école!" ),
- 'decode mixed numeric/named entities'
- );
- }
-
- function testDecodeMixedComplexEntities() {
- $this->assertEquals(
- "\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas Ĉio dans l'école)",
- Sanitizer::decodeCharReferences(
- "Ĉio bonas dans l'école! (mais pas &#x108;io dans l'&eacute;cole)"
- ),
- 'decode mixed complex entities'
- );
- }
-
- function testInvalidAmpersand() {
- $this->assertEquals(
- 'a & b',
- Sanitizer::decodeCharReferences( 'a & b' ),
- 'Invalid ampersand'
- );
- }
-
- function testInvalidEntities() {
- $this->assertEquals(
- '&foo;',
- Sanitizer::decodeCharReferences( '&foo;' ),
- 'Invalid named entity'
- );
- }
-
- function testInvalidNumberedEntities() {
- $this->assertEquals( UTF8_REPLACEMENT, Sanitizer::decodeCharReferences( "�" ), 'Invalid numbered entity' );
- }
-
- function testSelfClosingTag() {
- $GLOBALS['wgUseTidy'] = false;
- $this->assertEquals(
- '<div>Hello world</div>',
- Sanitizer::removeHTMLtags( '<div>Hello world</div />' ),
- 'Self-closing closing div'
- );
- }
-}
-
+++ /dev/null
-<?php
-
-require_once( 'MediaWiki_TestCase.php' );
-
-/** @todo document
- */
-
-class SearchEngineTest extends MediaWiki_TestCase {
- var $db, $search;
-
- function insertSearchData() {
- $this->db->safeQuery( <<<SQL
- INSERT INTO ! (page_id,page_namespace,page_title,page_latest)
- VALUES (1, 0, 'Main_Page', 1),
- (2, 1, 'Main_Page', 2),
- (3, 0, 'Smithee', 3),
- (4, 1, 'Smithee', 4),
- (5, 0, 'Unrelated_page', 5),
- (6, 0, 'Another_page', 6),
- (7, 4, 'Help', 7),
- (8, 0, 'Thppt', 8),
- (9, 0, 'Alan_Smithee', 9),
- (10, 0, 'Pages', 10)
-SQL
- , $this->db->tableName( 'page' ) );
- $this->db->safeQuery( <<<SQL
- INSERT INTO ! (rev_id,rev_page)
- VALUES (1, 1),
- (2, 2),
- (3, 3),
- (4, 4),
- (5, 5),
- (6, 6),
- (7, 7),
- (8, 8),
- (9, 9),
- (10, 10)
-SQL
- , $this->db->tableName( 'revision' ) );
- $this->db->safeQuery( <<<SQL
- INSERT INTO ! (old_id,old_text)
- VALUES (1, 'This is a main page'),
- (2, 'This is a talk page to the main page, see [[smithee]]'),
- (3, 'A smithee is one who smiths. See also [[Alan Smithee]]'),
- (4, 'This article sucks.'),
- (5, 'Nothing in this page is about the S word.'),
- (6, 'This page also is unrelated.'),
- (7, 'Help me!'),
- (8, 'Blah blah'),
- (9, 'yum'),
- (10,'are food')
-SQL
- , $this->db->tableName( 'text' ) );
- $this->db->safeQuery( <<<SQL
- INSERT INTO ! (si_page,si_title,si_text)
- VALUES (1, 'main page', 'this is a main page'),
- (2, 'main page', 'this is a talk page to the main page, see smithee'),
- (3, 'smithee', 'a smithee is one who smiths see also alan smithee'),
- (4, 'smithee', 'this article sucks'),
- (5, 'unrelated page', 'nothing in this page is about the s word'),
- (6, 'another page', 'this page also is unrelated'),
- (7, 'help', 'help me'),
- (8, 'thppt', 'blah blah'),
- (9, 'alan smithee', 'yum'),
- (10, 'pages', 'are food')
-SQL
- , $this->db->tableName( 'searchindex' ) );
- }
-
- function fetchIds( $results ) {
- $matches = array();
- while( $row = $results->next() ) {
- $matches[] = $row->getTitle()->getPrefixedText();
- }
- $results->free();
- # Search is not guaranteed to return results in a certain order;
- # sort them numerically so we will compare simply that we received
- # the expected matches.
- sort( $matches );
- return $matches;
- }
-
- function testTextSearch() {
- if( is_null( $this->db ) ) {
- $this->markTestIncomplete( "Can't find a database to test with." );
- }
- $this->assertEquals(
- array( 'Smithee' ),
- $this->fetchIds( $this->search->searchText( 'smithee' ) ),
- "Plain search failed" );
- }
-
- function testTextPowerSearch() {
- if( is_null( $this->db ) ) {
- $this->markTestIncomplete( "Can't find a database to test with." );
- }
- $this->search->setNamespaces( array( 0, 1, 4 ) );
- $this->assertEquals(
- array(
- 'Smithee',
- 'Talk:Main Page',
- ),
- $this->fetchIds( $this->search->searchText( 'smithee' ) ),
- "Power search failed" );
- }
-
- function testTitleSearch() {
- if( is_null( $this->db ) ) {
- $this->markTestIncomplete( "Can't find a database to test with." );
- }
- $this->assertEquals(
- array(
- 'Alan Smithee',
- 'Smithee',
- ),
- $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
- "Title search failed" );
- }
-
- function testTextTitlePowerSearch() {
- if( is_null( $this->db ) ) {
- $this->markTestIncomplete( "Can't find a database to test with." );
- }
- $this->search->setNamespaces( array( 0, 1, 4 ) );
- $this->assertEquals(
- array(
- 'Alan Smithee',
- 'Smithee',
- 'Talk:Smithee',
- ),
- $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
- "Title power search failed" );
- }
-
-}
-
-
-
+++ /dev/null
-<?php
-require_once( 'SearchEngineTest.php' );
-
-class SearchMySQL4Test extends SearchEngineTest {
- var $db;
-
- function setUp() {
- $GLOBALS['wgContLang'] = new Language;
- $this->db = $this->buildTestDatabase(
- array( 'page', 'revision', 'text', 'searchindex' ) );
- if( $this->db ) {
- $this->insertSearchData();
- }
- $this->search = new SearchMySQL4( $this->db );
- }
-
- function tearDown() {
- if( !is_null( $this->db ) ) {
- $this->db->close();
- }
- unset( $this->db );
- unset( $this->search );
- }
-
-}
-
-
+++ /dev/null
-<?php
-
-class DatabaseMock extends DatabaseBase {
- function __construct( $server = false, $user = false, $password = false, $dbName = false,
- $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
- {
- $this->mConn = true;
- $this->mOpened = true;
- }
-
- function open( $server, $user, $password, $dbName ) { return true; }
- function doQuery( $sql ) {}
- function fetchObject( $res ) {}
- function fetchRow( $res ) {}
- function numRows( $res ) {}
- function numFields( $res ) {}
- function fieldName( $res, $n ) {}
- function insertId() {}
- function dataSeek( $res, $row ) {}
- function lastErrno() { return 0; }
- function lastError() { return ''; }
- function affectedRows() {}
- function fieldInfo( $table, $field ) {}
- function strencode( $s ) {}
- function getSoftwareLink() {}
- function getServerVersion() {}
- function getType() {}
-}
-
-class MockSearch extends SearchEngine {
- public static $id;
- public static $title;
- public static $text;
-
- public function __construct( $db ) {
- }
-
- public function update( $id, $title, $text ) {
- self::$id = $id;
- self::$title = $title;
- self::$text = $text;
- }
-}
-
-class SearchUpdateTest extends PHPUnit_Framework_TestCase {
-
- function update( $text, $title = 'Test', $id = 1 ) {
- $u = new SearchUpdate( $id, $title, $text );
- $u->doUpdate();
- return array( MockSearch::$title, MockSearch::$text );
- }
-
- function updateText( $text ) {
- list( $title, $resultText ) = $this->update( $text );
- $resultText = trim( $resultText ); // abstract from some implementation details
- return $resultText;
- }
-
- function setUp() {
- global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers;
- $wgSearchType = 'MockSearch';
- $wgDBtype = 'mock';
- $wgLBFactoryConf['class'] = 'LBFactory_Simple';
- $wgDBservers = null;
- LBFactory::destroyInstance();
- }
-
- function tearDown() {
- LBFactory::destroyInstance();
- }
-
- function testUpdateText() {
- $this->assertEquals(
- 'test',
- $this->updateText( '<div>TeSt</div>' ),
- 'HTML stripped, text lowercased'
- );
-
- $this->assertEquals(
- 'foo bar boz quux',
- $this->updateText( <<<EOT
-<table style="color:red; font-size:100px">
- <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
- <tr><td>boz</td><tr>quux</td></tr>
-</table>
-EOT
- ), 'Stripping HTML tables' );
-
- $this->assertEquals(
- 'a b',
- $this->updateText( 'a > b' ),
- 'Handle unclosed tags'
- );
-
- $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
-
- $this->assertNotEquals(
- '',
- $this->updateText( $text ),
- 'Bug 18609'
- );
- }
-}
+++ /dev/null
-<?php
-
-function getSiteParams( $conf, $wiki ) {
- $site = null;
- $lang = null;
- foreach( $conf->suffixes as $suffix ) {
- if ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
- $site = $suffix;
- $lang = substr( $wiki, 0, -strlen( $suffix ) );
- break;
- }
- }
- return array(
- 'suffix' => $site,
- 'lang' => $lang,
- 'params' => array(
- 'lang' => $lang,
- 'site' => $site,
- 'wiki' => $wiki,
- ),
- 'tags' => array( 'tag' ),
- );
-}
-
-class SiteConfigurationTest extends PHPUnit_Framework_TestCase {
- var $mConf;
-
- function setUp() {
- $this->mConf = new SiteConfiguration;
-
- $this->mConf->suffixes = array( 'wiki' );
- $this->mConf->wikis = array( 'enwiki', 'dewiki', 'frwiki' );
- $this->mConf->settings = array(
- 'simple' => array(
- 'wiki' => 'wiki',
- 'tag' => 'tag',
- 'enwiki' => 'enwiki',
- 'dewiki' => 'dewiki',
- 'frwiki' => 'frwiki',
- ),
-
- 'fallback' => array(
- 'default' => 'default',
- 'wiki' => 'wiki',
- 'tag' => 'tag',
- ),
-
- 'params' => array(
- 'default' => '$lang $site $wiki',
- ),
-
- '+global' => array(
- 'wiki' => array(
- 'wiki' => 'wiki',
- ),
- 'tag' => array(
- 'tag' => 'tag',
- ),
- 'enwiki' => array(
- 'enwiki' => 'enwiki',
- ),
- 'dewiki' => array(
- 'dewiki' => 'dewiki',
- ),
- 'frwiki' => array(
- 'frwiki' => 'frwiki',
- ),
- ),
-
- 'merge' => array(
- '+wiki' => array(
- 'wiki' => 'wiki',
- ),
- '+tag' => array(
- 'tag' => 'tag',
- ),
- 'default' => array(
- 'default' => 'default',
- ),
- '+enwiki' => array(
- 'enwiki' => 'enwiki',
- ),
- '+dewiki' => array(
- 'dewiki' => 'dewiki',
- ),
- '+frwiki' => array(
- 'frwiki' => 'frwiki',
- ),
- ),
- );
-
- $GLOBALS['global'] = array( 'global' => 'global' );
- }
-
-
- function testSiteFromDB() {
- $this->assertEquals(
- array( 'wikipedia', 'en' ),
- $this->mConf->siteFromDB( 'enwiki' ),
- 'siteFromDB()'
- );
- $this->assertEquals(
- array( 'wikipedia', '' ),
- $this->mConf->siteFromDB( 'wiki' ),
- 'siteFromDB() on a suffix'
- );
- $this->assertEquals(
- array( null, null ),
- $this->mConf->siteFromDB( 'wikien' ),
- 'siteFromDB() on a non-existing wiki'
- );
-
- $this->mConf->suffixes = array( 'wiki', '' );
- $this->assertEquals(
- array( '', 'wikien' ),
- $this->mConf->siteFromDB( 'wikien' ),
- 'siteFromDB() on a non-existing wiki (2)'
- );
- }
-
- function testGetLocalDatabases() {
- $this->assertEquals(
- array( 'enwiki', 'dewiki', 'frwiki' ),
- $this->mConf->getLocalDatabases(),
- 'getLocalDatabases()'
- );
- }
-
- function testGet() {
- $this->assertEquals(
- 'enwiki',
- $this->mConf->get( 'simple', 'enwiki', 'wiki' ),
- 'get(): simple setting on an existing wiki'
- );
- $this->assertEquals(
- 'dewiki',
- $this->mConf->get( 'simple', 'dewiki', 'wiki' ),
- 'get(): simple setting on an existing wiki (2)'
- );
- $this->assertEquals(
- 'frwiki',
- $this->mConf->get( 'simple', 'frwiki', 'wiki' ),
- 'get(): simple setting on an existing wiki (3)'
- );
- $this->assertEquals(
- 'wiki',
- $this->mConf->get( 'simple', 'wiki', 'wiki' ),
- 'get(): simple setting on an suffix'
- );
- $this->assertEquals(
- 'wiki',
- $this->mConf->get( 'simple', 'eswiki', 'wiki' ),
- 'get(): simple setting on an non-existing wiki'
- );
-
- $this->assertEquals(
- 'wiki',
- $this->mConf->get( 'fallback', 'enwiki', 'wiki' ),
- 'get(): fallback setting on an existing wiki'
- );
- $this->assertEquals(
- 'tag',
- $this->mConf->get( 'fallback', 'dewiki', 'wiki', array(), array( 'tag' ) ),
- 'get(): fallback setting on an existing wiki (with wiki tag)'
- );
- $this->assertEquals(
- 'wiki',
- $this->mConf->get( 'fallback', 'wiki', 'wiki' ),
- 'get(): fallback setting on an suffix'
- );
- $this->assertEquals(
- 'wiki',
- $this->mConf->get( 'fallback', 'wiki', 'wiki', array(), array( 'tag' ) ),
- 'get(): fallback setting on an suffix (with wiki tag)'
- );
- $this->assertEquals(
- 'wiki',
- $this->mConf->get( 'fallback', 'eswiki', 'wiki' ),
- 'get(): fallback setting on an non-existing wiki'
- );
- $this->assertEquals(
- 'tag',
- $this->mConf->get( 'fallback', 'eswiki', 'wiki', array(), array( 'tag' ) ),
- 'get(): fallback setting on an non-existing wiki (with wiki tag)'
- );
-
- $common = array( 'wiki' => 'wiki', 'default' => 'default' );
- $commonTag = array( 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' );
- $this->assertEquals(
- array( 'enwiki' => 'enwiki' ) + $common,
- $this->mConf->get( 'merge', 'enwiki', 'wiki' ),
- 'get(): merging setting on an existing wiki'
- );
- $this->assertEquals(
- array( 'enwiki' => 'enwiki' ) + $commonTag,
- $this->mConf->get( 'merge', 'enwiki', 'wiki', array(), array( 'tag' ) ),
- 'get(): merging setting on an existing wiki (with tag)'
- );
- $this->assertEquals(
- array( 'dewiki' => 'dewiki' ) + $common,
- $this->mConf->get( 'merge', 'dewiki', 'wiki' ),
- 'get(): merging setting on an existing wiki (2)'
- );
- $this->assertEquals(
- array( 'dewiki' => 'dewiki' ) + $commonTag,
- $this->mConf->get( 'merge', 'dewiki', 'wiki', array(), array( 'tag' ) ),
- 'get(): merging setting on an existing wiki (2) (with tag)'
- );
- $this->assertEquals(
- array( 'frwiki' => 'frwiki' ) + $common,
- $this->mConf->get( 'merge', 'frwiki', 'wiki' ),
- 'get(): merging setting on an existing wiki (3)'
- );
- $this->assertEquals(
- array( 'frwiki' => 'frwiki' ) + $commonTag,
- $this->mConf->get( 'merge', 'frwiki', 'wiki', array(), array( 'tag' ) ),
- 'get(): merging setting on an existing wiki (3) (with tag)'
- );
- $this->assertEquals(
- array( 'wiki' => 'wiki' ) + $common,
- $this->mConf->get( 'merge', 'wiki', 'wiki' ),
- 'get(): merging setting on an suffix'
- );
- $this->assertEquals(
- array( 'wiki' => 'wiki' ) + $commonTag,
- $this->mConf->get( 'merge', 'wiki', 'wiki', array(), array( 'tag' ) ),
- 'get(): merging setting on an suffix (with tag)'
- );
- $this->assertEquals(
- $common,
- $this->mConf->get( 'merge', 'eswiki', 'wiki' ),
- 'get(): merging setting on an non-existing wiki'
- );
- $this->assertEquals(
- $commonTag,
- $this->mConf->get( 'merge', 'eswiki', 'wiki', array(), array( 'tag' ) ),
- 'get(): merging setting on an non-existing wiki (with tag)'
- );
- }
-
- function testSiteFromDBWithCallback() {
- $this->mConf->siteParamsCallback = 'getSiteParams';
-
- $this->assertEquals(
- array( 'wiki', 'en' ),
- $this->mConf->siteFromDB( 'enwiki' ),
- 'siteFromDB() with callback'
- );
- $this->assertEquals(
- array( 'wiki', '' ),
- $this->mConf->siteFromDB( 'wiki' ),
- 'siteFromDB() with callback on a suffix'
- );
- $this->assertEquals(
- array( null, null ),
- $this->mConf->siteFromDB( 'wikien' ),
- 'siteFromDB() with callback on a non-existing wiki'
- );
- }
-
- function testParamReplacement() {
- $this->mConf->siteParamsCallback = 'getSiteParams';
-
- $this->assertEquals(
- 'en wiki enwiki',
- $this->mConf->get( 'params', 'enwiki', 'wiki' ),
- 'get(): parameter replacement on an existing wiki'
- );
- $this->assertEquals(
- 'de wiki dewiki',
- $this->mConf->get( 'params', 'dewiki', 'wiki' ),
- 'get(): parameter replacement on an existing wiki (2)'
- );
- $this->assertEquals(
- 'fr wiki frwiki',
- $this->mConf->get( 'params', 'frwiki', 'wiki' ),
- 'get(): parameter replacement on an existing wiki (3)'
- );
- $this->assertEquals(
- ' wiki wiki',
- $this->mConf->get( 'params', 'wiki', 'wiki' ),
- 'get(): parameter replacement on an suffix'
- );
- $this->assertEquals(
- 'es wiki eswiki',
- $this->mConf->get( 'params', 'eswiki', 'wiki' ),
- 'get(): parameter replacement on an non-existing wiki'
- );
- }
-
- function testGetAll() {
- $this->mConf->siteParamsCallback = 'getSiteParams';
-
- $getall = array(
- 'simple' => 'enwiki',
- 'fallback' => 'tag',
- 'params' => 'en wiki enwiki',
- 'global' => array( 'enwiki' => 'enwiki' ) + $GLOBALS['global'],
- 'merge' => array( 'enwiki' => 'enwiki', 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' ),
- );
- $this->assertEquals( $getall, $this->mConf->getAll( 'enwiki' ), 'getAll()' );
-
- $this->mConf->extractAllGlobals( 'enwiki', 'wiki' );
-
- $this->assertEquals( $getall['simple'], $GLOBALS['simple'], 'extractAllGlobals(): simple setting' );
- $this->assertEquals( $getall['fallback'], $GLOBALS['fallback'], 'extractAllGlobals(): fallback setting' );
- $this->assertEquals( $getall['params'], $GLOBALS['params'], 'extractAllGlobals(): parameter replacement' );
- $this->assertEquals( $getall['global'], $GLOBALS['global'], 'extractAllGlobals(): merging with global' );
- $this->assertEquals( $getall['merge'], $GLOBALS['merge'], 'extractAllGlobals(): merging setting' );
- }
-}
+++ /dev/null
-<?php
-
-class TimeAdjustTest extends PHPUnit_Framework_TestCase {
-
- public function setUp() {
- $this->iniSet( 'precision', 15 );
- }
-
- # Test offset usage for a given language::userAdjust
- function testUserAdjust() {
- global $wgLocalTZoffset, $wgContLang, $wgUser;
-
- $wgContLang = $en = Language::factory( 'en' );
-
- # Collection of parameters for Language_t_Offset.
- # Format: date to be formatted, localTZoffset value, expected date
- $userAdjust_tests = array(
- array( 20061231235959, 0, 20061231235959 ),
- array( 20061231235959, 5, 20070101000459 ),
- array( 20061231235959, 15, 20070101001459 ),
- array( 20061231235959, 60, 20070101005959 ),
- array( 20061231235959, 90, 20070101012959 ),
- array( 20061231235959, 120, 20070101015959 ),
- array( 20061231235959, 540, 20070101085959 ),
- array( 20061231235959, -5, 20061231235459 ),
- array( 20061231235959, -30, 20061231232959 ),
- array( 20061231235959, -60, 20061231225959 ),
- );
-
- foreach( $userAdjust_tests as $data ) {
- $wgLocalTZoffset = $data[1];
-
- $this->assertEquals(
- strval( $data[2] ),
- strval( $en->userAdjust( $data[0], '' ) ),
- "User adjust {$data[0]} by {$data[1]} minutes should give {$data[2]}"
- );
- }
- }
-}
+++ /dev/null
-<?php
-
-class TitleTest extends PHPUnit_Framework_TestCase {
-
- function testLegalChars() {
- $titlechars = Title::legalChars();
-
- foreach ( range( 1, 255 ) as $num ) {
- $chr = chr( $num );
- if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
- $this->assertFalse( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid titlechar" );
- } else {
- $this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" );
- }
- }
- }
-}
+++ /dev/null
-<?php
-
-class XmlTest extends PHPUnit_Framework_TestCase {
-
- function testElementOpen() {
- $this->assertEquals(
- '<element>',
- Xml::element( 'element', null, null ),
- 'Opening element with no attributes'
- );
- }
-
- function testElementEmpty() {
- $this->assertEquals(
- '<element />',
- Xml::element( 'element', null, '' ),
- 'Terminated empty element'
- );
- }
-
- function testElementEscaping() {
- $this->assertEquals(
- '<element>hello <there> you & you</element>',
- Xml::element( 'element', null, 'hello <there> you & you' ),
- 'Element with no attributes and content that needs escaping'
- );
- }
-
- function testElementAttributes() {
- $this->assertEquals(
- '<element key="value" <>="<>">',
- Xml::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ),
- 'Element attributes, keys are not escaped'
- );
- }
-
- function testOpenElement() {
- $this->assertEquals(
- '<element k="v">',
- Xml::openElement( 'element', array( 'k' => 'v' ) ),
- 'openElement() shortcut'
- );
- }
-
- function testCloseElement() {
- $this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' );
- }
-
- #
- # textarea
- #
- function testTextareaNoContent() {
- $this->assertEquals(
- '<textarea name="name" id="name" cols="40" rows="5"></textarea>',
- Xml::textarea( 'name', '' ),
- 'textarea() with not content'
- );
- }
-
- function testTextareaAttribs() {
- $this->assertEquals(
- '<textarea name="name" id="name" cols="20" rows="10"><txt></textarea>',
- Xml::textarea( 'name', '<txt>', 20, 10 ),
- 'textarea() with custom attribs'
- );
- }
-
- #
- # JS
- #
- function testEscapeJsStringSpecialChars() {
- $this->assertEquals(
- '\\\\\r\n',
- Xml::escapeJsString( "\\\r\n" ),
- 'escapeJsString() with special characters'
- );
- }
-
- function testEncodeJsVarBoolean() {
- $this->assertEquals(
- 'true',
- Xml::encodeJsVar( true ),
- 'encodeJsVar() with boolean'
- );
- }
-
- function testEncodeJsVarNull() {
- $this->assertEquals(
- 'null',
- Xml::encodeJsVar( null ),
- 'encodeJsVar() with null'
- );
- }
-
- function testEncodeJsVarArray() {
- $this->assertEquals(
- '["a", 1]',
- Xml::encodeJsVar( array( 'a', 1 ) ),
- 'encodeJsVar() with array'
- );
- $this->assertEquals(
- '{"a": "a", "b": 1}',
- Xml::encodeJsVar( array( 'a' => 'a', 'b' => 1 ) ),
- 'encodeJsVar() with associative array'
- );
- }
-
- function testEncodeJsVarObject() {
- $this->assertEquals(
- '{"a": "a", "b": 1}',
- Xml::encodeJsVar( (object)array( 'a' => 'a', 'b' => 1 ) ),
- 'encodeJsVar() with object'
- );
- }
-}
+++ /dev/null
-<?php
-
-/**
- * Set up the MediaWiki environment when running tests with "phpunit" command
- *
- * Warning: this file is not included from global scope!
- * @file
- */
-
-global $wgCommandLineMode, $IP;
-$wgCommandLineMode = true;
-$IP = dirname( dirname( __FILE__ ) );
-
-define( 'MEDIAWIKI', true );
-define( 'MW_PHPUNIT_TEST', true );
-
-require_once( "$IP/includes/Defines.php" );
-require_once( "$IP/includes/AutoLoader.php" );
-require_once( "$IP/LocalSettings.php" );
-require_once( "$IP/includes/ProfilerStub.php" );
-require_once( "$IP/includes/GlobalFunctions.php" );
-require_once( "$IP/includes/Hooks.php" );
-$self = __FILE__;
-require_once( "$IP/includes/Setup.php" );
-
-
+++ /dev/null
-<!-- See http://www.phpunit.de/manual/3.3/en/appendixes.configuration.html -->
-<phpunit bootstrap="./bootstrap.php"
- colors="false"
- stopOnFailure="false">
- <!-- convertErrorsToExceptions="true" -->
- <!-- convertNoticesToExceptions="true" -->
- <!-- convertWarningsToExceptions="true" -->
- <testsuite name="MediaWiki Test Suite">
- <directory>.</directory>
- </testsuite>
- <groups>
- <exclude>
- <group>Broken</group>
- </exclude>
- </groups>
-</phpunit>
\ No newline at end of file
+++ /dev/null
-<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">
-<siteinfo>
- <sitename>DemoWiki</sitename>
- <base>http://example.com/wiki/Main_Page</base>
- <generator>MediaWiki 1.5.0</generator>
- <case>first-letter</case>
- <namespaces>
- <namespace key="-2">Media</namespace>
- <namespace key="-1">Special</namespace>
- <namespace key="0"></namespace>
- <namespace key="1">Talk</namespace>
- <namespace key="2">User</namespace>
- <namespace key="3">User talk</namespace>
- <namespace key="4">DemoWiki</namespace>
- <namespace key="5">DemoWIki talk</namespace>
- <namespace key="6">Image</namespace>
- <namespace key="7">Image talk</namespace>
- <namespace key="8">MediaWiki</namespace>
- <namespace key="9">MediaWiki talk</namespace>
- <namespace key="10">Template</namespace>
- <namespace key="11">Template talk</namespace>
- <namespace key="12">Help</namespace>
- <namespace key="13">Help talk</namespace>
- <namespace key="14">Category</namespace>
- <namespace key="15">Category talk</namespace>
- </namespaces>
-</siteinfo>
-<page>
- <title>First page</title>
- <id>1</id>
- <revision>
- <id>1</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 1, rev 1</comment>
- <text>page 1, rev 1</text>
- </revision>
- <revision>
- <id>2</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 1, rev 2</comment>
- <text>page 1, rev 2</text>
- </revision>
- <revision>
- <id>4</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 1, rev 4</comment>
- <text>page 1, rev 4</text>
- </revision>
-</page>
-<page>
- <title>Second page</title>
- <id>2</id>
- <revision>
- <id>3</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 2, rev 3</comment>
- <text>page 2, rev 3</text>
- </revision>
-</page>
-<page>
- <title>Third page</title>
- <id>3</id>
- <revision>
- <id>5</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 3, rev 5</comment>
- <text>page 3, rev 5</text>
- </revision>
-</page>
-</mediawiki>
+++ /dev/null
-<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">
-<siteinfo>
- <sitename>DemoWiki</sitename>
- <base>http://example.com/wiki/Main_Page</base>
- <generator>MediaWiki 1.5.0</generator>
- <case>first-letter</case>
- <namespaces>
- <namespace key="-2">Media</namespace>
- <namespace key="-1">Special</namespace>
- <namespace key="0"></namespace>
- <namespace key="1">Talk</namespace>
- <namespace key="2">User</namespace>
- <namespace key="3">User talk</namespace>
- <namespace key="4">DemoWiki</namespace>
- <namespace key="5">DemoWIki talk</namespace>
- <namespace key="6">Image</namespace>
- <namespace key="7">Image talk</namespace>
- <namespace key="8">MediaWiki</namespace>
- <namespace key="9">MediaWiki talk</namespace>
- <namespace key="10">Template</namespace>
- <namespace key="11">Template talk</namespace>
- <namespace key="12">Help</namespace>
- <namespace key="13">Help talk</namespace>
- <namespace key="14">Category</namespace>
- <namespace key="15">Category talk</namespace>
- </namespaces>
-</siteinfo>
-<page>
- <title>First page</title>
- <id>1</id>
- <revision>
- <id>1</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 1, rev 1</comment>
- <text>page 1, rev 1</text>
- </revision>
- <revision>
- <id>2</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 1, rev 2</comment>
- <text>page 1, rev 2</text>
- </revision>
-</page>
-<page>
- <title>Second page</title>
- <id>2</id>
- <revision>
- <id>3</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 2, rev 3</comment>
- <text>page 2, rev 3</text>
- </revision>
-</page>
-</mediawiki>
+++ /dev/null
-<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">
-<siteinfo>
- <sitename>DemoWiki</sitename>
- <base>http://example.com/wiki/Main_Page</base>
- <generator>MediaWiki 1.5.0</generator>
- <case>first-letter</case>
- <namespaces>
- <namespace key="-2">Media</namespace>
- <namespace key="-1">Special</namespace>
- <namespace key="0"></namespace>
- <namespace key="1">Talk</namespace>
- <namespace key="2">User</namespace>
- <namespace key="3">User talk</namespace>
- <namespace key="4">DemoWiki</namespace>
- <namespace key="5">DemoWIki talk</namespace>
- <namespace key="6">Image</namespace>
- <namespace key="7">Image talk</namespace>
- <namespace key="8">MediaWiki</namespace>
- <namespace key="9">MediaWiki talk</namespace>
- <namespace key="10">Template</namespace>
- <namespace key="11">Template talk</namespace>
- <namespace key="12">Help</namespace>
- <namespace key="13">Help talk</namespace>
- <namespace key="14">Category</namespace>
- <namespace key="15">Category talk</namespace>
- </namespaces>
-</siteinfo>
-<page>
- <title>First page</title>
- <id>1</id>
- <revision>
- <id>1</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 1, rev 1</comment>
- <text id="1" />
- </revision>
- <revision>
- <id>2</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 1, rev 2</comment>
- <text id="2" />
- </revision>
- <revision>
- <id>4</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 1, rev 4</comment>
- <text id="4" />
- </revision>
-</page>
-<page>
- <title>Second page</title>
- <id>2</id>
- <revision>
- <id>3</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 2, rev 3</comment>
- <text id="3" />
- </revision>
-</page>
-<page>
- <title>Third page</title>
- <id>3</id>
- <revision>
- <id>5</id>
- <timestamp>2001-01-15T12:00:00Z</timestamp>
- <contributor><ip>10.0.0.1</ip></contributor>
- <comment>page 3, rev 5</comment>
- <text id="5" />
- </revision>
-</page>
-</mediawiki>