r72566 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72565‎ | r72566 | r72567 >
Date:23:02, 7 September 2010
Author:tparscal
Status:deferred (Comments)
Tags:
Comment:
Merged reorganization work for PHPUnit from branches/phpunit-restructure/
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/maintenance/tests (modified) (history)
  • /trunk/phase3/maintenance/tests/ApiSetup.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/ApiTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/ApiWatchTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/CdbTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/DatabaseSqliteTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/DatabaseTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/ExtraParserTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/GlobalTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/HttpTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/IPTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/ImageFunctionsTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/LanguageConverterTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/LicensesTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/LocalFileTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/Makefile (deleted) (history)
  • /trunk/phase3/maintenance/tests/MediaWikiParserTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/MediaWiki_Setup.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/MessageTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/ParserHelpers.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/README (deleted) (history)
  • /trunk/phase3/maintenance/tests/ResourceLoaderFileModuleTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/ResourceLoaderTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/RevisionTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/SanitizerTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/SearchDbTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/SearchEngineTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/SearchUpdateTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/SiteConfigurationTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/TestFileList.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/TimeAdjustTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/TitlePermissionTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/TitleTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/UploadFromUrlTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/UploadFromUrlTestSuite.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/UploadTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/XmlTest.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/bootstrap.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/phpunit (added) (history)
  • /trunk/phase3/maintenance/tests/phpunit.bat (deleted) (history)
  • /trunk/phase3/maintenance/tests/phpunit.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/phpunit.xml (deleted) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/HttpTest.php (replaced) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/LanguageConverterTest.php (replaced) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/MessageTest.php (replaced) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/ResourceLoaderFileModuleTest.php (added) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/ResourceLoaderTest.php (added) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/TitlePermissionTest.php (replaced) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php (replaced) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/api/ApiSetup.php (replaced) (history)
  • /trunk/phase3/maintenance/tests/phpunit/suites/UploadFromUrlTestSuite.php (replaced) (history)
  • /trunk/phase3/maintenance/tests/test-prefetch-current.xml (deleted) (history)
  • /trunk/phase3/maintenance/tests/test-prefetch-previous.xml (deleted) (history)
  • /trunk/phase3/maintenance/tests/test-prefetch-stub.xml (deleted) (history)

Diff [purge]

Index: trunk/phase3/includes/AutoLoader.php
@@ -693,15 +693,6 @@
694694 'TestFileIterator' => 'maintenance/parserTests.inc',
695695 'TestRecorder' => 'maintenance/parserTests.inc',
696696
697 - # maintenance/tests
698 - 'ApiTestSetup' => 'maintenance/tests/ApiSetup.php',
699 - 'MediaWikiTestSetup' => 'maintenance/tests/MediaWiki_Setup.php',
700 - 'PHPUnitTestRecorder' => 'maintenance/tests/ParserHelpers.php',
701 - 'ParserTestSuiteBackend' => 'maintenance/tests/ParserHelpers.php',
702 - 'ParserUnitTest' => 'maintenance/tests/ParserHelpers.php',
703 - 'SearchEngineTest' => 'maintenance/tests/SearchEngineTest.php',
704 - 'UploadFromUrlTest' => 'maintenance/tests/UploadFromUrlTest.php',
705 -
706697 # maintenance/tests/selenium
707698 'SimpleSeleniumTestSuite' => 'maintenance/tests/selenium/SimpleSeleniumTestSuite.php',
708699 'Selenium' => 'maintenance/tests/selenium/Selenium.php',
Index: trunk/phase3/maintenance/tests/HttpTest.php
@@ -1,567 +0,0 @@
2 -<?php
3 -
4 -class MockCookie extends Cookie {
5 - public function canServeDomain( $arg ) { return parent::canServeDomain( $arg ); }
6 - public function canServePath( $arg ) { return parent::canServePath( $arg ); }
7 - public function isUnExpired() { return parent::isUnExpired(); }
8 -}
9 -
10 -class HttpTest extends PHPUnit_Framework_TestCase {
11 - static $content;
12 - static $headers;
13 - static $has_curl;
14 - static $has_fopen;
15 - static $has_proxy = false;
16 - static $proxy = "http://hulk:8080/";
17 - var $test_geturl = array(
18 - "http://www.example.com/",
19 - "http://pecl.php.net/feeds/pkg_apc.rss",
20 - "http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id=3",
21 - "http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw",
22 - "http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&format=php",
23 - );
24 - var $test_requesturl = array( "http://en.wikipedia.org/wiki/Special:Export/User:MarkAHershberger" );
25 -
26 - var $test_posturl = array( "http://www.comp.leeds.ac.uk/cgi-bin/Perl/environment-example" => "review=test" );
27 -
28 - function setup() {
29 - putenv( "http_proxy" ); /* Remove any proxy env var, so curl doesn't get confused */
30 - if ( is_array( self::$content ) ) {
31 - return;
32 - }
33 - self::$has_curl = function_exists( 'curl_init' );
34 - self::$has_fopen = wfIniGetBool( 'allow_url_fopen' );
35 -
36 - if ( !file_exists( "/usr/bin/curl" ) ) {
37 - $this->markTestIncomplete( "This test requires the curl binary at /usr/bin/curl. If you have curl, please file a bug on this test, or, better yet, provide a patch." );
38 - }
39 -
40 - $content = tempnam( wfTempDir(), "" );
41 - $headers = tempnam( wfTempDir(), "" );
42 - if ( !$content && !$headers ) {
43 - die( "Couldn't create temp file!" );
44 - }
45 -
46 - // This probably isn't the best test for a proxy, but it works on my system!
47 - system( "curl -0 -o $content -s " . self::$proxy );
48 - $out = file_get_contents( $content );
49 - if ( $out ) {
50 - self::$has_proxy = true;
51 - }
52 -
53 - /* Maybe use wget instead of curl here ... just to use a different codebase? */
54 - foreach ( $this->test_geturl as $u ) {
55 - system( "curl -0 -s -D $headers '$u' -o $content" );
56 - self::$content["GET $u"] = file_get_contents( $content );
57 - self::$headers["GET $u"] = file_get_contents( $headers );
58 - }
59 - foreach ( $this->test_requesturl as $u ) {
60 - system( "curl -0 -s -X POST -H 'Content-Length: 0' -D $headers '$u' -o $content" );
61 - self::$content["POST $u"] = file_get_contents( $content );
62 - self::$headers["POST $u"] = file_get_contents( $headers );
63 - }
64 - foreach ( $this->test_posturl as $u => $postData ) {
65 - system( "curl -0 -s -X POST -d '$postData' -D $headers '$u' -o $content" );
66 - self::$content["POST $u => $postData"] = file_get_contents( $content );
67 - self::$headers["POST $u => $postData"] = file_get_contents( $headers );
68 - }
69 - unlink( $content );
70 - unlink( $headers );
71 - }
72 -
73 -
74 - function testInstantiation() {
75 - Http::$httpEngine = false;
76 -
77 - $r = HttpRequest::factory( "http://www.example.com/" );
78 - if ( self::$has_curl ) {
79 - $this->assertThat( $r, $this->isInstanceOf( 'CurlHttpRequest' ) );
80 - } else {
81 - $this->assertThat( $r, $this->isInstanceOf( 'PhpHttpRequest' ) );
82 - }
83 - unset( $r );
84 -
85 - if ( !self::$has_fopen ) {
86 - $this->setExpectedException( 'MWException' );
87 - }
88 - Http::$httpEngine = 'php';
89 - $r = HttpRequest::factory( "http://www.example.com/" );
90 - $this->assertThat( $r, $this->isInstanceOf( 'PhpHttpRequest' ) );
91 - unset( $r );
92 -
93 - if ( !self::$has_curl ) {
94 - $this->setExpectedException( 'MWException' );
95 - }
96 - Http::$httpEngine = 'curl';
97 - $r = HttpRequest::factory( "http://www.example.com/" );
98 - if ( self::$has_curl ) {
99 - $this->assertThat( $r, $this->isInstanceOf( 'CurlHttpRequest' ) );
100 - }
101 - }
102 -
103 - function runHTTPFailureChecks() {
104 - // Each of the following requests should result in a failure.
105 -
106 - $timeout = 1;
107 - $start_time = time();
108 - $r = Http::get( "http://www.example.com:1/", $timeout );
109 - $end_time = time();
110 - $this->assertLessThan( $timeout + 2, $end_time - $start_time,
111 - "Request took less than {$timeout}s via " . Http::$httpEngine );
112 - $this->assertEquals( $r, false, "false -- what we get on error from Http::get()" );
113 -
114 - $r = Http::get( "http://www.example.com/this-file-does-not-exist", $timeout );
115 - $this->assertFalse( $r, "False on 404s" );
116 -
117 -
118 - $r = HttpRequest::factory( "http://www.example.com/this-file-does-not-exist" );
119 - $er = $r->execute();
120 - if ( is_a( $r, 'PhpHttpRequest' ) && version_compare( '5.2.10', phpversion(), '>' ) ) {
121 - $this->assertRegexp( "/HTTP request failed/", $er->getWikiText() );
122 - } else {
123 - $this->assertRegexp( "/404 Not Found/", $er->getWikiText() );
124 - }
125 - }
126 -
127 - function testFailureDefault() {
128 - Http::$httpEngine = false;
129 - $this->runHTTPFailureChecks();
130 - }
131 -
132 - function testFailurePhp() {
133 - if ( !self::$has_fopen ) {
134 - $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
135 - }
136 -
137 - Http::$httpEngine = "php";
138 - $this->runHTTPFailureChecks();
139 - }
140 -
141 - function testFailureCurl() {
142 - if ( !self::$has_curl ) {
143 - $this->markTestIncomplete( "This test requires curl." );
144 - }
145 -
146 - Http::$httpEngine = "curl";
147 - $this->runHTTPFailureChecks();
148 - }
149 -
150 - /* ./phase3/includes/Import.php:1108: $data = Http::request( $method, $url ); */
151 - /* ./includes/Import.php:1124: $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */
152 - /* ./includes/Import.php:1134: return ImportStreamSource::newFromURL( $url, "POST" ); */
153 - function runHTTPRequests( $proxy = null ) {
154 - $opt = array();
155 -
156 - if ( $proxy ) {
157 - $opt['proxy'] = $proxy;
158 - } elseif ( $proxy === false ) {
159 - $opt['noProxy'] = true;
160 - }
161 -
162 - /* no postData here because the only request I could find in code so far didn't have any */
163 - foreach ( $this->test_requesturl as $u ) {
164 - $r = Http::request( "POST", $u, $opt );
165 - $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with " . Http::$httpEngine );
166 - }
167 - }
168 -
169 - function testRequestDefault() {
170 - Http::$httpEngine = false;
171 - $this->runHTTPRequests();
172 - }
173 -
174 - function testRequestPhp() {
175 - if ( !self::$has_fopen ) {
176 - $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
177 - }
178 -
179 - Http::$httpEngine = "php";
180 - $this->runHTTPRequests();
181 - }
182 -
183 - function testRequestCurl() {
184 - if ( !self::$has_curl ) {
185 - $this->markTestIncomplete( "This test requires curl." );
186 - }
187 -
188 - Http::$httpEngine = "curl";
189 - $this->runHTTPRequests();
190 - }
191 -
192 - /* ./extensions/SpamBlacklist/SpamBlacklist_body.php:164: $httpText = Http::get( $fileName ); */
193 - /* ./extensions/ApiSVGProxy/ApiSVGProxy.body.php:44: $contents = Http::get( $file->getFullUrl() ); */
194 - /* ./extensions/BookInformation/drivers/IsbnDb.php:24: if( ( $xml = Http::get( $uri ) ) !== false ) { */
195 - /* ./extensions/BookInformation/drivers/Amazon.php:23: if( ( $xml = Http::get( $uri ) ) !== false ) { */
196 - /* ./extensions/TitleBlacklist/TitleBlacklist.list.php:217: $result = Http::get( $url ); */
197 - /* ./extensions/TSPoll/TSPoll.php:68: $get_server = Http::get( 'http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id='.$id ); */
198 - /* ./extensions/TSPoll/TSPoll.php:70: $get_server = Http::get( 'http://toolserver.org/~jan/poll/main.php?page=wiki_output&id='.$id ); */
199 - /* ./extensions/DoubleWiki/DoubleWiki.php:56: $translation = Http::get( $url.$sep.'action=render' ); */
200 - /* ./extensions/ExternalPages/ExternalPages_body.php:177: $serializedText = Http::get( $this->mPageURL ); */
201 - /* ./extensions/Translate/utils/TranslationHelpers.php:143: $suggestions = Http::get( $url, $timeout ); */
202 - /* ./extensions/Translate/SpecialImportTranslations.php:169: $filedata = Http::get( $url ); ; */
203 - /* ./extensions/Translate/TranslateEditAddons.php:338: $suggestions = Http::get( $url, $timeout ); */
204 - /* ./extensions/SecurePoll/includes/user/Auth.php:283: $value = Http::get( $url, 20, $curlParams ); */
205 - /* ./extensions/DumpHTML/dumpHTML.inc:778: $contents = Http::get( $url ); */
206 - /* ./extensions/DumpHTML/dumpHTML.inc:1298: $contents = Http::get( $sourceUrl ); */
207 - /* ./extensions/DumpHTML/dumpHTML.inc:1373: $contents = Http::get( $sourceUrl ); */
208 - /* ./phase3/maintenance/rebuildInterwiki.inc:101: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
209 - /* ./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' ); */
210 - /* ./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' ); */
211 - /* ./phase3/maintenance/dumpInterwiki.inc:95: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
212 - /* ./phase3/includes/parser/Parser.php:3204: $text = Http::get($url); */
213 - /* ./phase3/includes/filerepo/ForeignAPIRepo.php:131: $data = Http::get( $url ); */
214 - /* ./phase3/includes/filerepo/ForeignAPIRepo.php:205: $thumb = Http::get( $foreignUrl ); */
215 - /* ./phase3/includes/filerepo/File.php:1105: $res = Http::get( $renderUrl ); */
216 - /* ./phase3/includes/GlobalFunctions.php:2760: * @deprecated Use Http::get() instead */
217 - /* ./phase3/includes/GlobalFunctions.php:2764: return Http::get( $url ); */
218 - /* ./phase3/includes/ExternalStoreHttp.php:18: $ret = Http::get( $url ); */
219 - /* ./phase3/includes/Import.php:357: $data = Http::get( $src ); */
220 - /* ./extensions/ExternalData/ED_Utils.php:291: return Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
221 - /* ./extensions/ExternalData/ED_Utils.php:293: return Http::get( $url ); */
222 - /* ./extensions/ExternalData/ED_Utils.php:306: $page = Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
223 - /* ./extensions/ExternalData/ED_Utils.php:308: $page = Http::get( $url ); */
224 - /* ./extensions/CodeReview/backend/Subversion.php:320: $blob = Http::get( $target, $this->mTimeout ); */
225 - /* ./extensions/AmazonPlus/AmazonPlus.php:214: $this->response = Http::get( $urlstr ); */
226 - /* ./extensions/StaticWiki/StaticWiki.php:24: $text = Http::get( $url ) ; */
227 - /* ./extensions/StaticWiki/StaticWiki.php:64: $history = Http::get ( $wgStaticWikiExternalSite . "index.php?title=" . urlencode ( $url_title ) . "&action=history" ) ; */
228 - /* ./extensions/Configure/scripts/findSettings.php:126: $cont = Http::get( "http://www.mediawiki.org/w/index.php?title={$page}&action=raw" ); */
229 - /* ./extensions/TorBlock/TorBlock.class.php:148: $data = Http::get( $url ); */
230 - /* ./extensions/HoneypotIntegration/HoneypotIntegration.class.php:60: $data = Http::get( $wgHoneypotURLSource, 'default', */
231 - /* ./extensions/SemanticForms/includes/SF_Utils.inc:378: $page_contents = Http::get($url); */
232 - /* ./extensions/LocalisationUpdate/LocalisationUpdate.class.php:172: $basefilecontents = Http::get( $basefile ); */
233 - /* ./extensions/APC/SpecialAPC.php:245: $rss = Http::get( 'http://pecl.php.net/feeds/pkg_apc.rss' ); */
234 - /* ./extensions/Interlanguage/Interlanguage.php:56: $a = Http::get( $url ); */
235 - /* ./extensions/MWSearch/MWSearch_body.php:492: $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts); */
236 - function runHTTPGets( $proxy = null ) {
237 - $opt = array();
238 -
239 - if ( $proxy ) {
240 - $opt['proxy'] = $proxy;
241 - } elseif ( $proxy === false ) {
242 - $opt['noProxy'] = true;
243 - }
244 -
245 - foreach ( $this->test_geturl as $u ) {
246 - $r = Http::get( $u, 30, $opt ); /* timeout of 30s */
247 - $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with " . Http::$httpEngine );
248 - }
249 - }
250 -
251 - function testGetDefault() {
252 - Http::$httpEngine = false;
253 - $this->runHTTPGets();
254 - }
255 -
256 - function testGetPhp() {
257 - if ( !self::$has_fopen ) {
258 - $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
259 - }
260 -
261 - Http::$httpEngine = "php";
262 - $this->runHTTPGets();
263 - }
264 -
265 - function testGetCurl() {
266 - if ( !self::$has_curl ) {
267 - $this->markTestIncomplete( "This test requires curl." );
268 - }
269 -
270 - Http::$httpEngine = "curl";
271 - $this->runHTTPGets();
272 - }
273 -
274 - /* ./phase3/maintenance/parserTests.inc:1618: return Http::post( $url, array( 'postData' => wfArrayToCGI( $data ) ) ); */
275 - function runHTTPPosts( $proxy = null ) {
276 - $opt = array();
277 -
278 - if ( $proxy ) {
279 - $opt['proxy'] = $proxy;
280 - } elseif ( $proxy === false ) {
281 - $opt['noProxy'] = true;
282 - }
283 -
284 - foreach ( $this->test_posturl as $u => $postData ) {
285 - $opt['postData'] = $postData;
286 - $r = Http::post( $u, $opt );
287 - $this->assertEquals( self::$content["POST $u => $postData"], "$r",
288 - "POST $u (postData=$postData) with " . Http::$httpEngine );
289 - }
290 - }
291 -
292 - function testPostDefault() {
293 - Http::$httpEngine = false;
294 - $this->runHTTPPosts();
295 - }
296 -
297 - function testPostPhp() {
298 - if ( !self::$has_fopen ) {
299 - $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
300 - }
301 -
302 - Http::$httpEngine = "php";
303 - $this->runHTTPPosts();
304 - }
305 -
306 - function testPostCurl() {
307 - if ( !self::$has_curl ) {
308 - $this->markTestIncomplete( "This test requires curl." );
309 - }
310 -
311 - Http::$httpEngine = "curl";
312 - $this->runHTTPPosts();
313 - }
314 -
315 - function runProxyRequests() {
316 - if ( !self::$has_proxy ) {
317 - $this->markTestIncomplete( "This test requires a proxy." );
318 - }
319 - $this->runHTTPGets( self::$proxy );
320 - $this->runHTTPPosts( self::$proxy );
321 - $this->runHTTPRequests( self::$proxy );
322 -
323 - // Set false here to do noProxy
324 - $this->runHTTPGets( false );
325 - $this->runHTTPPosts( false );
326 - $this->runHTTPRequests( false );
327 - }
328 -
329 - function testProxyDefault() {
330 - Http::$httpEngine = false;
331 - $this->runProxyRequests();
332 - }
333 -
334 - function testProxyPhp() {
335 - if ( !self::$has_fopen ) {
336 - $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
337 - }
338 -
339 - Http::$httpEngine = 'php';
340 - $this->runProxyRequests();
341 - }
342 -
343 - function testProxyCurl() {
344 - if ( !self::$has_curl ) {
345 - $this->markTestIncomplete( "This test requires curl." );
346 - }
347 -
348 - Http::$httpEngine = 'curl';
349 - $this->runProxyRequests();
350 - }
351 -
352 - function testIsLocalUrl() {
353 - }
354 -
355 - /* ./extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php:559: $user_agent = Http::userAgent(); */
356 - function testUserAgent() {
357 - }
358 -
359 - function testIsValidUrl() {
360 - }
361 -
362 - function testValidateCookieDomain() {
363 - $this->assertFalse( Cookie::validateCookieDomain( "co.uk" ) );
364 - $this->assertFalse( Cookie::validateCookieDomain( ".co.uk" ) );
365 - $this->assertFalse( Cookie::validateCookieDomain( "gov.uk" ) );
366 - $this->assertFalse( Cookie::validateCookieDomain( ".gov.uk" ) );
367 - $this->assertTrue( Cookie::validateCookieDomain( "supermarket.uk" ) );
368 - $this->assertFalse( Cookie::validateCookieDomain( "uk" ) );
369 - $this->assertFalse( Cookie::validateCookieDomain( ".uk" ) );
370 - $this->assertFalse( Cookie::validateCookieDomain( "127.0.0." ) );
371 - $this->assertFalse( Cookie::validateCookieDomain( "127." ) );
372 - $this->assertFalse( Cookie::validateCookieDomain( "127.0.0.1." ) );
373 - $this->assertTrue( Cookie::validateCookieDomain( "127.0.0.1" ) );
374 - $this->assertFalse( Cookie::validateCookieDomain( "333.0.0.1" ) );
375 - $this->assertTrue( Cookie::validateCookieDomain( "example.com" ) );
376 - $this->assertFalse( Cookie::validateCookieDomain( "example.com." ) );
377 - $this->assertTrue( Cookie::validateCookieDomain( ".example.com" ) );
378 -
379 - $this->assertTrue( Cookie::validateCookieDomain( ".example.com", "www.example.com" ) );
380 - $this->assertFalse( Cookie::validateCookieDomain( "example.com", "www.example.com" ) );
381 - $this->assertTrue( Cookie::validateCookieDomain( "127.0.0.1", "127.0.0.1" ) );
382 - $this->assertFalse( Cookie::validateCookieDomain( "127.0.0.1", "localhost" ) );
383 -
384 -
385 - }
386 -
387 - function testSetCooke() {
388 - $c = new MockCookie( "name", "value",
389 - array(
390 - "domain" => "ac.th",
391 - "path" => "/path/",
392 - ) );
393 - $this->assertFalse( $c->canServeDomain( "ac.th" ) );
394 -
395 - $c = new MockCookie( "name", "value",
396 - array(
397 - "domain" => "example.com",
398 - "path" => "/path/",
399 - ) );
400 -
401 - $this->assertTrue( $c->canServeDomain( "example.com" ) );
402 - $this->assertFalse( $c->canServeDomain( "www.example.com" ) );
403 -
404 - $c = new MockCookie( "name", "value",
405 - array(
406 - "domain" => ".example.com",
407 - "path" => "/path/",
408 - ) );
409 -
410 - $this->assertFalse( $c->canServeDomain( "www.example.net" ) );
411 - $this->assertFalse( $c->canServeDomain( "example.com" ) );
412 - $this->assertTrue( $c->canServeDomain( "www.example.com" ) );
413 -
414 - $this->assertFalse( $c->canServePath( "/" ) );
415 - $this->assertFalse( $c->canServePath( "/bogus/path/" ) );
416 - $this->assertFalse( $c->canServePath( "/path" ) );
417 - $this->assertTrue( $c->canServePath( "/path/" ) );
418 -
419 - $this->assertTrue( $c->isUnExpired() );
420 -
421 - $this->assertEquals( "", $c->serializeToHttpRequest( "/path/", "www.example.net" ) );
422 - $this->assertEquals( "", $c->serializeToHttpRequest( "/", "www.example.com" ) );
423 - $this->assertEquals( "name=value", $c->serializeToHttpRequest( "/path/", "www.example.com" ) );
424 -
425 - $c = new MockCookie( "name", "value",
426 - array(
427 - "domain" => "www.example.com",
428 - "path" => "/path/",
429 - ) );
430 - $this->assertFalse( $c->canServeDomain( "example.com" ) );
431 - $this->assertFalse( $c->canServeDomain( "www.example.net" ) );
432 - $this->assertTrue( $c->canServeDomain( "www.example.com" ) );
433 -
434 - $c = new MockCookie( "name", "value",
435 - array(
436 - "domain" => ".example.com",
437 - "path" => "/path/",
438 - "expires" => "-1 day",
439 - ) );
440 - $this->assertFalse( $c->isUnExpired() );
441 - $this->assertEquals( "", $c->serializeToHttpRequest( "/path/", "www.example.com" ) );
442 -
443 - $c = new MockCookie( "name", "value",
444 - array(
445 - "domain" => ".example.com",
446 - "path" => "/path/",
447 - "expires" => "+1 day",
448 - ) );
449 - $this->assertTrue( $c->isUnExpired() );
450 - $this->assertEquals( "name=value", $c->serializeToHttpRequest( "/path/", "www.example.com" ) );
451 - }
452 -
453 - function testCookieJarSetCookie() {
454 - $cj = new CookieJar;
455 - $cj->setCookie( "name", "value",
456 - array(
457 - "domain" => ".example.com",
458 - "path" => "/path/",
459 - ) );
460 - $cj->setCookie( "name2", "value",
461 - array(
462 - "domain" => ".example.com",
463 - "path" => "/path/sub",
464 - ) );
465 - $cj->setCookie( "name3", "value",
466 - array(
467 - "domain" => ".example.com",
468 - "path" => "/",
469 - ) );
470 - $cj->setCookie( "name4", "value",
471 - array(
472 - "domain" => ".example.net",
473 - "path" => "/path/",
474 - ) );
475 - $cj->setCookie( "name5", "value",
476 - array(
477 - "domain" => ".example.net",
478 - "path" => "/path/",
479 - "expires" => "-1 day",
480 - ) );
481 -
482 - $this->assertEquals( "name4=value", $cj->serializeToHttpRequest( "/path/", "www.example.net" ) );
483 - $this->assertEquals( "name3=value", $cj->serializeToHttpRequest( "/", "www.example.com" ) );
484 - $this->assertEquals( "name=value; name3=value", $cj->serializeToHttpRequest( "/path/", "www.example.com" ) );
485 -
486 - $cj->setCookie( "name5", "value",
487 - array(
488 - "domain" => ".example.net",
489 - "path" => "/path/",
490 - "expires" => "+1 day",
491 - ) );
492 - $this->assertEquals( "name4=value; name5=value", $cj->serializeToHttpRequest( "/path/", "www.example.net" ) );
493 -
494 - $cj->setCookie( "name4", "value",
495 - array(
496 - "domain" => ".example.net",
497 - "path" => "/path/",
498 - "expires" => "-1 day",
499 - ) );
500 - $this->assertEquals( "name5=value", $cj->serializeToHttpRequest( "/path/", "www.example.net" ) );
501 - }
502 -
503 - function testParseResponseHeader() {
504 - $cj = new CookieJar;
505 -
506 - $h[] = "Set-Cookie: name4=value; domain=.example.com; path=/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
507 - $cj->parseCookieResponseHeader( $h[0], "www.example.com" );
508 - $this->assertEquals( "name4=value", $cj->serializeToHttpRequest( "/", "www.example.com" ) );
509 -
510 - $h[] = "name4=value2; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
511 - $cj->parseCookieResponseHeader( $h[1], "www.example.com" );
512 - $this->assertEquals( "", $cj->serializeToHttpRequest( "/", "www.example.com" ) );
513 - $this->assertEquals( "name4=value2", $cj->serializeToHttpRequest( "/path/", "www.example.com" ) );
514 -
515 - $h[] = "name5=value3; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
516 - $cj->parseCookieResponseHeader( $h[2], "www.example.com" );
517 - $this->assertEquals( "name4=value2; name5=value3", $cj->serializeToHttpRequest( "/path/", "www.example.com" ) );
518 -
519 - $h[] = "name6=value3; domain=.example.net; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
520 - $cj->parseCookieResponseHeader( $h[3], "www.example.com" );
521 - $this->assertEquals( "", $cj->serializeToHttpRequest( "/path/", "www.example.net" ) );
522 -
523 - $h[] = "name6=value0; domain=.example.net; path=/path/; expires=Mon, 09-Dec-1999 13:46:00 GMT";
524 - $cj->parseCookieResponseHeader( $h[4], "www.example.net" );
525 - $this->assertEquals( "", $cj->serializeToHttpRequest( "/path/", "www.example.net" ) );
526 -
527 - $h[] = "name6=value4; domain=.example.net; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
528 - $cj->parseCookieResponseHeader( $h[5], "www.example.net" );
529 - $this->assertEquals( "name6=value4", $cj->serializeToHttpRequest( "/path/", "www.example.net" ) );
530 - }
531 -
532 - function runCookieRequests() {
533 - $r = HttpRequest::factory( "http://www.php.net/manual", array( 'followRedirects' => true ) );
534 - $r->execute();
535 -
536 - $jar = $r->getCookieJar();
537 - $this->assertThat( $jar, $this->isInstanceOf( 'CookieJar' ) );
538 -
539 - if ( is_a( $r, 'PhpHttpRequest' ) && version_compare( '5.1.7', phpversion(), '>' ) ) {
540 - $this->markTestSkipped( 'Redirection fails or crashes PHP on 5.1.6 and prior' );
541 - }
542 - $serialized = $jar->serializeToHttpRequest( "/search?q=test", "www.php.net" );
543 - $this->assertRegExp( '/\bCOUNTRY=[^=;]+/', $serialized );
544 - $this->assertRegExp( '/\bLAST_LANG=[^=;]+/', $serialized );
545 - $this->assertEquals( '', $jar->serializeToHttpRequest( "/search?q=test", "www.php.com" ) );
546 - }
547 -
548 - function testCookieRequestDefault() {
549 - Http::$httpEngine = false;
550 - $this->runCookieRequests();
551 - }
552 - function testCookieRequestPhp() {
553 - if ( !self::$has_fopen ) {
554 - $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
555 - }
556 -
557 - Http::$httpEngine = 'php';
558 - $this->runCookieRequests();
559 - }
560 - function testCookieRequestCurl() {
561 - if ( !self::$has_curl ) {
562 - $this->markTestIncomplete( "This test requires curl." );
563 - }
564 -
565 - Http::$httpEngine = 'curl';
566 - $this->runCookieRequests();
567 - }
568 -}
Index: trunk/phase3/maintenance/tests/ParserHelpers.php
@@ -1,88 +0,0 @@
2 -<?php
3 -
4 -class ParserUnitTest extends PHPUnit_Framework_TestCase {
5 - private $test = "";
6 - private $suite;
7 -
8 - public function __construct( $suite, $test = null ) {
9 - $this->suite = $suite;
10 - $this->test = $test;
11 - }
12 -
13 - function count() { return 1; }
14 -
15 - public function run( PHPUnit_Framework_TestResult $result = null ) {
16 - PHPUnit_Framework_Assert::resetCount();
17 - if ( $result === NULL ) {
18 - $result = new PHPUnit_Framework_TestResult;
19 - }
20 -
21 - $backend = $this->suite->getBackend();
22 - $result->startTest( $this );
23 - PHPUnit_Util_Timer::start();
24 -
25 - $r = false;
26 - try {
27 - # Run the test.
28 - # On failure, the subclassed backend will throw an exception with
29 - # the details.
30 - $r = $backend->runTest(
31 - $this->test['test'],
32 - $this->test['input'],
33 - $this->test['result'],
34 - $this->test['options'],
35 - $this->test['config']
36 - );
37 - }
38 - catch ( PHPUnit_Framework_AssertionFailedError $e ) {
39 - $result->addFailure( $this, $e, PHPUnit_Util_Timer::stop() );
40 - }
41 - catch ( Exception $e ) {
42 - $result->addError( $this, $e, PHPUnit_Util_Timer::stop() );
43 - }
44 -
45 - $result->endTest( $this, PHPUnit_Util_Timer::stop() );
46 -
47 - $backend->recorder->record( $this->test['test'], $r );
48 - $this->addToAssertionCount( PHPUnit_Framework_Assert::getCount() );
49 -
50 - return $result;
51 - }
52 -
53 - public function toString() {
54 - return $this->test['test'];
55 - }
56 -
57 -}
58 -
59 -class ParserTestSuiteBackend extends ParserTest {
60 - function showTesting( $desc ) {
61 - }
62 -
63 - function showRunFile( $path ) {
64 - }
65 -
66 - function showSuccess( $desc ) {
67 - PHPUnit_Framework_Assert::assertTrue( true, $desc );
68 - return true;
69 - }
70 -
71 - function showFailure( $desc, $expected, $got ) {
72 - PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc );
73 - }
74 -
75 - public function setupRecorder( $options ) {
76 - $this->recorder = new PHPUnitTestRecorder( $this );
77 - }
78 -}
79 -
80 -class PHPUnitTestRecorder extends TestRecorder {
81 - function record( $test, $result ) {
82 - $this->total++;
83 - $this->success += $result;
84 -
85 - }
86 -
87 - function reportPercentage( $success, $total ) { }
88 -}
89 -
Index: trunk/phase3/maintenance/tests/TitleTest.php
@@ -1,17 +0,0 @@
2 -<?php
3 -
4 -class TitleTest extends PHPUnit_Framework_TestCase {
5 -
6 - function testLegalChars() {
7 - $titlechars = Title::legalChars();
8 -
9 - foreach ( range( 1, 255 ) as $num ) {
10 - $chr = chr( $num );
11 - if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
12 - $this->assertFalse( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid titlechar" );
13 - } else {
14 - $this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" );
15 - }
16 - }
17 - }
18 -}
Index: trunk/phase3/maintenance/tests/UploadTest.php
@@ -1,90 +0,0 @@
2 -<?php
3 -/**
4 - * @group Upload
5 - */
6 -class UploadTest extends PHPUnit_Framework_TestCase {
7 - protected $upload;
8 -
9 -
10 - function setUp() {
11 - global $wgContLang;
12 - parent::setup();
13 - $wgContLang = Language::factory( 'en' );
14 - $this->upload = new UploadTestHandler;
15 - }
16 -
17 - /**
18 - * Test various forms of valid and invalid titles that can be supplied.
19 - */
20 - public function testTitleValidation() {
21 -
22 -
23 - /* Test a valid title */
24 - $this->assertUploadTitleAndCode( 'ValidTitle.jpg',
25 - 'ValidTitle.jpg', UploadTestHandler::OK,
26 - 'upload valid title' );
27 -
28 - /* A title with a slash */
29 - $this->assertUploadTitleAndCode( 'A/B.jpg',
30 - 'B.jpg', UploadTestHandler::OK,
31 - 'upload title with slash' );
32 -
33 - /* A title with illegal char */
34 - $this->assertUploadTitleAndCode( 'A:B.jpg',
35 - 'A-B.jpg', UploadTestHandler::OK,
36 - 'upload title with colon' );
37 -
38 - /* A title without extension */
39 - $this->assertUploadTitleAndCode( 'A',
40 - null, UploadTestHandler::FILETYPE_MISSING,
41 - 'upload title without extension' );
42 -
43 - /* A title with no basename */
44 - $this->assertUploadTitleAndCode( '.jpg',
45 - null, UploadTestHandler::MIN_LENGTH_PARTNAME,
46 - 'upload title without basename' );
47 -
48 - }
49 - /**
50 - * Helper function for testTitleValidation. First checks the return code
51 - * of UploadBase::getTitle() and then the actual returned titl
52 - */
53 - private function assertUploadTitleAndCode( $srcFilename, $dstFilename, $code, $msg ) {
54 - /* Check the result code */
55 - $this->assertEquals( $code,
56 - $this->upload->testTitleValidation( $srcFilename ),
57 - "$msg code" );
58 -
59 - /* If we expect a valid title, check the title itself. */
60 - if ( $code == UploadTestHandler::OK ) {
61 - $this->assertEquals( $dstFilename,
62 - $this->upload->getTitle()->getText(),
63 - "$msg text" );
64 - }
65 - }
66 -
67 - /**
68 - * Test the upload verification functions
69 - */
70 - public function testVerifyUpload() {
71 - /* Setup with zero file size */
72 - $this->upload->initializePathInfo( '', '', 0 );
73 - $result = $this->upload->verifyUpload();
74 - $this->assertEquals( UploadTestHandler::EMPTY_FILE,
75 - $result['status'],
76 - 'upload empty file' );
77 - }
78 -
79 -}
80 -
81 -class UploadTestHandler extends UploadBase {
82 - public function initializeFromRequest( &$request ) { }
83 - public function testTitleValidation( $name ) {
84 - $this->mTitle = false;
85 - $this->mDesiredDestName = $name;
86 - $this->getTitle();
87 - return $this->mTitleError;
88 - }
89 -
90 -
91 -}
Index: trunk/phase3/maintenance/tests/MessageTest.php
@@ -1,40 +0,0 @@
2 -<?php
3 -
4 -class MessageTest extends PHPUnit_Framework_TestCase {
5 -
6 - function setUp() {
7 - global $wgLanguageCode;
8 -
9 - $wgLanguageCode = 'en'; # For mainpage to be 'Main Page'
10 - }
11 -
12 - function testExists() {
13 - $this->assertTrue( wfMessage( 'mainpage' )->exists() );
14 - $this->assertTrue( wfMessage( 'mainpage' )->params( array() )->exists() );
15 - $this->assertTrue( wfMessage( 'mainpage' )->rawParams( 'foo', 123 )->exists() );
16 - $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->exists() );
17 - $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->params( array() )->exists() );
18 - $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->rawParams( 'foo', 123 )->exists() );
19 - }
20 -
21 - function testKey() {
22 - $this->assertType( 'Message', wfMessage( 'mainpage' ) );
23 - $this->assertType( 'Message', wfMessage( 'i-dont-exist-evar' ) );
24 - $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->text() );
25 - $this->assertEquals( '&lt;i-dont-exist-evar&gt;', wfMessage( 'i-dont-exist-evar' )->text() );
26 - }
27 -
28 - function testInLanguage() {
29 - $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( 'en' )->text() );
30 - $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( 'ru' )->text() );
31 - $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'en' ) )->text() );
32 - $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'ru' ) )->text() );
33 - }
34 -
35 - /**
36 - * @expectedException MWException
37 - */
38 - function testInLanguageThrows() {
39 - wfMessage( 'foo' )->inLanguage( 123 );
40 - }
41 -}
Index: trunk/phase3/maintenance/tests/Makefile
@@ -1,32 +0,0 @@
2 -# If you have problems with excessive memory usage, use the "tap" or "separate" targets.
3 -
4 -TEST_FILES=$(shell php -r 'include( "./TestFileList.php" ); echo implode( " ", $$testFiles );')
5 -TEST_FILE_TARGETS=$(subst .php,.target,$(TEST_FILES))
6 -
7 -.PHONY: help test phpunit tap separate install $(TEST_FILE_TARGETS)
8 -
9 -all test: phpunit
10 -
11 -phpunit:
12 - php phpunit.php
13 -
14 -tap:
15 - prove -e 'php phpunit.php --tap' *Test*.php
16 -
17 -separate: $(TEST_FILE_TARGETS)
18 -
19 -# Need --tap because without it, the target specification doesn't work
20 -$(TEST_FILE_TARGETS) : %.target : %.php
21 - php phpunit.php --tap $<
22 -
23 -install:
24 - pear channel-discover pear.phpunit.de
25 - pear install phpunit/PHPUnit
26 -
27 -help:
28 - # Targets:
29 - # phpunit (default) Run all the tests with phpunit
30 - # separate Run each test file in a separate process
31 - # tap Run the tests individually through Test::Harness's prove(1)
32 - # install Install PHPUnit from phpunit.de
33 - # help You're looking at it!
Index: trunk/phase3/maintenance/tests/TitlePermissionTest.php
@@ -1,651 +0,0 @@
2 -<?php
3 -
4 -class TitlePermissionTest extends PHPUnit_Framework_TestCase {
5 - static $title;
6 - static $user;
7 - static $anonUser;
8 - static $userUser;
9 - static $altUser;
10 - static $userName;
11 - static $altUserName;
12 -
13 - function setUp() {
14 - global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang, $wgMessageCache;
15 -
16 - $wgMemc = new FakeMemCachedClient;
17 - $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
18 - $wgContLang = $wgLang = Language::factory( 'en' );
19 -
20 - self::$userName = "Useruser";
21 - self::$altUserName = "Altuseruser";
22 - date_default_timezone_set( $wgLocaltimezone );
23 - $wgLocalTZoffset = date( "Z" ) / 60;
24 -
25 - self::$title = Title::makeTitle( NS_MAIN, "Main Page" );
26 - if ( !isset( self::$userUser ) || !( self::$userUser instanceOf User ) ) {
27 - self::$userUser = User::newFromName( self::$userName );
28 -
29 - if ( !self::$userUser->getID() ) {
30 - self::$userUser = User::createNew( self::$userName, array(
31 - "email" => "test@example.com",
32 - "real_name" => "Test User" ) );
33 - }
34 -
35 - self::$altUser = User::newFromName( self::$altUserName );
36 - if ( !self::$altUser->getID() ) {
37 - self::$altUser = User::createNew( self::$altUserName, array(
38 - "email" => "alttest@example.com",
39 - "real_name" => "Test User Alt" ) );
40 - }
41 -
42 - self::$anonUser = User::newFromId( 0 );
43 -
44 - self::$user = self::$userUser;
45 - }
46 - }
47 -
48 - function tearDown() {
49 - global $wgMemc, $wgContLang, $wgLang;
50 - $wgMemc = $wgContLang = $wgLang = null;
51 - }
52 -
53 - function setUserPerm( $perm ) {
54 - if ( is_array( $perm ) ) {
55 - self::$user->mRights = $perm;
56 - } else {
57 - self::$user->mRights = array( $perm );
58 - }
59 - }
60 -
61 - function setTitle( $ns, $title = "Main_Page" ) {
62 - self::$title = Title::makeTitle( $ns, $title );
63 - }
64 -
65 - function setUser( $userName = null ) {
66 - if ( $userName === 'anon' ) {
67 - self::$user = self::$anonUser;
68 - } else if ( $userName === null || $userName === self::$userName ) {
69 - self::$user = self::$userUser;
70 - } else {
71 - self::$user = self::$altUser;
72 - }
73 -
74 - global $wgUser;
75 - $wgUser = self::$user;
76 - }
77 -
78 - function testQuickPermissions() {
79 - global $wgContLang;
80 - $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
81 -
82 - $this->setUser( 'anon' );
83 - $this->setTitle( NS_TALK );
84 - $this->setUserPerm( "createtalk" );
85 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
86 - $this->assertEquals( array(), $res );
87 -
88 - $this->setTitle( NS_TALK );
89 - $this->setUserPerm( "createpage" );
90 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
91 - $this->assertEquals( array( array( "nocreatetext" ) ), $res );
92 -
93 - $this->setTitle( NS_TALK );
94 - $this->setUserPerm( "" );
95 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
96 - $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
97 -
98 - $this->setTitle( NS_MAIN );
99 - $this->setUserPerm( "createpage" );
100 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
101 - $this->assertEquals( array( ), $res );
102 -
103 - $this->setTitle( NS_MAIN );
104 - $this->setUserPerm( "createtalk" );
105 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
106 - $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
107 -
108 - $this->setUser( self::$userName );
109 - $this->setTitle( NS_TALK );
110 - $this->setUserPerm( "createtalk" );
111 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
112 - $this->assertEquals( array( ), $res );
113 -
114 - $this->setTitle( NS_TALK );
115 - $this->setUserPerm( "createpage" );
116 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
117 - $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
118 -
119 - $this->setTitle( NS_TALK );
120 - $this->setUserPerm( "" );
121 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
122 - $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
123 -
124 - $this->setTitle( NS_MAIN );
125 - $this->setUserPerm( "createpage" );
126 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
127 - $this->assertEquals( array( ), $res );
128 -
129 - $this->setTitle( NS_MAIN );
130 - $this->setUserPerm( "createtalk" );
131 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
132 - $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
133 -
134 - $this->setTitle( NS_MAIN );
135 - $this->setUserPerm( "" );
136 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
137 - $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
138 -
139 - $this->setUser( 'anon' );
140 - $this->setTitle( NS_USER, self::$userName . '' );
141 - $this->setUserPerm( "" );
142 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
143 - $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
144 -
145 - $this->setTitle( NS_USER, self::$userName . '/subpage' );
146 - $this->setUserPerm( "" );
147 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
148 - $this->assertEquals( array( array( 'movenologintext' ) ), $res );
149 -
150 - $this->setTitle( NS_USER, self::$userName . '' );
151 - $this->setUserPerm( "move-rootuserpages" );
152 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
153 - $this->assertEquals( array( array( 'movenologintext' ) ), $res );
154 -
155 - $this->setTitle( NS_USER, self::$userName . '/subpage' );
156 - $this->setUserPerm( "move-rootuserpages" );
157 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
158 - $this->assertEquals( array( array( 'movenologintext' ) ), $res );
159 -
160 - $this->setTitle( NS_USER, self::$userName . '' );
161 - $this->setUserPerm( "" );
162 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
163 - $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
164 -
165 - $this->setTitle( NS_USER, self::$userName . '/subpage' );
166 - $this->setUserPerm( "" );
167 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
168 - $this->assertEquals( array( array( 'movenologintext' ) ), $res );
169 -
170 - $this->setTitle( NS_USER, self::$userName . '' );
171 - $this->setUserPerm( "move-rootuserpages" );
172 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
173 - $this->assertEquals( array( array( 'movenologintext' ) ), $res );
174 -
175 - $this->setTitle( NS_USER, self::$userName . '/subpage' );
176 - $this->setUserPerm( "move-rootuserpages" );
177 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
178 - $this->assertEquals( array( array( 'movenologintext' ) ), $res );
179 -
180 - $this->setUser( self::$userName );
181 - $this->setTitle( NS_FILE, "img.png" );
182 - $this->setUserPerm( "" );
183 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
184 - $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
185 -
186 - $this->setTitle( NS_FILE, "img.png" );
187 - $this->setUserPerm( "movefile" );
188 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
189 - $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
190 -
191 - $this->setUser( 'anon' );
192 - $this->setTitle( NS_FILE, "img.png" );
193 - $this->setUserPerm( "" );
194 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
195 - $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
196 -
197 - $this->setTitle( NS_FILE, "img.png" );
198 - $this->setUserPerm( "movefile" );
199 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
200 - $this->assertEquals( array( array( 'movenologintext' ) ), $res );
201 -
202 - $this->setUser( self::$userName );
203 - $this->setUserPerm( "move" );
204 - $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
205 -
206 - $this->setUserPerm( "" );
207 - $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
208 -
209 - $this->setUser( 'anon' );
210 - $this->setUserPerm( "move" );
211 - $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
212 -
213 - $this->setUserPerm( "" );
214 - $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
215 - array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
216 -
217 - $this->setTitle( NS_MAIN );
218 - $this->setUser( 'anon' );
219 - $this->setUserPerm( "move" );
220 - $this->runGroupPermissions( 'move', array( ) );
221 -
222 - $this->setUserPerm( "" );
223 - $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
224 - array( array( 'movenologintext' ) ) );
225 -
226 - $this->setUser( self::$userName );
227 - $this->setUserPerm( "" );
228 - $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
229 -
230 - $this->setUserPerm( "move" );
231 - $this->runGroupPermissions( 'move', array( ) );
232 -
233 - $this->setUser( 'anon' );
234 - $this->setUserPerm( 'move' );
235 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
236 - $this->assertEquals( array( ), $res );
237 -
238 - $this->setUserPerm( '' );
239 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
240 - $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
241 -
242 - $this->setTitle( NS_USER );
243 - $this->setUser( self::$userName );
244 - $this->setUserPerm( array( "move", "move-rootuserpages" ) );
245 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
246 - $this->assertEquals( array( ), $res );
247 -
248 - $this->setUserPerm( "move" );
249 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
250 - $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
251 -
252 - $this->setUser( 'anon' );
253 - $this->setUserPerm( array( "move", "move-rootuserpages" ) );
254 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
255 - $this->assertEquals( array( ), $res );
256 -
257 - $this->setTitle( NS_USER, "User/subpage" );
258 - $this->setUserPerm( array( "move", "move-rootuserpages" ) );
259 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
260 - $this->assertEquals( array( ), $res );
261 -
262 - $this->setUserPerm( "move" );
263 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
264 - $this->assertEquals( array( ), $res );
265 -
266 - $this->setUser( 'anon' );
267 - $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
268 - array( array( 'badaccess-group0' ) ),
269 - array( ), true ),
270 - 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
271 - array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
272 - array( array( 'protect-cantedit' ) ), false ),
273 - '' => array( array( ), array( ), array( ), true ) );
274 - global $wgUser;
275 - $wgUser = self::$user;
276 - foreach ( array( "edit", "protect", "" ) as $action ) {
277 - $this->setUserPerm( null );
278 - $this->assertEquals( $check[$action][0],
279 - self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
280 -
281 - global $wgGroupPermissions;
282 - $old = $wgGroupPermissions;
283 - $wgGroupPermissions = array();
284 -
285 - $this->assertEquals( $check[$action][1],
286 - self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
287 - $wgGroupPermissions = $old;
288 -
289 - $this->setUserPerm( $action );
290 - $this->assertEquals( $check[$action][2],
291 - self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
292 -
293 - $this->setUserPerm( $action );
294 - $this->assertEquals( $check[$action][3],
295 - self::$title->userCan( $action, true ) );
296 - $this->assertEquals( $check[$action][3],
297 - self::$title->quickUserCan( $action, false ) );
298 -
299 - # count( User::getGroupsWithPermissions( $action ) ) < 1
300 - }
301 - }
302 -
303 - function runGroupPermissions( $action, $result, $result2 = null ) {
304 - global $wgGroupPermissions;
305 -
306 - if ( $result2 === null ) $result2 = $result;
307 -
308 - $wgGroupPermissions['autoconfirmed']['move'] = false;
309 - $wgGroupPermissions['user']['move'] = false;
310 - $res = self::$title->getUserPermissionsErrors( $action, self::$user );
311 - $this->assertEquals( $result, $res );
312 -
313 - $wgGroupPermissions['autoconfirmed']['move'] = true;
314 - $wgGroupPermissions['user']['move'] = false;
315 - $res = self::$title->getUserPermissionsErrors( $action, self::$user );
316 - $this->assertEquals( $result2, $res );
317 -
318 - $wgGroupPermissions['autoconfirmed']['move'] = true;
319 - $wgGroupPermissions['user']['move'] = true;
320 - $res = self::$title->getUserPermissionsErrors( $action, self::$user );
321 - $this->assertEquals( $result2, $res );
322 -
323 - $wgGroupPermissions['autoconfirmed']['move'] = false;
324 - $wgGroupPermissions['user']['move'] = true;
325 - $res = self::$title->getUserPermissionsErrors( $action, self::$user );
326 - $this->assertEquals( $result2, $res );
327 - }
328 -
329 - function testPermissionHooks() { }
330 - function testSpecialsAndNSPermissions() {
331 - $this->setUser( self::$userName );
332 - global $wgUser, $wgContLang;
333 - $wgUser = self::$user;
334 - $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
335 -
336 - $this->setTitle( NS_SPECIAL );
337 -
338 - $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
339 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
340 - $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Administrators|Administrators]]", 2 ) ),
341 - self::$title->getUserPermissionsErrors( 'createaccount', self::$user ) );
342 - $this->assertEquals( array( array( 'badaccess-group0' ) ),
343 - self::$title->getUserPermissionsErrors( 'execute', self::$user ) );
344 -
345 - $this->setTitle( NS_MAIN );
346 - $this->setUserPerm( 'bogus' );
347 - $this->assertEquals( array( ),
348 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
349 -
350 - $this->setTitle( NS_MAIN );
351 - $this->setUserPerm( '' );
352 - $this->assertEquals( array( array( 'badaccess-group0' ) ),
353 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
354 -
355 - global $wgNamespaceProtection;
356 - $wgNamespaceProtection[NS_USER] = array ( 'bogus' );
357 - $this->setTitle( NS_USER );
358 - $this->setUserPerm( '' );
359 - $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
360 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
361 -
362 - $this->setTitle( NS_MEDIAWIKI );
363 - $this->setUserPerm( 'bogus' );
364 - $this->assertEquals( array( array( 'protectedinterface' ) ),
365 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
366 -
367 - $this->setTitle( NS_MEDIAWIKI );
368 - $this->setUserPerm( 'bogus' );
369 - $this->assertEquals( array( array( 'protectedinterface' ) ),
370 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
371 -
372 - $wgNamespaceProtection = null;
373 - $this->setUserPerm( 'bogus' );
374 - $this->assertEquals( array( ),
375 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
376 - $this->assertEquals( true,
377 - self::$title->userCan( 'bogus' ) );
378 -
379 - $this->setUserPerm( '' );
380 - $this->assertEquals( array( array( 'badaccess-group0' ) ),
381 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
382 - $this->assertEquals( false,
383 - self::$title->userCan( 'bogus' ) );
384 - }
385 -
386 - function testCSSandJSPermissions() {
387 - $this->setUser( self::$userName );
388 - global $wgUser;
389 - $wgUser = self::$user;
390 -
391 - $this->setTitle( NS_USER, self::$altUserName . '/test.js' );
392 - $this->runCSSandJSPermissions(
393 - array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
394 - array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
395 - array( array( 'badaccess-group0' ) ) );
396 -
397 - $this->setTitle( NS_USER, self::$altUserName . '/test.css' );
398 - $this->runCSSandJSPermissions(
399 - array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
400 - array( array( 'badaccess-group0' ) ),
401 - array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) );
402 -
403 - $this->setTitle( NS_USER, self::$altUserName . '/tempo' );
404 - $this->runCSSandJSPermissions(
405 - array( array( 'badaccess-group0' ) ),
406 - array( array( 'badaccess-group0' ) ),
407 - array( array( 'badaccess-group0' ) ) );
408 - }
409 -
410 - function runCSSandJSPermissions( $result0, $result1, $result2 ) {
411 - $this->setUserPerm( '' );
412 - $this->assertEquals( $result0,
413 - self::$title->getUserPermissionsErrors( 'bogus',
414 - self::$user ) );
415 -
416 - $this->setUserPerm( 'editusercss' );
417 - $this->assertEquals( $result1,
418 - self::$title->getUserPermissionsErrors( 'bogus',
419 - self::$user ) );
420 -
421 - $this->setUserPerm( 'edituserjs' );
422 - $this->assertEquals( $result2,
423 - self::$title->getUserPermissionsErrors( 'bogus',
424 - self::$user ) );
425 -
426 - $this->setUserPerm( 'editusercssjs' );
427 - $this->assertEquals( array( array( 'badaccess-group0' ) ),
428 - self::$title->getUserPermissionsErrors( 'bogus',
429 - self::$user ) );
430 -
431 - $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
432 - $this->assertEquals( array( array( 'badaccess-group0' ) ),
433 - self::$title->getUserPermissionsErrors( 'bogus',
434 - self::$user ) );
435 - }
436 -
437 - function testPageRestrictions() {
438 - global $wgUser, $wgContLang;
439 -
440 - $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
441 -
442 - $wgUser = self::$user;
443 - $this->setTitle( NS_MAIN );
444 - self::$title->mRestrictionsLoaded = true;
445 - $this->setUserPerm( "edit" );
446 - self::$title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
447 -
448 - $this->assertEquals( array( ),
449 - self::$title->getUserPermissionsErrors( 'edit',
450 - self::$user ) );
451 -
452 - $this->assertEquals( true,
453 - self::$title->quickUserCan( 'edit', false ) );
454 - self::$title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
455 - "bogus" => array( 'bogus', "sysop", "protect", "" ) );
456 -
457 - $this->assertEquals( array( array( 'badaccess-group0' ),
458 - array( 'protectedpagetext', 'bogus' ),
459 - array( 'protectedpagetext', 'protect' ),
460 - array( 'protectedpagetext', 'protect' ) ),
461 - self::$title->getUserPermissionsErrors( 'bogus',
462 - self::$user ) );
463 - $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
464 - array( 'protectedpagetext', 'protect' ),
465 - array( 'protectedpagetext', 'protect' ) ),
466 - self::$title->getUserPermissionsErrors( 'edit',
467 - self::$user ) );
468 - $this->setUserPerm( "" );
469 - $this->assertEquals( array( array( 'badaccess-group0' ),
470 - array( 'protectedpagetext', 'bogus' ),
471 - array( 'protectedpagetext', 'protect' ),
472 - array( 'protectedpagetext', 'protect' ) ),
473 - self::$title->getUserPermissionsErrors( 'bogus',
474 - self::$user ) );
475 - $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
476 - array( 'protectedpagetext', 'bogus' ),
477 - array( 'protectedpagetext', 'protect' ),
478 - array( 'protectedpagetext', 'protect' ) ),
479 - self::$title->getUserPermissionsErrors( 'edit',
480 - self::$user ) );
481 - $this->setUserPerm( array( "edit", "editprotected" ) );
482 - $this->assertEquals( array( array( 'badaccess-group0' ),
483 - array( 'protectedpagetext', 'bogus' ),
484 - array( 'protectedpagetext', 'protect' ),
485 - array( 'protectedpagetext', 'protect' ) ),
486 - self::$title->getUserPermissionsErrors( 'bogus',
487 - self::$user ) );
488 - $this->assertEquals( array( ),
489 - self::$title->getUserPermissionsErrors( 'edit',
490 - self::$user ) );
491 - self::$title->mCascadeRestriction = true;
492 - $this->assertEquals( false,
493 - self::$title->quickUserCan( 'bogus', false ) );
494 - $this->assertEquals( false,
495 - self::$title->quickUserCan( 'edit', false ) );
496 - $this->assertEquals( array( array( 'badaccess-group0' ),
497 - array( 'protectedpagetext', 'bogus' ),
498 - array( 'protectedpagetext', 'protect' ),
499 - array( 'protectedpagetext', 'protect' ) ),
500 - self::$title->getUserPermissionsErrors( 'bogus',
501 - self::$user ) );
502 - $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
503 - array( 'protectedpagetext', 'protect' ),
504 - array( 'protectedpagetext', 'protect' ) ),
505 - self::$title->getUserPermissionsErrors( 'edit',
506 - self::$user ) );
507 - }
508 -
509 - function testCascadingSourcesRestrictions() {
510 - global $wgUser;
511 - $wgUser = self::$user;
512 - $this->setTitle( NS_MAIN, "test page" );
513 - $this->setUserPerm( array( "edit", "bogus" ) );
514 -
515 - self::$title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) );
516 - self::$title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
517 -
518 - $this->assertEquals( false,
519 - self::$title->userCan( 'bogus' ) );
520 - $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
521 - array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
522 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
523 -
524 - $this->assertEquals( true,
525 - self::$title->userCan( 'edit' ) );
526 - $this->assertEquals( array( ),
527 - self::$title->getUserPermissionsErrors( 'edit', self::$user ) );
528 -
529 - }
530 -
531 - function testActionPermissions() {
532 - global $wgUser;
533 - $wgUser = self::$user;
534 -
535 - $this->setUserPerm( array( "createpage" ) );
536 - $this->setTitle( NS_MAIN, "test page" );
537 - self::$title->mTitleProtection['pt_create_perm'] = '';
538 - self::$title->mTitleProtection['pt_user'] = self::$user->getID();
539 - self::$title->mTitleProtection['pt_expiry'] = Block::infinity();
540 - self::$title->mTitleProtection['pt_reason'] = 'test';
541 - self::$title->mCascadeRestriction = false;
542 -
543 - $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
544 - self::$title->getUserPermissionsErrors( 'create', self::$user ) );
545 - $this->assertEquals( false,
546 - self::$title->userCan( 'create' ) );
547 -
548 - self::$title->mTitleProtection['pt_create_perm'] = 'sysop';
549 - $this->setUserPerm( array( 'createpage', 'protect' ) );
550 - $this->assertEquals( array( ),
551 - self::$title->getUserPermissionsErrors( 'create', self::$user ) );
552 - $this->assertEquals( true,
553 - self::$title->userCan( 'create' ) );
554 -
555 -
556 - $this->setUserPerm( array( 'createpage' ) );
557 - $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
558 - self::$title->getUserPermissionsErrors( 'create', self::$user ) );
559 - $this->assertEquals( false,
560 - self::$title->userCan( 'create' ) );
561 -
562 - $this->setTitle( NS_MEDIA, "test page" );
563 - $this->setUserPerm( array( "move" ) );
564 - $this->assertEquals( false,
565 - self::$title->userCan( 'move' ) );
566 - $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
567 - self::$title->getUserPermissionsErrors( 'move', self::$user ) );
568 -
569 - $this->setTitle( NS_MAIN, "test page" );
570 - $this->assertEquals( array( ),
571 - self::$title->getUserPermissionsErrors( 'move', self::$user ) );
572 - $this->assertEquals( true,
573 - self::$title->userCan( 'move' ) );
574 -
575 - self::$title->mInterwiki = "no";
576 - $this->assertEquals( array( array( 'immobile-page' ) ),
577 - self::$title->getUserPermissionsErrors( 'move', self::$user ) );
578 - $this->assertEquals( false,
579 - self::$title->userCan( 'move' ) );
580 -
581 - $this->setTitle( NS_MEDIA, "test page" );
582 - $this->assertEquals( false,
583 - self::$title->userCan( 'move-target' ) );
584 - $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
585 - self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
586 -
587 - $this->setTitle( NS_MAIN, "test page" );
588 - $this->assertEquals( array( ),
589 - self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
590 - $this->assertEquals( true,
591 - self::$title->userCan( 'move-target' ) );
592 -
593 - self::$title->mInterwiki = "no";
594 - $this->assertEquals( array( array( 'immobile-target-page' ) ),
595 - self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
596 - $this->assertEquals( false,
597 - self::$title->userCan( 'move-target' ) );
598 -
599 - }
600 -
601 - function testUserBlock() {
602 - global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
603 - $wgEmailConfirmToEdit = true;
604 - $wgEmailAuthentication = true;
605 - $wgUser = self::$user;
606 -
607 - $this->setUserPerm( array( "createpage", "move" ) );
608 - $this->setTitle( NS_MAIN, "test page" );
609 -
610 - # $short
611 - $this->assertEquals( array( array( 'confirmedittext' ) ),
612 - self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
613 - $this->assertEquals( true, self::$title->userCan( 'move-target' ) );
614 -
615 - $wgEmailConfirmToEdit = false;
616 - # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
617 - $this->assertEquals( array( ),
618 - self::$title->getUserPermissionsErrors( 'move-target',
619 - self::$user ) );
620 -
621 - global $wgLang;
622 - $prev = time();
623 - $now = time() + 120;
624 - self::$user->mBlockedby = self::$user->getId();
625 - self::$user->mBlock = new Block( '127.0.8.1', self::$user->getId(), self::$user->getId(),
626 - 'no reason given', $prev + 3600, 1, 0 );
627 - self::$user->mBlock->mTimestamp = 0;
628 - $this->assertEquals( array( array( 'autoblockedtext',
629 - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
630 - 'Useruser', 0, 'infinite', '127.0.8.1',
631 - $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ),
632 - self::$title->getUserPermissionsErrors( 'move-target',
633 - self::$user ) );
634 -
635 - $this->assertEquals( true,
636 - self::$title->userCan( 'move-target', self::$user ) );
637 -
638 - global $wgLocalTZoffset;
639 - $wgLocalTZoffset = -60;
640 - self::$user->mBlockedby = self::$user->getName();
641 - self::$user->mBlock = new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
642 - $this->assertEquals( array( array( 'blockedtext',
643 - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
644 - 'Useruser', 0, '23:00, 31 December 1969', '127.0.8.1',
645 - $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ),
646 - self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
647 -
648 - # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
649 - # $user->blockedFor() == ''
650 - # $user->mBlock->mExpiry == 'infinity'
651 - }
652 -}
Index: trunk/phase3/maintenance/tests/LocalFileTest.php
@@ -1,104 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * These tests should work regardless of $wgCapitalLinks
6 - */
7 -
8 -class LocalFileTest extends PHPUnit_Framework_TestCase {
9 - function setUp() {
10 - global $wgContLang, $wgCapitalLinks;
11 -
12 - $wgContLang = new Language;
13 - $wgCapitalLinks = true;
14 - $info = array(
15 - 'name' => 'test',
16 - 'directory' => '/testdir',
17 - 'url' => '/testurl',
18 - 'hashLevels' => 2,
19 - 'transformVia404' => false,
20 - );
21 - $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
22 - $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
23 - $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
24 - $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
25 - $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
26 - $this->file_lc = $this->repo_lc->newFile( 'test!' );
27 - }
28 -
29 - function tearDown() {
30 - global $wgContLang;
31 - unset( $wgContLang );
32 - }
33 -
34 - function testGetHashPath() {
35 - $this->assertEquals( '', $this->file_hl0->getHashPath() );
36 - $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
37 - $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
38 - }
39 -
40 - function testGetRel() {
41 - $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
42 - $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
43 - $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
44 - }
45 -
46 - function testGetUrlRel() {
47 - $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
48 - $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
49 - $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
50 - }
51 -
52 - function testGetArchivePath() {
53 - $this->assertEquals( '/testdir/archive', $this->file_hl0->getArchivePath() );
54 - $this->assertEquals( '/testdir/archive/a/a2', $this->file_hl2->getArchivePath() );
55 - $this->assertEquals( '/testdir/archive/!', $this->file_hl0->getArchivePath( '!' ) );
56 - $this->assertEquals( '/testdir/archive/a/a2/!', $this->file_hl2->getArchivePath( '!' ) );
57 - }
58 -
59 - function testGetThumbPath() {
60 - $this->assertEquals( '/testdir/thumb/Test!', $this->file_hl0->getThumbPath() );
61 - $this->assertEquals( '/testdir/thumb/a/a2/Test!', $this->file_hl2->getThumbPath() );
62 - $this->assertEquals( '/testdir/thumb/Test!/x', $this->file_hl0->getThumbPath( 'x' ) );
63 - $this->assertEquals( '/testdir/thumb/a/a2/Test!/x', $this->file_hl2->getThumbPath( 'x' ) );
64 - }
65 -
66 - function testGetArchiveUrl() {
67 - $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
68 - $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
69 - $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
70 - $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
71 - }
72 -
73 - function testGetThumbUrl() {
74 - $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
75 - $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
76 - $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
77 - $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
78 - }
79 -
80 - function testGetArchiveVirtualUrl() {
81 - $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
82 - $this->assertEquals( 'mwrepo://test/public/archive/a/a2', $this->file_hl2->getArchiveVirtualUrl() );
83 - $this->assertEquals( 'mwrepo://test/public/archive/%21', $this->file_hl0->getArchiveVirtualUrl( '!' ) );
84 - $this->assertEquals( 'mwrepo://test/public/archive/a/a2/%21', $this->file_hl2->getArchiveVirtualUrl( '!' ) );
85 - }
86 -
87 - function testGetThumbVirtualUrl() {
88 - $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
89 - $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
90 - $this->assertEquals( 'mwrepo://test/thumb/Test%21/%21', $this->file_hl0->getThumbVirtualUrl( '!' ) );
91 - $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21/%21', $this->file_hl2->getThumbVirtualUrl( '!' ) );
92 - }
93 -
94 - function testGetUrl() {
95 - $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
96 - $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
97 - }
98 -
99 - function testWfLocalFile() {
100 - $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
101 - $this->assertThat( $file, $this->isInstanceOf( 'LocalFile' ), 'wfLocalFile() returns LocalFile for valid Titles' );
102 - }
103 -}
104 -
105 -
Index: trunk/phase3/maintenance/tests/ApiSetup.php
@@ -1,39 +0,0 @@
2 -<?php
3 -
4 -abstract class ApiTestSetup extends PHPUnit_Framework_TestCase {
5 - protected static $userName;
6 - protected static $passWord;
7 - protected static $user;
8 - protected static $apiUrl;
9 -
10 - function setup() {
11 - global $wgServer, $wgContLang, $wgAuth, $wgScriptPath,
12 - $wgScriptExtension, $wgMemc, $wgRequest;
13 -
14 - self::$apiUrl = $wgServer . $wgScriptPath . "/api" . $wgScriptExtension;
15 -
16 - $wgMemc = new FakeMemCachedClient;
17 - $wgContLang = Language::factory( 'en' );
18 - $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
19 - $wgRequest = new FauxRequest( array() );
20 - self::setupUser();
21 - }
22 -
23 - static function setupUser() {
24 - if ( self::$user == NULL ) {
25 - self::$userName = "Useruser";
26 - self::$passWord = 'Passpass';
27 -
28 - self::$user = User::newFromName( self::$userName );
29 - if ( !self::$user->getID() ) {
30 - self::$user = User::createNew( self::$userName, array(
31 - "email" => "test@example.com",
32 - "real_name" => "Test User" ) );
33 - }
34 - self::$user->setPassword( self::$passWord );
35 - self::$user->saveSettings();
36 - }
37 -
38 - $GLOBALS['wgUser'] = self::$user;
39 - }
40 -}
Index: trunk/phase3/maintenance/tests/UploadFromUrlTest.php
@@ -1,349 +0,0 @@
2 -<?php
3 -
4 -
5 -class UploadFromUrlTest extends ApiTestSetup {
6 -
7 - public function setUp() {
8 - global $wgEnableUploads, $wgAllowCopyUploads;
9 - parent::setup();
10 -
11 - $wgEnableUploads = true;
12 - $wgAllowCopyUploads = true;
13 - wfSetupSession();
14 -
15 - ini_set( 'log_errors', 1 );
16 - ini_set( 'error_reporting', 1 );
17 - ini_set( 'display_errors', 1 );
18 -
19 - if ( wfLocalFile( 'UploadFromUrlTest.png' )->exists() ) {
20 - $this->deleteFile( 'UploadFromUrlTest.png' );
21 - }
22 - }
23 -
24 - protected function doApiRequest( $params ) {
25 - $sessionId = session_id();
26 - session_write_close();
27 -
28 - $req = new FauxRequest( $params, true, $_SESSION );
29 - $module = new ApiMain( $req, true );
30 - $module->execute();
31 -
32 - wfSetupSession( $sessionId );
33 - return array( $module->getResultData(), $req );
34 - }
35 -
36 - /**
37 - * Ensure that the job queue is empty before continuing
38 - */
39 - public function testClearQueue() {
40 - while ( $job = Job::pop() ) { }
41 - $this->assertFalse( $job );
42 - }
43 -
44 - /**
45 - * @todo Document why we test login, since the $wgUser hack used doesn't
46 - * require login
47 - */
48 - public function testLogin() {
49 - $data = $this->doApiRequest( array(
50 - 'action' => 'login',
51 - 'lgname' => self::$userName,
52 - 'lgpassword' => self::$passWord ) );
53 - $this->assertArrayHasKey( "login", $data[0] );
54 - $this->assertArrayHasKey( "result", $data[0]['login'] );
55 - $this->assertEquals( "NeedToken", $data[0]['login']['result'] );
56 - $token = $data[0]['login']['token'];
57 -
58 - $data = $this->doApiRequest( array(
59 - 'action' => 'login',
60 - "lgtoken" => $token,
61 - "lgname" => self::$userName,
62 - "lgpassword" => self::$passWord ) );
63 -
64 - $this->assertArrayHasKey( "login", $data[0] );
65 - $this->assertArrayHasKey( "result", $data[0]['login'] );
66 - $this->assertEquals( "Success", $data[0]['login']['result'] );
67 - $this->assertArrayHasKey( 'lgtoken', $data[0]['login'] );
68 -
69 - return $data;
70 - }
71 -
72 - /**
73 - * @depends testLogin
74 - * @depends testClearQueue
75 - */
76 - public function testSetupUrlDownload( $data ) {
77 - $token = self::$user->editToken();
78 - $exception = false;
79 -
80 - try {
81 - $this->doApiRequest( array(
82 - 'action' => 'upload',
83 - ) );
84 - } catch ( UsageException $e ) {
85 - $exception = true;
86 - $this->assertEquals( "The token parameter must be set", $e->getMessage() );
87 - }
88 - $this->assertTrue( $exception, "Got exception" );
89 -
90 - $exception = false;
91 - try {
92 - $this->doApiRequest( array(
93 - 'action' => 'upload',
94 - 'token' => $token,
95 - ), $data );
96 - } catch ( UsageException $e ) {
97 - $exception = true;
98 - $this->assertEquals( "One of the parameters sessionkey, file, url, statuskey is required",
99 - $e->getMessage() );
100 - }
101 - $this->assertTrue( $exception, "Got exception" );
102 -
103 - $exception = false;
104 - try {
105 - $this->doApiRequest( array(
106 - 'action' => 'upload',
107 - 'url' => 'http://www.example.com/test.png',
108 - 'token' => $token,
109 - ), $data );
110 - } catch ( UsageException $e ) {
111 - $exception = true;
112 - $this->assertEquals( "The filename parameter must be set", $e->getMessage() );
113 - }
114 - $this->assertTrue( $exception, "Got exception" );
115 -
116 - self::$user->removeGroup( 'sysop' );
117 - $exception = false;
118 - try {
119 - $this->doApiRequest( array(
120 - 'action' => 'upload',
121 - 'url' => 'http://www.example.com/test.png',
122 - 'filename' => 'UploadFromUrlTest.png',
123 - 'token' => $token,
124 - ), $data );
125 - } catch ( UsageException $e ) {
126 - $exception = true;
127 - $this->assertEquals( "Permission denied", $e->getMessage() );
128 - }
129 - $this->assertTrue( $exception, "Got exception" );
130 -
131 - self::$user->addGroup( '*' );
132 - self::$user->addGroup( 'sysop' );
133 - $exception = false;
134 - $data = $this->doApiRequest( array(
135 - 'action' => 'upload',
136 - 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
137 - 'asyncdownload' => 1,
138 - 'filename' => 'UploadFromUrlTest.png',
139 - 'token' => $token,
140 - ), $data );
141 -
142 - $this->assertEquals( $data[0]['upload']['result'], 'Queued', 'Queued upload' );
143 -
144 - $job = Job::pop();
145 - $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ), 'Queued upload inserted' );
146 - }
147 -
148 - /**
149 - * @depends testLogin
150 - * @depends testClearQueue
151 - */
152 - public function testAsyncUpload( $data ) {
153 - $token = self::$user->editToken();
154 -
155 - self::$user->addGroup( 'users' );
156 -
157 - $data = $this->doAsyncUpload( $token, true );
158 - $this->assertEquals( $data[0]['upload']['result'], 'Success' );
159 - $this->assertEquals( $data[0]['upload']['filename'], 'UploadFromUrlTest.png' );
160 - $this->assertTrue( wfLocalFile( $data[0]['upload']['filename'] )->exists() );
161 -
162 - $this->deleteFile( 'UploadFromUrlTest.png' );
163 -
164 - return $data;
165 - }
166 -
167 - /**
168 - * @depends testLogin
169 - * @depends testClearQueue
170 - */
171 - public function testAsyncUploadWarning( $data ) {
172 - $token = self::$user->editToken();
173 -
174 - self::$user->addGroup( 'users' );
175 -
176 -
177 - $data = $this->doAsyncUpload( $token );
178 -
179 - $this->assertEquals( $data[0]['upload']['result'], 'Warning' );
180 - $this->assertTrue( isset( $data[0]['upload']['sessionkey'] ) );
181 -
182 - $data = $this->doApiRequest( array(
183 - 'action' => 'upload',
184 - 'sessionkey' => $data[0]['upload']['sessionkey'],
185 - 'filename' => 'UploadFromUrlTest.png',
186 - 'ignorewarnings' => 1,
187 - 'token' => $token,
188 - ) );
189 - $this->assertEquals( $data[0]['upload']['result'], 'Success' );
190 - $this->assertEquals( $data[0]['upload']['filename'], 'UploadFromUrlTest.png' );
191 - $this->assertTrue( wfLocalFile( $data[0]['upload']['filename'] )->exists() );
192 -
193 - $this->deleteFile( 'UploadFromUrlTest.png' );
194 -
195 - return $data;
196 - }
197 -
198 - /**
199 - * @depends testLogin
200 - * @depends testClearQueue
201 - */
202 - public function testSyncDownload( $data ) {
203 - $token = self::$user->editToken();
204 -
205 - $job = Job::pop();
206 - $this->assertFalse( $job, 'Starting with an empty jobqueue' );
207 -
208 - self::$user->addGroup( 'users' );
209 - $data = $this->doApiRequest( array(
210 - 'action' => 'upload',
211 - 'filename' => 'UploadFromUrlTest.png',
212 - 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
213 - 'ignorewarnings' => true,
214 - 'token' => $token,
215 - ), $data );
216 -
217 - $job = Job::pop();
218 - $this->assertFalse( $job );
219 -
220 - $this->assertEquals( 'Success', $data[0]['upload']['result'] );
221 - $this->deleteFile( 'UploadFromUrlTest.png' );
222 -
223 - return $data;
224 - }
225 -
226 - public function testLeaveMessage() {
227 - $token = self::$user->editToken();
228 -
229 - $talk = self::$user->getTalkPage();
230 - if ( $talk->exists() ) {
231 - $a = new Article( $talk );
232 - $a->doDeleteArticle( '' );
233 - }
234 -
235 - $this->assertFalse( (bool)$talk->getArticleId( GAID_FOR_UPDATE ), 'User talk does not exist' );
236 -
237 - $data = $this->doApiRequest( array(
238 - 'action' => 'upload',
239 - 'filename' => 'UploadFromUrlTest.png',
240 - 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
241 - 'asyncdownload' => 1,
242 - 'token' => $token,
243 - 'leavemessage' => 1,
244 - 'ignorewarnings' => 1,
245 - ) );
246 -
247 - $job = Job::pop();
248 - $job->run();
249 -
250 - $this->assertTrue( wfLocalFile( 'UploadFromUrlTest.png' )->exists() );
251 - $this->assertTrue( (bool)$talk->getArticleId( GAID_FOR_UPDATE ), 'User talk exists' );
252 -
253 - $this->deleteFile( 'UploadFromUrlTest.png' );
254 -
255 - $talkRev = Revision::newFromTitle( $talk );
256 - $talkSize = $talkRev->getSize();
257 -
258 - $exception = false;
259 - try {
260 - $data = $this->doApiRequest( array(
261 - 'action' => 'upload',
262 - 'filename' => 'UploadFromUrlTest.png',
263 - 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
264 - 'asyncdownload' => 1,
265 - 'token' => $token,
266 - 'leavemessage' => 1,
267 - ) );
268 - } catch ( UsageException $e ) {
269 - $exception = true;
270 - $this->assertEquals( 'Using leavemessage without ignorewarnings is not supported', $e->getMessage() );
271 - }
272 - $this->assertTrue( $exception );
273 -
274 - $job = Job::pop();
275 - $this->assertFalse( $job );
276 -
277 - return;
278 -
279 - // Broken until using leavemessage with ignorewarnings is supported
280 - $job->run();
281 -
282 - $this->assertFalse( wfLocalFile( 'UploadFromUrlTest.png' )->exists() );
283 -
284 - $talkRev = Revision::newFromTitle( $talk );
285 - $this->assertTrue( $talkRev->getSize() > $talkSize, 'New message left' );
286 -
287 -
288 - }
289 -
290 - /**
291 - * Helper function to perform an async upload, execute the job and fetch
292 - * the status
293 - *
294 - * @return array The result of action=upload&statuskey=key
295 - */
296 - private function doAsyncUpload( $token, $ignoreWarnings = false, $leaveMessage = false ) {
297 - $params = array(
298 - 'action' => 'upload',
299 - 'filename' => 'UploadFromUrlTest.png',
300 - 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
301 - 'asyncdownload' => 1,
302 - 'token' => $token,
303 - );
304 - if ( $ignoreWarnings ) {
305 - $params['ignorewarnings'] = 1;
306 - }
307 - if ( $leaveMessage ) {
308 - $params['leavemessage'] = 1;
309 - }
310 -
311 - $data = $this->doApiRequest( $params );
312 - $this->assertEquals( $data[0]['upload']['result'], 'Queued' );
313 - $this->assertTrue( isset( $data[0]['upload']['statuskey'] ) );
314 - $statusKey = $data[0]['upload']['statuskey'];
315 -
316 - $job = Job::pop();
317 - $this->assertEquals( 'UploadFromUrlJob', get_class( $job ) );
318 -
319 - $status = $job->run();
320 - $this->assertTrue( $status );
321 -
322 - $data = $this->doApiRequest( array(
323 - 'action' => 'upload',
324 - 'statuskey' => $statusKey,
325 - 'token' => $token,
326 - ) );
327 -
328 - return $data;
329 - }
330 -
331 -
332 - /**
333 - *
334 - */
335 - protected function deleteFile( $name ) {
336 - $t = Title::newFromText( $name, NS_FILE );
337 - $this->assertTrue($t->exists(), "File '$name' exists");
338 -
339 - if ( $t->exists() ) {
340 - $file = wfFindFile( $name, array( 'ignoreRedirect' => true ) );
341 - $empty = "";
342 - FileDeleteForm::doDelete( $t, $file, $empty, "none", true );
343 - $a = new Article ( $t );
344 - $a->doDeleteArticle( "testing" );
345 - }
346 - $t = Title::newFromText( $name, NS_FILE );
347 -
348 - $this->assertFalse($t->exists(), "File '$name' was deleted");
349 - }
350 - }
Index: trunk/phase3/maintenance/tests/phpunit.xml
@@ -1,16 +0,0 @@
2 -<!-- See http://www.phpunit.de/manual/3.3/en/appendixes.configuration.html -->
3 -<phpunit bootstrap="./bootstrap.php"
4 - colors="false"
5 - backupGlobals="false"
6 - convertErrorsToExceptions="true"
7 - convertNoticesToExceptions="true"
8 - convertWarningsToExceptions="true"
9 - stopOnFailure="false">
10 - <!-- for the test file list, see TestFileList.php -->
11 - <groups>
12 - <exclude>
13 - <group>Broken</group>
14 - <group>Stub</group>
15 - </exclude>
16 - </groups>
17 -</phpunit>
Index: trunk/phase3/maintenance/tests/GlobalTest.php
@@ -1,212 +0,0 @@
2 -<?php
3 -
4 -class GlobalTest extends PHPUnit_Framework_TestCase {
5 - function setUp() {
6 - global $wgReadOnlyFile;
7 - $this->originals['wgReadOnlyFile'] = $wgReadOnlyFile;
8 - $wgReadOnlyFile = tempnam( wfTempDir(), "mwtest_readonly" );
9 - unlink( $wgReadOnlyFile );
10 - }
11 -
12 - function tearDown() {
13 - global $wgReadOnlyFile;
14 - if ( file_exists( $wgReadOnlyFile ) ) {
15 - unlink( $wgReadOnlyFile );
16 - }
17 - $wgReadOnlyFile = $this->originals['wgReadOnlyFile'];
18 - }
19 -
20 - function testRandom() {
21 - # This could hypothetically fail, but it shouldn't ;)
22 - $this->assertFalse(
23 - wfRandom() == wfRandom() );
24 - }
25 -
26 - function testUrlencode() {
27 - $this->assertEquals(
28 - "%E7%89%B9%E5%88%A5:Contributions/Foobar",
29 - wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
30 - }
31 -
32 - function testReadOnlyEmpty() {
33 - global $wgReadOnly;
34 - $wgReadOnly = null;
35 -
36 - $this->assertFalse( wfReadOnly() );
37 - $this->assertFalse( wfReadOnly() );
38 - }
39 -
40 - function testReadOnlySet() {
41 - global $wgReadOnly, $wgReadOnlyFile;
42 -
43 - $f = fopen( $wgReadOnlyFile, "wt" );
44 - fwrite( $f, 'Message' );
45 - fclose( $f );
46 - $wgReadOnly = null;
47 -
48 - $this->assertTrue( wfReadOnly() );
49 - $this->assertTrue( wfReadOnly() );
50 -
51 - unlink( $wgReadOnlyFile );
52 - $wgReadOnly = null;
53 -
54 - $this->assertFalse( wfReadOnly() );
55 - $this->assertFalse( wfReadOnly() );
56 - }
57 -
58 - function testQuotedPrintable() {
59 - $this->assertEquals(
60 - "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
61 - wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
62 - }
63 -
64 - function testTime() {
65 - $start = wfTime();
66 - $this->assertType( 'float', $start );
67 - $end = wfTime();
68 - $this->assertTrue( $end > $start, "Time is running backwards!" );
69 - }
70 -
71 - function testArrayToCGI() {
72 - $this->assertEquals(
73 - "baz=AT%26T&foo=bar",
74 - wfArrayToCGI(
75 - array( 'baz' => 'AT&T', 'ignore' => '' ),
76 - array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
77 - }
78 -
79 - function testMimeTypeMatch() {
80 - $this->assertEquals(
81 - 'text/html',
82 - mimeTypeMatch( 'text/html',
83 - array( 'application/xhtml+xml' => 1.0,
84 - 'text/html' => 0.7,
85 - 'text/plain' => 0.3 ) ) );
86 - $this->assertEquals(
87 - 'text/*',
88 - mimeTypeMatch( 'text/html',
89 - array( 'image/*' => 1.0,
90 - 'text/*' => 0.5 ) ) );
91 - $this->assertEquals(
92 - '*/*',
93 - mimeTypeMatch( 'text/html',
94 - array( '*/*' => 1.0 ) ) );
95 - $this->assertNull(
96 - mimeTypeMatch( 'text/html',
97 - array( 'image/png' => 1.0,
98 - 'image/svg+xml' => 0.5 ) ) );
99 - }
100 -
101 - function testNegotiateType() {
102 - $this->assertEquals(
103 - 'text/html',
104 - wfNegotiateType(
105 - array( 'application/xhtml+xml' => 1.0,
106 - 'text/html' => 0.7,
107 - 'text/plain' => 0.5,
108 - 'text/*' => 0.2 ),
109 - array( 'text/html' => 1.0 ) ) );
110 - $this->assertEquals(
111 - 'application/xhtml+xml',
112 - wfNegotiateType(
113 - array( 'application/xhtml+xml' => 1.0,
114 - 'text/html' => 0.7,
115 - 'text/plain' => 0.5,
116 - 'text/*' => 0.2 ),
117 - array( 'application/xhtml+xml' => 1.0,
118 - 'text/html' => 0.5 ) ) );
119 - $this->assertEquals(
120 - 'text/html',
121 - wfNegotiateType(
122 - array( 'text/html' => 1.0,
123 - 'text/plain' => 0.5,
124 - 'text/*' => 0.5,
125 - 'application/xhtml+xml' => 0.2 ),
126 - array( 'application/xhtml+xml' => 1.0,
127 - 'text/html' => 0.5 ) ) );
128 - $this->assertEquals(
129 - 'text/html',
130 - wfNegotiateType(
131 - array( 'text/*' => 1.0,
132 - 'image/*' => 0.7,
133 - '*/*' => 0.3 ),
134 - array( 'application/xhtml+xml' => 1.0,
135 - 'text/html' => 0.5 ) ) );
136 - $this->assertNull(
137 - wfNegotiateType(
138 - array( 'text/*' => 1.0 ),
139 - array( 'application/xhtml+xml' => 1.0 ) ) );
140 - }
141 -
142 - function testTimestamp() {
143 - $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
144 - $this->assertEquals(
145 - '20010115123456',
146 - wfTimestamp( TS_MW, $t ),
147 - 'TS_UNIX to TS_MW' );
148 - $this->assertEquals(
149 - 979562096,
150 - wfTimestamp( TS_UNIX, $t ),
151 - 'TS_UNIX to TS_UNIX' );
152 - $this->assertEquals(
153 - '2001-01-15 12:34:56',
154 - wfTimestamp( TS_DB, $t ),
155 - 'TS_UNIX to TS_DB' );
156 -
157 - $this->assertEquals(
158 - '20010115123456',
159 - wfTimestamp( TS_MW, '20010115123456' ),
160 - 'TS_MW to TS_MW' );
161 - $this->assertEquals(
162 - 979562096,
163 - wfTimestamp( TS_UNIX, '20010115123456' ),
164 - 'TS_MW to TS_UNIX' );
165 - $this->assertEquals(
166 - '2001-01-15 12:34:56',
167 - wfTimestamp( TS_DB, '20010115123456' ),
168 - 'TS_MW to TS_DB' );
169 -
170 - $this->assertEquals(
171 - '20010115123456',
172 - wfTimestamp( TS_MW, '2001-01-15 12:34:56' ),
173 - 'TS_DB to TS_MW' );
174 - $this->assertEquals(
175 - 979562096,
176 - wfTimestamp( TS_UNIX, '2001-01-15 12:34:56' ),
177 - 'TS_DB to TS_UNIX' );
178 - $this->assertEquals(
179 - '2001-01-15 12:34:56',
180 - wfTimestamp( TS_DB, '2001-01-15 12:34:56' ),
181 - 'TS_DB to TS_DB' );
182 - }
183 -
184 - function testBasename() {
185 - $sets = array(
186 - '' => '',
187 - '/' => '',
188 - '\\' => '',
189 - '//' => '',
190 - '\\\\' => '',
191 - 'a' => 'a',
192 - 'aaaa' => 'aaaa',
193 - '/a' => 'a',
194 - '\\a' => 'a',
195 - '/aaaa' => 'aaaa',
196 - '\\aaaa' => 'aaaa',
197 - '/aaaa/' => 'aaaa',
198 - '\\aaaa\\' => 'aaaa',
199 - '\\aaaa\\' => 'aaaa',
200 - '/mnt/upload3/wikipedia/en/thumb/8/8b/Zork_Grand_Inquisitor_box_cover.jpg/93px-Zork_Grand_Inquisitor_box_cover.jpg' => '93px-Zork_Grand_Inquisitor_box_cover.jpg',
201 - 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
202 - 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
203 - );
204 - foreach ( $sets as $from => $to ) {
205 - $this->assertEquals( $to, wfBaseName( $from ),
206 - "wfBaseName('$from') => '$to'" );
207 - }
208 - }
209 -
210 - /* TODO: many more! */
211 -}
212 -
213 -
Index: trunk/phase3/maintenance/tests/test-prefetch-previous.xml
@@ -1,57 +0,0 @@
2 -<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="en">
3 -<siteinfo>
4 - <sitename>DemoWiki</sitename>
5 - <base>http://example.com/wiki/Main_Page</base>
6 - <generator>MediaWiki 1.5.0</generator>
7 - <case>first-letter</case>
8 - <namespaces>
9 - <namespace key="-2">Media</namespace>
10 - <namespace key="-1">Special</namespace>
11 - <namespace key="0"></namespace>
12 - <namespace key="1">Talk</namespace>
13 - <namespace key="2">User</namespace>
14 - <namespace key="3">User talk</namespace>
15 - <namespace key="4">DemoWiki</namespace>
16 - <namespace key="5">DemoWIki talk</namespace>
17 - <namespace key="6">Image</namespace>
18 - <namespace key="7">Image talk</namespace>
19 - <namespace key="8">MediaWiki</namespace>
20 - <namespace key="9">MediaWiki talk</namespace>
21 - <namespace key="10">Template</namespace>
22 - <namespace key="11">Template talk</namespace>
23 - <namespace key="12">Help</namespace>
24 - <namespace key="13">Help talk</namespace>
25 - <namespace key="14">Category</namespace>
26 - <namespace key="15">Category talk</namespace>
27 - </namespaces>
28 -</siteinfo>
29 -<page>
30 - <title>First page</title>
31 - <id>1</id>
32 - <revision>
33 - <id>1</id>
34 - <timestamp>2001-01-15T12:00:00Z</timestamp>
35 - <contributor><ip>10.0.0.1</ip></contributor>
36 - <comment>page 1, rev 1</comment>
37 - <text>page 1, rev 1</text>
38 - </revision>
39 - <revision>
40 - <id>2</id>
41 - <timestamp>2001-01-15T12:00:00Z</timestamp>
42 - <contributor><ip>10.0.0.1</ip></contributor>
43 - <comment>page 1, rev 2</comment>
44 - <text>page 1, rev 2</text>
45 - </revision>
46 -</page>
47 -<page>
48 - <title>Second page</title>
49 - <id>2</id>
50 - <revision>
51 - <id>3</id>
52 - <timestamp>2001-01-15T12:00:00Z</timestamp>
53 - <contributor><ip>10.0.0.1</ip></contributor>
54 - <comment>page 2, rev 3</comment>
55 - <text>page 2, rev 3</text>
56 - </revision>
57 -</page>
58 -</mediawiki>
Index: trunk/phase3/maintenance/tests/DatabaseTest.php
@@ -1,92 +0,0 @@
2 -<?php
3 -
4 -class DatabaseTest extends PHPUnit_Framework_TestCase {
5 - var $db;
6 -
7 - function setUp() {
8 - $this->db = wfGetDB( DB_SLAVE );
9 - }
10 -
11 - function testAddQuotesNull() {
12 - $check = "NULL";
13 - if ( $this->db->getType() === 'sqlite' ) {
14 - $check = "''";
15 - }
16 - $this->assertEquals( $check, $this->db->addQuotes( null ) );
17 - }
18 -
19 - function testAddQuotesInt() {
20 - # returning just "1234" should be ok too, though...
21 - # maybe
22 - $this->assertEquals(
23 - "'1234'",
24 - $this->db->addQuotes( 1234 ) );
25 - }
26 -
27 - function testAddQuotesFloat() {
28 - # returning just "1234.5678" would be ok too, though
29 - $this->assertEquals(
30 - "'1234.5678'",
31 - $this->db->addQuotes( 1234.5678 ) );
32 - }
33 -
34 - function testAddQuotesString() {
35 - $this->assertEquals(
36 - "'string'",
37 - $this->db->addQuotes( 'string' ) );
38 - }
39 -
40 - function testAddQuotesStringQuote() {
41 - $check = "'string''s cause trouble'";
42 - if ( $this->db->getType() === 'mysql' ) {
43 - $check = "'string\'s cause trouble'";
44 - }
45 - $this->assertEquals(
46 - $check,
47 - $this->db->addQuotes( "string's cause trouble" ) );
48 - }
49 -
50 - function testFillPreparedEmpty() {
51 - $sql = $this->db->fillPrepared(
52 - 'SELECT * FROM interwiki', array() );
53 - $this->assertEquals(
54 - "SELECT * FROM interwiki",
55 - $sql );
56 - }
57 -
58 - function testFillPreparedQuestion() {
59 - $sql = $this->db->fillPrepared(
60 - 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
61 - array( 4, "Snicker's_paradox" ) );
62 -
63 - $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker''s_paradox'";
64 - if ( $this->db->getType() === 'mysql' ) {
65 - $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'";
66 - }
67 - $this->assertEquals( $check, $sql );
68 - }
69 -
70 - function testFillPreparedBang() {
71 - $sql = $this->db->fillPrepared(
72 - 'SELECT user_id FROM ! WHERE user_name=?',
73 - array( '"user"', "Slash's Dot" ) );
74 -
75 - $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash''s Dot'";
76 - if ( $this->db->getType() === 'mysql' ) {
77 - $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'";
78 - }
79 - $this->assertEquals( $check, $sql );
80 - }
81 -
82 - function testFillPreparedRaw() {
83 - $sql = $this->db->fillPrepared(
84 - "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
85 - array( '"user"', "Slash's Dot" ) );
86 - $this->assertEquals(
87 - "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",
88 - $sql );
89 - }
90 -
91 -}
92 -
93 -
Index: trunk/phase3/maintenance/tests/LicensesTest.php
@@ -1,17 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * @group Broken
6 - */
7 -class LicensesTest extends PHPUnit_Framework_TestCase {
8 -
9 - function testLicenses() {
10 - $str = "
11 -* Free licenses:
12 -** GFLD|Debian disagrees
13 -";
14 -
15 - $lc = new Licenses( $str );
16 - $this->assertTrue( is_a( $lc, 'Licenses' ), 'Correct class' );
17 - }
18 -}
\ No newline at end of file
Index: trunk/phase3/maintenance/tests/README
@@ -1,24 +0,0 @@
2 -Some quickie unit tests done with the PHPUnit testing framework. To run the
3 -test suite, run 'make test' in this dir. This directly invokes 'phpunit.'
4 -
5 -PHPUnit is no longer maintained by PEAR. To get the current version of
6 -PHPUnit, first uninstall any old version of PHPUnit or PHPUnit2 from PEAR,
7 -then install the current version from phpunit.de like this:
8 -
9 -# pear channel-discover pear.phpunit.de
10 -# pear install phpunit/PHPUnit
11 -
12 -You also may wish to install this via your normal package mechanism:
13 -
14 -# aptitude install phpunit
15 - - or -
16 -# yum install phpunit
17 -
18 -Notes:
19 -- Label currently broken tests in the group Broken and they will not
20 - be run by phpunit. You can add them to the group by putting the
21 - following comment at the top of the file:
22 - /**
23 - * @group Broken
24 - */
25 -- Need to fix some broken tests
Index: trunk/phase3/maintenance/tests/SanitizerTest.php
@@ -1,72 +0,0 @@
2 -<?php
3 -
4 -class SanitizerTest extends PHPUnit_Framework_TestCase {
5 -
6 - function setUp() {
7 - AutoLoader::loadClass( 'Sanitizer' );
8 - }
9 -
10 - function testDecodeNamedEntities() {
11 - $this->assertEquals(
12 - "\xc3\xa9cole",
13 - Sanitizer::decodeCharReferences( '&eacute;cole' ),
14 - 'decode named entities'
15 - );
16 - }
17 -
18 - function testDecodeNumericEntities() {
19 - $this->assertEquals(
20 - "\xc4\x88io bonas dans l'\xc3\xa9cole!",
21 - Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&#233;cole!" ),
22 - 'decode numeric entities'
23 - );
24 - }
25 -
26 - function testDecodeMixedEntities() {
27 - $this->assertEquals(
28 - "\xc4\x88io bonas dans l'\xc3\xa9cole!",
29 - Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&eacute;cole!" ),
30 - 'decode mixed numeric/named entities'
31 - );
32 - }
33 -
34 - function testDecodeMixedComplexEntities() {
35 - $this->assertEquals(
36 - "\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas &#x108;io dans l'&eacute;cole)",
37 - Sanitizer::decodeCharReferences(
38 - "&#x108;io bonas dans l'&eacute;cole! (mais pas &amp;#x108;io dans l'&#38;eacute;cole)"
39 - ),
40 - 'decode mixed complex entities'
41 - );
42 - }
43 -
44 - function testInvalidAmpersand() {
45 - $this->assertEquals(
46 - 'a & b',
47 - Sanitizer::decodeCharReferences( 'a & b' ),
48 - 'Invalid ampersand'
49 - );
50 - }
51 -
52 - function testInvalidEntities() {
53 - $this->assertEquals(
54 - '&foo;',
55 - Sanitizer::decodeCharReferences( '&foo;' ),
56 - 'Invalid named entity'
57 - );
58 - }
59 -
60 - function testInvalidNumberedEntities() {
61 - $this->assertEquals( UTF8_REPLACEMENT, Sanitizer::decodeCharReferences( "&#88888888888888;" ), 'Invalid numbered entity' );
62 - }
63 -
64 - function testSelfClosingTag() {
65 - $GLOBALS['wgUseTidy'] = false;
66 - $this->assertEquals(
67 - '<div>Hello world</div>',
68 - Sanitizer::removeHTMLtags( '<div>Hello world</div />' ),
69 - 'Self-closing closing div'
70 - );
71 - }
72 -}
73 -
Index: trunk/phase3/maintenance/tests/SearchUpdateTest.php
@@ -1,123 +0,0 @@
2 -<?php
3 -
4 -class DatabaseMock extends DatabaseBase {
5 - function __construct( $server = false, $user = false, $password = false, $dbName = false,
6 - $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
7 - {
8 - $this->mConn = true;
9 - $this->mOpened = true;
10 - }
11 -
12 - function open( $server, $user, $password, $dbName ) { return true; }
13 - function doQuery( $sql ) { }
14 - function fetchObject( $res ) { }
15 - function fetchRow( $res ) { }
16 - function numRows( $res ) { }
17 - function numFields( $res ) { }
18 - function fieldName( $res, $n ) { }
19 - function insertId() { }
20 - function dataSeek( $res, $row ) { }
21 - function lastErrno() { return 0; }
22 - function lastError() { return ''; }
23 - function affectedRows() { }
24 - function fieldInfo( $table, $field ) { }
25 - function strencode( $s ) { }
26 - static function getSoftwareLink() { }
27 - function getServerVersion() { }
28 - function getType() { }
29 - function getSearchEngine() { }
30 -}
31 -
32 -class MockSearch extends SearchEngine {
33 - public static $id;
34 - public static $title;
35 - public static $text;
36 -
37 - public function __construct( $db ) {
38 - }
39 -
40 - public function update( $id, $title, $text ) {
41 - self::$id = $id;
42 - self::$title = $title;
43 - self::$text = $text;
44 - }
45 -}
46 -
47 -class SearchUpdateTest extends PHPUnit_Framework_TestCase {
48 - static $searchType;
49 - static $dbtype;
50 - static $factoryconf;
51 - static $dbservers;
52 -
53 - function update( $text, $title = 'Test', $id = 1 ) {
54 - $u = new SearchUpdate( $id, $title, $text );
55 - $u->doUpdate();
56 - return array( MockSearch::$title, MockSearch::$text );
57 - }
58 -
59 - function updateText( $text ) {
60 - list( $title, $resultText ) = $this->update( $text );
61 - $resultText = trim( $resultText ); // abstract from some implementation details
62 - return $resultText;
63 - }
64 -
65 - function setUp() {
66 - global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers, $wgContLang;
67 -
68 - self::$searchType = $wgSearchType;
69 - self::$dbtype = $wgDBtype;
70 - self::$factoryconf = $wgLBFactoryConf;
71 - self::$dbservers = $wgDBservers;
72 -
73 - $wgSearchType = 'MockSearch';
74 - $wgDBtype = 'mock';
75 - $wgLBFactoryConf['class'] = 'LBFactory_Simple';
76 - $wgDBservers = null;
77 - $wgContLang = Language::factory( 'en' );
78 - LBFactory::destroyInstance();
79 - }
80 -
81 - function tearDown() {
82 - global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers, $wgContLang;
83 -
84 - LBFactory::destroyInstance();
85 -
86 - $wgSearchType = self::$searchType;
87 - $wgDBtype = self::$dbtype;
88 - $wgLBFactoryConf = self::$factoryconf;
89 - $wgDBservers = self::$dbservers;
90 - $wgContLang = null;
91 - }
92 -
93 - function testUpdateText() {
94 - $this->assertEquals(
95 - 'test',
96 - $this->updateText( '<div>TeSt</div>' ),
97 - 'HTML stripped, text lowercased'
98 - );
99 -
100 - $this->assertEquals(
101 - 'foo bar boz quux',
102 - $this->updateText( <<<EOT
103 -<table style="color:red; font-size:100px">
104 - <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
105 - <tr><td>boz</td><tr>quux</td></tr>
106 -</table>
107 -EOT
108 - ), 'Stripping HTML tables' );
109 -
110 - $this->assertEquals(
111 - 'a b',
112 - $this->updateText( 'a > b' ),
113 - 'Handle unclosed tags'
114 - );
115 -
116 - $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
117 -
118 - $this->assertNotEquals(
119 - '',
120 - $this->updateText( $text ),
121 - 'Bug 18609'
122 - );
123 - }
124 -}
Index: trunk/phase3/maintenance/tests/IPTest.php
@@ -1,52 +0,0 @@
2 -<?php
3 -/*
4 - * Tests for IP validity functions. Ported from /t/inc/IP.t by avar.
5 - */
6 -
7 -class IPTest extends PHPUnit_Framework_TestCase {
8 -
9 - public function testValidIPs() {
10 - foreach ( range( 0, 255 ) as $i ) {
11 - $a = sprintf( "%03d", $i );
12 - $b = sprintf( "%02d", $i );
13 - $c = sprintf( "%01d", $i );
14 - foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
15 - $ip = "$f.$f.$f.$f";
16 - $this->assertTrue( IP::isValid( $ip ) , "$ip is a valid IPv4 address" );
17 - }
18 - }
19 - }
20 -
21 - public function testInvalidIPs() {
22 - foreach ( range( 256, 999 ) as $i ) {
23 - $a = sprintf( "%03d", $i );
24 - $b = sprintf( "%02d", $i );
25 - $c = sprintf( "%01d", $i );
26 - foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
27 - $ip = "$f.$f.$f.$f";
28 - $this->assertFalse( IP::isValid( $ip ), "$ip is not a valid IPv4 address" );
29 - }
30 - }
31 - }
32 -
33 - public function testBogusIPs() {
34 - $invalid = array(
35 - 'www.xn--var-xla.net',
36 - '216.17.184.G',
37 - '216.17.184.1.',
38 - '216.17.184',
39 - '216.17.184.',
40 - '256.17.184.1'
41 - );
42 - foreach ( $invalid as $i ) {
43 - $this->assertFalse( IP::isValid( $i ), "$i is an invalid IPv4 address" );
44 - }
45 - }
46 -
47 - public function testPrivateIPs() {
48 - $private = array( '10.0.0.1', '172.16.0.1', '192.168.0.1' );
49 - foreach ( $private as $p ) {
50 - $this->assertFalse( IP::isPublic( $p ), "$p is not a public IP address" );
51 - }
52 - }
53 -}
Index: trunk/phase3/maintenance/tests/TestFileList.php
@@ -1,30 +0,0 @@
2 -<?php
3 -
4 -$testFiles = array(
5 - #'ApiTest.php',
6 - #'ApiWatchTest.php',
7 - 'CdbTest.php',
8 - 'DatabaseSqliteTest.php',
9 - 'DatabaseTest.php',
10 - 'GlobalTest.php',
11 - #'HttpTest.php',
12 - 'IPTest.php',
13 - 'ImageFunctionsTest.php',
14 - 'LanguageConverterTest.php',
15 - 'LicensesTest.php',
16 - 'LocalFileTest.php',
17 - 'MediaWikiParserTest.php',
18 - 'MessageTest.php',
19 - 'RevisionTest.php',
20 - 'SanitizerTest.php',
21 - 'SearchDbTest.php',
22 - 'SearchEngineTest.php',
23 - 'SearchUpdateTest.php',
24 - 'SiteConfigurationTest.php',
25 - 'TimeAdjustTest.php',
26 - 'TitlePermissionTest.php',
27 - 'TitleTest.php',
28 - 'UploadTest.php',
29 - 'UploadFromUrlTestSuite.php',
30 - 'XmlTest.php',
31 -);
Index: trunk/phase3/maintenance/tests/ResourceLoaderTest.php
@@ -1,15 +0,0 @@
2 -<?php
3 -
4 -class ResourceLoaderTest extends PHPUnit_Framework_TestCase {
5 - /* Provider Methods */
6 -
7 - public function provide() {
8 -
9 - }
10 -
11 - /* Test Methods */
12 -
13 - public function test() {
14 -
15 - }
16 -}
Index: trunk/phase3/maintenance/tests/MediaWikiParserTest.php
@@ -1,55 +0,0 @@
2 -<?php
3 -
4 -class MediaWikiParserTestSuite extends PHPUnit_Framework_TestSuite {
5 - private $count;
6 - public $backend;
7 -
8 - public static function suite() {
9 - return new self;
10 - }
11 -
12 - public function __construct() {
13 - $this->backend = new ParserTestSuiteBackend;
14 - parent::__construct();
15 - $this->setName( 'Parser tests' );
16 - }
17 -
18 - public function run( PHPUnit_Framework_TestResult $result = null, $filter = false,
19 - array $groups = array(), array $excludeGroups = array(), $processIsolation = false
20 - ) {
21 - global $IP, $wgContLang, $wgMemc;
22 - $wgContLang = Language::factory( 'en' );
23 - $wgMemc = new FakeMemCachedClient;
24 - $this->backend->setupDatabase();
25 -
26 - $iter = new TestFileIterator( "$IP/maintenance/parserTests.txt" );
27 - $iter->setParser( $this->backend );
28 - $this->count = 0;
29 -
30 - foreach ( $iter as $test ) {
31 - $this->addTest( new ParserUnitTest( $this, $test ) );
32 - $this->count++;
33 - }
34 -
35 - parent::run( $result, $filter, $groups, $excludeGroups, $processIsolation );
36 -
37 - $this->backend->teardownDatabase();
38 - }
39 -
40 - public function count() {
41 - return $this->count;
42 - }
43 -
44 - public function toString() {
45 - return "MediaWiki Parser Tests";
46 - }
47 -
48 - public function getBackend() {
49 - return $this->backend;
50 - }
51 -
52 - public function getIterator() {
53 - return $this->iterator;
54 - }
55 -}
56 -
Index: trunk/phase3/maintenance/tests/MediaWiki_Setup.php
@@ -1,34 +0,0 @@
2 -<?php
3 -
4 -abstract class MediaWikiTestSetup extends PHPUnit_Framework_TestCase {
5 -
6 - protected function buildTestDatabase( $tables ) {
7 - global $wgDBprefix;
8 -
9 - $db = wfGetDB( DB_MASTER );
10 - $oldTableNames = array();
11 - foreach ( $tables as $table )
12 - $oldTableNames[$table] = $db->tableName( $table );
13 - if ( $db->getType() == 'oracle' ) {
14 - $wgDBprefix = 'pt_';
15 - } else {
16 - $wgDBprefix = 'parsertest_';
17 - }
18 -
19 - $db->tablePrefix( $wgDBprefix );
20 -
21 - if ( $db->isOpen() ) {
22 - foreach ( $tables as $tbl ) {
23 - $newTableName = $db->tableName( $tbl );
24 - $tableName = $oldTableNames[$tbl];
25 - $db->query( "DROP TABLE IF EXISTS $newTableName", __METHOD__ );
26 - $db->duplicateTableStructure( $tableName, $newTableName, __METHOD__ );
27 - }
28 - return $db;
29 - } else {
30 - // Something amiss
31 - return null;
32 - }
33 - }
34 -}
35 -
Index: trunk/phase3/maintenance/tests/ResourceLoaderFileModuleTest.php
@@ -1,15 +0,0 @@
2 -<?php
3 -
4 -class ResourceLoaderFileModuleTest extends PHPUnit_Framework_TestCase {
5 - /* Provider Methods */
6 -
7 - public function provide() {
8 -
9 - }
10 -
11 - /* Test Methods */
12 -
13 - public function test() {
14 -
15 - }
16 -}
Index: trunk/phase3/maintenance/tests/DatabaseSqliteTest.php
@@ -1,70 +0,0 @@
2 -<?php
3 -
4 -class MockDatabaseSqlite extends DatabaseSqliteStandalone {
5 - var $lastQuery;
6 -
7 - function __construct( ) {
8 - parent::__construct( '' );
9 - }
10 -
11 - function query( $sql, $fname = '', $tempIgnore = false ) {
12 - $this->lastQuery = $sql;
13 - return true;
14 - }
15 -
16 - function replaceVars( $s ) {
17 - return parent::replaceVars( $s );
18 - }
19 -}
20 -
21 -class DatabaseSqliteTest extends PHPUnit_Framework_TestCase {
22 - var $db;
23 -
24 - function setup() {
25 - if ( !Sqlite::isPresent() ) {
26 - $this->markTestIncomplete( 'No SQLite support detected' );
27 - }
28 - $this->db = new MockDatabaseSqlite();
29 - }
30 -
31 - function replaceVars( $sql ) {
32 - // normalize spacing to hide implementation details
33 - return preg_replace( '/\s+/', ' ', $this->db->replaceVars( $sql ) );
34 - }
35 -
36 - function testReplaceVars() {
37 - $this->assertEquals( 'foo', $this->replaceVars( 'foo' ), "Don't break anything accidentally" );
38 -
39 - $this->assertEquals( "CREATE TABLE /**/foo (foo_key INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "
40 - . "foo_bar TEXT, foo_name TEXT NOT NULL DEFAULT '', foo_int INTEGER, foo_int2 INTEGER );",
41 - $this->replaceVars( "CREATE TABLE /**/foo (foo_key int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
42 - foo_bar char(13), foo_name varchar(255) binary NOT NULL DEFAULT '', foo_int tinyint ( 8 ), foo_int2 int(16) ) ENGINE=MyISAM;" )
43 - );
44 -
45 - $this->assertEquals( "CREATE TABLE foo ( foo_binary1 BLOB, foo_binary2 BLOB );",
46 - $this->replaceVars( "CREATE TABLE foo ( foo_binary1 binary(16), foo_binary2 varbinary(32) );" )
47 - );
48 -
49 - $this->assertEquals( "CREATE TABLE text ( text_foo TEXT );",
50 - $this->replaceVars( "CREATE TABLE text ( text_foo tinytext );" ),
51 - 'Table name changed'
52 - );
53 -
54 - $this->assertEquals( "CREATE TABLE enums( enum1 TEXT, myenum TEXT)",
55 - $this->replaceVars( "CREATE TABLE enums( enum1 ENUM('A', 'B'), myenum ENUM ('X', 'Y'))" )
56 - );
57 -
58 - $this->assertEquals( "ALTER TABLE foo ADD COLUMN foo_bar INTEGER DEFAULT 42",
59 - $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" )
60 - );
61 - }
62 -
63 - function testEntireSchema() {
64 - global $IP;
65 -
66 - $result = Sqlite::checkSqlSyntax( "$IP/maintenance/tables.sql" );
67 - if ( $result !== true ) {
68 - $this->fail( $result );
69 - }
70 - }
71 -}
\ No newline at end of file
Index: trunk/phase3/maintenance/tests/phpunit.php
@@ -1,54 +0,0 @@
2 -#!/usr/bin/env php
3 -<?php
4 -
5 -require( dirname( __FILE__ ) . '/../commandLine.inc' );
6 -// XXX: This can go away if everyone switches to PHPUnit 3.5
7 -if ( @file_get_contents( 'PHPUnit/Autoload.php', true ) !== false ) {
8 - // Works for PHPUnit >= 3.5
9 - require_once 'PHPUnit/Autoload.php';
10 -} else {
11 - // Works for PHPUnit < 3.5
12 - require_once 'PHPUnit/TextUI/Command.php';
13 -}
14 -define( 'MW_PHPUNIT_TEST', 1 );
15 -
16 -$wgLocaltimezone = 'UTC';
17 -
18 -/* Tests were failing with sqlite */
19 -global $wgCaches;
20 -$wgCaches[CACHE_DB] = false;
21 -
22 -if ( !version_compare( PHPUnit_Runner_Version::id(), "3.4.1", ">" ) ) {
23 - echo <<<EOF
24 -************************************************************
25 -
26 -These tests run best with version PHPUnit 3.4.2 or later.
27 -Earlier versions may show failures because earlier versions
28 -of PHPUnit do not properly implement dependencies.
29 -
30 -************************************************************
31 -
32 -EOF;
33 -}
34 -
35 -class MWPHPUnitCommand extends PHPUnit_TextUI_Command {
36 - protected function handleCustomTestSuite() {
37 - $suite = new PHPUnit_Framework_TestSuite;
38 - if ( !empty( $this->options[1] ) ) {
39 - $files = $this->options[1];
40 - } else {
41 - require( dirname( __FILE__ ) . '/TestFileList.php' );
42 - $files = $testFiles;
43 - wfRunHooks( 'UnitTestsList', array( &$files ) );
44 - }
45 - foreach ( $files as $file ) {
46 - $suite->addTestFile( $file );
47 - }
48 - $suite->setName( 'MediaWiki test suite' );
49 - $this->arguments['test'] = $suite;
50 - }
51 -}
52 -
53 -$command = new MWPHPUnitCommand;
54 -$command->run( $argv );
55 -
Index: trunk/phase3/maintenance/tests/CdbTest.php
@@ -1,84 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Test the CDB reader/writer
6 - */
7 -
8 -class CdbTest extends PHPUnit_Framework_TestCase {
9 -
10 - public function setup() {
11 - if ( !CdbReader::haveExtension() ) {
12 - $this->markTestIncomplete( 'This test requires native CDB support to be present.' );
13 - }
14 - }
15 -
16 - public function testCdb() {
17 - $dir = wfTempDir();
18 - if ( !is_writable( $dir ) ) {
19 - $this->markTestSkipped( "Temp dir isn't writable" );
20 - }
21 -
22 - $w1 = new CdbWriter_PHP( "$dir/php.cdb" );
23 - $w2 = new CdbWriter_DBA( "$dir/dba.cdb" );
24 -
25 - $data = array();
26 - for ( $i = 0; $i < 1000; $i++ ) {
27 - $key = $this->randomString();
28 - $value = $this->randomString();
29 - $w1->set( $key, $value );
30 - $w2->set( $key, $value );
31 -
32 - if ( !isset( $data[$key] ) ) {
33 - $data[$key] = $value;
34 - }
35 - }
36 -
37 - $w1->close();
38 - $w2->close();
39 -
40 - $this->assertEquals(
41 - md5_file( "$dir/dba.cdb" ),
42 - md5_file( "$dir/php.cdb" ),
43 - 'same hash'
44 - );
45 -
46 - $r1 = new CdbReader_PHP( "$dir/php.cdb" );
47 - $r2 = new CdbReader_DBA( "$dir/dba.cdb" );
48 -
49 - foreach ( $data as $key => $value ) {
50 - if ( $key === '' ) {
51 - // Known bug
52 - continue;
53 - }
54 - $v1 = $r1->get( $key );
55 - $v2 = $r2->get( $key );
56 -
57 - $v1 = $v1 === false ? '(not found)' : $v1;
58 - $v2 = $v2 === false ? '(not found)' : $v2;
59 -
60 - # cdbAssert( 'Mismatch', $key, $v1, $v2 );
61 - $this->cdbAssert( "PHP error", $key, $v1, $value );
62 - $this->cdbAssert( "DBA error", $key, $v2, $value );
63 - }
64 -
65 - unlink( "$dir/dba.cdb" );
66 - unlink( "$dir/php.cdb" );
67 - }
68 -
69 - private function randomString() {
70 - $len = mt_rand( 0, 10 );
71 - $s = '';
72 - for ( $j = 0; $j < $len; $j++ ) {
73 - $s .= chr( mt_rand( 0, 255 ) );
74 - }
75 - return $s;
76 - }
77 -
78 - private function cdbAssert( $msg, $key, $v1, $v2 ) {
79 - $this->assertEquals(
80 - $v2,
81 - $v1,
82 - $msg . ', k=' . bin2hex( $key )
83 - );
84 - }
85 -}
Index: trunk/phase3/maintenance/tests/SearchEngineTest.php
@@ -1,176 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * @group Stub
6 - */
7 -class SearchEngineTest extends MediaWikiTestSetup {
8 - var $db, $search, $pageList;
9 -
10 - function pageExists( $title ) {
11 - return false;
12 - }
13 -
14 - function insertSearchData() {
15 - if ( $this->pageExists( 'Not_Main_Page' ) ) {
16 - return;
17 - }
18 - $this->insertPage( "Not_Main_Page", "This is not a main page", 0 );
19 - $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 );
20 - $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 );
21 - $this->insertPage( 'Talk:Smithee', 'This article sucks.', 1 );
22 - $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.', 0 );
23 - $this->insertPage( 'Another_page', 'This page also is unrelated.', 0 );
24 - $this->insertPage( 'Help:Help', 'Help me!', 4 );
25 - $this->insertPage( 'Thppt', 'Blah blah', 0 );
26 - $this->insertPage( 'Alan_Smithee', 'yum', 0 );
27 - $this->insertPage( 'Pages', 'are\'food', 0 );
28 - $this->insertPage( 'HalfOneUp', 'AZ', 0 );
29 - $this->insertPage( 'FullOneUp', 'AZ', 0 );
30 - $this->insertPage( 'HalfTwoLow', 'az', 0 );
31 - $this->insertPage( 'FullTwoLow', 'az', 0 );
32 - $this->insertPage( 'HalfNumbers', '1234567890', 0 );
33 - $this->insertPage( 'FullNumbers', '1234567890', 0 );
34 - $this->insertPage( 'DomainName', 'example.com', 0 );
35 - }
36 -
37 - function removeSearchData() {
38 - return;
39 - /*while ( count( $this->pageList ) ) {
40 - list( $title, $id ) = array_pop( $this->pageList );
41 - $article = new Article( $title, $id );
42 - $article->doDeleteArticle( "Search Test" );
43 - }*/
44 - }
45 -
46 - function fetchIds( $results ) {
47 - $this->assertTrue( is_object( $results ) );
48 -
49 - if ( $this->db->getType() !== 'mysql' && $this->db->getType() !== 'sqlite' ) {
50 - $this->markTestSkipped( "MySQL or SQLite only" );
51 - }
52 - $matches = array();
53 - while ( $row = $results->next() ) {
54 - $matches[] = $row->getTitle()->getPrefixedText();
55 - }
56 - $results->free();
57 - # Search is not guaranteed to return results in a certain order;
58 - # sort them numerically so we will compare simply that we received
59 - # the expected matches.
60 - sort( $matches );
61 - return $matches;
62 - }
63 -
64 - // Modified version of WikiRevision::importOldRevision()
65 - function insertPage( $pageName, $text, $ns ) {
66 - $dbw = $this->db;
67 - $title = Title::newFromText( $pageName );
68 -
69 - $userId = 0;
70 - $userText = 'WikiSysop';
71 - $comment = 'Search Test';
72 -
73 - // avoid memory leak...?
74 - $linkCache = LinkCache::singleton();
75 - $linkCache->clear();
76 -
77 - $article = new Article( $title );
78 - $pageId = $article->getId();
79 - $created = false;
80 - if ( $pageId == 0 ) {
81 - # must create the page...
82 - $pageId = $article->insertOn( $dbw );
83 - $created = true;
84 - }
85 -
86 - # FIXME: Use original rev_id optionally (better for backups)
87 - # Insert the row
88 - $revision = new Revision( array(
89 - 'page' => $pageId,
90 - 'text' => $text,
91 - 'comment' => $comment,
92 - 'user' => $userId,
93 - 'user_text' => $userText,
94 - 'timestamp' => 0,
95 - 'minor_edit' => false,
96 - ) );
97 - $revId = $revision->insertOn( $dbw );
98 - $changed = $article->updateIfNewerOn( $dbw, $revision );
99 -
100 - $GLOBALS['wgTitle'] = $title;
101 - if ( $created ) {
102 - Article::onArticleCreate( $title );
103 - $article->createUpdates( $revision );
104 - } elseif ( $changed ) {
105 - Article::onArticleEdit( $title );
106 - $article->editUpdates(
107 - $text, $comment, false, 0, $revId );
108 - }
109 -
110 - $su = new SearchUpdate( $article->getId(), $pageName, $text );
111 - $su->doUpdate();
112 -
113 - $this->pageList[] = array( $title, $article->getId() );
114 -
115 - return true;
116 - }
117 -
118 - function testFullWidth() {
119 - $this->assertEquals(
120 - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
121 - $this->fetchIds( $this->search->searchText( 'AZ' ) ),
122 - "Search for normalized from Half-width Upper" );
123 - $this->assertEquals(
124 - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
125 - $this->fetchIds( $this->search->searchText( 'az' ) ),
126 - "Search for normalized from Half-width Lower" );
127 - $this->assertEquals(
128 - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
129 - $this->fetchIds( $this->search->searchText( 'AZ' ) ),
130 - "Search for normalized from Full-width Upper" );
131 - $this->assertEquals(
132 - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
133 - $this->fetchIds( $this->search->searchText( 'az' ) ),
134 - "Search for normalized from Full-width Lower" );
135 - }
136 -
137 - function testTextSearch() {
138 - $this->assertEquals(
139 - array( 'Smithee' ),
140 - $this->fetchIds( $this->search->searchText( 'smithee' ) ),
141 - "Plain search failed" );
142 - }
143 -
144 - function testTextPowerSearch() {
145 - $this->search->setNamespaces( array( 0, 1, 4 ) );
146 - $this->assertEquals(
147 - array(
148 - 'Smithee',
149 - 'Talk:Not Main Page',
150 - ),
151 - $this->fetchIds( $this->search->searchText( 'smithee' ) ),
152 - "Power search failed" );
153 - }
154 -
155 - function testTitleSearch() {
156 - $this->assertEquals(
157 - array(
158 - 'Alan Smithee',
159 - 'Smithee',
160 - ),
161 - $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
162 - "Title search failed" );
163 - }
164 -
165 - function testTextTitlePowerSearch() {
166 - $this->search->setNamespaces( array( 0, 1, 4 ) );
167 - $this->assertEquals(
168 - array(
169 - 'Alan Smithee',
170 - 'Smithee',
171 - 'Talk:Smithee',
172 - ),
173 - $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
174 - "Title power search failed" );
175 - }
176 -
177 -}
Index: trunk/phase3/maintenance/tests/SiteConfigurationTest.php
@@ -1,311 +0,0 @@
2 -<?php
3 -
4 -function getSiteParams( $conf, $wiki ) {
5 - $site = null;
6 - $lang = null;
7 - foreach ( $conf->suffixes as $suffix ) {
8 - if ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
9 - $site = $suffix;
10 - $lang = substr( $wiki, 0, -strlen( $suffix ) );
11 - break;
12 - }
13 - }
14 - return array(
15 - 'suffix' => $site,
16 - 'lang' => $lang,
17 - 'params' => array(
18 - 'lang' => $lang,
19 - 'site' => $site,
20 - 'wiki' => $wiki,
21 - ),
22 - 'tags' => array( 'tag' ),
23 - );
24 -}
25 -
26 -class SiteConfigurationTest extends PHPUnit_Framework_TestCase {
27 - var $mConf;
28 -
29 - function setUp() {
30 - $this->mConf = new SiteConfiguration;
31 -
32 - $this->mConf->suffixes = array( 'wiki' );
33 - $this->mConf->wikis = array( 'enwiki', 'dewiki', 'frwiki' );
34 - $this->mConf->settings = array(
35 - 'simple' => array(
36 - 'wiki' => 'wiki',
37 - 'tag' => 'tag',
38 - 'enwiki' => 'enwiki',
39 - 'dewiki' => 'dewiki',
40 - 'frwiki' => 'frwiki',
41 - ),
42 -
43 - 'fallback' => array(
44 - 'default' => 'default',
45 - 'wiki' => 'wiki',
46 - 'tag' => 'tag',
47 - ),
48 -
49 - 'params' => array(
50 - 'default' => '$lang $site $wiki',
51 - ),
52 -
53 - '+global' => array(
54 - 'wiki' => array(
55 - 'wiki' => 'wiki',
56 - ),
57 - 'tag' => array(
58 - 'tag' => 'tag',
59 - ),
60 - 'enwiki' => array(
61 - 'enwiki' => 'enwiki',
62 - ),
63 - 'dewiki' => array(
64 - 'dewiki' => 'dewiki',
65 - ),
66 - 'frwiki' => array(
67 - 'frwiki' => 'frwiki',
68 - ),
69 - ),
70 -
71 - 'merge' => array(
72 - '+wiki' => array(
73 - 'wiki' => 'wiki',
74 - ),
75 - '+tag' => array(
76 - 'tag' => 'tag',
77 - ),
78 - 'default' => array(
79 - 'default' => 'default',
80 - ),
81 - '+enwiki' => array(
82 - 'enwiki' => 'enwiki',
83 - ),
84 - '+dewiki' => array(
85 - 'dewiki' => 'dewiki',
86 - ),
87 - '+frwiki' => array(
88 - 'frwiki' => 'frwiki',
89 - ),
90 - ),
91 - );
92 -
93 - $GLOBALS['global'] = array( 'global' => 'global' );
94 - }
95 -
96 -
97 - function testSiteFromDB() {
98 - $this->assertEquals(
99 - array( 'wikipedia', 'en' ),
100 - $this->mConf->siteFromDB( 'enwiki' ),
101 - 'siteFromDB()'
102 - );
103 - $this->assertEquals(
104 - array( 'wikipedia', '' ),
105 - $this->mConf->siteFromDB( 'wiki' ),
106 - 'siteFromDB() on a suffix'
107 - );
108 - $this->assertEquals(
109 - array( null, null ),
110 - $this->mConf->siteFromDB( 'wikien' ),
111 - 'siteFromDB() on a non-existing wiki'
112 - );
113 -
114 - $this->mConf->suffixes = array( 'wiki', '' );
115 - $this->assertEquals(
116 - array( '', 'wikien' ),
117 - $this->mConf->siteFromDB( 'wikien' ),
118 - 'siteFromDB() on a non-existing wiki (2)'
119 - );
120 - }
121 -
122 - function testGetLocalDatabases() {
123 - $this->assertEquals(
124 - array( 'enwiki', 'dewiki', 'frwiki' ),
125 - $this->mConf->getLocalDatabases(),
126 - 'getLocalDatabases()'
127 - );
128 - }
129 -
130 - function testGet() {
131 - $this->assertEquals(
132 - 'enwiki',
133 - $this->mConf->get( 'simple', 'enwiki', 'wiki' ),
134 - 'get(): simple setting on an existing wiki'
135 - );
136 - $this->assertEquals(
137 - 'dewiki',
138 - $this->mConf->get( 'simple', 'dewiki', 'wiki' ),
139 - 'get(): simple setting on an existing wiki (2)'
140 - );
141 - $this->assertEquals(
142 - 'frwiki',
143 - $this->mConf->get( 'simple', 'frwiki', 'wiki' ),
144 - 'get(): simple setting on an existing wiki (3)'
145 - );
146 - $this->assertEquals(
147 - 'wiki',
148 - $this->mConf->get( 'simple', 'wiki', 'wiki' ),
149 - 'get(): simple setting on an suffix'
150 - );
151 - $this->assertEquals(
152 - 'wiki',
153 - $this->mConf->get( 'simple', 'eswiki', 'wiki' ),
154 - 'get(): simple setting on an non-existing wiki'
155 - );
156 -
157 - $this->assertEquals(
158 - 'wiki',
159 - $this->mConf->get( 'fallback', 'enwiki', 'wiki' ),
160 - 'get(): fallback setting on an existing wiki'
161 - );
162 - $this->assertEquals(
163 - 'tag',
164 - $this->mConf->get( 'fallback', 'dewiki', 'wiki', array(), array( 'tag' ) ),
165 - 'get(): fallback setting on an existing wiki (with wiki tag)'
166 - );
167 - $this->assertEquals(
168 - 'wiki',
169 - $this->mConf->get( 'fallback', 'wiki', 'wiki' ),
170 - 'get(): fallback setting on an suffix'
171 - );
172 - $this->assertEquals(
173 - 'wiki',
174 - $this->mConf->get( 'fallback', 'wiki', 'wiki', array(), array( 'tag' ) ),
175 - 'get(): fallback setting on an suffix (with wiki tag)'
176 - );
177 - $this->assertEquals(
178 - 'wiki',
179 - $this->mConf->get( 'fallback', 'eswiki', 'wiki' ),
180 - 'get(): fallback setting on an non-existing wiki'
181 - );
182 - $this->assertEquals(
183 - 'tag',
184 - $this->mConf->get( 'fallback', 'eswiki', 'wiki', array(), array( 'tag' ) ),
185 - 'get(): fallback setting on an non-existing wiki (with wiki tag)'
186 - );
187 -
188 - $common = array( 'wiki' => 'wiki', 'default' => 'default' );
189 - $commonTag = array( 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' );
190 - $this->assertEquals(
191 - array( 'enwiki' => 'enwiki' ) + $common,
192 - $this->mConf->get( 'merge', 'enwiki', 'wiki' ),
193 - 'get(): merging setting on an existing wiki'
194 - );
195 - $this->assertEquals(
196 - array( 'enwiki' => 'enwiki' ) + $commonTag,
197 - $this->mConf->get( 'merge', 'enwiki', 'wiki', array(), array( 'tag' ) ),
198 - 'get(): merging setting on an existing wiki (with tag)'
199 - );
200 - $this->assertEquals(
201 - array( 'dewiki' => 'dewiki' ) + $common,
202 - $this->mConf->get( 'merge', 'dewiki', 'wiki' ),
203 - 'get(): merging setting on an existing wiki (2)'
204 - );
205 - $this->assertEquals(
206 - array( 'dewiki' => 'dewiki' ) + $commonTag,
207 - $this->mConf->get( 'merge', 'dewiki', 'wiki', array(), array( 'tag' ) ),
208 - 'get(): merging setting on an existing wiki (2) (with tag)'
209 - );
210 - $this->assertEquals(
211 - array( 'frwiki' => 'frwiki' ) + $common,
212 - $this->mConf->get( 'merge', 'frwiki', 'wiki' ),
213 - 'get(): merging setting on an existing wiki (3)'
214 - );
215 - $this->assertEquals(
216 - array( 'frwiki' => 'frwiki' ) + $commonTag,
217 - $this->mConf->get( 'merge', 'frwiki', 'wiki', array(), array( 'tag' ) ),
218 - 'get(): merging setting on an existing wiki (3) (with tag)'
219 - );
220 - $this->assertEquals(
221 - array( 'wiki' => 'wiki' ) + $common,
222 - $this->mConf->get( 'merge', 'wiki', 'wiki' ),
223 - 'get(): merging setting on an suffix'
224 - );
225 - $this->assertEquals(
226 - array( 'wiki' => 'wiki' ) + $commonTag,
227 - $this->mConf->get( 'merge', 'wiki', 'wiki', array(), array( 'tag' ) ),
228 - 'get(): merging setting on an suffix (with tag)'
229 - );
230 - $this->assertEquals(
231 - $common,
232 - $this->mConf->get( 'merge', 'eswiki', 'wiki' ),
233 - 'get(): merging setting on an non-existing wiki'
234 - );
235 - $this->assertEquals(
236 - $commonTag,
237 - $this->mConf->get( 'merge', 'eswiki', 'wiki', array(), array( 'tag' ) ),
238 - 'get(): merging setting on an non-existing wiki (with tag)'
239 - );
240 - }
241 -
242 - function testSiteFromDBWithCallback() {
243 - $this->mConf->siteParamsCallback = 'getSiteParams';
244 -
245 - $this->assertEquals(
246 - array( 'wiki', 'en' ),
247 - $this->mConf->siteFromDB( 'enwiki' ),
248 - 'siteFromDB() with callback'
249 - );
250 - $this->assertEquals(
251 - array( 'wiki', '' ),
252 - $this->mConf->siteFromDB( 'wiki' ),
253 - 'siteFromDB() with callback on a suffix'
254 - );
255 - $this->assertEquals(
256 - array( null, null ),
257 - $this->mConf->siteFromDB( 'wikien' ),
258 - 'siteFromDB() with callback on a non-existing wiki'
259 - );
260 - }
261 -
262 - function testParamReplacement() {
263 - $this->mConf->siteParamsCallback = 'getSiteParams';
264 -
265 - $this->assertEquals(
266 - 'en wiki enwiki',
267 - $this->mConf->get( 'params', 'enwiki', 'wiki' ),
268 - 'get(): parameter replacement on an existing wiki'
269 - );
270 - $this->assertEquals(
271 - 'de wiki dewiki',
272 - $this->mConf->get( 'params', 'dewiki', 'wiki' ),
273 - 'get(): parameter replacement on an existing wiki (2)'
274 - );
275 - $this->assertEquals(
276 - 'fr wiki frwiki',
277 - $this->mConf->get( 'params', 'frwiki', 'wiki' ),
278 - 'get(): parameter replacement on an existing wiki (3)'
279 - );
280 - $this->assertEquals(
281 - ' wiki wiki',
282 - $this->mConf->get( 'params', 'wiki', 'wiki' ),
283 - 'get(): parameter replacement on an suffix'
284 - );
285 - $this->assertEquals(
286 - 'es wiki eswiki',
287 - $this->mConf->get( 'params', 'eswiki', 'wiki' ),
288 - 'get(): parameter replacement on an non-existing wiki'
289 - );
290 - }
291 -
292 - function testGetAll() {
293 - $this->mConf->siteParamsCallback = 'getSiteParams';
294 -
295 - $getall = array(
296 - 'simple' => 'enwiki',
297 - 'fallback' => 'tag',
298 - 'params' => 'en wiki enwiki',
299 - 'global' => array( 'enwiki' => 'enwiki' ) + $GLOBALS['global'],
300 - 'merge' => array( 'enwiki' => 'enwiki', 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' ),
301 - );
302 - $this->assertEquals( $getall, $this->mConf->getAll( 'enwiki' ), 'getAll()' );
303 -
304 - $this->mConf->extractAllGlobals( 'enwiki', 'wiki' );
305 -
306 - $this->assertEquals( $getall['simple'], $GLOBALS['simple'], 'extractAllGlobals(): simple setting' );
307 - $this->assertEquals( $getall['fallback'], $GLOBALS['fallback'], 'extractAllGlobals(): fallback setting' );
308 - $this->assertEquals( $getall['params'], $GLOBALS['params'], 'extractAllGlobals(): parameter replacement' );
309 - $this->assertEquals( $getall['global'], $GLOBALS['global'], 'extractAllGlobals(): merging with global' );
310 - $this->assertEquals( $getall['merge'], $GLOBALS['merge'], 'extractAllGlobals(): merging setting' );
311 - }
312 -}
Index: trunk/phase3/maintenance/tests/RevisionTest.php
@@ -1,114 +0,0 @@
2 -<?php
3 -
4 -class RevisionTest extends PHPUnit_Framework_TestCase {
5 - var $saveGlobals = array();
6 -
7 - function setUp() {
8 - global $wgContLang;
9 - $wgContLang = Language::factory( 'en' );
10 - $globalSet = array(
11 - 'wgLegacyEncoding' => false,
12 - 'wgCompressRevisions' => false,
13 - 'wgInputEncoding' => 'utf-8',
14 - 'wgOutputEncoding' => 'utf-8' );
15 - foreach ( $globalSet as $var => $data ) {
16 - $this->saveGlobals[$var] = $GLOBALS[$var];
17 - $GLOBALS[$var] = $data;
18 - }
19 - }
20 -
21 - function tearDown() {
22 - foreach ( $this->saveGlobals as $var => $data ) {
23 - $GLOBALS[$var] = $data;
24 - }
25 - }
26 -
27 - function testGetRevisionText() {
28 - $row = new stdClass;
29 - $row->old_flags = '';
30 - $row->old_text = 'This is a bunch of revision text.';
31 - $this->assertEquals(
32 - 'This is a bunch of revision text.',
33 - Revision::getRevisionText( $row ) );
34 - }
35 -
36 - function testGetRevisionTextGzip() {
37 - $row = new stdClass;
38 - $row->old_flags = 'gzip';
39 - $row->old_text = gzdeflate( 'This is a bunch of revision text.' );
40 - $this->assertEquals(
41 - 'This is a bunch of revision text.',
42 - Revision::getRevisionText( $row ) );
43 - }
44 -
45 - function testGetRevisionTextUtf8Native() {
46 - $row = new stdClass;
47 - $row->old_flags = 'utf-8';
48 - $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
49 - $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
50 - $this->assertEquals(
51 - "Wiki est l'\xc3\xa9cole superieur !",
52 - Revision::getRevisionText( $row ) );
53 - }
54 -
55 - function testGetRevisionTextUtf8Legacy() {
56 - $row = new stdClass;
57 - $row->old_flags = '';
58 - $row->old_text = "Wiki est l'\xe9cole superieur !";
59 - $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
60 - $this->assertEquals(
61 - "Wiki est l'\xc3\xa9cole superieur !",
62 - Revision::getRevisionText( $row ) );
63 - }
64 -
65 - function testGetRevisionTextUtf8NativeGzip() {
66 - $row = new stdClass;
67 - $row->old_flags = 'gzip,utf-8';
68 - $row->old_text = gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" );
69 - $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
70 - $this->assertEquals(
71 - "Wiki est l'\xc3\xa9cole superieur !",
72 - Revision::getRevisionText( $row ) );
73 - }
74 -
75 - function testGetRevisionTextUtf8LegacyGzip() {
76 - $row = new stdClass;
77 - $row->old_flags = 'gzip';
78 - $row->old_text = gzdeflate( "Wiki est l'\xe9cole superieur !" );
79 - $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
80 - $this->assertEquals(
81 - "Wiki est l'\xc3\xa9cole superieur !",
82 - Revision::getRevisionText( $row ) );
83 - }
84 -
85 - function testCompressRevisionTextUtf8() {
86 - $row = new stdClass;
87 - $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
88 - $row->old_flags = Revision::compressRevisionText( $row->old_text );
89 - $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
90 - "Flags should contain 'utf-8'" );
91 - $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ),
92 - "Flags should not contain 'gzip'" );
93 - $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
94 - $row->old_text, "Direct check" );
95 - $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
96 - Revision::getRevisionText( $row ), "getRevisionText" );
97 - }
98 -
99 - function testCompressRevisionTextUtf8Gzip() {
100 - $GLOBALS['wgCompressRevisions'] = true;
101 - $row = new stdClass;
102 - $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
103 - $row->old_flags = Revision::compressRevisionText( $row->old_text );
104 - $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
105 - "Flags should contain 'utf-8'" );
106 - $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ),
107 - "Flags should contain 'gzip'" );
108 - $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
109 - gzinflate( $row->old_text ), "Direct check" );
110 - $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
111 - Revision::getRevisionText( $row ), "getRevisionText" );
112 - }
113 -}
114 -
115 -
Index: trunk/phase3/maintenance/tests/ApiWatchTest.php
@@ -1,211 +0,0 @@
2 -<?php
3 -
4 -class ApiWatchTest extends ApiTestSetup {
5 -
6 - function setUp() {
7 - ini_set( 'log_errors', 1 );
8 - ini_set( 'error_reporting', 1 );
9 - ini_set( 'display_errors', 1 );
10 -
11 - global $wgMemc;
12 - $wgMemc = new FakeMemCachedClient;
13 - }
14 -
15 - function tearDown() {
16 - global $wgMemc;
17 -
18 - $wgMemc = null;
19 - }
20 -
21 -
22 - function doApiRequest( $params, $data = null ) {
23 - $_SESSION = isset( $data[2] ) ? $data[2] : array();
24 -
25 - $req = new FauxRequest( $params, true, $_SESSION );
26 - $module = new ApiMain( $req, true );
27 - $module->execute();
28 -
29 - $data[0] = $module->getResultData();
30 - $data[1] = $req;
31 - $data[2] = $_SESSION;
32 -
33 - return $data;
34 - }
35 -
36 - function testLogin() {
37 - $data = $this->doApiRequest( array(
38 - 'action' => 'login',
39 - 'lgname' => 'WikiSysop',
40 - 'lgpassword' => 'none' ), $data );
41 -
42 - $this->assertArrayHasKey( "login", $data[0] );
43 - $this->assertArrayHasKey( "result", $data[0]['login'] );
44 - $this->assertEquals( "NeedToken", $data[0]['login']['result'] );
45 - $token = $data[0]['login']['token'];
46 -
47 - $data = $this->doApiRequest( array(
48 - 'action' => 'login',
49 - "lgtoken" => $token,
50 - "lgname" => 'WikiSysop',
51 - "lgpassword" => 'none' ), $data );
52 -
53 - $this->assertArrayHasKey( "login", $data[0] );
54 - $this->assertArrayHasKey( "result", $data[0]['login'] );
55 - $this->assertEquals( "Success", $data[0]['login']['result'] );
56 - $this->assertArrayHasKey( 'lgtoken', $data[0]['login'] );
57 -
58 - return $data;
59 - }
60 -
61 - function testGetToken() {
62 -
63 - $data = $this->doApiRequest( array(
64 - 'action' => 'query',
65 - 'titles' => 'Main Page',
66 - 'intoken' => 'edit|delete|protect|move|block|unblock',
67 - 'prop' => 'info' ), $data );
68 -
69 - $this->assertArrayHasKey( 'query', $data[0] );
70 - $this->assertArrayHasKey( 'pages', $data[0]['query'] );
71 - $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
72 -
73 - $this->assertArrayHasKey( $key, $data[0]['query']['pages'] );
74 - $this->assertArrayHasKey( 'edittoken', $data[0]['query']['pages'][$key] );
75 - $this->assertArrayHasKey( 'movetoken', $data[0]['query']['pages'][$key] );
76 - $this->assertArrayHasKey( 'deletetoken', $data[0]['query']['pages'][$key] );
77 - $this->assertArrayHasKey( 'blocktoken', $data[0]['query']['pages'][$key] );
78 - $this->assertArrayHasKey( 'unblocktoken', $data[0]['query']['pages'][$key] );
79 - $this->assertArrayHasKey( 'protecttoken', $data[0]['query']['pages'][$key] );
80 -
81 - return $data;
82 - }
83 -
84 - /**
85 - * @depends testGetToken
86 - */
87 - function testWatchEdit( $data ) {
88 - $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
89 - $pageinfo = $data[0]['query']['pages'][$key];
90 -
91 - $data = $this->doApiRequest( array(
92 - 'action' => 'edit',
93 - 'title' => 'Main Page',
94 - 'text' => 'new text',
95 - 'token' => $pageinfo['edittoken'],
96 - 'watchlist' => 'watch' ), $data );
97 - $this->assertArrayHasKey( 'edit', $data[0] );
98 - $this->assertArrayHasKey( 'result', $data[0]['edit'] );
99 - $this->assertEquals( 'Success', $data[0]['edit']['result'] );
100 -
101 - return $data;
102 - }
103 -
104 -
105 - /**
106 - * @depends testWatchEdit
107 - */
108 - function testWatchClear( $data ) {
109 - $data = $this->doApiRequest( array(
110 - 'action' => 'query',
111 - 'list' => 'watchlist' ), $data );
112 -
113 - if ( isset( $data[0]['query']['watchlist'] ) ) {
114 - $wl = $data[0]['query']['watchlist'];
115 -
116 - foreach ( $wl as $page ) {
117 - $data = $this->doApiRequest( array(
118 - 'action' => 'watch',
119 - 'title' => $page['title'],
120 - 'unwatch' => true ), $data );
121 - }
122 - }
123 - $data = $this->doApiRequest( array(
124 - 'action' => 'query',
125 - 'list' => 'watchlist' ), $data );
126 - $this->assertArrayHasKey( 'query', $data[0] );
127 - $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
128 - $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
129 -
130 - return $data;
131 - }
132 -
133 - /**
134 - * @depends testGetToken
135 - */
136 - function testWatchProtect( $data ) {
137 - $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
138 - $pageinfo = $data[0]['query']['pages'][$key];
139 -
140 - $data = $this->doApiRequest( array(
141 - 'action' => 'protect',
142 - 'token' => $pageinfo['protecttoken'],
143 - 'title' => 'Main Page',
144 - 'protections' => 'edit=sysop',
145 - 'watchlist' => 'unwatch' ), $data );
146 -
147 - $this->assertArrayHasKey( 'protect', $data[0] );
148 - $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
149 - $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
150 - $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
151 - }
152 -
153 - /**
154 - * @depends testGetToken
155 - */
156 - function testGetRollbackToken( $data ) {
157 - $data = $this->doApiRequest( array(
158 - 'action' => 'query',
159 - 'prop' => 'revisions',
160 - 'titles' => 'Main Page',
161 - 'rvtoken' => 'rollback' ), $data );
162 -
163 - $this->assertArrayHasKey( 'query', $data[0] );
164 - $this->assertArrayHasKey( 'pages', $data[0]['query'] );
165 - $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
166 -
167 - $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
168 - $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
169 - $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
170 - $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
171 -
172 - return $data;
173 - }
174 -
175 - /**
176 - * @depends testGetRollbackToken
177 - */
178 - function testWatchRollback( $data ) {
179 - $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
180 - $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0];
181 -
182 - $data = $this->doApiRequest( array(
183 - 'action' => 'rollback',
184 - 'title' => 'Main Page',
185 - 'user' => 'WikiSysop',
186 - 'token' => $pageinfo['rollbacktoken'],
187 - 'watchlist' => 'watch' ), $data );
188 -
189 - $this->assertArrayHasKey( 'rollback', $data[0] );
190 - $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
191 - }
192 -
193 - /**
194 - * @depends testGetToken
195 - */
196 - function testWatchDelete( $data ) {
197 - $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
198 - $pageinfo = $data[0]['query']['pages'][$key];
199 -
200 - $data = $this->doApiRequest( array(
201 - 'action' => 'delete',
202 - 'token' => $pageinfo['deletetoken'],
203 - 'title' => 'Main Page' ), $data );
204 - $this->assertArrayHasKey( 'delete', $data[0] );
205 - $this->assertArrayHasKey( 'title', $data[0]['delete'] );
206 -
207 - $data = $this->doApiRequest( array(
208 - 'action' => 'query',
209 - 'list' => 'watchlist' ), $data );
210 - }
211 -
212 -}
Index: trunk/phase3/maintenance/tests/ExtraParserTest.php
@@ -1,30 +0,0 @@
2 -<?php
3 -/**
4 - * Parser-related tests that don't suit for parserTests.txt
5 - */
6 -
7 -class ExtraParserTest extends PHPUnit_Framework_TestCase {
8 -
9 - function setUp() {
10 - global $wgMemc;
11 -
12 - $wgMemc = new FakeMemCachedClient;
13 - }
14 -
15 - function tearDown() {
16 - global $wgMemc;
17 -
18 - $wgMemc = null;
19 - }
20 -
21 - // Bug 8689 - Long numeric lines kill the parser
22 - function testBug8689() {
23 - $longLine = '1.' . str_repeat( '1234567890', 100000 ) . "\n";
24 -
25 - $parser = new Parser();
26 - $t = Title::newFromText( 'Unit test' );
27 - $options = new ParserOptions();
28 - $this->assertEquals( "<p>$longLine</p>",
29 - $parser->parse( $longLine, $t, $options )->getText() );
30 - }
31 - }
Index: trunk/phase3/maintenance/tests/XmlTest.php
@@ -1,115 +0,0 @@
2 -<?php
3 -
4 -class XmlTest extends PHPUnit_Framework_TestCase {
5 -
6 - function testElementOpen() {
7 - $this->assertEquals(
8 - '<element>',
9 - Xml::element( 'element', null, null ),
10 - 'Opening element with no attributes'
11 - );
12 - }
13 -
14 - function testElementEmpty() {
15 - $this->assertEquals(
16 - '<element />',
17 - Xml::element( 'element', null, '' ),
18 - 'Terminated empty element'
19 - );
20 - }
21 -
22 - function testElementEscaping() {
23 - $this->assertEquals(
24 - '<element>hello &lt;there&gt; you &amp; you</element>',
25 - Xml::element( 'element', null, 'hello <there> you & you' ),
26 - 'Element with no attributes and content that needs escaping'
27 - );
28 - }
29 -
30 - function testElementAttributes() {
31 - $this->assertEquals(
32 - '<element key="value" <>="&lt;&gt;">',
33 - Xml::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ),
34 - 'Element attributes, keys are not escaped'
35 - );
36 - }
37 -
38 - function testOpenElement() {
39 - $this->assertEquals(
40 - '<element k="v">',
41 - Xml::openElement( 'element', array( 'k' => 'v' ) ),
42 - 'openElement() shortcut'
43 - );
44 - }
45 -
46 - function testCloseElement() {
47 - $this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' );
48 - }
49 -
50 - #
51 - # textarea
52 - #
53 - function testTextareaNoContent() {
54 - $this->assertEquals(
55 - '<textarea name="name" id="name" cols="40" rows="5"></textarea>',
56 - Xml::textarea( 'name', '' ),
57 - 'textarea() with not content'
58 - );
59 - }
60 -
61 - function testTextareaAttribs() {
62 - $this->assertEquals(
63 - '<textarea name="name" id="name" cols="20" rows="10">&lt;txt&gt;</textarea>',
64 - Xml::textarea( 'name', '<txt>', 20, 10 ),
65 - 'textarea() with custom attribs'
66 - );
67 - }
68 -
69 - #
70 - # JS
71 - #
72 - function testEscapeJsStringSpecialChars() {
73 - $this->assertEquals(
74 - '\\\\\r\n',
75 - Xml::escapeJsString( "\\\r\n" ),
76 - 'escapeJsString() with special characters'
77 - );
78 - }
79 -
80 - function testEncodeJsVarBoolean() {
81 - $this->assertEquals(
82 - 'true',
83 - Xml::encodeJsVar( true ),
84 - 'encodeJsVar() with boolean'
85 - );
86 - }
87 -
88 - function testEncodeJsVarNull() {
89 - $this->assertEquals(
90 - 'null',
91 - Xml::encodeJsVar( null ),
92 - 'encodeJsVar() with null'
93 - );
94 - }
95 -
96 - function testEncodeJsVarArray() {
97 - $this->assertEquals(
98 - '["a", 1]',
99 - Xml::encodeJsVar( array( 'a', 1 ) ),
100 - 'encodeJsVar() with array'
101 - );
102 - $this->assertEquals(
103 - '{"a": "a", "b": 1}',
104 - Xml::encodeJsVar( array( 'a' => 'a', 'b' => 1 ) ),
105 - 'encodeJsVar() with associative array'
106 - );
107 - }
108 -
109 - function testEncodeJsVarObject() {
110 - $this->assertEquals(
111 - '{"a": "a", "b": 1}',
112 - Xml::encodeJsVar( (object)array( 'a' => 'a', 'b' => 1 ) ),
113 - 'encodeJsVar() with object'
114 - );
115 - }
116 -}
Index: trunk/phase3/maintenance/tests/test-prefetch-stub.xml
@@ -1,75 +0,0 @@
2 -<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="en">
3 -<siteinfo>
4 - <sitename>DemoWiki</sitename>
5 - <base>http://example.com/wiki/Main_Page</base>
6 - <generator>MediaWiki 1.5.0</generator>
7 - <case>first-letter</case>
8 - <namespaces>
9 - <namespace key="-2">Media</namespace>
10 - <namespace key="-1">Special</namespace>
11 - <namespace key="0"></namespace>
12 - <namespace key="1">Talk</namespace>
13 - <namespace key="2">User</namespace>
14 - <namespace key="3">User talk</namespace>
15 - <namespace key="4">DemoWiki</namespace>
16 - <namespace key="5">DemoWIki talk</namespace>
17 - <namespace key="6">Image</namespace>
18 - <namespace key="7">Image talk</namespace>
19 - <namespace key="8">MediaWiki</namespace>
20 - <namespace key="9">MediaWiki talk</namespace>
21 - <namespace key="10">Template</namespace>
22 - <namespace key="11">Template talk</namespace>
23 - <namespace key="12">Help</namespace>
24 - <namespace key="13">Help talk</namespace>
25 - <namespace key="14">Category</namespace>
26 - <namespace key="15">Category talk</namespace>
27 - </namespaces>
28 -</siteinfo>
29 -<page>
30 - <title>First page</title>
31 - <id>1</id>
32 - <revision>
33 - <id>1</id>
34 - <timestamp>2001-01-15T12:00:00Z</timestamp>
35 - <contributor><ip>10.0.0.1</ip></contributor>
36 - <comment>page 1, rev 1</comment>
37 - <text id="1" />
38 - </revision>
39 - <revision>
40 - <id>2</id>
41 - <timestamp>2001-01-15T12:00:00Z</timestamp>
42 - <contributor><ip>10.0.0.1</ip></contributor>
43 - <comment>page 1, rev 2</comment>
44 - <text id="2" />
45 - </revision>
46 - <revision>
47 - <id>4</id>
48 - <timestamp>2001-01-15T12:00:00Z</timestamp>
49 - <contributor><ip>10.0.0.1</ip></contributor>
50 - <comment>page 1, rev 4</comment>
51 - <text id="4" />
52 - </revision>
53 -</page>
54 -<page>
55 - <title>Second page</title>
56 - <id>2</id>
57 - <revision>
58 - <id>3</id>
59 - <timestamp>2001-01-15T12:00:00Z</timestamp>
60 - <contributor><ip>10.0.0.1</ip></contributor>
61 - <comment>page 2, rev 3</comment>
62 - <text id="3" />
63 - </revision>
64 -</page>
65 -<page>
66 - <title>Third page</title>
67 - <id>3</id>
68 - <revision>
69 - <id>5</id>
70 - <timestamp>2001-01-15T12:00:00Z</timestamp>
71 - <contributor><ip>10.0.0.1</ip></contributor>
72 - <comment>page 3, rev 5</comment>
73 - <text id="5" />
74 - </revision>
75 -</page>
76 -</mediawiki>
Index: trunk/phase3/maintenance/tests/UploadFromUrlTestSuite.php
@@ -1,179 +0,0 @@
2 -<?php
3 -
4 -class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
5 - public static function addTables( &$tables ) {
6 - $tables[] = 'user_properties';
7 - $tables[] = 'filearchive';
8 - $tables[] = 'logging';
9 - $tables[] = 'updatelog';
10 - $tables[] = 'iwlinks';
11 -
12 - return true;
13 - }
14 -
15 - function setUp() {
16 - global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
17 - $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
18 - $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
19 - $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
20 - $wgThumbnailScriptPath, $wgScriptPath,
21 - $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
22 -
23 - $wgScript = '/index.php';
24 - $wgScriptPath = '/';
25 - $wgArticlePath = '/wiki/$1';
26 - $wgStyleSheetPath = '/skins';
27 - $wgStylePath = '/skins';
28 - $wgThumbnailScriptPath = false;
29 - $wgLocalFileRepo = array(
30 - 'class' => 'LocalRepo',
31 - 'name' => 'local',
32 - 'directory' => wfTempDir() . '/test-repo',
33 - 'url' => 'http://example.com/images',
34 - 'deletedDir' => wfTempDir() . '/test-repo/delete',
35 - 'hashLevels' => 2,
36 - 'transformVia404' => false,
37 - );
38 - $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
39 - $wgNamespaceAliases['Image'] = NS_FILE;
40 - $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
41 -
42 -
43 - $wgEnableParserCache = false;
44 - $wgDeferredUpdateList = array();
45 - $wgMemc =& wfGetMainCache();
46 - $messageMemc =& wfGetMessageCacheStorage();
47 - $parserMemc =& wfGetParserCacheStorage();
48 -
49 - // $wgContLang = new StubContLang;
50 - $wgUser = new User;
51 - $wgLang = new StubUserLang;
52 - $wgOut = new StubObject( 'wgOut', 'OutputPage' );
53 - $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
54 - $wgRequest = new WebRequest;
55 -
56 - $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
57 - array( $messageMemc, $wgUseDatabaseMessages,
58 - $wgMsgCacheExpiry ) );
59 - if ( $wgStyleDirectory === false ) {
60 - $wgStyleDirectory = "$IP/skins";
61 - }
62 -
63 - }
64 -
65 - public function tearDown() {
66 - $this->teardownUploadDir( $this->uploadDir );
67 - }
68 -
69 - private $uploadDir;
70 - private $keepUploads;
71 -
72 - /**
73 - * Remove the dummy uploads directory
74 - */
75 - private function teardownUploadDir( $dir ) {
76 - if ( $this->keepUploads ) {
77 - return;
78 - }
79 -
80 - // delete the files first, then the dirs.
81 - self::deleteFiles(
82 - array (
83 - "$dir/3/3a/Foobar.jpg",
84 - "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
85 - "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
86 - "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
87 - "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
88 -
89 - "$dir/0/09/Bad.jpg",
90 - )
91 - );
92 -
93 - self::deleteDirs(
94 - array (
95 - "$dir/3/3a",
96 - "$dir/3",
97 - "$dir/thumb/6/65",
98 - "$dir/thumb/6",
99 - "$dir/thumb/3/3a/Foobar.jpg",
100 - "$dir/thumb/3/3a",
101 - "$dir/thumb/3",
102 -
103 - "$dir/0/09/",
104 - "$dir/0/",
105 -
106 - "$dir/thumb",
107 - "$dir",
108 - )
109 - );
110 - }
111 -
112 - /**
113 - * Delete the specified files, if they exist.
114 - *
115 - * @param $files Array: full paths to files to delete.
116 - */
117 - private static function deleteFiles( $files ) {
118 - foreach ( $files as $file ) {
119 - if ( file_exists( $file ) ) {
120 - unlink( $file );
121 - }
122 - }
123 - }
124 -
125 - /**
126 - * Delete the specified directories, if they exist. Must be empty.
127 - *
128 - * @param $dirs Array: full paths to directories to delete.
129 - */
130 - private static function deleteDirs( $dirs ) {
131 - foreach ( $dirs as $dir ) {
132 - if ( is_dir( $dir ) ) {
133 - rmdir( $dir );
134 - }
135 - }
136 - }
137 -
138 - /**
139 - * Create a dummy uploads directory which will contain a couple
140 - * of files in order to pass existence tests.
141 - *
142 - * @return String: the directory
143 - */
144 - private function setupUploadDir() {
145 - global $IP;
146 -
147 - if ( $this->keepUploads ) {
148 - $dir = wfTempDir() . '/mwParser-images';
149 -
150 - if ( is_dir( $dir ) ) {
151 - return $dir;
152 - }
153 - } else {
154 - $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
155 - }
156 -
157 - wfDebug( "Creating upload directory $dir\n" );
158 -
159 - if ( file_exists( $dir ) ) {
160 - wfDebug( "Already exists!\n" );
161 - return $dir;
162 - }
163 -
164 - wfMkdirParents( $dir . '/3/3a' );
165 - copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
166 -
167 - wfMkdirParents( $dir . '/0/09' );
168 - copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
169 -
170 - return $dir;
171 - }
172 -
173 - public static function suite() {
174 - // Hack to invoke the autoloader required to get phpunit to recognize
175 - // the UploadFromUrlTest class
176 - class_exists( 'UploadFromUrlTest' );
177 - $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );
178 - return $suite;
179 - }
180 -}
Index: trunk/phase3/maintenance/tests/phpunit.bat
@@ -1 +0,0 @@
2 -@php phpunit %1 %2 %3 %4 %5 %6 %7 %8 %9
\ No newline at end of file
Index: trunk/phase3/maintenance/tests/test-prefetch-current.xml
@@ -1,75 +0,0 @@
2 -<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="en">
3 -<siteinfo>
4 - <sitename>DemoWiki</sitename>
5 - <base>http://example.com/wiki/Main_Page</base>
6 - <generator>MediaWiki 1.5.0</generator>
7 - <case>first-letter</case>
8 - <namespaces>
9 - <namespace key="-2">Media</namespace>
10 - <namespace key="-1">Special</namespace>
11 - <namespace key="0"></namespace>
12 - <namespace key="1">Talk</namespace>
13 - <namespace key="2">User</namespace>
14 - <namespace key="3">User talk</namespace>
15 - <namespace key="4">DemoWiki</namespace>
16 - <namespace key="5">DemoWIki talk</namespace>
17 - <namespace key="6">Image</namespace>
18 - <namespace key="7">Image talk</namespace>
19 - <namespace key="8">MediaWiki</namespace>
20 - <namespace key="9">MediaWiki talk</namespace>
21 - <namespace key="10">Template</namespace>
22 - <namespace key="11">Template talk</namespace>
23 - <namespace key="12">Help</namespace>
24 - <namespace key="13">Help talk</namespace>
25 - <namespace key="14">Category</namespace>
26 - <namespace key="15">Category talk</namespace>
27 - </namespaces>
28 -</siteinfo>
29 -<page>
30 - <title>First page</title>
31 - <id>1</id>
32 - <revision>
33 - <id>1</id>
34 - <timestamp>2001-01-15T12:00:00Z</timestamp>
35 - <contributor><ip>10.0.0.1</ip></contributor>
36 - <comment>page 1, rev 1</comment>
37 - <text>page 1, rev 1</text>
38 - </revision>
39 - <revision>
40 - <id>2</id>
41 - <timestamp>2001-01-15T12:00:00Z</timestamp>
42 - <contributor><ip>10.0.0.1</ip></contributor>
43 - <comment>page 1, rev 2</comment>
44 - <text>page 1, rev 2</text>
45 - </revision>
46 - <revision>
47 - <id>4</id>
48 - <timestamp>2001-01-15T12:00:00Z</timestamp>
49 - <contributor><ip>10.0.0.1</ip></contributor>
50 - <comment>page 1, rev 4</comment>
51 - <text>page 1, rev 4</text>
52 - </revision>
53 -</page>
54 -<page>
55 - <title>Second page</title>
56 - <id>2</id>
57 - <revision>
58 - <id>3</id>
59 - <timestamp>2001-01-15T12:00:00Z</timestamp>
60 - <contributor><ip>10.0.0.1</ip></contributor>
61 - <comment>page 2, rev 3</comment>
62 - <text>page 2, rev 3</text>
63 - </revision>
64 -</page>
65 -<page>
66 - <title>Third page</title>
67 - <id>3</id>
68 - <revision>
69 - <id>5</id>
70 - <timestamp>2001-01-15T12:00:00Z</timestamp>
71 - <contributor><ip>10.0.0.1</ip></contributor>
72 - <comment>page 3, rev 5</comment>
73 - <text>page 3, rev 5</text>
74 - </revision>
75 -</page>
76 -</mediawiki>
Index: trunk/phase3/maintenance/tests/TimeAdjustTest.php
@@ -1,49 +0,0 @@
2 -<?php
3 -
4 -class TimeAdjustTest extends PHPUnit_Framework_TestCase {
5 - static $offset;
6 -
7 - public function setUp() {
8 - global $wgLocalTZoffset;
9 - self::$offset = $wgLocalTZoffset;
10 -
11 - $this->iniSet( 'precision', 15 );
12 - }
13 -
14 - public function tearDown() {
15 - global $wgLocalTZoffset;
16 - $wgLocalTZoffset = self::$offset;
17 - }
18 -
19 - # Test offset usage for a given language::userAdjust
20 - function testUserAdjust() {
21 - global $wgLocalTZoffset, $wgContLang;
22 -
23 - $wgContLang = $en = Language::factory( 'en' );
24 -
25 - #  Collection of parameters for Language_t_Offset.
26 - # Format: date to be formatted, localTZoffset value, expected date
27 - $userAdjust_tests = array(
28 - array( 20061231235959, 0, 20061231235959 ),
29 - array( 20061231235959, 5, 20070101000459 ),
30 - array( 20061231235959, 15, 20070101001459 ),
31 - array( 20061231235959, 60, 20070101005959 ),
32 - array( 20061231235959, 90, 20070101012959 ),
33 - array( 20061231235959, 120, 20070101015959 ),
34 - array( 20061231235959, 540, 20070101085959 ),
35 - array( 20061231235959, -5, 20061231235459 ),
36 - array( 20061231235959, -30, 20061231232959 ),
37 - array( 20061231235959, -60, 20061231225959 ),
38 - );
39 -
40 - foreach ( $userAdjust_tests as $data ) {
41 - $wgLocalTZoffset = $data[1];
42 -
43 - $this->assertEquals(
44 - strval( $data[2] ),
45 - strval( $en->userAdjust( $data[0], '' ) ),
46 - "User adjust {$data[0]} by {$data[1]} minutes should give {$data[2]}"
47 - );
48 - }
49 - }
50 -}
Index: trunk/phase3/maintenance/tests/ApiTest.php
@@ -1,220 +0,0 @@
2 -<?php
3 -
4 -class MockApi extends ApiBase {
5 - public function execute() { }
6 - public function getVersion() { }
7 -
8 - public function __construct() { }
9 -
10 - public function getAllowedParams() {
11 - return array(
12 - 'filename' => null,
13 - 'enablechunks' => false,
14 - 'sessionkey' => null,
15 - );
16 - }
17 -}
18 -
19 -class ApiTest extends ApiTestSetup {
20 -
21 - function setup() {
22 - parent::setup();
23 - }
24 -
25 - function testRequireOnlyOneParameterDefault() {
26 - $mock = new MockApi();
27 -
28 - $this->assertEquals(
29 - null, $mock->requireOnlyOneParameter( array( "filename" => "foo.txt",
30 - "enablechunks" => false ), "filename", "enablechunks" ) );
31 - }
32 -
33 - /**
34 - * @expectedException UsageException
35 - */
36 - function testRequireOnlyOneParameterZero() {
37 - $mock = new MockApi();
38 -
39 - $this->assertEquals(
40 - null, $mock->requireOnlyOneParameter( array( "filename" => "foo.txt",
41 - "enablechunks" => 0 ), "filename", "enablechunks" ) );
42 - }
43 -
44 - /**
45 - * @expectedException UsageException
46 - */
47 - function testRequireOnlyOneParameterTrue() {
48 - $mock = new MockApi();
49 -
50 - $this->assertEquals(
51 - null, $mock->requireOnlyOneParameter( array( "filename" => "foo.txt",
52 - "enablechunks" => true ), "filename", "enablechunks" ) );
53 - }
54 -
55 - function testApi() {
56 - global $wgServerName, $wgServer;
57 -
58 - if ( !isset( $wgServerName ) || !isset( $wgServer ) ) {
59 - $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
60 - 'be set in LocalSettings.php' );
61 - }
62 - /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */
63 - $resp = Http::get( self::$apiUrl . "?format=xml" );
64 -
65 - libxml_use_internal_errors( true );
66 - $sxe = simplexml_load_string( $resp );
67 - $this->assertNotType( "bool", $sxe );
68 - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
69 - }
70 -
71 - function testApiLoginNoName() {
72 - global $wgServerName, $wgServer;
73 -
74 - if ( !isset( $wgServerName ) || !isset( $wgServer ) ) {
75 - $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
76 - 'be set in LocalSettings.php' );
77 - }
78 - $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
79 - array( "postData" => array(
80 - "lgname" => "",
81 - "lgpassword" => self::$passWord ) ) );
82 - libxml_use_internal_errors( true );
83 - $sxe = simplexml_load_string( $resp );
84 - $this->assertNotType( "bool", $sxe );
85 - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
86 - $a = $sxe->login[0]->attributes()->result;
87 - $this->assertEquals( ' result="NoName"', $a->asXML() );
88 - }
89 -
90 - function testApiLoginBadPass() {
91 - global $wgServerName, $wgServer;
92 -
93 - if ( !isset( $wgServerName ) || !isset( $wgServer ) ) {
94 - $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
95 - 'be set in LocalSettings.php' );
96 - }
97 - $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
98 - array( "postData" => array(
99 - "lgname" => self::$userName,
100 - "lgpassword" => "bad" ) ) );
101 - libxml_use_internal_errors( true );
102 - $sxe = simplexml_load_string( $resp );
103 - $this->assertNotType( "bool", $sxe );
104 - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
105 - $a = $sxe->login[0]->attributes()->result[0];
106 - $this->assertEquals( ' result="NeedToken"', $a->asXML() );
107 -
108 - $token = (string)$sxe->login[0]->attributes()->token;
109 -
110 - $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
111 - array( "postData" => array(
112 - "lgtoken" => $token,
113 - "lgname" => self::$userName,
114 - "lgpassword" => "bad" ) ) );
115 -
116 -
117 - $sxe = simplexml_load_string( $resp );
118 - $this->assertNotType( "bool", $sxe );
119 - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
120 - $a = $sxe->login[0]->attributes()->result[0];
121 -
122 - $this->assertEquals( ' result="NeedToken"', $a->asXML() );
123 - }
124 -
125 - function testApiLoginGoodPass() {
126 - global $wgServerName, $wgServer;
127 -
128 - if ( !isset( $wgServerName ) || !isset( $wgServer ) ) {
129 - $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
130 - 'be set in LocalSettings.php' );
131 - }
132 - $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml",
133 - array( "method" => "POST",
134 - "postData" => array(
135 - "lgname" => self::$userName,
136 - "lgpassword" => self::$passWord ) ) );
137 - $req->execute();
138 -
139 - libxml_use_internal_errors( true );
140 - $sxe = simplexml_load_string( $req->getContent() );
141 - $this->assertNotType( "bool", $sxe );
142 - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
143 -
144 - $a = $sxe->login[0]->attributes()->result[0];
145 - $this->assertEquals( ' result="NeedToken"', $a->asXML() );
146 - $token = (string)$sxe->login[0]->attributes()->token;
147 -
148 - $req->setData( array(
149 - "lgtoken" => $token,
150 - "lgname" => self::$userName,
151 - "lgpassword" => self::$passWord ) );
152 - $req->execute();
153 -
154 - $sxe = simplexml_load_string( $req->getContent() );
155 -
156 - $this->assertNotType( "bool", $sxe );
157 - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
158 - $a = $sxe->login[0]->attributes()->result[0];
159 -
160 - $this->assertEquals( ' result="Success"', $a->asXML() );
161 - }
162 -
163 - function testApiGotCookie() {
164 - global $wgServerName, $wgServer, $wgScriptPath;
165 -
166 - if ( !isset( $wgServerName ) || !isset( $wgServer ) ) {
167 - $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
168 - 'be set in LocalSettings.php' );
169 - }
170 - $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml",
171 - array( "method" => "POST",
172 - "postData" => array(
173 - "lgname" => self::$userName,
174 - "lgpassword" => self::$passWord ) ) );
175 - $req->execute();
176 -
177 - libxml_use_internal_errors( true );
178 - $sxe = simplexml_load_string( $req->getContent() );
179 - $this->assertNotType( "bool", $sxe );
180 - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
181 -
182 - $a = $sxe->login[0]->attributes()->result[0];
183 - $this->assertEquals( ' result="NeedToken"', $a->asXML() );
184 - $token = (string)$sxe->login[0]->attributes()->token;
185 -
186 - $req->setData( array(
187 - "lgtoken" => $token,
188 - "lgname" => self::$userName,
189 - "lgpassword" => self::$passWord ) );
190 - $req->execute();
191 -
192 - $cj = $req->getCookieJar();
193 - $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/',
194 - $cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ) );
195 -
196 -
197 - return $cj;
198 - }
199 -
200 - /**
201 - * @depends testApiGotCookie
202 - */
203 - function testApiListPages( CookieJar $cj ) {
204 - $this->markTestIncomplete( "Not done with this yet" );
205 - global $wgServerName, $wgServer;
206 -
207 - if ( $wgServerName == "localhost" || $wgServer == "http://localhost" ) {
208 - $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
209 - 'be set in LocalSettings.php' );
210 - }
211 - $req = HttpRequest::factory( self::$apiUrl . "?action=query&format=xml&prop=revisions&" .
212 - "titles=Main%20Page&rvprop=timestamp|user|comment|content" );
213 - $req->setCookieJar( $cj );
214 - $req->execute();
215 - libxml_use_internal_errors( true );
216 - $sxe = simplexml_load_string( $req->getContent() );
217 - $this->assertNotType( "bool", $sxe );
218 - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
219 - $a = $sxe->query[0]->pages[0]->page[0]->attributes();
220 - }
221 -}
Index: trunk/phase3/maintenance/tests/ImageFunctionsTest.php
@@ -1,48 +0,0 @@
2 -<?php
3 -
4 -class ImageFunctionsTest extends PHPUnit_Framework_TestCase {
5 - function testFitBoxWidth() {
6 - $vals = array(
7 - array(
8 - 'width' => 50,
9 - 'height' => 50,
10 - 'tests' => array(
11 - 50 => 50,
12 - 17 => 17,
13 - 18 => 18 ) ),
14 - array(
15 - 'width' => 366,
16 - 'height' => 300,
17 - 'tests' => array(
18 - 50 => 61,
19 - 17 => 21,
20 - 18 => 22 ) ),
21 - array(
22 - 'width' => 300,
23 - 'height' => 366,
24 - 'tests' => array(
25 - 50 => 41,
26 - 17 => 14,
27 - 18 => 15 ) ),
28 - array(
29 - 'width' => 100,
30 - 'height' => 400,
31 - 'tests' => array(
32 - 50 => 12,
33 - 17 => 4,
34 - 18 => 4 ) ) );
35 - foreach ( $vals as $row ) {
36 - extract( $row );
37 - foreach ( $tests as $max => $expected ) {
38 - $y = round( $expected * $height / $width );
39 - $result = wfFitBoxWidth( $width, $height, $max );
40 - $y2 = round( $result * $height / $width );
41 - $this->assertEquals( $expected,
42 - $result,
43 - "($width, $height, $max) wanted: {$expected}x$y, got: {$result}x$y2" );
44 - }
45 - }
46 - }
47 -}
48 -
49 -
Index: trunk/phase3/maintenance/tests/SearchDbTest.php
@@ -1,31 +0,0 @@
2 -<?php
3 -class SearchDbTest extends SearchEngineTest {
4 - var $db;
5 -
6 - function setUp() {
7 - $this->db = wfGetDB( DB_MASTER );
8 - if ( !$this->db ) {
9 - $this->markTestIncomplete( "Can't find a database to test with." );
10 - }
11 -
12 - $GLOBALS['wgContLang'] = new Language;
13 - $this->insertSearchData();
14 -
15 - $this->insertSearchData();
16 - $searchType = preg_replace( "/Database/", "Search",
17 - get_class( $this->db ) );
18 - $this->search = new $searchType( $this->db );
19 - }
20 -
21 - function tearDown() {
22 - $this->removeSearchData();
23 - if ( !is_null( $this->db ) ) {
24 - wfGetLB()->closeConnecton( $this->db );
25 - }
26 - unset( $this->db );
27 - unset( $this->search );
28 - $GLOBALS['wgContLang'] = null;
29 - }
30 -}
31 -
32 -
Index: trunk/phase3/maintenance/tests/LanguageConverterTest.php
@@ -1,150 +0,0 @@
2 -<?php
3 -
4 -class LanguageConverterTest extends PHPUnit_Framework_TestCase {
5 - protected $lang = null;
6 - protected $lc = null;
7 -
8 - function setUp() {
9 - global $wgMemc, $wgRequest, $wgUser, $wgContLang;
10 -
11 - $wgUser = new User;
12 - $wgRequest = new FauxRequest( array() );
13 - $wgMemc = new FakeMemCachedClient;
14 - $wgContLang = Language::factory( 'tg' );
15 - $this->lang = new LanguageTest();
16 - $this->lc = new TestConverter( $this->lang, 'tg',
17 - array( 'tg', 'tg-latn' ) );
18 - }
19 -
20 - function tearDown() {
21 - global $wgMemc, $wgContLang;
22 - unset( $wgMemc );
23 - unset( $this->lc );
24 - unset( $this->lang );
25 - $wgContLang = null;
26 - }
27 -
28 - function testGetPreferredVariantDefaults() {
29 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
30 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, true ) );
31 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, false ) );
32 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, true ) );
33 - }
34 -
35 - function testGetPreferredVariantHeaders() {
36 - global $wgRequest;
37 - $wgRequest->setHeader( 'Accept-Language', 'tg-latn' );
38 -
39 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
40 - $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( false, true ) );
41 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, false ) );
42 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, true ) );
43 - }
44 -
45 - function testGetPreferredVariantHeaderWeight() {
46 - global $wgRequest;
47 - $wgRequest->setHeader( 'Accept-Language', 'tg;q=1' );
48 -
49 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
50 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, true ) );
51 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, false ) );
52 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, true ) );
53 - }
54 -
55 - function testGetPreferredVariantHeaderWeight2() {
56 - global $wgRequest;
57 - $wgRequest->setHeader( 'Accept-Language', 'tg-latn;q=1' );
58 -
59 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
60 - $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( false, true ) );
61 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, false ) );
62 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, true ) );
63 - }
64 -
65 - function testGetPreferredVariantHeaderMulti() {
66 - global $wgRequest;
67 - $wgRequest->setHeader( 'Accept-Language', 'en, tg-latn;q=1' );
68 -
69 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
70 - $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( false, true ) );
71 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, false ) );
72 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, true ) );
73 - }
74 -
75 - function testGetPreferredVariantUserOption() {
76 - global $wgUser;
77 -
78 - $wgUser = new User;
79 - $wgUser->setId( 1 );
80 - $wgUser->mDataLoaded = true;
81 - $wgUser->setOption( 'variant', 'tg-latn' );
82 -
83 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
84 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, true ) );
85 - $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( true, false ) );
86 - $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( true, true ) );
87 - }
88 -
89 - function testGetPreferredVariantHeaderUserVsUrl() {
90 - global $wgRequest, $wgUser, $wgContLang;
91 -
92 - $wgContLang = Language::factory( 'tg-latn' );
93 - $wgRequest->setVal( 'variant', 'tg' );
94 - $wgUser = User::newFromId( "admin" );
95 - $wgUser->setId( 1 );
96 - $wgUser->setOption( 'variant', 'tg-latn' ); // The user's data is ignored
97 - // because the variant is set in the URL.
98 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, false ) );
99 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, true ) );
100 - }
101 -
102 -
103 - function testGetPreferredVariantDefaultLanguageVariant() {
104 - global $wgDefaultLanguageVariant;
105 -
106 - $wgDefaultLanguageVariant = 'tg-latn';
107 - $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( false, false ) );
108 - $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( false, true ) );
109 - $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( true, false ) );
110 - $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( true, true ) );
111 - }
112 -
113 - function testGetPreferredVariantDefaultLanguageVsUrlVariant() {
114 - global $wgDefaultLanguageVariant, $wgRequest, $wgContLang;
115 -
116 - $wgContLang = Language::factory( 'tg-latn' );
117 - $wgDefaultLanguageVariant = 'tg';
118 - $wgRequest->setVal( 'variant', null );
119 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
120 - $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, true ) );
121 - $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( true, false ) );
122 - $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( true, true ) );
123 - }
124 -}
125 -
126 -/**
127 - * Test converter (from Tajiki to latin orthography)
128 - */
129 -class TestConverter extends LanguageConverter {
130 - private $table = array(
131 - 'б' => 'b',
132 - 'в' => 'v',
133 - 'г' => 'g',
134 - );
135 -
136 - function loadDefaultTables() {
137 - $this->mTables = array(
138 - 'tg-latn' => new ReplacementArray( $this->table ),
139 - 'tg' => new ReplacementArray()
140 - );
141 - }
142 -
143 -}
144 -
145 -class LanguageTest extends Language {
146 - function __construct() {
147 - parent::__construct();
148 - $variants = array( 'tg', 'tg-latn' );
149 - $this->mConverter = new TestConverter( $this, 'tg', $variants );
150 - }
151 -}
Index: trunk/phase3/maintenance/tests/bootstrap.php
@@ -1,6 +0,0 @@
2 -<?php
3 -
4 -if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
5 - echo "Please run PHPUnit via maintenance/tests/phpunit\n";
6 - exit( 1 );
7 -}
Index: trunk/phase3/maintenance/tests/phpunit/Makefile
@@ -0,0 +1,16 @@
 2+.PHONY: help test phpunit install
 3+
 4+all test: phpunit
 5+
 6+phpunit:
 7+ phpunit --configuration suite.xml
 8+
 9+install:
 10+ pear channel-discover pear.phpunit.de
 11+ pear install phpunit/PHPUnit
 12+
 13+help:
 14+ # Targets:
 15+ # phpunit (default) Run all the tests with phpunit
 16+ # install Install PHPUnit from phpunit.de
 17+ # help You're looking at it!
\ No newline at end of file
Index: trunk/phase3/maintenance/tests/phpunit/README
@@ -0,0 +1,29 @@
 2+== MediaWiki PHPUnit Tests ==
 3+
 4+Some quickie unit tests done with the PHPUnit testing framework. To run the
 5+test suite, run 'make test' in this (maintenance/tests/phpunit) directory.
 6+
 7+=== Installation ===
 8+
 9+PHPUnit is no longer maintained by PEAR. To get the current version of
 10+PHPUnit, first uninstall any old version of PHPUnit or PHPUnit2 from PEAR,
 11+then install the current version from phpunit.de like this:
 12+
 13+ pear channel-discover pear.phpunit.de
 14+ pear install phpunit/PHPUnit
 15+
 16+You also may wish to install this via your normal package mechanism:
 17+
 18+ aptitude install phpunit
 19+- or -
 20+ yum install phpunit
 21+
 22+=== Notes ===
 23+
 24+* Label currently broken tests in the group Broken and they will not be run
 25+by phpunit. You can add them to the group by putting the following comment at
 26+the top of the file:
 27+ /**
 28+ * @group Broken
 29+ */
 30+* Need to fix some broken tests
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/tests/phpunit/README
___________________________________________________________________
Added: svn:keywords
131 + Author Date Id Revision
Added: svn:eol-style
232 + native
Index: trunk/phase3/maintenance/tests/phpunit/bootstrap.php
@@ -0,0 +1,76 @@
 2+<?php
 3+/**
 4+ * Bootstrapping for MediaWiki PHPUnit tests
 5+ *
 6+ * @file
 7+ */
 8+
 9+/* Configuration */
 10+
 11+// This file is not included in the global scope, but rather within a function, so we must global anything we need to
 12+// have access to in the global scope explicitly
 13+global $wgCommandLineMode, $IP, $optionsWithArgs;
 14+
 15+// Evaluate the include path relative to this file
 16+$IP = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
 17+
 18+// Set a flag which can be used to detect when other scripts have been entered through this entry point or not
 19+define( 'MW_PHPUNIT_TEST', true );
 20+
 21+// Start up MediaWiki in command-line mode
 22+require_once( "$IP/maintenance/commandLine.inc" );
 23+
 24+// Assume UTC for testing purposes
 25+$wgLocaltimezone = 'UTC';
 26+
 27+// To prevent tests from failing with SQLite, we need to turn database caching off
 28+global $wgCaches;
 29+$wgCaches[CACHE_DB] = false;
 30+
 31+// Output a notice when running with older versions of PHPUnit
 32+if ( !version_compare( PHPUnit_Runner_Version::id(), "3.4.1", ">" ) ) {
 33+ echo <<<EOF
 34+********************************************************************************
 35+
 36+These tests run best with version PHPUnit 3.4.2 or better. Earlier versions may
 37+show failures because earlier versions of PHPUnit do not properly implement
 38+dependencies.
 39+
 40+********************************************************************************
 41+
 42+EOF;
 43+}
 44+
 45+/* Classes */
 46+
 47+abstract class MediaWikiTestSetup extends PHPUnit_Framework_TestCase {
 48+
 49+ protected function buildTestDatabase( $tables ) {
 50+ global $wgDBprefix;
 51+
 52+ $db = wfGetDB( DB_MASTER );
 53+ $oldTableNames = array();
 54+ foreach ( $tables as $table )
 55+ $oldTableNames[$table] = $db->tableName( $table );
 56+ if ( $db->getType() == 'oracle' ) {
 57+ $wgDBprefix = 'pt_';
 58+ } else {
 59+ $wgDBprefix = 'parsertest_';
 60+ }
 61+
 62+ $db->tablePrefix( $wgDBprefix );
 63+
 64+ if ( $db->isOpen() ) {
 65+ foreach ( $tables as $tbl ) {
 66+ $newTableName = $db->tableName( $tbl );
 67+ $tableName = $oldTableNames[$tbl];
 68+ $db->query( "DROP TABLE IF EXISTS $newTableName", __METHOD__ );
 69+ $db->duplicateTableStructure( $tableName, $newTableName, __METHOD__ );
 70+ }
 71+ return $db;
 72+ } else {
 73+ // Something amiss
 74+ return null;
 75+ }
 76+ }
 77+}
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/tests/phpunit/bootstrap.php
___________________________________________________________________
Added: svn:eol-style
178 + native
Index: trunk/phase3/maintenance/tests/phpunit/TODO
@@ -0,0 +1,11 @@
 2+== Things To Do ==
 3+
 4+* Most of the tests are named poorly; naming should describe a use case in story-like language, not simply identify the
 5+unit under test. An example would be the difference between testCalculate and testAddingIntegersTogetherWorks.
 6+* Many of the tests make multiple assertions, and are thus not unitary tests. By using data-providers and more use-case
 7+oriented test selection nearly all of these cases can be easily resolved.
 8+* Some of the test files are either incorrectly named or in the wrong folder. Tests should be organized in a mirrored
 9+structure to the source they are testing, and named the same, with the exception of the word "Test" at the end.
 10+* Shared set-up code or base classes are present, but usually named improperly or appear to be poorly factored. Support
 11+code should share as much of the same naming as the code it's supporting, and test and test-case depenencies should be
 12+considered to resolve other shared needs.
\ No newline at end of file
Index: trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php
@@ -0,0 +1,349 @@
 2+<?php
 3+
 4+
 5+class UploadFromUrlTest extends ApiTestSetup {
 6+
 7+ public function setUp() {
 8+ global $wgEnableUploads, $wgAllowCopyUploads;
 9+ parent::setup();
 10+
 11+ $wgEnableUploads = true;
 12+ $wgAllowCopyUploads = true;
 13+ wfSetupSession();
 14+
 15+ ini_set( 'log_errors', 1 );
 16+ ini_set( 'error_reporting', 1 );
 17+ ini_set( 'display_errors', 1 );
 18+
 19+ if ( wfLocalFile( 'UploadFromUrlTest.png' )->exists() ) {
 20+ $this->deleteFile( 'UploadFromUrlTest.png' );
 21+ }
 22+ }
 23+
 24+ protected function doApiRequest( $params ) {
 25+ $sessionId = session_id();
 26+ session_write_close();
 27+
 28+ $req = new FauxRequest( $params, true, $_SESSION );
 29+ $module = new ApiMain( $req, true );
 30+ $module->execute();
 31+
 32+ wfSetupSession( $sessionId );
 33+ return array( $module->getResultData(), $req );
 34+ }
 35+
 36+ /**
 37+ * Ensure that the job queue is empty before continuing
 38+ */
 39+ public function testClearQueue() {
 40+ while ( $job = Job::pop() ) { }
 41+ $this->assertFalse( $job );
 42+ }
 43+
 44+ /**
 45+ * @todo Document why we test login, since the $wgUser hack used doesn't
 46+ * require login
 47+ */
 48+ public function testLogin() {
 49+ $data = $this->doApiRequest( array(
 50+ 'action' => 'login',
 51+ 'lgname' => self::$userName,
 52+ 'lgpassword' => self::$passWord ) );
 53+ $this->assertArrayHasKey( "login", $data[0] );
 54+ $this->assertArrayHasKey( "result", $data[0]['login'] );
 55+ $this->assertEquals( "NeedToken", $data[0]['login']['result'] );
 56+ $token = $data[0]['login']['token'];
 57+
 58+ $data = $this->doApiRequest( array(
 59+ 'action' => 'login',
 60+ "lgtoken" => $token,
 61+ "lgname" => self::$userName,
 62+ "lgpassword" => self::$passWord ) );
 63+
 64+ $this->assertArrayHasKey( "login", $data[0] );
 65+ $this->assertArrayHasKey( "result", $data[0]['login'] );
 66+ $this->assertEquals( "Success", $data[0]['login']['result'] );
 67+ $this->assertArrayHasKey( 'lgtoken', $data[0]['login'] );
 68+
 69+ return $data;
 70+ }
 71+
 72+ /**
 73+ * @depends testLogin
 74+ * @depends testClearQueue
 75+ */
 76+ public function testSetupUrlDownload( $data ) {
 77+ $token = self::$user->editToken();
 78+ $exception = false;
 79+
 80+ try {
 81+ $this->doApiRequest( array(
 82+ 'action' => 'upload',
 83+ ) );
 84+ } catch ( UsageException $e ) {
 85+ $exception = true;
 86+ $this->assertEquals( "The token parameter must be set", $e->getMessage() );
 87+ }
 88+ $this->assertTrue( $exception, "Got exception" );
 89+
 90+ $exception = false;
 91+ try {
 92+ $this->doApiRequest( array(
 93+ 'action' => 'upload',
 94+ 'token' => $token,
 95+ ), $data );
 96+ } catch ( UsageException $e ) {
 97+ $exception = true;
 98+ $this->assertEquals( "One of the parameters sessionkey, file, url, statuskey is required",
 99+ $e->getMessage() );
 100+ }
 101+ $this->assertTrue( $exception, "Got exception" );
 102+
 103+ $exception = false;
 104+ try {
 105+ $this->doApiRequest( array(
 106+ 'action' => 'upload',
 107+ 'url' => 'http://www.example.com/test.png',
 108+ 'token' => $token,
 109+ ), $data );
 110+ } catch ( UsageException $e ) {
 111+ $exception = true;
 112+ $this->assertEquals( "The filename parameter must be set", $e->getMessage() );
 113+ }
 114+ $this->assertTrue( $exception, "Got exception" );
 115+
 116+ self::$user->removeGroup( 'sysop' );
 117+ $exception = false;
 118+ try {
 119+ $this->doApiRequest( array(
 120+ 'action' => 'upload',
 121+ 'url' => 'http://www.example.com/test.png',
 122+ 'filename' => 'UploadFromUrlTest.png',
 123+ 'token' => $token,
 124+ ), $data );
 125+ } catch ( UsageException $e ) {
 126+ $exception = true;
 127+ $this->assertEquals( "Permission denied", $e->getMessage() );
 128+ }
 129+ $this->assertTrue( $exception, "Got exception" );
 130+
 131+ self::$user->addGroup( '*' );
 132+ self::$user->addGroup( 'sysop' );
 133+ $exception = false;
 134+ $data = $this->doApiRequest( array(
 135+ 'action' => 'upload',
 136+ 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
 137+ 'asyncdownload' => 1,
 138+ 'filename' => 'UploadFromUrlTest.png',
 139+ 'token' => $token,
 140+ ), $data );
 141+
 142+ $this->assertEquals( $data[0]['upload']['result'], 'Queued', 'Queued upload' );
 143+
 144+ $job = Job::pop();
 145+ $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ), 'Queued upload inserted' );
 146+ }
 147+
 148+ /**
 149+ * @depends testLogin
 150+ * @depends testClearQueue
 151+ */
 152+ public function testAsyncUpload( $data ) {
 153+ $token = self::$user->editToken();
 154+
 155+ self::$user->addGroup( 'users' );
 156+
 157+ $data = $this->doAsyncUpload( $token, true );
 158+ $this->assertEquals( $data[0]['upload']['result'], 'Success' );
 159+ $this->assertEquals( $data[0]['upload']['filename'], 'UploadFromUrlTest.png' );
 160+ $this->assertTrue( wfLocalFile( $data[0]['upload']['filename'] )->exists() );
 161+
 162+ $this->deleteFile( 'UploadFromUrlTest.png' );
 163+
 164+ return $data;
 165+ }
 166+
 167+ /**
 168+ * @depends testLogin
 169+ * @depends testClearQueue
 170+ */
 171+ public function testAsyncUploadWarning( $data ) {
 172+ $token = self::$user->editToken();
 173+
 174+ self::$user->addGroup( 'users' );
 175+
 176+
 177+ $data = $this->doAsyncUpload( $token );
 178+
 179+ $this->assertEquals( $data[0]['upload']['result'], 'Warning' );
 180+ $this->assertTrue( isset( $data[0]['upload']['sessionkey'] ) );
 181+
 182+ $data = $this->doApiRequest( array(
 183+ 'action' => 'upload',
 184+ 'sessionkey' => $data[0]['upload']['sessionkey'],
 185+ 'filename' => 'UploadFromUrlTest.png',
 186+ 'ignorewarnings' => 1,
 187+ 'token' => $token,
 188+ ) );
 189+ $this->assertEquals( $data[0]['upload']['result'], 'Success' );
 190+ $this->assertEquals( $data[0]['upload']['filename'], 'UploadFromUrlTest.png' );
 191+ $this->assertTrue( wfLocalFile( $data[0]['upload']['filename'] )->exists() );
 192+
 193+ $this->deleteFile( 'UploadFromUrlTest.png' );
 194+
 195+ return $data;
 196+ }
 197+
 198+ /**
 199+ * @depends testLogin
 200+ * @depends testClearQueue
 201+ */
 202+ public function testSyncDownload( $data ) {
 203+ $token = self::$user->editToken();
 204+
 205+ $job = Job::pop();
 206+ $this->assertFalse( $job, 'Starting with an empty jobqueue' );
 207+
 208+ self::$user->addGroup( 'users' );
 209+ $data = $this->doApiRequest( array(
 210+ 'action' => 'upload',
 211+ 'filename' => 'UploadFromUrlTest.png',
 212+ 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
 213+ 'ignorewarnings' => true,
 214+ 'token' => $token,
 215+ ), $data );
 216+
 217+ $job = Job::pop();
 218+ $this->assertFalse( $job );
 219+
 220+ $this->assertEquals( 'Success', $data[0]['upload']['result'] );
 221+ $this->deleteFile( 'UploadFromUrlTest.png' );
 222+
 223+ return $data;
 224+ }
 225+
 226+ public function testLeaveMessage() {
 227+ $token = self::$user->editToken();
 228+
 229+ $talk = self::$user->getTalkPage();
 230+ if ( $talk->exists() ) {
 231+ $a = new Article( $talk );
 232+ $a->doDeleteArticle( '' );
 233+ }
 234+
 235+ $this->assertFalse( (bool)$talk->getArticleId( GAID_FOR_UPDATE ), 'User talk does not exist' );
 236+
 237+ $data = $this->doApiRequest( array(
 238+ 'action' => 'upload',
 239+ 'filename' => 'UploadFromUrlTest.png',
 240+ 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
 241+ 'asyncdownload' => 1,
 242+ 'token' => $token,
 243+ 'leavemessage' => 1,
 244+ 'ignorewarnings' => 1,
 245+ ) );
 246+
 247+ $job = Job::pop();
 248+ $job->run();
 249+
 250+ $this->assertTrue( wfLocalFile( 'UploadFromUrlTest.png' )->exists() );
 251+ $this->assertTrue( (bool)$talk->getArticleId( GAID_FOR_UPDATE ), 'User talk exists' );
 252+
 253+ $this->deleteFile( 'UploadFromUrlTest.png' );
 254+
 255+ $talkRev = Revision::newFromTitle( $talk );
 256+ $talkSize = $talkRev->getSize();
 257+
 258+ $exception = false;
 259+ try {
 260+ $data = $this->doApiRequest( array(
 261+ 'action' => 'upload',
 262+ 'filename' => 'UploadFromUrlTest.png',
 263+ 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
 264+ 'asyncdownload' => 1,
 265+ 'token' => $token,
 266+ 'leavemessage' => 1,
 267+ ) );
 268+ } catch ( UsageException $e ) {
 269+ $exception = true;
 270+ $this->assertEquals( 'Using leavemessage without ignorewarnings is not supported', $e->getMessage() );
 271+ }
 272+ $this->assertTrue( $exception );
 273+
 274+ $job = Job::pop();
 275+ $this->assertFalse( $job );
 276+
 277+ return;
 278+
 279+ // Broken until using leavemessage with ignorewarnings is supported
 280+ $job->run();
 281+
 282+ $this->assertFalse( wfLocalFile( 'UploadFromUrlTest.png' )->exists() );
 283+
 284+ $talkRev = Revision::newFromTitle( $talk );
 285+ $this->assertTrue( $talkRev->getSize() > $talkSize, 'New message left' );
 286+
 287+
 288+ }
 289+
 290+ /**
 291+ * Helper function to perform an async upload, execute the job and fetch
 292+ * the status
 293+ *
 294+ * @return array The result of action=upload&statuskey=key
 295+ */
 296+ private function doAsyncUpload( $token, $ignoreWarnings = false, $leaveMessage = false ) {
 297+ $params = array(
 298+ 'action' => 'upload',
 299+ 'filename' => 'UploadFromUrlTest.png',
 300+ 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
 301+ 'asyncdownload' => 1,
 302+ 'token' => $token,
 303+ );
 304+ if ( $ignoreWarnings ) {
 305+ $params['ignorewarnings'] = 1;
 306+ }
 307+ if ( $leaveMessage ) {
 308+ $params['leavemessage'] = 1;
 309+ }
 310+
 311+ $data = $this->doApiRequest( $params );
 312+ $this->assertEquals( $data[0]['upload']['result'], 'Queued' );
 313+ $this->assertTrue( isset( $data[0]['upload']['statuskey'] ) );
 314+ $statusKey = $data[0]['upload']['statuskey'];
 315+
 316+ $job = Job::pop();
 317+ $this->assertEquals( 'UploadFromUrlJob', get_class( $job ) );
 318+
 319+ $status = $job->run();
 320+ $this->assertTrue( $status );
 321+
 322+ $data = $this->doApiRequest( array(
 323+ 'action' => 'upload',
 324+ 'statuskey' => $statusKey,
 325+ 'token' => $token,
 326+ ) );
 327+
 328+ return $data;
 329+ }
 330+
 331+
 332+ /**
 333+ *
 334+ */
 335+ protected function deleteFile( $name ) {
 336+ $t = Title::newFromText( $name, NS_FILE );
 337+ $this->assertTrue($t->exists(), "File '$name' exists");
 338+
 339+ if ( $t->exists() ) {
 340+ $file = wfFindFile( $name, array( 'ignoreRedirect' => true ) );
 341+ $empty = "";
 342+ FileDeleteForm::doDelete( $t, $file, $empty, "none", true );
 343+ $a = new Article ( $t );
 344+ $a->doDeleteArticle( "testing" );
 345+ }
 346+ $t = Title::newFromText( $name, NS_FILE );
 347+
 348+ $this->assertFalse($t->exists(), "File '$name' was deleted");
 349+ }
 350+ }
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php
___________________________________________________________________
Added: svn:eol-style
1351 + native
Added: svn:eol-syle
2352 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/SiteConfigurationTest.php
@@ -0,0 +1,311 @@
 2+<?php
 3+
 4+function getSiteParams( $conf, $wiki ) {
 5+ $site = null;
 6+ $lang = null;
 7+ foreach ( $conf->suffixes as $suffix ) {
 8+ if ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
 9+ $site = $suffix;
 10+ $lang = substr( $wiki, 0, -strlen( $suffix ) );
 11+ break;
 12+ }
 13+ }
 14+ return array(
 15+ 'suffix' => $site,
 16+ 'lang' => $lang,
 17+ 'params' => array(
 18+ 'lang' => $lang,
 19+ 'site' => $site,
 20+ 'wiki' => $wiki,
 21+ ),
 22+ 'tags' => array( 'tag' ),
 23+ );
 24+}
 25+
 26+class SiteConfigurationTest extends PHPUnit_Framework_TestCase {
 27+ var $mConf;
 28+
 29+ function setUp() {
 30+ $this->mConf = new SiteConfiguration;
 31+
 32+ $this->mConf->suffixes = array( 'wiki' );
 33+ $this->mConf->wikis = array( 'enwiki', 'dewiki', 'frwiki' );
 34+ $this->mConf->settings = array(
 35+ 'simple' => array(
 36+ 'wiki' => 'wiki',
 37+ 'tag' => 'tag',
 38+ 'enwiki' => 'enwiki',
 39+ 'dewiki' => 'dewiki',
 40+ 'frwiki' => 'frwiki',
 41+ ),
 42+
 43+ 'fallback' => array(
 44+ 'default' => 'default',
 45+ 'wiki' => 'wiki',
 46+ 'tag' => 'tag',
 47+ ),
 48+
 49+ 'params' => array(
 50+ 'default' => '$lang $site $wiki',
 51+ ),
 52+
 53+ '+global' => array(
 54+ 'wiki' => array(
 55+ 'wiki' => 'wiki',
 56+ ),
 57+ 'tag' => array(
 58+ 'tag' => 'tag',
 59+ ),
 60+ 'enwiki' => array(
 61+ 'enwiki' => 'enwiki',
 62+ ),
 63+ 'dewiki' => array(
 64+ 'dewiki' => 'dewiki',
 65+ ),
 66+ 'frwiki' => array(
 67+ 'frwiki' => 'frwiki',
 68+ ),
 69+ ),
 70+
 71+ 'merge' => array(
 72+ '+wiki' => array(
 73+ 'wiki' => 'wiki',
 74+ ),
 75+ '+tag' => array(
 76+ 'tag' => 'tag',
 77+ ),
 78+ 'default' => array(
 79+ 'default' => 'default',
 80+ ),
 81+ '+enwiki' => array(
 82+ 'enwiki' => 'enwiki',
 83+ ),
 84+ '+dewiki' => array(
 85+ 'dewiki' => 'dewiki',
 86+ ),
 87+ '+frwiki' => array(
 88+ 'frwiki' => 'frwiki',
 89+ ),
 90+ ),
 91+ );
 92+
 93+ $GLOBALS['global'] = array( 'global' => 'global' );
 94+ }
 95+
 96+
 97+ function testSiteFromDB() {
 98+ $this->assertEquals(
 99+ array( 'wikipedia', 'en' ),
 100+ $this->mConf->siteFromDB( 'enwiki' ),
 101+ 'siteFromDB()'
 102+ );
 103+ $this->assertEquals(
 104+ array( 'wikipedia', '' ),
 105+ $this->mConf->siteFromDB( 'wiki' ),
 106+ 'siteFromDB() on a suffix'
 107+ );
 108+ $this->assertEquals(
 109+ array( null, null ),
 110+ $this->mConf->siteFromDB( 'wikien' ),
 111+ 'siteFromDB() on a non-existing wiki'
 112+ );
 113+
 114+ $this->mConf->suffixes = array( 'wiki', '' );
 115+ $this->assertEquals(
 116+ array( '', 'wikien' ),
 117+ $this->mConf->siteFromDB( 'wikien' ),
 118+ 'siteFromDB() on a non-existing wiki (2)'
 119+ );
 120+ }
 121+
 122+ function testGetLocalDatabases() {
 123+ $this->assertEquals(
 124+ array( 'enwiki', 'dewiki', 'frwiki' ),
 125+ $this->mConf->getLocalDatabases(),
 126+ 'getLocalDatabases()'
 127+ );
 128+ }
 129+
 130+ function testGet() {
 131+ $this->assertEquals(
 132+ 'enwiki',
 133+ $this->mConf->get( 'simple', 'enwiki', 'wiki' ),
 134+ 'get(): simple setting on an existing wiki'
 135+ );
 136+ $this->assertEquals(
 137+ 'dewiki',
 138+ $this->mConf->get( 'simple', 'dewiki', 'wiki' ),
 139+ 'get(): simple setting on an existing wiki (2)'
 140+ );
 141+ $this->assertEquals(
 142+ 'frwiki',
 143+ $this->mConf->get( 'simple', 'frwiki', 'wiki' ),
 144+ 'get(): simple setting on an existing wiki (3)'
 145+ );
 146+ $this->assertEquals(
 147+ 'wiki',
 148+ $this->mConf->get( 'simple', 'wiki', 'wiki' ),
 149+ 'get(): simple setting on an suffix'
 150+ );
 151+ $this->assertEquals(
 152+ 'wiki',
 153+ $this->mConf->get( 'simple', 'eswiki', 'wiki' ),
 154+ 'get(): simple setting on an non-existing wiki'
 155+ );
 156+
 157+ $this->assertEquals(
 158+ 'wiki',
 159+ $this->mConf->get( 'fallback', 'enwiki', 'wiki' ),
 160+ 'get(): fallback setting on an existing wiki'
 161+ );
 162+ $this->assertEquals(
 163+ 'tag',
 164+ $this->mConf->get( 'fallback', 'dewiki', 'wiki', array(), array( 'tag' ) ),
 165+ 'get(): fallback setting on an existing wiki (with wiki tag)'
 166+ );
 167+ $this->assertEquals(
 168+ 'wiki',
 169+ $this->mConf->get( 'fallback', 'wiki', 'wiki' ),
 170+ 'get(): fallback setting on an suffix'
 171+ );
 172+ $this->assertEquals(
 173+ 'wiki',
 174+ $this->mConf->get( 'fallback', 'wiki', 'wiki', array(), array( 'tag' ) ),
 175+ 'get(): fallback setting on an suffix (with wiki tag)'
 176+ );
 177+ $this->assertEquals(
 178+ 'wiki',
 179+ $this->mConf->get( 'fallback', 'eswiki', 'wiki' ),
 180+ 'get(): fallback setting on an non-existing wiki'
 181+ );
 182+ $this->assertEquals(
 183+ 'tag',
 184+ $this->mConf->get( 'fallback', 'eswiki', 'wiki', array(), array( 'tag' ) ),
 185+ 'get(): fallback setting on an non-existing wiki (with wiki tag)'
 186+ );
 187+
 188+ $common = array( 'wiki' => 'wiki', 'default' => 'default' );
 189+ $commonTag = array( 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' );
 190+ $this->assertEquals(
 191+ array( 'enwiki' => 'enwiki' ) + $common,
 192+ $this->mConf->get( 'merge', 'enwiki', 'wiki' ),
 193+ 'get(): merging setting on an existing wiki'
 194+ );
 195+ $this->assertEquals(
 196+ array( 'enwiki' => 'enwiki' ) + $commonTag,
 197+ $this->mConf->get( 'merge', 'enwiki', 'wiki', array(), array( 'tag' ) ),
 198+ 'get(): merging setting on an existing wiki (with tag)'
 199+ );
 200+ $this->assertEquals(
 201+ array( 'dewiki' => 'dewiki' ) + $common,
 202+ $this->mConf->get( 'merge', 'dewiki', 'wiki' ),
 203+ 'get(): merging setting on an existing wiki (2)'
 204+ );
 205+ $this->assertEquals(
 206+ array( 'dewiki' => 'dewiki' ) + $commonTag,
 207+ $this->mConf->get( 'merge', 'dewiki', 'wiki', array(), array( 'tag' ) ),
 208+ 'get(): merging setting on an existing wiki (2) (with tag)'
 209+ );
 210+ $this->assertEquals(
 211+ array( 'frwiki' => 'frwiki' ) + $common,
 212+ $this->mConf->get( 'merge', 'frwiki', 'wiki' ),
 213+ 'get(): merging setting on an existing wiki (3)'
 214+ );
 215+ $this->assertEquals(
 216+ array( 'frwiki' => 'frwiki' ) + $commonTag,
 217+ $this->mConf->get( 'merge', 'frwiki', 'wiki', array(), array( 'tag' ) ),
 218+ 'get(): merging setting on an existing wiki (3) (with tag)'
 219+ );
 220+ $this->assertEquals(
 221+ array( 'wiki' => 'wiki' ) + $common,
 222+ $this->mConf->get( 'merge', 'wiki', 'wiki' ),
 223+ 'get(): merging setting on an suffix'
 224+ );
 225+ $this->assertEquals(
 226+ array( 'wiki' => 'wiki' ) + $commonTag,
 227+ $this->mConf->get( 'merge', 'wiki', 'wiki', array(), array( 'tag' ) ),
 228+ 'get(): merging setting on an suffix (with tag)'
 229+ );
 230+ $this->assertEquals(
 231+ $common,
 232+ $this->mConf->get( 'merge', 'eswiki', 'wiki' ),
 233+ 'get(): merging setting on an non-existing wiki'
 234+ );
 235+ $this->assertEquals(
 236+ $commonTag,
 237+ $this->mConf->get( 'merge', 'eswiki', 'wiki', array(), array( 'tag' ) ),
 238+ 'get(): merging setting on an non-existing wiki (with tag)'
 239+ );
 240+ }
 241+
 242+ function testSiteFromDBWithCallback() {
 243+ $this->mConf->siteParamsCallback = 'getSiteParams';
 244+
 245+ $this->assertEquals(
 246+ array( 'wiki', 'en' ),
 247+ $this->mConf->siteFromDB( 'enwiki' ),
 248+ 'siteFromDB() with callback'
 249+ );
 250+ $this->assertEquals(
 251+ array( 'wiki', '' ),
 252+ $this->mConf->siteFromDB( 'wiki' ),
 253+ 'siteFromDB() with callback on a suffix'
 254+ );
 255+ $this->assertEquals(
 256+ array( null, null ),
 257+ $this->mConf->siteFromDB( 'wikien' ),
 258+ 'siteFromDB() with callback on a non-existing wiki'
 259+ );
 260+ }
 261+
 262+ function testParamReplacement() {
 263+ $this->mConf->siteParamsCallback = 'getSiteParams';
 264+
 265+ $this->assertEquals(
 266+ 'en wiki enwiki',
 267+ $this->mConf->get( 'params', 'enwiki', 'wiki' ),
 268+ 'get(): parameter replacement on an existing wiki'
 269+ );
 270+ $this->assertEquals(
 271+ 'de wiki dewiki',
 272+ $this->mConf->get( 'params', 'dewiki', 'wiki' ),
 273+ 'get(): parameter replacement on an existing wiki (2)'
 274+ );
 275+ $this->assertEquals(
 276+ 'fr wiki frwiki',
 277+ $this->mConf->get( 'params', 'frwiki', 'wiki' ),
 278+ 'get(): parameter replacement on an existing wiki (3)'
 279+ );
 280+ $this->assertEquals(
 281+ ' wiki wiki',
 282+ $this->mConf->get( 'params', 'wiki', 'wiki' ),
 283+ 'get(): parameter replacement on an suffix'
 284+ );
 285+ $this->assertEquals(
 286+ 'es wiki eswiki',
 287+ $this->mConf->get( 'params', 'eswiki', 'wiki' ),
 288+ 'get(): parameter replacement on an non-existing wiki'
 289+ );
 290+ }
 291+
 292+ function testGetAll() {
 293+ $this->mConf->siteParamsCallback = 'getSiteParams';
 294+
 295+ $getall = array(
 296+ 'simple' => 'enwiki',
 297+ 'fallback' => 'tag',
 298+ 'params' => 'en wiki enwiki',
 299+ 'global' => array( 'enwiki' => 'enwiki' ) + $GLOBALS['global'],
 300+ 'merge' => array( 'enwiki' => 'enwiki', 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' ),
 301+ );
 302+ $this->assertEquals( $getall, $this->mConf->getAll( 'enwiki' ), 'getAll()' );
 303+
 304+ $this->mConf->extractAllGlobals( 'enwiki', 'wiki' );
 305+
 306+ $this->assertEquals( $getall['simple'], $GLOBALS['simple'], 'extractAllGlobals(): simple setting' );
 307+ $this->assertEquals( $getall['fallback'], $GLOBALS['fallback'], 'extractAllGlobals(): fallback setting' );
 308+ $this->assertEquals( $getall['params'], $GLOBALS['params'], 'extractAllGlobals(): parameter replacement' );
 309+ $this->assertEquals( $getall['global'], $GLOBALS['global'], 'extractAllGlobals(): merging with global' );
 310+ $this->assertEquals( $getall['merge'], $GLOBALS['merge'], 'extractAllGlobals(): merging setting' );
 311+ }
 312+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/SiteConfigurationTest.php
___________________________________________________________________
Added: svn:eol-style
1313 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/RevisionTest.php
@@ -0,0 +1,114 @@
 2+<?php
 3+
 4+class RevisionTest extends PHPUnit_Framework_TestCase {
 5+ var $saveGlobals = array();
 6+
 7+ function setUp() {
 8+ global $wgContLang;
 9+ $wgContLang = Language::factory( 'en' );
 10+ $globalSet = array(
 11+ 'wgLegacyEncoding' => false,
 12+ 'wgCompressRevisions' => false,
 13+ 'wgInputEncoding' => 'utf-8',
 14+ 'wgOutputEncoding' => 'utf-8' );
 15+ foreach ( $globalSet as $var => $data ) {
 16+ $this->saveGlobals[$var] = $GLOBALS[$var];
 17+ $GLOBALS[$var] = $data;
 18+ }
 19+ }
 20+
 21+ function tearDown() {
 22+ foreach ( $this->saveGlobals as $var => $data ) {
 23+ $GLOBALS[$var] = $data;
 24+ }
 25+ }
 26+
 27+ function testGetRevisionText() {
 28+ $row = new stdClass;
 29+ $row->old_flags = '';
 30+ $row->old_text = 'This is a bunch of revision text.';
 31+ $this->assertEquals(
 32+ 'This is a bunch of revision text.',
 33+ Revision::getRevisionText( $row ) );
 34+ }
 35+
 36+ function testGetRevisionTextGzip() {
 37+ $row = new stdClass;
 38+ $row->old_flags = 'gzip';
 39+ $row->old_text = gzdeflate( 'This is a bunch of revision text.' );
 40+ $this->assertEquals(
 41+ 'This is a bunch of revision text.',
 42+ Revision::getRevisionText( $row ) );
 43+ }
 44+
 45+ function testGetRevisionTextUtf8Native() {
 46+ $row = new stdClass;
 47+ $row->old_flags = 'utf-8';
 48+ $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
 49+ $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
 50+ $this->assertEquals(
 51+ "Wiki est l'\xc3\xa9cole superieur !",
 52+ Revision::getRevisionText( $row ) );
 53+ }
 54+
 55+ function testGetRevisionTextUtf8Legacy() {
 56+ $row = new stdClass;
 57+ $row->old_flags = '';
 58+ $row->old_text = "Wiki est l'\xe9cole superieur !";
 59+ $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
 60+ $this->assertEquals(
 61+ "Wiki est l'\xc3\xa9cole superieur !",
 62+ Revision::getRevisionText( $row ) );
 63+ }
 64+
 65+ function testGetRevisionTextUtf8NativeGzip() {
 66+ $row = new stdClass;
 67+ $row->old_flags = 'gzip,utf-8';
 68+ $row->old_text = gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" );
 69+ $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
 70+ $this->assertEquals(
 71+ "Wiki est l'\xc3\xa9cole superieur !",
 72+ Revision::getRevisionText( $row ) );
 73+ }
 74+
 75+ function testGetRevisionTextUtf8LegacyGzip() {
 76+ $row = new stdClass;
 77+ $row->old_flags = 'gzip';
 78+ $row->old_text = gzdeflate( "Wiki est l'\xe9cole superieur !" );
 79+ $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
 80+ $this->assertEquals(
 81+ "Wiki est l'\xc3\xa9cole superieur !",
 82+ Revision::getRevisionText( $row ) );
 83+ }
 84+
 85+ function testCompressRevisionTextUtf8() {
 86+ $row = new stdClass;
 87+ $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
 88+ $row->old_flags = Revision::compressRevisionText( $row->old_text );
 89+ $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
 90+ "Flags should contain 'utf-8'" );
 91+ $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ),
 92+ "Flags should not contain 'gzip'" );
 93+ $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
 94+ $row->old_text, "Direct check" );
 95+ $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
 96+ Revision::getRevisionText( $row ), "getRevisionText" );
 97+ }
 98+
 99+ function testCompressRevisionTextUtf8Gzip() {
 100+ $GLOBALS['wgCompressRevisions'] = true;
 101+ $row = new stdClass;
 102+ $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
 103+ $row->old_flags = Revision::compressRevisionText( $row->old_text );
 104+ $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
 105+ "Flags should contain 'utf-8'" );
 106+ $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ),
 107+ "Flags should contain 'gzip'" );
 108+ $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
 109+ gzinflate( $row->old_text ), "Direct check" );
 110+ $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
 111+ Revision::getRevisionText( $row ), "getRevisionText" );
 112+ }
 113+}
 114+
 115+
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/RevisionTest.php
___________________________________________________________________
Added: svn:keywords
1116 + Author Date Id Revision
Added: svn:eol-style
2117 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/db/DatabaseTest.php
@@ -0,0 +1,92 @@
 2+<?php
 3+
 4+class DatabaseTest extends PHPUnit_Framework_TestCase {
 5+ var $db;
 6+
 7+ function setUp() {
 8+ $this->db = wfGetDB( DB_SLAVE );
 9+ }
 10+
 11+ function testAddQuotesNull() {
 12+ $check = "NULL";
 13+ if ( $this->db->getType() === 'sqlite' ) {
 14+ $check = "''";
 15+ }
 16+ $this->assertEquals( $check, $this->db->addQuotes( null ) );
 17+ }
 18+
 19+ function testAddQuotesInt() {
 20+ # returning just "1234" should be ok too, though...
 21+ # maybe
 22+ $this->assertEquals(
 23+ "'1234'",
 24+ $this->db->addQuotes( 1234 ) );
 25+ }
 26+
 27+ function testAddQuotesFloat() {
 28+ # returning just "1234.5678" would be ok too, though
 29+ $this->assertEquals(
 30+ "'1234.5678'",
 31+ $this->db->addQuotes( 1234.5678 ) );
 32+ }
 33+
 34+ function testAddQuotesString() {
 35+ $this->assertEquals(
 36+ "'string'",
 37+ $this->db->addQuotes( 'string' ) );
 38+ }
 39+
 40+ function testAddQuotesStringQuote() {
 41+ $check = "'string''s cause trouble'";
 42+ if ( $this->db->getType() === 'mysql' ) {
 43+ $check = "'string\'s cause trouble'";
 44+ }
 45+ $this->assertEquals(
 46+ $check,
 47+ $this->db->addQuotes( "string's cause trouble" ) );
 48+ }
 49+
 50+ function testFillPreparedEmpty() {
 51+ $sql = $this->db->fillPrepared(
 52+ 'SELECT * FROM interwiki', array() );
 53+ $this->assertEquals(
 54+ "SELECT * FROM interwiki",
 55+ $sql );
 56+ }
 57+
 58+ function testFillPreparedQuestion() {
 59+ $sql = $this->db->fillPrepared(
 60+ 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
 61+ array( 4, "Snicker's_paradox" ) );
 62+
 63+ $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker''s_paradox'";
 64+ if ( $this->db->getType() === 'mysql' ) {
 65+ $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'";
 66+ }
 67+ $this->assertEquals( $check, $sql );
 68+ }
 69+
 70+ function testFillPreparedBang() {
 71+ $sql = $this->db->fillPrepared(
 72+ 'SELECT user_id FROM ! WHERE user_name=?',
 73+ array( '"user"', "Slash's Dot" ) );
 74+
 75+ $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash''s Dot'";
 76+ if ( $this->db->getType() === 'mysql' ) {
 77+ $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'";
 78+ }
 79+ $this->assertEquals( $check, $sql );
 80+ }
 81+
 82+ function testFillPreparedRaw() {
 83+ $sql = $this->db->fillPrepared(
 84+ "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
 85+ array( '"user"', "Slash's Dot" ) );
 86+ $this->assertEquals(
 87+ "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",
 88+ $sql );
 89+ }
 90+
 91+}
 92+
 93+
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/db/DatabaseTest.php
___________________________________________________________________
Added: svn:keywords
194 + Author Date Id Revision
Added: svn:eol-style
295 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php
@@ -0,0 +1,70 @@
 2+<?php
 3+
 4+class MockDatabaseSqlite extends DatabaseSqliteStandalone {
 5+ var $lastQuery;
 6+
 7+ function __construct( ) {
 8+ parent::__construct( '' );
 9+ }
 10+
 11+ function query( $sql, $fname = '', $tempIgnore = false ) {
 12+ $this->lastQuery = $sql;
 13+ return true;
 14+ }
 15+
 16+ function replaceVars( $s ) {
 17+ return parent::replaceVars( $s );
 18+ }
 19+}
 20+
 21+class DatabaseSqliteTest extends PHPUnit_Framework_TestCase {
 22+ var $db;
 23+
 24+ function setup() {
 25+ if ( !Sqlite::isPresent() ) {
 26+ $this->markTestIncomplete( 'No SQLite support detected' );
 27+ }
 28+ $this->db = new MockDatabaseSqlite();
 29+ }
 30+
 31+ function replaceVars( $sql ) {
 32+ // normalize spacing to hide implementation details
 33+ return preg_replace( '/\s+/', ' ', $this->db->replaceVars( $sql ) );
 34+ }
 35+
 36+ function testReplaceVars() {
 37+ $this->assertEquals( 'foo', $this->replaceVars( 'foo' ), "Don't break anything accidentally" );
 38+
 39+ $this->assertEquals( "CREATE TABLE /**/foo (foo_key INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "
 40+ . "foo_bar TEXT, foo_name TEXT NOT NULL DEFAULT '', foo_int INTEGER, foo_int2 INTEGER );",
 41+ $this->replaceVars( "CREATE TABLE /**/foo (foo_key int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
 42+ foo_bar char(13), foo_name varchar(255) binary NOT NULL DEFAULT '', foo_int tinyint ( 8 ), foo_int2 int(16) ) ENGINE=MyISAM;" )
 43+ );
 44+
 45+ $this->assertEquals( "CREATE TABLE foo ( foo_binary1 BLOB, foo_binary2 BLOB );",
 46+ $this->replaceVars( "CREATE TABLE foo ( foo_binary1 binary(16), foo_binary2 varbinary(32) );" )
 47+ );
 48+
 49+ $this->assertEquals( "CREATE TABLE text ( text_foo TEXT );",
 50+ $this->replaceVars( "CREATE TABLE text ( text_foo tinytext );" ),
 51+ 'Table name changed'
 52+ );
 53+
 54+ $this->assertEquals( "CREATE TABLE enums( enum1 TEXT, myenum TEXT)",
 55+ $this->replaceVars( "CREATE TABLE enums( enum1 ENUM('A', 'B'), myenum ENUM ('X', 'Y'))" )
 56+ );
 57+
 58+ $this->assertEquals( "ALTER TABLE foo ADD COLUMN foo_bar INTEGER DEFAULT 42",
 59+ $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" )
 60+ );
 61+ }
 62+
 63+ function testEntireSchema() {
 64+ global $IP;
 65+
 66+ $result = Sqlite::checkSqlSyntax( "$IP/maintenance/tables.sql" );
 67+ if ( $result !== true ) {
 68+ $this->fail( $result );
 69+ }
 70+ }
 71+}
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php
___________________________________________________________________
Added: svn:eol-style
172 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/XmlTest.php
@@ -0,0 +1,115 @@
 2+<?php
 3+
 4+class XmlTest extends PHPUnit_Framework_TestCase {
 5+
 6+ function testElementOpen() {
 7+ $this->assertEquals(
 8+ '<element>',
 9+ Xml::element( 'element', null, null ),
 10+ 'Opening element with no attributes'
 11+ );
 12+ }
 13+
 14+ function testElementEmpty() {
 15+ $this->assertEquals(
 16+ '<element />',
 17+ Xml::element( 'element', null, '' ),
 18+ 'Terminated empty element'
 19+ );
 20+ }
 21+
 22+ function testElementEscaping() {
 23+ $this->assertEquals(
 24+ '<element>hello &lt;there&gt; you &amp; you</element>',
 25+ Xml::element( 'element', null, 'hello <there> you & you' ),
 26+ 'Element with no attributes and content that needs escaping'
 27+ );
 28+ }
 29+
 30+ function testElementAttributes() {
 31+ $this->assertEquals(
 32+ '<element key="value" <>="&lt;&gt;">',
 33+ Xml::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ),
 34+ 'Element attributes, keys are not escaped'
 35+ );
 36+ }
 37+
 38+ function testOpenElement() {
 39+ $this->assertEquals(
 40+ '<element k="v">',
 41+ Xml::openElement( 'element', array( 'k' => 'v' ) ),
 42+ 'openElement() shortcut'
 43+ );
 44+ }
 45+
 46+ function testCloseElement() {
 47+ $this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' );
 48+ }
 49+
 50+ #
 51+ # textarea
 52+ #
 53+ function testTextareaNoContent() {
 54+ $this->assertEquals(
 55+ '<textarea name="name" id="name" cols="40" rows="5"></textarea>',
 56+ Xml::textarea( 'name', '' ),
 57+ 'textarea() with not content'
 58+ );
 59+ }
 60+
 61+ function testTextareaAttribs() {
 62+ $this->assertEquals(
 63+ '<textarea name="name" id="name" cols="20" rows="10">&lt;txt&gt;</textarea>',
 64+ Xml::textarea( 'name', '<txt>', 20, 10 ),
 65+ 'textarea() with custom attribs'
 66+ );
 67+ }
 68+
 69+ #
 70+ # JS
 71+ #
 72+ function testEscapeJsStringSpecialChars() {
 73+ $this->assertEquals(
 74+ '\\\\\r\n',
 75+ Xml::escapeJsString( "\\\r\n" ),
 76+ 'escapeJsString() with special characters'
 77+ );
 78+ }
 79+
 80+ function testEncodeJsVarBoolean() {
 81+ $this->assertEquals(
 82+ 'true',
 83+ Xml::encodeJsVar( true ),
 84+ 'encodeJsVar() with boolean'
 85+ );
 86+ }
 87+
 88+ function testEncodeJsVarNull() {
 89+ $this->assertEquals(
 90+ 'null',
 91+ Xml::encodeJsVar( null ),
 92+ 'encodeJsVar() with null'
 93+ );
 94+ }
 95+
 96+ function testEncodeJsVarArray() {
 97+ $this->assertEquals(
 98+ '["a", 1]',
 99+ Xml::encodeJsVar( array( 'a', 1 ) ),
 100+ 'encodeJsVar() with array'
 101+ );
 102+ $this->assertEquals(
 103+ '{"a": "a", "b": 1}',
 104+ Xml::encodeJsVar( array( 'a' => 'a', 'b' => 1 ) ),
 105+ 'encodeJsVar() with associative array'
 106+ );
 107+ }
 108+
 109+ function testEncodeJsVarObject() {
 110+ $this->assertEquals(
 111+ '{"a": "a", "b": 1}',
 112+ Xml::encodeJsVar( (object)array( 'a' => 'a', 'b' => 1 ) ),
 113+ 'encodeJsVar() with object'
 114+ );
 115+ }
 116+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/XmlTest.php
___________________________________________________________________
Added: svn:eol-style
1117 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/ExtraParserTest.php
@@ -0,0 +1,30 @@
 2+<?php
 3+/**
 4+ * Parser-related tests that don't suit for parserTests.txt
 5+ */
 6+
 7+class ExtraParserTest extends PHPUnit_Framework_TestCase {
 8+
 9+ function setUp() {
 10+ global $wgMemc;
 11+
 12+ $wgMemc = new FakeMemCachedClient;
 13+ }
 14+
 15+ function tearDown() {
 16+ global $wgMemc;
 17+
 18+ $wgMemc = null;
 19+ }
 20+
 21+ // Bug 8689 - Long numeric lines kill the parser
 22+ function testBug8689() {
 23+ $longLine = '1.' . str_repeat( '1234567890', 100000 ) . "\n";
 24+
 25+ $parser = new Parser();
 26+ $t = Title::newFromText( 'Unit test' );
 27+ $options = new ParserOptions();
 28+ $this->assertEquals( "<p>$longLine</p>",
 29+ $parser->parse( $longLine, $t, $options )->getText() );
 30+ }
 31+ }
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/ExtraParserTest.php
___________________________________________________________________
Added: svn:eol-style
132 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/GlobalTest.php
@@ -0,0 +1,212 @@
 2+<?php
 3+
 4+class GlobalTest extends PHPUnit_Framework_TestCase {
 5+ function setUp() {
 6+ global $wgReadOnlyFile;
 7+ $this->originals['wgReadOnlyFile'] = $wgReadOnlyFile;
 8+ $wgReadOnlyFile = tempnam( wfTempDir(), "mwtest_readonly" );
 9+ unlink( $wgReadOnlyFile );
 10+ }
 11+
 12+ function tearDown() {
 13+ global $wgReadOnlyFile;
 14+ if ( file_exists( $wgReadOnlyFile ) ) {
 15+ unlink( $wgReadOnlyFile );
 16+ }
 17+ $wgReadOnlyFile = $this->originals['wgReadOnlyFile'];
 18+ }
 19+
 20+ function testRandom() {
 21+ # This could hypothetically fail, but it shouldn't ;)
 22+ $this->assertFalse(
 23+ wfRandom() == wfRandom() );
 24+ }
 25+
 26+ function testUrlencode() {
 27+ $this->assertEquals(
 28+ "%E7%89%B9%E5%88%A5:Contributions/Foobar",
 29+ wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
 30+ }
 31+
 32+ function testReadOnlyEmpty() {
 33+ global $wgReadOnly;
 34+ $wgReadOnly = null;
 35+
 36+ $this->assertFalse( wfReadOnly() );
 37+ $this->assertFalse( wfReadOnly() );
 38+ }
 39+
 40+ function testReadOnlySet() {
 41+ global $wgReadOnly, $wgReadOnlyFile;
 42+
 43+ $f = fopen( $wgReadOnlyFile, "wt" );
 44+ fwrite( $f, 'Message' );
 45+ fclose( $f );
 46+ $wgReadOnly = null;
 47+
 48+ $this->assertTrue( wfReadOnly() );
 49+ $this->assertTrue( wfReadOnly() );
 50+
 51+ unlink( $wgReadOnlyFile );
 52+ $wgReadOnly = null;
 53+
 54+ $this->assertFalse( wfReadOnly() );
 55+ $this->assertFalse( wfReadOnly() );
 56+ }
 57+
 58+ function testQuotedPrintable() {
 59+ $this->assertEquals(
 60+ "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
 61+ wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
 62+ }
 63+
 64+ function testTime() {
 65+ $start = wfTime();
 66+ $this->assertType( 'float', $start );
 67+ $end = wfTime();
 68+ $this->assertTrue( $end > $start, "Time is running backwards!" );
 69+ }
 70+
 71+ function testArrayToCGI() {
 72+ $this->assertEquals(
 73+ "baz=AT%26T&foo=bar",
 74+ wfArrayToCGI(
 75+ array( 'baz' => 'AT&T', 'ignore' => '' ),
 76+ array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
 77+ }
 78+
 79+ function testMimeTypeMatch() {
 80+ $this->assertEquals(
 81+ 'text/html',
 82+ mimeTypeMatch( 'text/html',
 83+ array( 'application/xhtml+xml' => 1.0,
 84+ 'text/html' => 0.7,
 85+ 'text/plain' => 0.3 ) ) );
 86+ $this->assertEquals(
 87+ 'text/*',
 88+ mimeTypeMatch( 'text/html',
 89+ array( 'image/*' => 1.0,
 90+ 'text/*' => 0.5 ) ) );
 91+ $this->assertEquals(
 92+ '*/*',
 93+ mimeTypeMatch( 'text/html',
 94+ array( '*/*' => 1.0 ) ) );
 95+ $this->assertNull(
 96+ mimeTypeMatch( 'text/html',
 97+ array( 'image/png' => 1.0,
 98+ 'image/svg+xml' => 0.5 ) ) );
 99+ }
 100+
 101+ function testNegotiateType() {
 102+ $this->assertEquals(
 103+ 'text/html',
 104+ wfNegotiateType(
 105+ array( 'application/xhtml+xml' => 1.0,
 106+ 'text/html' => 0.7,
 107+ 'text/plain' => 0.5,
 108+ 'text/*' => 0.2 ),
 109+ array( 'text/html' => 1.0 ) ) );
 110+ $this->assertEquals(
 111+ 'application/xhtml+xml',
 112+ wfNegotiateType(
 113+ array( 'application/xhtml+xml' => 1.0,
 114+ 'text/html' => 0.7,
 115+ 'text/plain' => 0.5,
 116+ 'text/*' => 0.2 ),
 117+ array( 'application/xhtml+xml' => 1.0,
 118+ 'text/html' => 0.5 ) ) );
 119+ $this->assertEquals(
 120+ 'text/html',
 121+ wfNegotiateType(
 122+ array( 'text/html' => 1.0,
 123+ 'text/plain' => 0.5,
 124+ 'text/*' => 0.5,
 125+ 'application/xhtml+xml' => 0.2 ),
 126+ array( 'application/xhtml+xml' => 1.0,
 127+ 'text/html' => 0.5 ) ) );
 128+ $this->assertEquals(
 129+ 'text/html',
 130+ wfNegotiateType(
 131+ array( 'text/*' => 1.0,
 132+ 'image/*' => 0.7,
 133+ '*/*' => 0.3 ),
 134+ array( 'application/xhtml+xml' => 1.0,
 135+ 'text/html' => 0.5 ) ) );
 136+ $this->assertNull(
 137+ wfNegotiateType(
 138+ array( 'text/*' => 1.0 ),
 139+ array( 'application/xhtml+xml' => 1.0 ) ) );
 140+ }
 141+
 142+ function testTimestamp() {
 143+ $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
 144+ $this->assertEquals(
 145+ '20010115123456',
 146+ wfTimestamp( TS_MW, $t ),
 147+ 'TS_UNIX to TS_MW' );
 148+ $this->assertEquals(
 149+ 979562096,
 150+ wfTimestamp( TS_UNIX, $t ),
 151+ 'TS_UNIX to TS_UNIX' );
 152+ $this->assertEquals(
 153+ '2001-01-15 12:34:56',
 154+ wfTimestamp( TS_DB, $t ),
 155+ 'TS_UNIX to TS_DB' );
 156+
 157+ $this->assertEquals(
 158+ '20010115123456',
 159+ wfTimestamp( TS_MW, '20010115123456' ),
 160+ 'TS_MW to TS_MW' );
 161+ $this->assertEquals(
 162+ 979562096,
 163+ wfTimestamp( TS_UNIX, '20010115123456' ),
 164+ 'TS_MW to TS_UNIX' );
 165+ $this->assertEquals(
 166+ '2001-01-15 12:34:56',
 167+ wfTimestamp( TS_DB, '20010115123456' ),
 168+ 'TS_MW to TS_DB' );
 169+
 170+ $this->assertEquals(
 171+ '20010115123456',
 172+ wfTimestamp( TS_MW, '2001-01-15 12:34:56' ),
 173+ 'TS_DB to TS_MW' );
 174+ $this->assertEquals(
 175+ 979562096,
 176+ wfTimestamp( TS_UNIX, '2001-01-15 12:34:56' ),
 177+ 'TS_DB to TS_UNIX' );
 178+ $this->assertEquals(
 179+ '2001-01-15 12:34:56',
 180+ wfTimestamp( TS_DB, '2001-01-15 12:34:56' ),
 181+ 'TS_DB to TS_DB' );
 182+ }
 183+
 184+ function testBasename() {
 185+ $sets = array(
 186+ '' => '',
 187+ '/' => '',
 188+ '\\' => '',
 189+ '//' => '',
 190+ '\\\\' => '',
 191+ 'a' => 'a',
 192+ 'aaaa' => 'aaaa',
 193+ '/a' => 'a',
 194+ '\\a' => 'a',
 195+ '/aaaa' => 'aaaa',
 196+ '\\aaaa' => 'aaaa',
 197+ '/aaaa/' => 'aaaa',
 198+ '\\aaaa\\' => 'aaaa',
 199+ '\\aaaa\\' => 'aaaa',
 200+ '/mnt/upload3/wikipedia/en/thumb/8/8b/Zork_Grand_Inquisitor_box_cover.jpg/93px-Zork_Grand_Inquisitor_box_cover.jpg' => '93px-Zork_Grand_Inquisitor_box_cover.jpg',
 201+ 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
 202+ 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
 203+ );
 204+ foreach ( $sets as $from => $to ) {
 205+ $this->assertEquals( $to, wfBaseName( $from ),
 206+ "wfBaseName('$from') => '$to'" );
 207+ }
 208+ }
 209+
 210+ /* TODO: many more! */
 211+}
 212+
 213+
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/GlobalTest.php
___________________________________________________________________
Added: svn:keywords
1214 + Author Date Id Revision
Added: svn:eol-style
2215 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/LicensesTest.php
@@ -0,0 +1,17 @@
 2+<?php
 3+
 4+/**
 5+ * @group Broken
 6+ */
 7+class LicensesTest extends PHPUnit_Framework_TestCase {
 8+
 9+ function testLicenses() {
 10+ $str = "
 11+* Free licenses:
 12+** GFLD|Debian disagrees
 13+";
 14+
 15+ $lc = new Licenses( $str );
 16+ $this->assertTrue( is_a( $lc, 'Licenses' ), 'Correct class' );
 17+ }
 18+}
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/LicensesTest.php
___________________________________________________________________
Added: svn:eol-style
119 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/parser/ParserHelpers.php
@@ -0,0 +1,88 @@
 2+<?php
 3+
 4+class ParserUnitTest extends PHPUnit_Framework_TestCase {
 5+ private $test = "";
 6+ private $suite;
 7+
 8+ public function __construct( $suite, $test = null ) {
 9+ $this->suite = $suite;
 10+ $this->test = $test;
 11+ }
 12+
 13+ function count() { return 1; }
 14+
 15+ public function run( PHPUnit_Framework_TestResult $result = null ) {
 16+ PHPUnit_Framework_Assert::resetCount();
 17+ if ( $result === NULL ) {
 18+ $result = new PHPUnit_Framework_TestResult;
 19+ }
 20+
 21+ $backend = $this->suite->getBackend();
 22+ $result->startTest( $this );
 23+ PHPUnit_Util_Timer::start();
 24+
 25+ $r = false;
 26+ try {
 27+ # Run the test.
 28+ # On failure, the subclassed backend will throw an exception with
 29+ # the details.
 30+ $r = $backend->runTest(
 31+ $this->test['test'],
 32+ $this->test['input'],
 33+ $this->test['result'],
 34+ $this->test['options'],
 35+ $this->test['config']
 36+ );
 37+ }
 38+ catch ( PHPUnit_Framework_AssertionFailedError $e ) {
 39+ $result->addFailure( $this, $e, PHPUnit_Util_Timer::stop() );
 40+ }
 41+ catch ( Exception $e ) {
 42+ $result->addError( $this, $e, PHPUnit_Util_Timer::stop() );
 43+ }
 44+
 45+ $result->endTest( $this, PHPUnit_Util_Timer::stop() );
 46+
 47+ $backend->recorder->record( $this->test['test'], $r );
 48+ $this->addToAssertionCount( PHPUnit_Framework_Assert::getCount() );
 49+
 50+ return $result;
 51+ }
 52+
 53+ public function toString() {
 54+ return $this->test['test'];
 55+ }
 56+
 57+}
 58+
 59+class ParserTestSuiteBackend extends ParserTest {
 60+ function showTesting( $desc ) {
 61+ }
 62+
 63+ function showRunFile( $path ) {
 64+ }
 65+
 66+ function showSuccess( $desc ) {
 67+ PHPUnit_Framework_Assert::assertTrue( true, $desc );
 68+ return true;
 69+ }
 70+
 71+ function showFailure( $desc, $expected, $got ) {
 72+ PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc );
 73+ }
 74+
 75+ public function setupRecorder( $options ) {
 76+ $this->recorder = new PHPUnitTestRecorder( $this );
 77+ }
 78+}
 79+
 80+class PHPUnitTestRecorder extends TestRecorder {
 81+ function record( $test, $result ) {
 82+ $this->total++;
 83+ $this->success += $result;
 84+
 85+ }
 86+
 87+ function reportPercentage( $success, $total ) { }
 88+}
 89+
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/parser/ParserHelpers.php
___________________________________________________________________
Added: svn:eol-style
190 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php
@@ -0,0 +1,57 @@
 2+<?php
 3+
 4+require_once( 'ParserHelpers.php' );
 5+
 6+class MediaWikiParserTestSuite extends PHPUnit_Framework_TestSuite {
 7+ private $count;
 8+ public $backend;
 9+
 10+ public static function suite() {
 11+ return new self;
 12+ }
 13+
 14+ public function __construct() {
 15+ $this->backend = new ParserTestSuiteBackend;
 16+ parent::__construct();
 17+ $this->setName( 'Parser tests' );
 18+ }
 19+
 20+ public function run( PHPUnit_Framework_TestResult $result = null, $filter = false,
 21+ array $groups = array(), array $excludeGroups = array(), $processIsolation = false
 22+ ) {
 23+ global $IP, $wgContLang, $wgMemc;
 24+ $wgContLang = Language::factory( 'en' );
 25+ $wgMemc = new FakeMemCachedClient;
 26+ $this->backend->setupDatabase();
 27+
 28+ $iter = new TestFileIterator( "$IP/maintenance/parserTests.txt" );
 29+ $iter->setParser( $this->backend );
 30+ $this->count = 0;
 31+
 32+ foreach ( $iter as $test ) {
 33+ $this->addTest( new ParserUnitTest( $this, $test ) );
 34+ $this->count++;
 35+ }
 36+
 37+ parent::run( $result, $filter, $groups, $excludeGroups, $processIsolation );
 38+
 39+ $this->backend->teardownDatabase();
 40+ }
 41+
 42+ public function count() {
 43+ return $this->count;
 44+ }
 45+
 46+ public function toString() {
 47+ return "MediaWiki Parser Tests";
 48+ }
 49+
 50+ public function getBackend() {
 51+ return $this->backend;
 52+ }
 53+
 54+ public function getIterator() {
 55+ return $this->iterator;
 56+ }
 57+}
 58+
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php
___________________________________________________________________
Added: svn:eol-style
159 + native
Added: svn:eol-syle
260 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/SanitizerTest.php
@@ -0,0 +1,72 @@
 2+<?php
 3+
 4+class SanitizerTest extends PHPUnit_Framework_TestCase {
 5+
 6+ function setUp() {
 7+ AutoLoader::loadClass( 'Sanitizer' );
 8+ }
 9+
 10+ function testDecodeNamedEntities() {
 11+ $this->assertEquals(
 12+ "\xc3\xa9cole",
 13+ Sanitizer::decodeCharReferences( '&eacute;cole' ),
 14+ 'decode named entities'
 15+ );
 16+ }
 17+
 18+ function testDecodeNumericEntities() {
 19+ $this->assertEquals(
 20+ "\xc4\x88io bonas dans l'\xc3\xa9cole!",
 21+ Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&#233;cole!" ),
 22+ 'decode numeric entities'
 23+ );
 24+ }
 25+
 26+ function testDecodeMixedEntities() {
 27+ $this->assertEquals(
 28+ "\xc4\x88io bonas dans l'\xc3\xa9cole!",
 29+ Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&eacute;cole!" ),
 30+ 'decode mixed numeric/named entities'
 31+ );
 32+ }
 33+
 34+ function testDecodeMixedComplexEntities() {
 35+ $this->assertEquals(
 36+ "\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas &#x108;io dans l'&eacute;cole)",
 37+ Sanitizer::decodeCharReferences(
 38+ "&#x108;io bonas dans l'&eacute;cole! (mais pas &amp;#x108;io dans l'&#38;eacute;cole)"
 39+ ),
 40+ 'decode mixed complex entities'
 41+ );
 42+ }
 43+
 44+ function testInvalidAmpersand() {
 45+ $this->assertEquals(
 46+ 'a & b',
 47+ Sanitizer::decodeCharReferences( 'a & b' ),
 48+ 'Invalid ampersand'
 49+ );
 50+ }
 51+
 52+ function testInvalidEntities() {
 53+ $this->assertEquals(
 54+ '&foo;',
 55+ Sanitizer::decodeCharReferences( '&foo;' ),
 56+ 'Invalid named entity'
 57+ );
 58+ }
 59+
 60+ function testInvalidNumberedEntities() {
 61+ $this->assertEquals( UTF8_REPLACEMENT, Sanitizer::decodeCharReferences( "&#88888888888888;" ), 'Invalid numbered entity' );
 62+ }
 63+
 64+ function testSelfClosingTag() {
 65+ $GLOBALS['wgUseTidy'] = false;
 66+ $this->assertEquals(
 67+ '<div>Hello world</div>',
 68+ Sanitizer::removeHTMLtags( '<div>Hello world</div />' ),
 69+ 'Self-closing closing div'
 70+ );
 71+ }
 72+}
 73+
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/SanitizerTest.php
___________________________________________________________________
Added: svn:eol-style
174 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/IPTest.php
@@ -0,0 +1,52 @@
 2+<?php
 3+/*
 4+ * Tests for IP validity functions. Ported from /t/inc/IP.t by avar.
 5+ */
 6+
 7+class IPTest extends PHPUnit_Framework_TestCase {
 8+
 9+ public function testValidIPs() {
 10+ foreach ( range( 0, 255 ) as $i ) {
 11+ $a = sprintf( "%03d", $i );
 12+ $b = sprintf( "%02d", $i );
 13+ $c = sprintf( "%01d", $i );
 14+ foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
 15+ $ip = "$f.$f.$f.$f";
 16+ $this->assertTrue( IP::isValid( $ip ) , "$ip is a valid IPv4 address" );
 17+ }
 18+ }
 19+ }
 20+
 21+ public function testInvalidIPs() {
 22+ foreach ( range( 256, 999 ) as $i ) {
 23+ $a = sprintf( "%03d", $i );
 24+ $b = sprintf( "%02d", $i );
 25+ $c = sprintf( "%01d", $i );
 26+ foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
 27+ $ip = "$f.$f.$f.$f";
 28+ $this->assertFalse( IP::isValid( $ip ), "$ip is not a valid IPv4 address" );
 29+ }
 30+ }
 31+ }
 32+
 33+ public function testBogusIPs() {
 34+ $invalid = array(
 35+ 'www.xn--var-xla.net',
 36+ '216.17.184.G',
 37+ '216.17.184.1.',
 38+ '216.17.184',
 39+ '216.17.184.',
 40+ '256.17.184.1'
 41+ );
 42+ foreach ( $invalid as $i ) {
 43+ $this->assertFalse( IP::isValid( $i ), "$i is an invalid IPv4 address" );
 44+ }
 45+ }
 46+
 47+ public function testPrivateIPs() {
 48+ $private = array( '10.0.0.1', '172.16.0.1', '192.168.0.1' );
 49+ foreach ( $private as $p ) {
 50+ $this->assertFalse( IP::isPublic( $p ), "$p is not a public IP address" );
 51+ }
 52+ }
 53+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/IPTest.php
___________________________________________________________________
Added: svn:eol-style
154 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/TimeAdjustTest.php
@@ -0,0 +1,49 @@
 2+<?php
 3+
 4+class TimeAdjustTest extends PHPUnit_Framework_TestCase {
 5+ static $offset;
 6+
 7+ public function setUp() {
 8+ global $wgLocalTZoffset;
 9+ self::$offset = $wgLocalTZoffset;
 10+
 11+ $this->iniSet( 'precision', 15 );
 12+ }
 13+
 14+ public function tearDown() {
 15+ global $wgLocalTZoffset;
 16+ $wgLocalTZoffset = self::$offset;
 17+ }
 18+
 19+ # Test offset usage for a given language::userAdjust
 20+ function testUserAdjust() {
 21+ global $wgLocalTZoffset, $wgContLang;
 22+
 23+ $wgContLang = $en = Language::factory( 'en' );
 24+
 25+ #  Collection of parameters for Language_t_Offset.
 26+ # Format: date to be formatted, localTZoffset value, expected date
 27+ $userAdjust_tests = array(
 28+ array( 20061231235959, 0, 20061231235959 ),
 29+ array( 20061231235959, 5, 20070101000459 ),
 30+ array( 20061231235959, 15, 20070101001459 ),
 31+ array( 20061231235959, 60, 20070101005959 ),
 32+ array( 20061231235959, 90, 20070101012959 ),
 33+ array( 20061231235959, 120, 20070101015959 ),
 34+ array( 20061231235959, 540, 20070101085959 ),
 35+ array( 20061231235959, -5, 20061231235459 ),
 36+ array( 20061231235959, -30, 20061231232959 ),
 37+ array( 20061231235959, -60, 20061231225959 ),
 38+ );
 39+
 40+ foreach ( $userAdjust_tests as $data ) {
 41+ $wgLocalTZoffset = $data[1];
 42+
 43+ $this->assertEquals(
 44+ strval( $data[2] ),
 45+ strval( $en->userAdjust( $data[0], '' ) ),
 46+ "User adjust {$data[0]} by {$data[1]} minutes should give {$data[2]}"
 47+ );
 48+ }
 49+ }
 50+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/TimeAdjustTest.php
___________________________________________________________________
Added: svn:eol-style
151 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/LanguageConverterTest.php
@@ -0,0 +1,150 @@
 2+<?php
 3+
 4+class LanguageConverterTest extends PHPUnit_Framework_TestCase {
 5+ protected $lang = null;
 6+ protected $lc = null;
 7+
 8+ function setUp() {
 9+ global $wgMemc, $wgRequest, $wgUser, $wgContLang;
 10+
 11+ $wgUser = new User;
 12+ $wgRequest = new FauxRequest( array() );
 13+ $wgMemc = new FakeMemCachedClient;
 14+ $wgContLang = Language::factory( 'tg' );
 15+ $this->lang = new LanguageTest();
 16+ $this->lc = new TestConverter( $this->lang, 'tg',
 17+ array( 'tg', 'tg-latn' ) );
 18+ }
 19+
 20+ function tearDown() {
 21+ global $wgMemc, $wgContLang;
 22+ unset( $wgMemc );
 23+ unset( $this->lc );
 24+ unset( $this->lang );
 25+ $wgContLang = null;
 26+ }
 27+
 28+ function testGetPreferredVariantDefaults() {
 29+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
 30+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, true ) );
 31+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, false ) );
 32+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, true ) );
 33+ }
 34+
 35+ function testGetPreferredVariantHeaders() {
 36+ global $wgRequest;
 37+ $wgRequest->setHeader( 'Accept-Language', 'tg-latn' );
 38+
 39+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
 40+ $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( false, true ) );
 41+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, false ) );
 42+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, true ) );
 43+ }
 44+
 45+ function testGetPreferredVariantHeaderWeight() {
 46+ global $wgRequest;
 47+ $wgRequest->setHeader( 'Accept-Language', 'tg;q=1' );
 48+
 49+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
 50+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, true ) );
 51+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, false ) );
 52+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, true ) );
 53+ }
 54+
 55+ function testGetPreferredVariantHeaderWeight2() {
 56+ global $wgRequest;
 57+ $wgRequest->setHeader( 'Accept-Language', 'tg-latn;q=1' );
 58+
 59+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
 60+ $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( false, true ) );
 61+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, false ) );
 62+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, true ) );
 63+ }
 64+
 65+ function testGetPreferredVariantHeaderMulti() {
 66+ global $wgRequest;
 67+ $wgRequest->setHeader( 'Accept-Language', 'en, tg-latn;q=1' );
 68+
 69+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
 70+ $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( false, true ) );
 71+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, false ) );
 72+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, true ) );
 73+ }
 74+
 75+ function testGetPreferredVariantUserOption() {
 76+ global $wgUser;
 77+
 78+ $wgUser = new User;
 79+ $wgUser->setId( 1 );
 80+ $wgUser->mDataLoaded = true;
 81+ $wgUser->setOption( 'variant', 'tg-latn' );
 82+
 83+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
 84+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, true ) );
 85+ $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( true, false ) );
 86+ $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( true, true ) );
 87+ }
 88+
 89+ function testGetPreferredVariantHeaderUserVsUrl() {
 90+ global $wgRequest, $wgUser, $wgContLang;
 91+
 92+ $wgContLang = Language::factory( 'tg-latn' );
 93+ $wgRequest->setVal( 'variant', 'tg' );
 94+ $wgUser = User::newFromId( "admin" );
 95+ $wgUser->setId( 1 );
 96+ $wgUser->setOption( 'variant', 'tg-latn' ); // The user's data is ignored
 97+ // because the variant is set in the URL.
 98+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, false ) );
 99+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( true, true ) );
 100+ }
 101+
 102+
 103+ function testGetPreferredVariantDefaultLanguageVariant() {
 104+ global $wgDefaultLanguageVariant;
 105+
 106+ $wgDefaultLanguageVariant = 'tg-latn';
 107+ $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( false, false ) );
 108+ $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( false, true ) );
 109+ $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( true, false ) );
 110+ $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( true, true ) );
 111+ }
 112+
 113+ function testGetPreferredVariantDefaultLanguageVsUrlVariant() {
 114+ global $wgDefaultLanguageVariant, $wgRequest, $wgContLang;
 115+
 116+ $wgContLang = Language::factory( 'tg-latn' );
 117+ $wgDefaultLanguageVariant = 'tg';
 118+ $wgRequest->setVal( 'variant', null );
 119+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, false ) );
 120+ $this->assertEquals( 'tg', $this->lc->getPreferredVariant( false, true ) );
 121+ $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( true, false ) );
 122+ $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant( true, true ) );
 123+ }
 124+}
 125+
 126+/**
 127+ * Test converter (from Tajiki to latin orthography)
 128+ */
 129+class TestConverter extends LanguageConverter {
 130+ private $table = array(
 131+ 'б' => 'b',
 132+ 'в' => 'v',
 133+ 'г' => 'g',
 134+ );
 135+
 136+ function loadDefaultTables() {
 137+ $this->mTables = array(
 138+ 'tg-latn' => new ReplacementArray( $this->table ),
 139+ 'tg' => new ReplacementArray()
 140+ );
 141+ }
 142+
 143+}
 144+
 145+class LanguageTest extends Language {
 146+ function __construct() {
 147+ parent::__construct();
 148+ $variants = array( 'tg', 'tg-latn' );
 149+ $this->mConverter = new TestConverter( $this, 'tg', $variants );
 150+ }
 151+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/LanguageConverterTest.php
___________________________________________________________________
Added: svn:eol-style
1152 + native
Added: svn:eol-syle
2153 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/ImageFunctionsTest.php
@@ -0,0 +1,48 @@
 2+<?php
 3+
 4+class ImageFunctionsTest extends PHPUnit_Framework_TestCase {
 5+ function testFitBoxWidth() {
 6+ $vals = array(
 7+ array(
 8+ 'width' => 50,
 9+ 'height' => 50,
 10+ 'tests' => array(
 11+ 50 => 50,
 12+ 17 => 17,
 13+ 18 => 18 ) ),
 14+ array(
 15+ 'width' => 366,
 16+ 'height' => 300,
 17+ 'tests' => array(
 18+ 50 => 61,
 19+ 17 => 21,
 20+ 18 => 22 ) ),
 21+ array(
 22+ 'width' => 300,
 23+ 'height' => 366,
 24+ 'tests' => array(
 25+ 50 => 41,
 26+ 17 => 14,
 27+ 18 => 15 ) ),
 28+ array(
 29+ 'width' => 100,
 30+ 'height' => 400,
 31+ 'tests' => array(
 32+ 50 => 12,
 33+ 17 => 4,
 34+ 18 => 4 ) ) );
 35+ foreach ( $vals as $row ) {
 36+ extract( $row );
 37+ foreach ( $tests as $max => $expected ) {
 38+ $y = round( $expected * $height / $width );
 39+ $result = wfFitBoxWidth( $width, $height, $max );
 40+ $y2 = round( $result * $height / $width );
 41+ $this->assertEquals( $expected,
 42+ $result,
 43+ "($width, $height, $max) wanted: {$expected}x$y, got: {$result}x$y2" );
 44+ }
 45+ }
 46+ }
 47+}
 48+
 49+
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/ImageFunctionsTest.php
___________________________________________________________________
Added: svn:keywords
150 + Author Date Id Revision
Added: svn:eol-style
251 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/ResourceLoaderTest.php
@@ -0,0 +1,15 @@
 2+<?php
 3+
 4+class ResourceLoaderTest extends PHPUnit_Framework_TestCase {
 5+ /* Provider Methods */
 6+
 7+ public function provide() {
 8+
 9+ }
 10+
 11+ /* Test Methods */
 12+
 13+ public function test() {
 14+
 15+ }
 16+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/ResourceLoaderTest.php
___________________________________________________________________
Added: svn:eol-style
117 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/HttpTest.php
@@ -0,0 +1,567 @@
 2+<?php
 3+
 4+class MockCookie extends Cookie {
 5+ public function canServeDomain( $arg ) { return parent::canServeDomain( $arg ); }
 6+ public function canServePath( $arg ) { return parent::canServePath( $arg ); }
 7+ public function isUnExpired() { return parent::isUnExpired(); }
 8+}
 9+
 10+class HttpTest extends PHPUnit_Framework_TestCase {
 11+ static $content;
 12+ static $headers;
 13+ static $has_curl;
 14+ static $has_fopen;
 15+ static $has_proxy = false;
 16+ static $proxy = "http://hulk:8080/";
 17+ var $test_geturl = array(
 18+ "http://www.example.com/",
 19+ "http://pecl.php.net/feeds/pkg_apc.rss",
 20+ "http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id=3",
 21+ "http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw",
 22+ "http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&format=php",
 23+ );
 24+ var $test_requesturl = array( "http://en.wikipedia.org/wiki/Special:Export/User:MarkAHershberger" );
 25+
 26+ var $test_posturl = array( "http://www.comp.leeds.ac.uk/cgi-bin/Perl/environment-example" => "review=test" );
 27+
 28+ function setup() {
 29+ putenv( "http_proxy" ); /* Remove any proxy env var, so curl doesn't get confused */
 30+ if ( is_array( self::$content ) ) {
 31+ return;
 32+ }
 33+ self::$has_curl = function_exists( 'curl_init' );
 34+ self::$has_fopen = wfIniGetBool( 'allow_url_fopen' );
 35+
 36+ if ( !file_exists( "/usr/bin/curl" ) ) {
 37+ $this->markTestIncomplete( "This test requires the curl binary at /usr/bin/curl. If you have curl, please file a bug on this test, or, better yet, provide a patch." );
 38+ }
 39+
 40+ $content = tempnam( wfTempDir(), "" );
 41+ $headers = tempnam( wfTempDir(), "" );
 42+ if ( !$content && !$headers ) {
 43+ die( "Couldn't create temp file!" );
 44+ }
 45+
 46+ // This probably isn't the best test for a proxy, but it works on my system!
 47+ system( "curl -0 -o $content -s " . self::$proxy );
 48+ $out = file_get_contents( $content );
 49+ if ( $out ) {
 50+ self::$has_proxy = true;
 51+ }
 52+
 53+ /* Maybe use wget instead of curl here ... just to use a different codebase? */
 54+ foreach ( $this->test_geturl as $u ) {
 55+ system( "curl -0 -s -D $headers '$u' -o $content" );
 56+ self::$content["GET $u"] = file_get_contents( $content );
 57+ self::$headers["GET $u"] = file_get_contents( $headers );
 58+ }
 59+ foreach ( $this->test_requesturl as $u ) {
 60+ system( "curl -0 -s -X POST -H 'Content-Length: 0' -D $headers '$u' -o $content" );
 61+ self::$content["POST $u"] = file_get_contents( $content );
 62+ self::$headers["POST $u"] = file_get_contents( $headers );
 63+ }
 64+ foreach ( $this->test_posturl as $u => $postData ) {
 65+ system( "curl -0 -s -X POST -d '$postData' -D $headers '$u' -o $content" );
 66+ self::$content["POST $u => $postData"] = file_get_contents( $content );
 67+ self::$headers["POST $u => $postData"] = file_get_contents( $headers );
 68+ }
 69+ unlink( $content );
 70+ unlink( $headers );
 71+ }
 72+
 73+
 74+ function testInstantiation() {
 75+ Http::$httpEngine = false;
 76+
 77+ $r = HttpRequest::factory( "http://www.example.com/" );
 78+ if ( self::$has_curl ) {
 79+ $this->assertThat( $r, $this->isInstanceOf( 'CurlHttpRequest' ) );
 80+ } else {
 81+ $this->assertThat( $r, $this->isInstanceOf( 'PhpHttpRequest' ) );
 82+ }
 83+ unset( $r );
 84+
 85+ if ( !self::$has_fopen ) {
 86+ $this->setExpectedException( 'MWException' );
 87+ }
 88+ Http::$httpEngine = 'php';
 89+ $r = HttpRequest::factory( "http://www.example.com/" );
 90+ $this->assertThat( $r, $this->isInstanceOf( 'PhpHttpRequest' ) );
 91+ unset( $r );
 92+
 93+ if ( !self::$has_curl ) {
 94+ $this->setExpectedException( 'MWException' );
 95+ }
 96+ Http::$httpEngine = 'curl';
 97+ $r = HttpRequest::factory( "http://www.example.com/" );
 98+ if ( self::$has_curl ) {
 99+ $this->assertThat( $r, $this->isInstanceOf( 'CurlHttpRequest' ) );
 100+ }
 101+ }
 102+
 103+ function runHTTPFailureChecks() {
 104+ // Each of the following requests should result in a failure.
 105+
 106+ $timeout = 1;
 107+ $start_time = time();
 108+ $r = Http::get( "http://www.example.com:1/", $timeout );
 109+ $end_time = time();
 110+ $this->assertLessThan( $timeout + 2, $end_time - $start_time,
 111+ "Request took less than {$timeout}s via " . Http::$httpEngine );
 112+ $this->assertEquals( $r, false, "false -- what we get on error from Http::get()" );
 113+
 114+ $r = Http::get( "http://www.example.com/this-file-does-not-exist", $timeout );
 115+ $this->assertFalse( $r, "False on 404s" );
 116+
 117+
 118+ $r = HttpRequest::factory( "http://www.example.com/this-file-does-not-exist" );
 119+ $er = $r->execute();
 120+ if ( is_a( $r, 'PhpHttpRequest' ) && version_compare( '5.2.10', phpversion(), '>' ) ) {
 121+ $this->assertRegexp( "/HTTP request failed/", $er->getWikiText() );
 122+ } else {
 123+ $this->assertRegexp( "/404 Not Found/", $er->getWikiText() );
 124+ }
 125+ }
 126+
 127+ function testFailureDefault() {
 128+ Http::$httpEngine = false;
 129+ $this->runHTTPFailureChecks();
 130+ }
 131+
 132+ function testFailurePhp() {
 133+ if ( !self::$has_fopen ) {
 134+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
 135+ }
 136+
 137+ Http::$httpEngine = "php";
 138+ $this->runHTTPFailureChecks();
 139+ }
 140+
 141+ function testFailureCurl() {
 142+ if ( !self::$has_curl ) {
 143+ $this->markTestIncomplete( "This test requires curl." );
 144+ }
 145+
 146+ Http::$httpEngine = "curl";
 147+ $this->runHTTPFailureChecks();
 148+ }
 149+
 150+ /* ./phase3/includes/Import.php:1108: $data = Http::request( $method, $url ); */
 151+ /* ./includes/Import.php:1124: $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */
 152+ /* ./includes/Import.php:1134: return ImportStreamSource::newFromURL( $url, "POST" ); */
 153+ function runHTTPRequests( $proxy = null ) {
 154+ $opt = array();
 155+
 156+ if ( $proxy ) {
 157+ $opt['proxy'] = $proxy;
 158+ } elseif ( $proxy === false ) {
 159+ $opt['noProxy'] = true;
 160+ }
 161+
 162+ /* no postData here because the only request I could find in code so far didn't have any */
 163+ foreach ( $this->test_requesturl as $u ) {
 164+ $r = Http::request( "POST", $u, $opt );
 165+ $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with " . Http::$httpEngine );
 166+ }
 167+ }
 168+
 169+ function testRequestDefault() {
 170+ Http::$httpEngine = false;
 171+ $this->runHTTPRequests();
 172+ }
 173+
 174+ function testRequestPhp() {
 175+ if ( !self::$has_fopen ) {
 176+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
 177+ }
 178+
 179+ Http::$httpEngine = "php";
 180+ $this->runHTTPRequests();
 181+ }
 182+
 183+ function testRequestCurl() {
 184+ if ( !self::$has_curl ) {
 185+ $this->markTestIncomplete( "This test requires curl." );
 186+ }
 187+
 188+ Http::$httpEngine = "curl";
 189+ $this->runHTTPRequests();
 190+ }
 191+
 192+ /* ./extensions/SpamBlacklist/SpamBlacklist_body.php:164: $httpText = Http::get( $fileName ); */
 193+ /* ./extensions/ApiSVGProxy/ApiSVGProxy.body.php:44: $contents = Http::get( $file->getFullUrl() ); */
 194+ /* ./extensions/BookInformation/drivers/IsbnDb.php:24: if( ( $xml = Http::get( $uri ) ) !== false ) { */
 195+ /* ./extensions/BookInformation/drivers/Amazon.php:23: if( ( $xml = Http::get( $uri ) ) !== false ) { */
 196+ /* ./extensions/TitleBlacklist/TitleBlacklist.list.php:217: $result = Http::get( $url ); */
 197+ /* ./extensions/TSPoll/TSPoll.php:68: $get_server = Http::get( 'http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id='.$id ); */
 198+ /* ./extensions/TSPoll/TSPoll.php:70: $get_server = Http::get( 'http://toolserver.org/~jan/poll/main.php?page=wiki_output&id='.$id ); */
 199+ /* ./extensions/DoubleWiki/DoubleWiki.php:56: $translation = Http::get( $url.$sep.'action=render' ); */
 200+ /* ./extensions/ExternalPages/ExternalPages_body.php:177: $serializedText = Http::get( $this->mPageURL ); */
 201+ /* ./extensions/Translate/utils/TranslationHelpers.php:143: $suggestions = Http::get( $url, $timeout ); */
 202+ /* ./extensions/Translate/SpecialImportTranslations.php:169: $filedata = Http::get( $url ); ; */
 203+ /* ./extensions/Translate/TranslateEditAddons.php:338: $suggestions = Http::get( $url, $timeout ); */
 204+ /* ./extensions/SecurePoll/includes/user/Auth.php:283: $value = Http::get( $url, 20, $curlParams ); */
 205+ /* ./extensions/DumpHTML/dumpHTML.inc:778: $contents = Http::get( $url ); */
 206+ /* ./extensions/DumpHTML/dumpHTML.inc:1298: $contents = Http::get( $sourceUrl ); */
 207+ /* ./extensions/DumpHTML/dumpHTML.inc:1373: $contents = Http::get( $sourceUrl ); */
 208+ /* ./phase3/maintenance/rebuildInterwiki.inc:101: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
 209+ /* ./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' ); */
 210+ /* ./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' ); */
 211+ /* ./phase3/maintenance/dumpInterwiki.inc:95: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
 212+ /* ./phase3/includes/parser/Parser.php:3204: $text = Http::get($url); */
 213+ /* ./phase3/includes/filerepo/ForeignAPIRepo.php:131: $data = Http::get( $url ); */
 214+ /* ./phase3/includes/filerepo/ForeignAPIRepo.php:205: $thumb = Http::get( $foreignUrl ); */
 215+ /* ./phase3/includes/filerepo/File.php:1105: $res = Http::get( $renderUrl ); */
 216+ /* ./phase3/includes/GlobalFunctions.php:2760: * @deprecated Use Http::get() instead */
 217+ /* ./phase3/includes/GlobalFunctions.php:2764: return Http::get( $url ); */
 218+ /* ./phase3/includes/ExternalStoreHttp.php:18: $ret = Http::get( $url ); */
 219+ /* ./phase3/includes/Import.php:357: $data = Http::get( $src ); */
 220+ /* ./extensions/ExternalData/ED_Utils.php:291: return Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
 221+ /* ./extensions/ExternalData/ED_Utils.php:293: return Http::get( $url ); */
 222+ /* ./extensions/ExternalData/ED_Utils.php:306: $page = Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
 223+ /* ./extensions/ExternalData/ED_Utils.php:308: $page = Http::get( $url ); */
 224+ /* ./extensions/CodeReview/backend/Subversion.php:320: $blob = Http::get( $target, $this->mTimeout ); */
 225+ /* ./extensions/AmazonPlus/AmazonPlus.php:214: $this->response = Http::get( $urlstr ); */
 226+ /* ./extensions/StaticWiki/StaticWiki.php:24: $text = Http::get( $url ) ; */
 227+ /* ./extensions/StaticWiki/StaticWiki.php:64: $history = Http::get ( $wgStaticWikiExternalSite . "index.php?title=" . urlencode ( $url_title ) . "&action=history" ) ; */
 228+ /* ./extensions/Configure/scripts/findSettings.php:126: $cont = Http::get( "http://www.mediawiki.org/w/index.php?title={$page}&action=raw" ); */
 229+ /* ./extensions/TorBlock/TorBlock.class.php:148: $data = Http::get( $url ); */
 230+ /* ./extensions/HoneypotIntegration/HoneypotIntegration.class.php:60: $data = Http::get( $wgHoneypotURLSource, 'default', */
 231+ /* ./extensions/SemanticForms/includes/SF_Utils.inc:378: $page_contents = Http::get($url); */
 232+ /* ./extensions/LocalisationUpdate/LocalisationUpdate.class.php:172: $basefilecontents = Http::get( $basefile ); */
 233+ /* ./extensions/APC/SpecialAPC.php:245: $rss = Http::get( 'http://pecl.php.net/feeds/pkg_apc.rss' ); */
 234+ /* ./extensions/Interlanguage/Interlanguage.php:56: $a = Http::get( $url ); */
 235+ /* ./extensions/MWSearch/MWSearch_body.php:492: $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts); */
 236+ function runHTTPGets( $proxy = null ) {
 237+ $opt = array();
 238+
 239+ if ( $proxy ) {
 240+ $opt['proxy'] = $proxy;
 241+ } elseif ( $proxy === false ) {
 242+ $opt['noProxy'] = true;
 243+ }
 244+
 245+ foreach ( $this->test_geturl as $u ) {
 246+ $r = Http::get( $u, 30, $opt ); /* timeout of 30s */
 247+ $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with " . Http::$httpEngine );
 248+ }
 249+ }
 250+
 251+ function testGetDefault() {
 252+ Http::$httpEngine = false;
 253+ $this->runHTTPGets();
 254+ }
 255+
 256+ function testGetPhp() {
 257+ if ( !self::$has_fopen ) {
 258+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
 259+ }
 260+
 261+ Http::$httpEngine = "php";
 262+ $this->runHTTPGets();
 263+ }
 264+
 265+ function testGetCurl() {
 266+ if ( !self::$has_curl ) {
 267+ $this->markTestIncomplete( "This test requires curl." );
 268+ }
 269+
 270+ Http::$httpEngine = "curl";
 271+ $this->runHTTPGets();
 272+ }
 273+
 274+ /* ./phase3/maintenance/parserTests.inc:1618: return Http::post( $url, array( 'postData' => wfArrayToCGI( $data ) ) ); */
 275+ function runHTTPPosts( $proxy = null ) {
 276+ $opt = array();
 277+
 278+ if ( $proxy ) {
 279+ $opt['proxy'] = $proxy;
 280+ } elseif ( $proxy === false ) {
 281+ $opt['noProxy'] = true;
 282+ }
 283+
 284+ foreach ( $this->test_posturl as $u => $postData ) {
 285+ $opt['postData'] = $postData;
 286+ $r = Http::post( $u, $opt );
 287+ $this->assertEquals( self::$content["POST $u => $postData"], "$r",
 288+ "POST $u (postData=$postData) with " . Http::$httpEngine );
 289+ }
 290+ }
 291+
 292+ function testPostDefault() {
 293+ Http::$httpEngine = false;
 294+ $this->runHTTPPosts();
 295+ }
 296+
 297+ function testPostPhp() {
 298+ if ( !self::$has_fopen ) {
 299+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
 300+ }
 301+
 302+ Http::$httpEngine = "php";
 303+ $this->runHTTPPosts();
 304+ }
 305+
 306+ function testPostCurl() {
 307+ if ( !self::$has_curl ) {
 308+ $this->markTestIncomplete( "This test requires curl." );
 309+ }
 310+
 311+ Http::$httpEngine = "curl";
 312+ $this->runHTTPPosts();
 313+ }
 314+
 315+ function runProxyRequests() {
 316+ if ( !self::$has_proxy ) {
 317+ $this->markTestIncomplete( "This test requires a proxy." );
 318+ }
 319+ $this->runHTTPGets( self::$proxy );
 320+ $this->runHTTPPosts( self::$proxy );
 321+ $this->runHTTPRequests( self::$proxy );
 322+
 323+ // Set false here to do noProxy
 324+ $this->runHTTPGets( false );
 325+ $this->runHTTPPosts( false );
 326+ $this->runHTTPRequests( false );
 327+ }
 328+
 329+ function testProxyDefault() {
 330+ Http::$httpEngine = false;
 331+ $this->runProxyRequests();
 332+ }
 333+
 334+ function testProxyPhp() {
 335+ if ( !self::$has_fopen ) {
 336+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
 337+ }
 338+
 339+ Http::$httpEngine = 'php';
 340+ $this->runProxyRequests();
 341+ }
 342+
 343+ function testProxyCurl() {
 344+ if ( !self::$has_curl ) {
 345+ $this->markTestIncomplete( "This test requires curl." );
 346+ }
 347+
 348+ Http::$httpEngine = 'curl';
 349+ $this->runProxyRequests();
 350+ }
 351+
 352+ function testIsLocalUrl() {
 353+ }
 354+
 355+ /* ./extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php:559: $user_agent = Http::userAgent(); */
 356+ function testUserAgent() {
 357+ }
 358+
 359+ function testIsValidUrl() {
 360+ }
 361+
 362+ function testValidateCookieDomain() {
 363+ $this->assertFalse( Cookie::validateCookieDomain( "co.uk" ) );
 364+ $this->assertFalse( Cookie::validateCookieDomain( ".co.uk" ) );
 365+ $this->assertFalse( Cookie::validateCookieDomain( "gov.uk" ) );
 366+ $this->assertFalse( Cookie::validateCookieDomain( ".gov.uk" ) );
 367+ $this->assertTrue( Cookie::validateCookieDomain( "supermarket.uk" ) );
 368+ $this->assertFalse( Cookie::validateCookieDomain( "uk" ) );
 369+ $this->assertFalse( Cookie::validateCookieDomain( ".uk" ) );
 370+ $this->assertFalse( Cookie::validateCookieDomain( "127.0.0." ) );
 371+ $this->assertFalse( Cookie::validateCookieDomain( "127." ) );
 372+ $this->assertFalse( Cookie::validateCookieDomain( "127.0.0.1." ) );
 373+ $this->assertTrue( Cookie::validateCookieDomain( "127.0.0.1" ) );
 374+ $this->assertFalse( Cookie::validateCookieDomain( "333.0.0.1" ) );
 375+ $this->assertTrue( Cookie::validateCookieDomain( "example.com" ) );
 376+ $this->assertFalse( Cookie::validateCookieDomain( "example.com." ) );
 377+ $this->assertTrue( Cookie::validateCookieDomain( ".example.com" ) );
 378+
 379+ $this->assertTrue( Cookie::validateCookieDomain( ".example.com", "www.example.com" ) );
 380+ $this->assertFalse( Cookie::validateCookieDomain( "example.com", "www.example.com" ) );
 381+ $this->assertTrue( Cookie::validateCookieDomain( "127.0.0.1", "127.0.0.1" ) );
 382+ $this->assertFalse( Cookie::validateCookieDomain( "127.0.0.1", "localhost" ) );
 383+
 384+
 385+ }
 386+
 387+ function testSetCooke() {
 388+ $c = new MockCookie( "name", "value",
 389+ array(
 390+ "domain" => "ac.th",
 391+ "path" => "/path/",
 392+ ) );
 393+ $this->assertFalse( $c->canServeDomain( "ac.th" ) );
 394+
 395+ $c = new MockCookie( "name", "value",
 396+ array(
 397+ "domain" => "example.com",
 398+ "path" => "/path/",
 399+ ) );
 400+
 401+ $this->assertTrue( $c->canServeDomain( "example.com" ) );
 402+ $this->assertFalse( $c->canServeDomain( "www.example.com" ) );
 403+
 404+ $c = new MockCookie( "name", "value",
 405+ array(
 406+ "domain" => ".example.com",
 407+ "path" => "/path/",
 408+ ) );
 409+
 410+ $this->assertFalse( $c->canServeDomain( "www.example.net" ) );
 411+ $this->assertFalse( $c->canServeDomain( "example.com" ) );
 412+ $this->assertTrue( $c->canServeDomain( "www.example.com" ) );
 413+
 414+ $this->assertFalse( $c->canServePath( "/" ) );
 415+ $this->assertFalse( $c->canServePath( "/bogus/path/" ) );
 416+ $this->assertFalse( $c->canServePath( "/path" ) );
 417+ $this->assertTrue( $c->canServePath( "/path/" ) );
 418+
 419+ $this->assertTrue( $c->isUnExpired() );
 420+
 421+ $this->assertEquals( "", $c->serializeToHttpRequest( "/path/", "www.example.net" ) );
 422+ $this->assertEquals( "", $c->serializeToHttpRequest( "/", "www.example.com" ) );
 423+ $this->assertEquals( "name=value", $c->serializeToHttpRequest( "/path/", "www.example.com" ) );
 424+
 425+ $c = new MockCookie( "name", "value",
 426+ array(
 427+ "domain" => "www.example.com",
 428+ "path" => "/path/",
 429+ ) );
 430+ $this->assertFalse( $c->canServeDomain( "example.com" ) );
 431+ $this->assertFalse( $c->canServeDomain( "www.example.net" ) );
 432+ $this->assertTrue( $c->canServeDomain( "www.example.com" ) );
 433+
 434+ $c = new MockCookie( "name", "value",
 435+ array(
 436+ "domain" => ".example.com",
 437+ "path" => "/path/",
 438+ "expires" => "-1 day",
 439+ ) );
 440+ $this->assertFalse( $c->isUnExpired() );
 441+ $this->assertEquals( "", $c->serializeToHttpRequest( "/path/", "www.example.com" ) );
 442+
 443+ $c = new MockCookie( "name", "value",
 444+ array(
 445+ "domain" => ".example.com",
 446+ "path" => "/path/",
 447+ "expires" => "+1 day",
 448+ ) );
 449+ $this->assertTrue( $c->isUnExpired() );
 450+ $this->assertEquals( "name=value", $c->serializeToHttpRequest( "/path/", "www.example.com" ) );
 451+ }
 452+
 453+ function testCookieJarSetCookie() {
 454+ $cj = new CookieJar;
 455+ $cj->setCookie( "name", "value",
 456+ array(
 457+ "domain" => ".example.com",
 458+ "path" => "/path/",
 459+ ) );
 460+ $cj->setCookie( "name2", "value",
 461+ array(
 462+ "domain" => ".example.com",
 463+ "path" => "/path/sub",
 464+ ) );
 465+ $cj->setCookie( "name3", "value",
 466+ array(
 467+ "domain" => ".example.com",
 468+ "path" => "/",
 469+ ) );
 470+ $cj->setCookie( "name4", "value",
 471+ array(
 472+ "domain" => ".example.net",
 473+ "path" => "/path/",
 474+ ) );
 475+ $cj->setCookie( "name5", "value",
 476+ array(
 477+ "domain" => ".example.net",
 478+ "path" => "/path/",
 479+ "expires" => "-1 day",
 480+ ) );
 481+
 482+ $this->assertEquals( "name4=value", $cj->serializeToHttpRequest( "/path/", "www.example.net" ) );
 483+ $this->assertEquals( "name3=value", $cj->serializeToHttpRequest( "/", "www.example.com" ) );
 484+ $this->assertEquals( "name=value; name3=value", $cj->serializeToHttpRequest( "/path/", "www.example.com" ) );
 485+
 486+ $cj->setCookie( "name5", "value",
 487+ array(
 488+ "domain" => ".example.net",
 489+ "path" => "/path/",
 490+ "expires" => "+1 day",
 491+ ) );
 492+ $this->assertEquals( "name4=value; name5=value", $cj->serializeToHttpRequest( "/path/", "www.example.net" ) );
 493+
 494+ $cj->setCookie( "name4", "value",
 495+ array(
 496+ "domain" => ".example.net",
 497+ "path" => "/path/",
 498+ "expires" => "-1 day",
 499+ ) );
 500+ $this->assertEquals( "name5=value", $cj->serializeToHttpRequest( "/path/", "www.example.net" ) );
 501+ }
 502+
 503+ function testParseResponseHeader() {
 504+ $cj = new CookieJar;
 505+
 506+ $h[] = "Set-Cookie: name4=value; domain=.example.com; path=/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
 507+ $cj->parseCookieResponseHeader( $h[0], "www.example.com" );
 508+ $this->assertEquals( "name4=value", $cj->serializeToHttpRequest( "/", "www.example.com" ) );
 509+
 510+ $h[] = "name4=value2; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
 511+ $cj->parseCookieResponseHeader( $h[1], "www.example.com" );
 512+ $this->assertEquals( "", $cj->serializeToHttpRequest( "/", "www.example.com" ) );
 513+ $this->assertEquals( "name4=value2", $cj->serializeToHttpRequest( "/path/", "www.example.com" ) );
 514+
 515+ $h[] = "name5=value3; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
 516+ $cj->parseCookieResponseHeader( $h[2], "www.example.com" );
 517+ $this->assertEquals( "name4=value2; name5=value3", $cj->serializeToHttpRequest( "/path/", "www.example.com" ) );
 518+
 519+ $h[] = "name6=value3; domain=.example.net; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
 520+ $cj->parseCookieResponseHeader( $h[3], "www.example.com" );
 521+ $this->assertEquals( "", $cj->serializeToHttpRequest( "/path/", "www.example.net" ) );
 522+
 523+ $h[] = "name6=value0; domain=.example.net; path=/path/; expires=Mon, 09-Dec-1999 13:46:00 GMT";
 524+ $cj->parseCookieResponseHeader( $h[4], "www.example.net" );
 525+ $this->assertEquals( "", $cj->serializeToHttpRequest( "/path/", "www.example.net" ) );
 526+
 527+ $h[] = "name6=value4; domain=.example.net; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
 528+ $cj->parseCookieResponseHeader( $h[5], "www.example.net" );
 529+ $this->assertEquals( "name6=value4", $cj->serializeToHttpRequest( "/path/", "www.example.net" ) );
 530+ }
 531+
 532+ function runCookieRequests() {
 533+ $r = HttpRequest::factory( "http://www.php.net/manual", array( 'followRedirects' => true ) );
 534+ $r->execute();
 535+
 536+ $jar = $r->getCookieJar();
 537+ $this->assertThat( $jar, $this->isInstanceOf( 'CookieJar' ) );
 538+
 539+ if ( is_a( $r, 'PhpHttpRequest' ) && version_compare( '5.1.7', phpversion(), '>' ) ) {
 540+ $this->markTestSkipped( 'Redirection fails or crashes PHP on 5.1.6 and prior' );
 541+ }
 542+ $serialized = $jar->serializeToHttpRequest( "/search?q=test", "www.php.net" );
 543+ $this->assertRegExp( '/\bCOUNTRY=[^=;]+/', $serialized );
 544+ $this->assertRegExp( '/\bLAST_LANG=[^=;]+/', $serialized );
 545+ $this->assertEquals( '', $jar->serializeToHttpRequest( "/search?q=test", "www.php.com" ) );
 546+ }
 547+
 548+ function testCookieRequestDefault() {
 549+ Http::$httpEngine = false;
 550+ $this->runCookieRequests();
 551+ }
 552+ function testCookieRequestPhp() {
 553+ if ( !self::$has_fopen ) {
 554+ $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
 555+ }
 556+
 557+ Http::$httpEngine = 'php';
 558+ $this->runCookieRequests();
 559+ }
 560+ function testCookieRequestCurl() {
 561+ if ( !self::$has_curl ) {
 562+ $this->markTestIncomplete( "This test requires curl." );
 563+ }
 564+
 565+ Http::$httpEngine = 'curl';
 566+ $this->runCookieRequests();
 567+ }
 568+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/HttpTest.php
___________________________________________________________________
Added: svn:eol-style
1569 + native
Added: svn:eol-syle
2570 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/search/SearchUpdateTest.php
@@ -0,0 +1,123 @@
 2+<?php
 3+
 4+class DatabaseMock extends DatabaseBase {
 5+ function __construct( $server = false, $user = false, $password = false, $dbName = false,
 6+ $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
 7+ {
 8+ $this->mConn = true;
 9+ $this->mOpened = true;
 10+ }
 11+
 12+ function open( $server, $user, $password, $dbName ) { return true; }
 13+ function doQuery( $sql ) { }
 14+ function fetchObject( $res ) { }
 15+ function fetchRow( $res ) { }
 16+ function numRows( $res ) { }
 17+ function numFields( $res ) { }
 18+ function fieldName( $res, $n ) { }
 19+ function insertId() { }
 20+ function dataSeek( $res, $row ) { }
 21+ function lastErrno() { return 0; }
 22+ function lastError() { return ''; }
 23+ function affectedRows() { }
 24+ function fieldInfo( $table, $field ) { }
 25+ function strencode( $s ) { }
 26+ static function getSoftwareLink() { }
 27+ function getServerVersion() { }
 28+ function getType() { }
 29+ function getSearchEngine() { }
 30+}
 31+
 32+class MockSearch extends SearchEngine {
 33+ public static $id;
 34+ public static $title;
 35+ public static $text;
 36+
 37+ public function __construct( $db ) {
 38+ }
 39+
 40+ public function update( $id, $title, $text ) {
 41+ self::$id = $id;
 42+ self::$title = $title;
 43+ self::$text = $text;
 44+ }
 45+}
 46+
 47+class SearchUpdateTest extends PHPUnit_Framework_TestCase {
 48+ static $searchType;
 49+ static $dbtype;
 50+ static $factoryconf;
 51+ static $dbservers;
 52+
 53+ function update( $text, $title = 'Test', $id = 1 ) {
 54+ $u = new SearchUpdate( $id, $title, $text );
 55+ $u->doUpdate();
 56+ return array( MockSearch::$title, MockSearch::$text );
 57+ }
 58+
 59+ function updateText( $text ) {
 60+ list( $title, $resultText ) = $this->update( $text );
 61+ $resultText = trim( $resultText ); // abstract from some implementation details
 62+ return $resultText;
 63+ }
 64+
 65+ function setUp() {
 66+ global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers, $wgContLang;
 67+
 68+ self::$searchType = $wgSearchType;
 69+ self::$dbtype = $wgDBtype;
 70+ self::$factoryconf = $wgLBFactoryConf;
 71+ self::$dbservers = $wgDBservers;
 72+
 73+ $wgSearchType = 'MockSearch';
 74+ $wgDBtype = 'mock';
 75+ $wgLBFactoryConf['class'] = 'LBFactory_Simple';
 76+ $wgDBservers = null;
 77+ $wgContLang = Language::factory( 'en' );
 78+ LBFactory::destroyInstance();
 79+ }
 80+
 81+ function tearDown() {
 82+ global $wgSearchType, $wgDBtype, $wgLBFactoryConf, $wgDBservers, $wgContLang;
 83+
 84+ LBFactory::destroyInstance();
 85+
 86+ $wgSearchType = self::$searchType;
 87+ $wgDBtype = self::$dbtype;
 88+ $wgLBFactoryConf = self::$factoryconf;
 89+ $wgDBservers = self::$dbservers;
 90+ $wgContLang = null;
 91+ }
 92+
 93+ function testUpdateText() {
 94+ $this->assertEquals(
 95+ 'test',
 96+ $this->updateText( '<div>TeSt</div>' ),
 97+ 'HTML stripped, text lowercased'
 98+ );
 99+
 100+ $this->assertEquals(
 101+ 'foo bar boz quux',
 102+ $this->updateText( <<<EOT
 103+<table style="color:red; font-size:100px">
 104+ <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>
 105+ <tr><td>boz</td><tr>quux</td></tr>
 106+</table>
 107+EOT
 108+ ), 'Stripping HTML tables' );
 109+
 110+ $this->assertEquals(
 111+ 'a b',
 112+ $this->updateText( 'a > b' ),
 113+ 'Handle unclosed tags'
 114+ );
 115+
 116+ $text = str_pad( "foo <barbarbar \n", 10000, 'x' );
 117+
 118+ $this->assertNotEquals(
 119+ '',
 120+ $this->updateText( $text ),
 121+ 'Bug 18609'
 122+ );
 123+ }
 124+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/search/SearchUpdateTest.php
___________________________________________________________________
Added: svn:eol-style
1125 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/search/SearchDbTest.php
@@ -0,0 +1,34 @@
 2+<?php
 3+
 4+require_once( 'SearchEngineTest.php' );
 5+
 6+class SearchDbTest extends SearchEngineTest {
 7+ var $db;
 8+
 9+ function setUp() {
 10+ $this->db = wfGetDB( DB_MASTER );
 11+ if ( !$this->db ) {
 12+ $this->markTestIncomplete( "Can't find a database to test with." );
 13+ }
 14+
 15+ $GLOBALS['wgContLang'] = new Language;
 16+ $this->insertSearchData();
 17+
 18+ $this->insertSearchData();
 19+ $searchType = preg_replace( "/Database/", "Search",
 20+ get_class( $this->db ) );
 21+ $this->search = new $searchType( $this->db );
 22+ }
 23+
 24+ function tearDown() {
 25+ $this->removeSearchData();
 26+ if ( !is_null( $this->db ) ) {
 27+ wfGetLB()->closeConnecton( $this->db );
 28+ }
 29+ unset( $this->db );
 30+ unset( $this->search );
 31+ $GLOBALS['wgContLang'] = null;
 32+ }
 33+}
 34+
 35+
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/search/SearchDbTest.php
___________________________________________________________________
Added: svn:keywords
136 + Author Date Id Revision
Added: svn:eol-style
237 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/search/SearchEngineTest.php
@@ -0,0 +1,176 @@
 2+<?php
 3+
 4+/**
 5+ * @group Stub
 6+ */
 7+class SearchEngineTest extends MediaWikiTestSetup {
 8+ var $db, $search, $pageList;
 9+
 10+ function pageExists( $title ) {
 11+ return false;
 12+ }
 13+
 14+ function insertSearchData() {
 15+ if ( $this->pageExists( 'Not_Main_Page' ) ) {
 16+ return;
 17+ }
 18+ $this->insertPage( "Not_Main_Page", "This is not a main page", 0 );
 19+ $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 );
 20+ $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 );
 21+ $this->insertPage( 'Talk:Smithee', 'This article sucks.', 1 );
 22+ $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.', 0 );
 23+ $this->insertPage( 'Another_page', 'This page also is unrelated.', 0 );
 24+ $this->insertPage( 'Help:Help', 'Help me!', 4 );
 25+ $this->insertPage( 'Thppt', 'Blah blah', 0 );
 26+ $this->insertPage( 'Alan_Smithee', 'yum', 0 );
 27+ $this->insertPage( 'Pages', 'are\'food', 0 );
 28+ $this->insertPage( 'HalfOneUp', 'AZ', 0 );
 29+ $this->insertPage( 'FullOneUp', 'AZ', 0 );
 30+ $this->insertPage( 'HalfTwoLow', 'az', 0 );
 31+ $this->insertPage( 'FullTwoLow', 'az', 0 );
 32+ $this->insertPage( 'HalfNumbers', '1234567890', 0 );
 33+ $this->insertPage( 'FullNumbers', '1234567890', 0 );
 34+ $this->insertPage( 'DomainName', 'example.com', 0 );
 35+ }
 36+
 37+ function removeSearchData() {
 38+ return;
 39+ /*while ( count( $this->pageList ) ) {
 40+ list( $title, $id ) = array_pop( $this->pageList );
 41+ $article = new Article( $title, $id );
 42+ $article->doDeleteArticle( "Search Test" );
 43+ }*/
 44+ }
 45+
 46+ function fetchIds( $results ) {
 47+ $this->assertTrue( is_object( $results ) );
 48+
 49+ if ( $this->db->getType() !== 'mysql' && $this->db->getType() !== 'sqlite' ) {
 50+ $this->markTestSkipped( "MySQL or SQLite only" );
 51+ }
 52+ $matches = array();
 53+ while ( $row = $results->next() ) {
 54+ $matches[] = $row->getTitle()->getPrefixedText();
 55+ }
 56+ $results->free();
 57+ # Search is not guaranteed to return results in a certain order;
 58+ # sort them numerically so we will compare simply that we received
 59+ # the expected matches.
 60+ sort( $matches );
 61+ return $matches;
 62+ }
 63+
 64+ // Modified version of WikiRevision::importOldRevision()
 65+ function insertPage( $pageName, $text, $ns ) {
 66+ $dbw = $this->db;
 67+ $title = Title::newFromText( $pageName );
 68+
 69+ $userId = 0;
 70+ $userText = 'WikiSysop';
 71+ $comment = 'Search Test';
 72+
 73+ // avoid memory leak...?
 74+ $linkCache = LinkCache::singleton();
 75+ $linkCache->clear();
 76+
 77+ $article = new Article( $title );
 78+ $pageId = $article->getId();
 79+ $created = false;
 80+ if ( $pageId == 0 ) {
 81+ # must create the page...
 82+ $pageId = $article->insertOn( $dbw );
 83+ $created = true;
 84+ }
 85+
 86+ # FIXME: Use original rev_id optionally (better for backups)
 87+ # Insert the row
 88+ $revision = new Revision( array(
 89+ 'page' => $pageId,
 90+ 'text' => $text,
 91+ 'comment' => $comment,
 92+ 'user' => $userId,
 93+ 'user_text' => $userText,
 94+ 'timestamp' => 0,
 95+ 'minor_edit' => false,
 96+ ) );
 97+ $revId = $revision->insertOn( $dbw );
 98+ $changed = $article->updateIfNewerOn( $dbw, $revision );
 99+
 100+ $GLOBALS['wgTitle'] = $title;
 101+ if ( $created ) {
 102+ Article::onArticleCreate( $title );
 103+ $article->createUpdates( $revision );
 104+ } elseif ( $changed ) {
 105+ Article::onArticleEdit( $title );
 106+ $article->editUpdates(
 107+ $text, $comment, false, 0, $revId );
 108+ }
 109+
 110+ $su = new SearchUpdate( $article->getId(), $pageName, $text );
 111+ $su->doUpdate();
 112+
 113+ $this->pageList[] = array( $title, $article->getId() );
 114+
 115+ return true;
 116+ }
 117+
 118+ function testFullWidth() {
 119+ $this->assertEquals(
 120+ array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
 121+ $this->fetchIds( $this->search->searchText( 'AZ' ) ),
 122+ "Search for normalized from Half-width Upper" );
 123+ $this->assertEquals(
 124+ array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
 125+ $this->fetchIds( $this->search->searchText( 'az' ) ),
 126+ "Search for normalized from Half-width Lower" );
 127+ $this->assertEquals(
 128+ array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
 129+ $this->fetchIds( $this->search->searchText( 'AZ' ) ),
 130+ "Search for normalized from Full-width Upper" );
 131+ $this->assertEquals(
 132+ array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
 133+ $this->fetchIds( $this->search->searchText( 'az' ) ),
 134+ "Search for normalized from Full-width Lower" );
 135+ }
 136+
 137+ function testTextSearch() {
 138+ $this->assertEquals(
 139+ array( 'Smithee' ),
 140+ $this->fetchIds( $this->search->searchText( 'smithee' ) ),
 141+ "Plain search failed" );
 142+ }
 143+
 144+ function testTextPowerSearch() {
 145+ $this->search->setNamespaces( array( 0, 1, 4 ) );
 146+ $this->assertEquals(
 147+ array(
 148+ 'Smithee',
 149+ 'Talk:Not Main Page',
 150+ ),
 151+ $this->fetchIds( $this->search->searchText( 'smithee' ) ),
 152+ "Power search failed" );
 153+ }
 154+
 155+ function testTitleSearch() {
 156+ $this->assertEquals(
 157+ array(
 158+ 'Alan Smithee',
 159+ 'Smithee',
 160+ ),
 161+ $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
 162+ "Title search failed" );
 163+ }
 164+
 165+ function testTextTitlePowerSearch() {
 166+ $this->search->setNamespaces( array( 0, 1, 4 ) );
 167+ $this->assertEquals(
 168+ array(
 169+ 'Alan Smithee',
 170+ 'Smithee',
 171+ 'Talk:Smithee',
 172+ ),
 173+ $this->fetchIds( $this->search->searchTitle( 'smithee' ) ),
 174+ "Title power search failed" );
 175+ }
 176+
 177+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/search/SearchEngineTest.php
___________________________________________________________________
Added: svn:keywords
1178 + Author Date Id Revision
Added: svn:eol-style
2179 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/TitleTest.php
@@ -0,0 +1,17 @@
 2+<?php
 3+
 4+class TitleTest extends PHPUnit_Framework_TestCase {
 5+
 6+ function testLegalChars() {
 7+ $titlechars = Title::legalChars();
 8+
 9+ foreach ( range( 1, 255 ) as $num ) {
 10+ $chr = chr( $num );
 11+ if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
 12+ $this->assertFalse( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid titlechar" );
 13+ } else {
 14+ $this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" );
 15+ }
 16+ }
 17+ }
 18+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/TitleTest.php
___________________________________________________________________
Added: svn:eol-style
119 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php
@@ -0,0 +1,222 @@
 2+<?php
 3+
 4+require_once( 'ApiSetup.php' );
 5+
 6+class MockApi extends ApiBase {
 7+ public function execute() { }
 8+ public function getVersion() { }
 9+
 10+ public function __construct() { }
 11+
 12+ public function getAllowedParams() {
 13+ return array(
 14+ 'filename' => null,
 15+ 'enablechunks' => false,
 16+ 'sessionkey' => null,
 17+ );
 18+ }
 19+}
 20+
 21+class ApiTest extends ApiTestSetup {
 22+
 23+ function setup() {
 24+ parent::setup();
 25+ }
 26+
 27+ function testRequireOnlyOneParameterDefault() {
 28+ $mock = new MockApi();
 29+
 30+ $this->assertEquals(
 31+ null, $mock->requireOnlyOneParameter( array( "filename" => "foo.txt",
 32+ "enablechunks" => false ), "filename", "enablechunks" ) );
 33+ }
 34+
 35+ /**
 36+ * @expectedException UsageException
 37+ */
 38+ function testRequireOnlyOneParameterZero() {
 39+ $mock = new MockApi();
 40+
 41+ $this->assertEquals(
 42+ null, $mock->requireOnlyOneParameter( array( "filename" => "foo.txt",
 43+ "enablechunks" => 0 ), "filename", "enablechunks" ) );
 44+ }
 45+
 46+ /**
 47+ * @expectedException UsageException
 48+ */
 49+ function testRequireOnlyOneParameterTrue() {
 50+ $mock = new MockApi();
 51+
 52+ $this->assertEquals(
 53+ null, $mock->requireOnlyOneParameter( array( "filename" => "foo.txt",
 54+ "enablechunks" => true ), "filename", "enablechunks" ) );
 55+ }
 56+
 57+ function testApi() {
 58+ global $wgServerName, $wgServer;
 59+
 60+ if ( !isset( $wgServerName ) || !isset( $wgServer ) ) {
 61+ $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
 62+ 'be set in LocalSettings.php' );
 63+ }
 64+ /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */
 65+ $resp = Http::get( self::$apiUrl . "?format=xml" );
 66+
 67+ libxml_use_internal_errors( true );
 68+ $sxe = simplexml_load_string( $resp );
 69+ $this->assertNotType( "bool", $sxe );
 70+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
 71+ }
 72+
 73+ function testApiLoginNoName() {
 74+ global $wgServerName, $wgServer;
 75+
 76+ if ( !isset( $wgServerName ) || !isset( $wgServer ) ) {
 77+ $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
 78+ 'be set in LocalSettings.php' );
 79+ }
 80+ $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
 81+ array( "postData" => array(
 82+ "lgname" => "",
 83+ "lgpassword" => self::$passWord ) ) );
 84+ libxml_use_internal_errors( true );
 85+ $sxe = simplexml_load_string( $resp );
 86+ $this->assertNotType( "bool", $sxe );
 87+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
 88+ $a = $sxe->login[0]->attributes()->result;
 89+ $this->assertEquals( ' result="NoName"', $a->asXML() );
 90+ }
 91+
 92+ function testApiLoginBadPass() {
 93+ global $wgServerName, $wgServer;
 94+
 95+ if ( !isset( $wgServerName ) || !isset( $wgServer ) ) {
 96+ $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
 97+ 'be set in LocalSettings.php' );
 98+ }
 99+ $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
 100+ array( "postData" => array(
 101+ "lgname" => self::$userName,
 102+ "lgpassword" => "bad" ) ) );
 103+ libxml_use_internal_errors( true );
 104+ $sxe = simplexml_load_string( $resp );
 105+ $this->assertNotType( "bool", $sxe );
 106+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
 107+ $a = $sxe->login[0]->attributes()->result[0];
 108+ $this->assertEquals( ' result="NeedToken"', $a->asXML() );
 109+
 110+ $token = (string)$sxe->login[0]->attributes()->token;
 111+
 112+ $resp = Http::post( self::$apiUrl . "?action=login&format=xml",
 113+ array( "postData" => array(
 114+ "lgtoken" => $token,
 115+ "lgname" => self::$userName,
 116+ "lgpassword" => "bad" ) ) );
 117+
 118+
 119+ $sxe = simplexml_load_string( $resp );
 120+ $this->assertNotType( "bool", $sxe );
 121+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
 122+ $a = $sxe->login[0]->attributes()->result[0];
 123+
 124+ $this->assertEquals( ' result="NeedToken"', $a->asXML() );
 125+ }
 126+
 127+ function testApiLoginGoodPass() {
 128+ global $wgServerName, $wgServer;
 129+
 130+ if ( !isset( $wgServerName ) || !isset( $wgServer ) ) {
 131+ $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
 132+ 'be set in LocalSettings.php' );
 133+ }
 134+ $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml",
 135+ array( "method" => "POST",
 136+ "postData" => array(
 137+ "lgname" => self::$userName,
 138+ "lgpassword" => self::$passWord ) ) );
 139+ $req->execute();
 140+
 141+ libxml_use_internal_errors( true );
 142+ $sxe = simplexml_load_string( $req->getContent() );
 143+ $this->assertNotType( "bool", $sxe );
 144+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
 145+
 146+ $a = $sxe->login[0]->attributes()->result[0];
 147+ $this->assertEquals( ' result="NeedToken"', $a->asXML() );
 148+ $token = (string)$sxe->login[0]->attributes()->token;
 149+
 150+ $req->setData( array(
 151+ "lgtoken" => $token,
 152+ "lgname" => self::$userName,
 153+ "lgpassword" => self::$passWord ) );
 154+ $req->execute();
 155+
 156+ $sxe = simplexml_load_string( $req->getContent() );
 157+
 158+ $this->assertNotType( "bool", $sxe );
 159+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
 160+ $a = $sxe->login[0]->attributes()->result[0];
 161+
 162+ $this->assertEquals( ' result="Success"', $a->asXML() );
 163+ }
 164+
 165+ function testApiGotCookie() {
 166+ global $wgServerName, $wgServer, $wgScriptPath;
 167+
 168+ if ( !isset( $wgServerName ) || !isset( $wgServer ) ) {
 169+ $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
 170+ 'be set in LocalSettings.php' );
 171+ }
 172+ $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml",
 173+ array( "method" => "POST",
 174+ "postData" => array(
 175+ "lgname" => self::$userName,
 176+ "lgpassword" => self::$passWord ) ) );
 177+ $req->execute();
 178+
 179+ libxml_use_internal_errors( true );
 180+ $sxe = simplexml_load_string( $req->getContent() );
 181+ $this->assertNotType( "bool", $sxe );
 182+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
 183+
 184+ $a = $sxe->login[0]->attributes()->result[0];
 185+ $this->assertEquals( ' result="NeedToken"', $a->asXML() );
 186+ $token = (string)$sxe->login[0]->attributes()->token;
 187+
 188+ $req->setData( array(
 189+ "lgtoken" => $token,
 190+ "lgname" => self::$userName,
 191+ "lgpassword" => self::$passWord ) );
 192+ $req->execute();
 193+
 194+ $cj = $req->getCookieJar();
 195+ $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/',
 196+ $cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ) );
 197+
 198+
 199+ return $cj;
 200+ }
 201+
 202+ /**
 203+ * @depends testApiGotCookie
 204+ */
 205+ function testApiListPages( CookieJar $cj ) {
 206+ $this->markTestIncomplete( "Not done with this yet" );
 207+ global $wgServerName, $wgServer;
 208+
 209+ if ( $wgServerName == "localhost" || $wgServer == "http://localhost" ) {
 210+ $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
 211+ 'be set in LocalSettings.php' );
 212+ }
 213+ $req = HttpRequest::factory( self::$apiUrl . "?action=query&format=xml&prop=revisions&" .
 214+ "titles=Main%20Page&rvprop=timestamp|user|comment|content" );
 215+ $req->setCookieJar( $cj );
 216+ $req->execute();
 217+ libxml_use_internal_errors( true );
 218+ $sxe = simplexml_load_string( $req->getContent() );
 219+ $this->assertNotType( "bool", $sxe );
 220+ $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
 221+ $a = $sxe->query[0]->pages[0]->page[0]->attributes();
 222+ }
 223+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php
___________________________________________________________________
Added: svn:eol-style
1224 + native
Added: svn:eol-syle
2225 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiSetup.php
@@ -0,0 +1,39 @@
 2+<?php
 3+
 4+abstract class ApiTestSetup extends PHPUnit_Framework_TestCase {
 5+ protected static $userName;
 6+ protected static $passWord;
 7+ protected static $user;
 8+ protected static $apiUrl;
 9+
 10+ function setup() {
 11+ global $wgServer, $wgContLang, $wgAuth, $wgScriptPath,
 12+ $wgScriptExtension, $wgMemc, $wgRequest;
 13+
 14+ self::$apiUrl = $wgServer . $wgScriptPath . "/api" . $wgScriptExtension;
 15+
 16+ $wgMemc = new FakeMemCachedClient;
 17+ $wgContLang = Language::factory( 'en' );
 18+ $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
 19+ $wgRequest = new FauxRequest( array() );
 20+ self::setupUser();
 21+ }
 22+
 23+ static function setupUser() {
 24+ if ( self::$user == NULL ) {
 25+ self::$userName = "Useruser";
 26+ self::$passWord = 'Passpass';
 27+
 28+ self::$user = User::newFromName( self::$userName );
 29+ if ( !self::$user->getID() ) {
 30+ self::$user = User::createNew( self::$userName, array(
 31+ "email" => "test@example.com",
 32+ "real_name" => "Test User" ) );
 33+ }
 34+ self::$user->setPassword( self::$passWord );
 35+ self::$user->saveSettings();
 36+ }
 37+
 38+ $GLOBALS['wgUser'] = self::$user;
 39+ }
 40+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiSetup.php
___________________________________________________________________
Added: svn:eol-style
141 + native
Added: svn:eol-syle
242 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiWatchTest.php
@@ -0,0 +1,211 @@
 2+<?php
 3+
 4+class ApiWatchTest extends ApiTestSetup {
 5+
 6+ function setUp() {
 7+ ini_set( 'log_errors', 1 );
 8+ ini_set( 'error_reporting', 1 );
 9+ ini_set( 'display_errors', 1 );
 10+
 11+ global $wgMemc;
 12+ $wgMemc = new FakeMemCachedClient;
 13+ }
 14+
 15+ function tearDown() {
 16+ global $wgMemc;
 17+
 18+ $wgMemc = null;
 19+ }
 20+
 21+
 22+ function doApiRequest( $params, $data = null ) {
 23+ $_SESSION = isset( $data[2] ) ? $data[2] : array();
 24+
 25+ $req = new FauxRequest( $params, true, $_SESSION );
 26+ $module = new ApiMain( $req, true );
 27+ $module->execute();
 28+
 29+ $data[0] = $module->getResultData();
 30+ $data[1] = $req;
 31+ $data[2] = $_SESSION;
 32+
 33+ return $data;
 34+ }
 35+
 36+ function testLogin() {
 37+ $data = $this->doApiRequest( array(
 38+ 'action' => 'login',
 39+ 'lgname' => 'WikiSysop',
 40+ 'lgpassword' => 'none' ), $data );
 41+
 42+ $this->assertArrayHasKey( "login", $data[0] );
 43+ $this->assertArrayHasKey( "result", $data[0]['login'] );
 44+ $this->assertEquals( "NeedToken", $data[0]['login']['result'] );
 45+ $token = $data[0]['login']['token'];
 46+
 47+ $data = $this->doApiRequest( array(
 48+ 'action' => 'login',
 49+ "lgtoken" => $token,
 50+ "lgname" => 'WikiSysop',
 51+ "lgpassword" => 'none' ), $data );
 52+
 53+ $this->assertArrayHasKey( "login", $data[0] );
 54+ $this->assertArrayHasKey( "result", $data[0]['login'] );
 55+ $this->assertEquals( "Success", $data[0]['login']['result'] );
 56+ $this->assertArrayHasKey( 'lgtoken', $data[0]['login'] );
 57+
 58+ return $data;
 59+ }
 60+
 61+ function testGetToken() {
 62+
 63+ $data = $this->doApiRequest( array(
 64+ 'action' => 'query',
 65+ 'titles' => 'Main Page',
 66+ 'intoken' => 'edit|delete|protect|move|block|unblock',
 67+ 'prop' => 'info' ), $data );
 68+
 69+ $this->assertArrayHasKey( 'query', $data[0] );
 70+ $this->assertArrayHasKey( 'pages', $data[0]['query'] );
 71+ $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
 72+
 73+ $this->assertArrayHasKey( $key, $data[0]['query']['pages'] );
 74+ $this->assertArrayHasKey( 'edittoken', $data[0]['query']['pages'][$key] );
 75+ $this->assertArrayHasKey( 'movetoken', $data[0]['query']['pages'][$key] );
 76+ $this->assertArrayHasKey( 'deletetoken', $data[0]['query']['pages'][$key] );
 77+ $this->assertArrayHasKey( 'blocktoken', $data[0]['query']['pages'][$key] );
 78+ $this->assertArrayHasKey( 'unblocktoken', $data[0]['query']['pages'][$key] );
 79+ $this->assertArrayHasKey( 'protecttoken', $data[0]['query']['pages'][$key] );
 80+
 81+ return $data;
 82+ }
 83+
 84+ /**
 85+ * @depends testGetToken
 86+ */
 87+ function testWatchEdit( $data ) {
 88+ $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
 89+ $pageinfo = $data[0]['query']['pages'][$key];
 90+
 91+ $data = $this->doApiRequest( array(
 92+ 'action' => 'edit',
 93+ 'title' => 'Main Page',
 94+ 'text' => 'new text',
 95+ 'token' => $pageinfo['edittoken'],
 96+ 'watchlist' => 'watch' ), $data );
 97+ $this->assertArrayHasKey( 'edit', $data[0] );
 98+ $this->assertArrayHasKey( 'result', $data[0]['edit'] );
 99+ $this->assertEquals( 'Success', $data[0]['edit']['result'] );
 100+
 101+ return $data;
 102+ }
 103+
 104+
 105+ /**
 106+ * @depends testWatchEdit
 107+ */
 108+ function testWatchClear( $data ) {
 109+ $data = $this->doApiRequest( array(
 110+ 'action' => 'query',
 111+ 'list' => 'watchlist' ), $data );
 112+
 113+ if ( isset( $data[0]['query']['watchlist'] ) ) {
 114+ $wl = $data[0]['query']['watchlist'];
 115+
 116+ foreach ( $wl as $page ) {
 117+ $data = $this->doApiRequest( array(
 118+ 'action' => 'watch',
 119+ 'title' => $page['title'],
 120+ 'unwatch' => true ), $data );
 121+ }
 122+ }
 123+ $data = $this->doApiRequest( array(
 124+ 'action' => 'query',
 125+ 'list' => 'watchlist' ), $data );
 126+ $this->assertArrayHasKey( 'query', $data[0] );
 127+ $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
 128+ $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
 129+
 130+ return $data;
 131+ }
 132+
 133+ /**
 134+ * @depends testGetToken
 135+ */
 136+ function testWatchProtect( $data ) {
 137+ $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
 138+ $pageinfo = $data[0]['query']['pages'][$key];
 139+
 140+ $data = $this->doApiRequest( array(
 141+ 'action' => 'protect',
 142+ 'token' => $pageinfo['protecttoken'],
 143+ 'title' => 'Main Page',
 144+ 'protections' => 'edit=sysop',
 145+ 'watchlist' => 'unwatch' ), $data );
 146+
 147+ $this->assertArrayHasKey( 'protect', $data[0] );
 148+ $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
 149+ $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
 150+ $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
 151+ }
 152+
 153+ /**
 154+ * @depends testGetToken
 155+ */
 156+ function testGetRollbackToken( $data ) {
 157+ $data = $this->doApiRequest( array(
 158+ 'action' => 'query',
 159+ 'prop' => 'revisions',
 160+ 'titles' => 'Main Page',
 161+ 'rvtoken' => 'rollback' ), $data );
 162+
 163+ $this->assertArrayHasKey( 'query', $data[0] );
 164+ $this->assertArrayHasKey( 'pages', $data[0]['query'] );
 165+ $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
 166+
 167+ $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
 168+ $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
 169+ $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
 170+ $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
 171+
 172+ return $data;
 173+ }
 174+
 175+ /**
 176+ * @depends testGetRollbackToken
 177+ */
 178+ function testWatchRollback( $data ) {
 179+ $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
 180+ $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0];
 181+
 182+ $data = $this->doApiRequest( array(
 183+ 'action' => 'rollback',
 184+ 'title' => 'Main Page',
 185+ 'user' => 'WikiSysop',
 186+ 'token' => $pageinfo['rollbacktoken'],
 187+ 'watchlist' => 'watch' ), $data );
 188+
 189+ $this->assertArrayHasKey( 'rollback', $data[0] );
 190+ $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
 191+ }
 192+
 193+ /**
 194+ * @depends testGetToken
 195+ */
 196+ function testWatchDelete( $data ) {
 197+ $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
 198+ $pageinfo = $data[0]['query']['pages'][$key];
 199+
 200+ $data = $this->doApiRequest( array(
 201+ 'action' => 'delete',
 202+ 'token' => $pageinfo['deletetoken'],
 203+ 'title' => 'Main Page' ), $data );
 204+ $this->assertArrayHasKey( 'delete', $data[0] );
 205+ $this->assertArrayHasKey( 'title', $data[0]['delete'] );
 206+
 207+ $data = $this->doApiRequest( array(
 208+ 'action' => 'query',
 209+ 'list' => 'watchlist' ), $data );
 210+ }
 211+
 212+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiWatchTest.php
___________________________________________________________________
Added: svn:eol-style
1213 + native
Added: svn:eol-syle
2214 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/UploadTest.php
@@ -0,0 +1,90 @@
 2+<?php
 3+/**
 4+ * @group Upload
 5+ */
 6+class UploadTest extends PHPUnit_Framework_TestCase {
 7+ protected $upload;
 8+
 9+
 10+ function setUp() {
 11+ global $wgContLang;
 12+ parent::setup();
 13+ $wgContLang = Language::factory( 'en' );
 14+ $this->upload = new UploadTestHandler;
 15+ }
 16+
 17+ /**
 18+ * Test various forms of valid and invalid titles that can be supplied.
 19+ */
 20+ public function testTitleValidation() {
 21+
 22+
 23+ /* Test a valid title */
 24+ $this->assertUploadTitleAndCode( 'ValidTitle.jpg',
 25+ 'ValidTitle.jpg', UploadTestHandler::OK,
 26+ 'upload valid title' );
 27+
 28+ /* A title with a slash */
 29+ $this->assertUploadTitleAndCode( 'A/B.jpg',
 30+ 'B.jpg', UploadTestHandler::OK,
 31+ 'upload title with slash' );
 32+
 33+ /* A title with illegal char */
 34+ $this->assertUploadTitleAndCode( 'A:B.jpg',
 35+ 'A-B.jpg', UploadTestHandler::OK,
 36+ 'upload title with colon' );
 37+
 38+ /* A title without extension */
 39+ $this->assertUploadTitleAndCode( 'A',
 40+ null, UploadTestHandler::FILETYPE_MISSING,
 41+ 'upload title without extension' );
 42+
 43+ /* A title with no basename */
 44+ $this->assertUploadTitleAndCode( '.jpg',
 45+ null, UploadTestHandler::MIN_LENGTH_PARTNAME,
 46+ 'upload title without basename' );
 47+
 48+ }
 49+ /**
 50+ * Helper function for testTitleValidation. First checks the return code
 51+ * of UploadBase::getTitle() and then the actual returned titl
 52+ */
 53+ private function assertUploadTitleAndCode( $srcFilename, $dstFilename, $code, $msg ) {
 54+ /* Check the result code */
 55+ $this->assertEquals( $code,
 56+ $this->upload->testTitleValidation( $srcFilename ),
 57+ "$msg code" );
 58+
 59+ /* If we expect a valid title, check the title itself. */
 60+ if ( $code == UploadTestHandler::OK ) {
 61+ $this->assertEquals( $dstFilename,
 62+ $this->upload->getTitle()->getText(),
 63+ "$msg text" );
 64+ }
 65+ }
 66+
 67+ /**
 68+ * Test the upload verification functions
 69+ */
 70+ public function testVerifyUpload() {
 71+ /* Setup with zero file size */
 72+ $this->upload->initializePathInfo( '', '', 0 );
 73+ $result = $this->upload->verifyUpload();
 74+ $this->assertEquals( UploadTestHandler::EMPTY_FILE,
 75+ $result['status'],
 76+ 'upload empty file' );
 77+ }
 78+
 79+}
 80+
 81+class UploadTestHandler extends UploadBase {
 82+ public function initializeFromRequest( &$request ) { }
 83+ public function testTitleValidation( $name ) {
 84+ $this->mTitle = false;
 85+ $this->mDesiredDestName = $name;
 86+ $this->getTitle();
 87+ return $this->mTitleError;
 88+ }
 89+
 90+
 91+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/UploadTest.php
___________________________________________________________________
Added: svn:eol-style
192 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/MessageTest.php
@@ -0,0 +1,40 @@
 2+<?php
 3+
 4+class MessageTest extends PHPUnit_Framework_TestCase {
 5+
 6+ function setUp() {
 7+ global $wgLanguageCode;
 8+
 9+ $wgLanguageCode = 'en'; # For mainpage to be 'Main Page'
 10+ }
 11+
 12+ function testExists() {
 13+ $this->assertTrue( wfMessage( 'mainpage' )->exists() );
 14+ $this->assertTrue( wfMessage( 'mainpage' )->params( array() )->exists() );
 15+ $this->assertTrue( wfMessage( 'mainpage' )->rawParams( 'foo', 123 )->exists() );
 16+ $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->exists() );
 17+ $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->params( array() )->exists() );
 18+ $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->rawParams( 'foo', 123 )->exists() );
 19+ }
 20+
 21+ function testKey() {
 22+ $this->assertType( 'Message', wfMessage( 'mainpage' ) );
 23+ $this->assertType( 'Message', wfMessage( 'i-dont-exist-evar' ) );
 24+ $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->text() );
 25+ $this->assertEquals( '&lt;i-dont-exist-evar&gt;', wfMessage( 'i-dont-exist-evar' )->text() );
 26+ }
 27+
 28+ function testInLanguage() {
 29+ $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( 'en' )->text() );
 30+ $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( 'ru' )->text() );
 31+ $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'en' ) )->text() );
 32+ $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'ru' ) )->text() );
 33+ }
 34+
 35+ /**
 36+ * @expectedException MWException
 37+ */
 38+ function testInLanguageThrows() {
 39+ wfMessage( 'foo' )->inLanguage( 123 );
 40+ }
 41+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/MessageTest.php
___________________________________________________________________
Added: svn:eol-style
142 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/ResourceLoaderFileModuleTest.php
@@ -0,0 +1,15 @@
 2+<?php
 3+
 4+class ResourceLoaderFileModuleTest extends PHPUnit_Framework_TestCase {
 5+ /* Provider Methods */
 6+
 7+ public function provide() {
 8+
 9+ }
 10+
 11+ /* Test Methods */
 12+
 13+ public function test() {
 14+
 15+ }
 16+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/ResourceLoaderFileModuleTest.php
___________________________________________________________________
Added: svn:eol-style
117 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/CdbTest.php
@@ -0,0 +1,84 @@
 2+<?php
 3+
 4+/**
 5+ * Test the CDB reader/writer
 6+ */
 7+
 8+class CdbTest extends PHPUnit_Framework_TestCase {
 9+
 10+ public function setup() {
 11+ if ( !CdbReader::haveExtension() ) {
 12+ $this->markTestIncomplete( 'This test requires native CDB support to be present.' );
 13+ }
 14+ }
 15+
 16+ public function testCdb() {
 17+ $dir = wfTempDir();
 18+ if ( !is_writable( $dir ) ) {
 19+ $this->markTestSkipped( "Temp dir isn't writable" );
 20+ }
 21+
 22+ $w1 = new CdbWriter_PHP( "$dir/php.cdb" );
 23+ $w2 = new CdbWriter_DBA( "$dir/dba.cdb" );
 24+
 25+ $data = array();
 26+ for ( $i = 0; $i < 1000; $i++ ) {
 27+ $key = $this->randomString();
 28+ $value = $this->randomString();
 29+ $w1->set( $key, $value );
 30+ $w2->set( $key, $value );
 31+
 32+ if ( !isset( $data[$key] ) ) {
 33+ $data[$key] = $value;
 34+ }
 35+ }
 36+
 37+ $w1->close();
 38+ $w2->close();
 39+
 40+ $this->assertEquals(
 41+ md5_file( "$dir/dba.cdb" ),
 42+ md5_file( "$dir/php.cdb" ),
 43+ 'same hash'
 44+ );
 45+
 46+ $r1 = new CdbReader_PHP( "$dir/php.cdb" );
 47+ $r2 = new CdbReader_DBA( "$dir/dba.cdb" );
 48+
 49+ foreach ( $data as $key => $value ) {
 50+ if ( $key === '' ) {
 51+ // Known bug
 52+ continue;
 53+ }
 54+ $v1 = $r1->get( $key );
 55+ $v2 = $r2->get( $key );
 56+
 57+ $v1 = $v1 === false ? '(not found)' : $v1;
 58+ $v2 = $v2 === false ? '(not found)' : $v2;
 59+
 60+ # cdbAssert( 'Mismatch', $key, $v1, $v2 );
 61+ $this->cdbAssert( "PHP error", $key, $v1, $value );
 62+ $this->cdbAssert( "DBA error", $key, $v2, $value );
 63+ }
 64+
 65+ unlink( "$dir/dba.cdb" );
 66+ unlink( "$dir/php.cdb" );
 67+ }
 68+
 69+ private function randomString() {
 70+ $len = mt_rand( 0, 10 );
 71+ $s = '';
 72+ for ( $j = 0; $j < $len; $j++ ) {
 73+ $s .= chr( mt_rand( 0, 255 ) );
 74+ }
 75+ return $s;
 76+ }
 77+
 78+ private function cdbAssert( $msg, $key, $v1, $v2 ) {
 79+ $this->assertEquals(
 80+ $v2,
 81+ $v1,
 82+ $msg . ', k=' . bin2hex( $key )
 83+ );
 84+ }
 85+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/CdbTest.php
___________________________________________________________________
Added: svn:eol-style
186 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/TitlePermissionTest.php
@@ -0,0 +1,651 @@
 2+<?php
 3+
 4+class TitlePermissionTest extends PHPUnit_Framework_TestCase {
 5+ static $title;
 6+ static $user;
 7+ static $anonUser;
 8+ static $userUser;
 9+ static $altUser;
 10+ static $userName;
 11+ static $altUserName;
 12+
 13+ function setUp() {
 14+ global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang, $wgMessageCache;
 15+
 16+ $wgMemc = new FakeMemCachedClient;
 17+ $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
 18+ $wgContLang = $wgLang = Language::factory( 'en' );
 19+
 20+ self::$userName = "Useruser";
 21+ self::$altUserName = "Altuseruser";
 22+ date_default_timezone_set( $wgLocaltimezone );
 23+ $wgLocalTZoffset = date( "Z" ) / 60;
 24+
 25+ self::$title = Title::makeTitle( NS_MAIN, "Main Page" );
 26+ if ( !isset( self::$userUser ) || !( self::$userUser instanceOf User ) ) {
 27+ self::$userUser = User::newFromName( self::$userName );
 28+
 29+ if ( !self::$userUser->getID() ) {
 30+ self::$userUser = User::createNew( self::$userName, array(
 31+ "email" => "test@example.com",
 32+ "real_name" => "Test User" ) );
 33+ }
 34+
 35+ self::$altUser = User::newFromName( self::$altUserName );
 36+ if ( !self::$altUser->getID() ) {
 37+ self::$altUser = User::createNew( self::$altUserName, array(
 38+ "email" => "alttest@example.com",
 39+ "real_name" => "Test User Alt" ) );
 40+ }
 41+
 42+ self::$anonUser = User::newFromId( 0 );
 43+
 44+ self::$user = self::$userUser;
 45+ }
 46+ }
 47+
 48+ function tearDown() {
 49+ global $wgMemc, $wgContLang, $wgLang;
 50+ $wgMemc = $wgContLang = $wgLang = null;
 51+ }
 52+
 53+ function setUserPerm( $perm ) {
 54+ if ( is_array( $perm ) ) {
 55+ self::$user->mRights = $perm;
 56+ } else {
 57+ self::$user->mRights = array( $perm );
 58+ }
 59+ }
 60+
 61+ function setTitle( $ns, $title = "Main_Page" ) {
 62+ self::$title = Title::makeTitle( $ns, $title );
 63+ }
 64+
 65+ function setUser( $userName = null ) {
 66+ if ( $userName === 'anon' ) {
 67+ self::$user = self::$anonUser;
 68+ } else if ( $userName === null || $userName === self::$userName ) {
 69+ self::$user = self::$userUser;
 70+ } else {
 71+ self::$user = self::$altUser;
 72+ }
 73+
 74+ global $wgUser;
 75+ $wgUser = self::$user;
 76+ }
 77+
 78+ function testQuickPermissions() {
 79+ global $wgContLang;
 80+ $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
 81+
 82+ $this->setUser( 'anon' );
 83+ $this->setTitle( NS_TALK );
 84+ $this->setUserPerm( "createtalk" );
 85+ $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 86+ $this->assertEquals( array(), $res );
 87+
 88+ $this->setTitle( NS_TALK );
 89+ $this->setUserPerm( "createpage" );
 90+ $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 91+ $this->assertEquals( array( array( "nocreatetext" ) ), $res );
 92+
 93+ $this->setTitle( NS_TALK );
 94+ $this->setUserPerm( "" );
 95+ $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 96+ $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
 97+
 98+ $this->setTitle( NS_MAIN );
 99+ $this->setUserPerm( "createpage" );
 100+ $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 101+ $this->assertEquals( array( ), $res );
 102+
 103+ $this->setTitle( NS_MAIN );
 104+ $this->setUserPerm( "createtalk" );
 105+ $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 106+ $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
 107+
 108+ $this->setUser( self::$userName );
 109+ $this->setTitle( NS_TALK );
 110+ $this->setUserPerm( "createtalk" );
 111+ $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 112+ $this->assertEquals( array( ), $res );
 113+
 114+ $this->setTitle( NS_TALK );
 115+ $this->setUserPerm( "createpage" );
 116+ $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 117+ $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
 118+
 119+ $this->setTitle( NS_TALK );
 120+ $this->setUserPerm( "" );
 121+ $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 122+ $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
 123+
 124+ $this->setTitle( NS_MAIN );
 125+ $this->setUserPerm( "createpage" );
 126+ $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 127+ $this->assertEquals( array( ), $res );
 128+
 129+ $this->setTitle( NS_MAIN );
 130+ $this->setUserPerm( "createtalk" );
 131+ $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 132+ $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
 133+
 134+ $this->setTitle( NS_MAIN );
 135+ $this->setUserPerm( "" );
 136+ $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 137+ $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
 138+
 139+ $this->setUser( 'anon' );
 140+ $this->setTitle( NS_USER, self::$userName . '' );
 141+ $this->setUserPerm( "" );
 142+ $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 143+ $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
 144+
 145+ $this->setTitle( NS_USER, self::$userName . '/subpage' );
 146+ $this->setUserPerm( "" );
 147+ $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 148+ $this->assertEquals( array( array( 'movenologintext' ) ), $res );
 149+
 150+ $this->setTitle( NS_USER, self::$userName . '' );
 151+ $this->setUserPerm( "move-rootuserpages" );
 152+ $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 153+ $this->assertEquals( array( array( 'movenologintext' ) ), $res );
 154+
 155+ $this->setTitle( NS_USER, self::$userName . '/subpage' );
 156+ $this->setUserPerm( "move-rootuserpages" );
 157+ $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 158+ $this->assertEquals( array( array( 'movenologintext' ) ), $res );
 159+
 160+ $this->setTitle( NS_USER, self::$userName . '' );
 161+ $this->setUserPerm( "" );
 162+ $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 163+ $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
 164+
 165+ $this->setTitle( NS_USER, self::$userName . '/subpage' );
 166+ $this->setUserPerm( "" );
 167+ $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 168+ $this->assertEquals( array( array( 'movenologintext' ) ), $res );
 169+
 170+ $this->setTitle( NS_USER, self::$userName . '' );
 171+ $this->setUserPerm( "move-rootuserpages" );
 172+ $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 173+ $this->assertEquals( array( array( 'movenologintext' ) ), $res );
 174+
 175+ $this->setTitle( NS_USER, self::$userName . '/subpage' );
 176+ $this->setUserPerm( "move-rootuserpages" );
 177+ $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 178+ $this->assertEquals( array( array( 'movenologintext' ) ), $res );
 179+
 180+ $this->setUser( self::$userName );
 181+ $this->setTitle( NS_FILE, "img.png" );
 182+ $this->setUserPerm( "" );
 183+ $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 184+ $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
 185+
 186+ $this->setTitle( NS_FILE, "img.png" );
 187+ $this->setUserPerm( "movefile" );
 188+ $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 189+ $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
 190+
 191+ $this->setUser( 'anon' );
 192+ $this->setTitle( NS_FILE, "img.png" );
 193+ $this->setUserPerm( "" );
 194+ $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 195+ $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
 196+
 197+ $this->setTitle( NS_FILE, "img.png" );
 198+ $this->setUserPerm( "movefile" );
 199+ $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 200+ $this->assertEquals( array( array( 'movenologintext' ) ), $res );
 201+
 202+ $this->setUser( self::$userName );
 203+ $this->setUserPerm( "move" );
 204+ $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
 205+
 206+ $this->setUserPerm( "" );
 207+ $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
 208+
 209+ $this->setUser( 'anon' );
 210+ $this->setUserPerm( "move" );
 211+ $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
 212+
 213+ $this->setUserPerm( "" );
 214+ $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
 215+ array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
 216+
 217+ $this->setTitle( NS_MAIN );
 218+ $this->setUser( 'anon' );
 219+ $this->setUserPerm( "move" );
 220+ $this->runGroupPermissions( 'move', array( ) );
 221+
 222+ $this->setUserPerm( "" );
 223+ $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
 224+ array( array( 'movenologintext' ) ) );
 225+
 226+ $this->setUser( self::$userName );
 227+ $this->setUserPerm( "" );
 228+ $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
 229+
 230+ $this->setUserPerm( "move" );
 231+ $this->runGroupPermissions( 'move', array( ) );
 232+
 233+ $this->setUser( 'anon' );
 234+ $this->setUserPerm( 'move' );
 235+ $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 236+ $this->assertEquals( array( ), $res );
 237+
 238+ $this->setUserPerm( '' );
 239+ $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 240+ $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
 241+
 242+ $this->setTitle( NS_USER );
 243+ $this->setUser( self::$userName );
 244+ $this->setUserPerm( array( "move", "move-rootuserpages" ) );
 245+ $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 246+ $this->assertEquals( array( ), $res );
 247+
 248+ $this->setUserPerm( "move" );
 249+ $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 250+ $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
 251+
 252+ $this->setUser( 'anon' );
 253+ $this->setUserPerm( array( "move", "move-rootuserpages" ) );
 254+ $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 255+ $this->assertEquals( array( ), $res );
 256+
 257+ $this->setTitle( NS_USER, "User/subpage" );
 258+ $this->setUserPerm( array( "move", "move-rootuserpages" ) );
 259+ $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 260+ $this->assertEquals( array( ), $res );
 261+
 262+ $this->setUserPerm( "move" );
 263+ $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 264+ $this->assertEquals( array( ), $res );
 265+
 266+ $this->setUser( 'anon' );
 267+ $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
 268+ array( array( 'badaccess-group0' ) ),
 269+ array( ), true ),
 270+ 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
 271+ array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
 272+ array( array( 'protect-cantedit' ) ), false ),
 273+ '' => array( array( ), array( ), array( ), true ) );
 274+ global $wgUser;
 275+ $wgUser = self::$user;
 276+ foreach ( array( "edit", "protect", "" ) as $action ) {
 277+ $this->setUserPerm( null );
 278+ $this->assertEquals( $check[$action][0],
 279+ self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
 280+
 281+ global $wgGroupPermissions;
 282+ $old = $wgGroupPermissions;
 283+ $wgGroupPermissions = array();
 284+
 285+ $this->assertEquals( $check[$action][1],
 286+ self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
 287+ $wgGroupPermissions = $old;
 288+
 289+ $this->setUserPerm( $action );
 290+ $this->assertEquals( $check[$action][2],
 291+ self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
 292+
 293+ $this->setUserPerm( $action );
 294+ $this->assertEquals( $check[$action][3],
 295+ self::$title->userCan( $action, true ) );
 296+ $this->assertEquals( $check[$action][3],
 297+ self::$title->quickUserCan( $action, false ) );
 298+
 299+ # count( User::getGroupsWithPermissions( $action ) ) < 1
 300+ }
 301+ }
 302+
 303+ function runGroupPermissions( $action, $result, $result2 = null ) {
 304+ global $wgGroupPermissions;
 305+
 306+ if ( $result2 === null ) $result2 = $result;
 307+
 308+ $wgGroupPermissions['autoconfirmed']['move'] = false;
 309+ $wgGroupPermissions['user']['move'] = false;
 310+ $res = self::$title->getUserPermissionsErrors( $action, self::$user );
 311+ $this->assertEquals( $result, $res );
 312+
 313+ $wgGroupPermissions['autoconfirmed']['move'] = true;
 314+ $wgGroupPermissions['user']['move'] = false;
 315+ $res = self::$title->getUserPermissionsErrors( $action, self::$user );
 316+ $this->assertEquals( $result2, $res );
 317+
 318+ $wgGroupPermissions['autoconfirmed']['move'] = true;
 319+ $wgGroupPermissions['user']['move'] = true;
 320+ $res = self::$title->getUserPermissionsErrors( $action, self::$user );
 321+ $this->assertEquals( $result2, $res );
 322+
 323+ $wgGroupPermissions['autoconfirmed']['move'] = false;
 324+ $wgGroupPermissions['user']['move'] = true;
 325+ $res = self::$title->getUserPermissionsErrors( $action, self::$user );
 326+ $this->assertEquals( $result2, $res );
 327+ }
 328+
 329+ function testPermissionHooks() { }
 330+ function testSpecialsAndNSPermissions() {
 331+ $this->setUser( self::$userName );
 332+ global $wgUser, $wgContLang;
 333+ $wgUser = self::$user;
 334+ $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
 335+
 336+ $this->setTitle( NS_SPECIAL );
 337+
 338+ $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
 339+ self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 340+ $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Administrators|Administrators]]", 2 ) ),
 341+ self::$title->getUserPermissionsErrors( 'createaccount', self::$user ) );
 342+ $this->assertEquals( array( array( 'badaccess-group0' ) ),
 343+ self::$title->getUserPermissionsErrors( 'execute', self::$user ) );
 344+
 345+ $this->setTitle( NS_MAIN );
 346+ $this->setUserPerm( 'bogus' );
 347+ $this->assertEquals( array( ),
 348+ self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 349+
 350+ $this->setTitle( NS_MAIN );
 351+ $this->setUserPerm( '' );
 352+ $this->assertEquals( array( array( 'badaccess-group0' ) ),
 353+ self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 354+
 355+ global $wgNamespaceProtection;
 356+ $wgNamespaceProtection[NS_USER] = array ( 'bogus' );
 357+ $this->setTitle( NS_USER );
 358+ $this->setUserPerm( '' );
 359+ $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
 360+ self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 361+
 362+ $this->setTitle( NS_MEDIAWIKI );
 363+ $this->setUserPerm( 'bogus' );
 364+ $this->assertEquals( array( array( 'protectedinterface' ) ),
 365+ self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 366+
 367+ $this->setTitle( NS_MEDIAWIKI );
 368+ $this->setUserPerm( 'bogus' );
 369+ $this->assertEquals( array( array( 'protectedinterface' ) ),
 370+ self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 371+
 372+ $wgNamespaceProtection = null;
 373+ $this->setUserPerm( 'bogus' );
 374+ $this->assertEquals( array( ),
 375+ self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 376+ $this->assertEquals( true,
 377+ self::$title->userCan( 'bogus' ) );
 378+
 379+ $this->setUserPerm( '' );
 380+ $this->assertEquals( array( array( 'badaccess-group0' ) ),
 381+ self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 382+ $this->assertEquals( false,
 383+ self::$title->userCan( 'bogus' ) );
 384+ }
 385+
 386+ function testCSSandJSPermissions() {
 387+ $this->setUser( self::$userName );
 388+ global $wgUser;
 389+ $wgUser = self::$user;
 390+
 391+ $this->setTitle( NS_USER, self::$altUserName . '/test.js' );
 392+ $this->runCSSandJSPermissions(
 393+ array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
 394+ array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
 395+ array( array( 'badaccess-group0' ) ) );
 396+
 397+ $this->setTitle( NS_USER, self::$altUserName . '/test.css' );
 398+ $this->runCSSandJSPermissions(
 399+ array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
 400+ array( array( 'badaccess-group0' ) ),
 401+ array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) );
 402+
 403+ $this->setTitle( NS_USER, self::$altUserName . '/tempo' );
 404+ $this->runCSSandJSPermissions(
 405+ array( array( 'badaccess-group0' ) ),
 406+ array( array( 'badaccess-group0' ) ),
 407+ array( array( 'badaccess-group0' ) ) );
 408+ }
 409+
 410+ function runCSSandJSPermissions( $result0, $result1, $result2 ) {
 411+ $this->setUserPerm( '' );
 412+ $this->assertEquals( $result0,
 413+ self::$title->getUserPermissionsErrors( 'bogus',
 414+ self::$user ) );
 415+
 416+ $this->setUserPerm( 'editusercss' );
 417+ $this->assertEquals( $result1,
 418+ self::$title->getUserPermissionsErrors( 'bogus',
 419+ self::$user ) );
 420+
 421+ $this->setUserPerm( 'edituserjs' );
 422+ $this->assertEquals( $result2,
 423+ self::$title->getUserPermissionsErrors( 'bogus',
 424+ self::$user ) );
 425+
 426+ $this->setUserPerm( 'editusercssjs' );
 427+ $this->assertEquals( array( array( 'badaccess-group0' ) ),
 428+ self::$title->getUserPermissionsErrors( 'bogus',
 429+ self::$user ) );
 430+
 431+ $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
 432+ $this->assertEquals( array( array( 'badaccess-group0' ) ),
 433+ self::$title->getUserPermissionsErrors( 'bogus',
 434+ self::$user ) );
 435+ }
 436+
 437+ function testPageRestrictions() {
 438+ global $wgUser, $wgContLang;
 439+
 440+ $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
 441+
 442+ $wgUser = self::$user;
 443+ $this->setTitle( NS_MAIN );
 444+ self::$title->mRestrictionsLoaded = true;
 445+ $this->setUserPerm( "edit" );
 446+ self::$title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
 447+
 448+ $this->assertEquals( array( ),
 449+ self::$title->getUserPermissionsErrors( 'edit',
 450+ self::$user ) );
 451+
 452+ $this->assertEquals( true,
 453+ self::$title->quickUserCan( 'edit', false ) );
 454+ self::$title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
 455+ "bogus" => array( 'bogus', "sysop", "protect", "" ) );
 456+
 457+ $this->assertEquals( array( array( 'badaccess-group0' ),
 458+ array( 'protectedpagetext', 'bogus' ),
 459+ array( 'protectedpagetext', 'protect' ),
 460+ array( 'protectedpagetext', 'protect' ) ),
 461+ self::$title->getUserPermissionsErrors( 'bogus',
 462+ self::$user ) );
 463+ $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
 464+ array( 'protectedpagetext', 'protect' ),
 465+ array( 'protectedpagetext', 'protect' ) ),
 466+ self::$title->getUserPermissionsErrors( 'edit',
 467+ self::$user ) );
 468+ $this->setUserPerm( "" );
 469+ $this->assertEquals( array( array( 'badaccess-group0' ),
 470+ array( 'protectedpagetext', 'bogus' ),
 471+ array( 'protectedpagetext', 'protect' ),
 472+ array( 'protectedpagetext', 'protect' ) ),
 473+ self::$title->getUserPermissionsErrors( 'bogus',
 474+ self::$user ) );
 475+ $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
 476+ array( 'protectedpagetext', 'bogus' ),
 477+ array( 'protectedpagetext', 'protect' ),
 478+ array( 'protectedpagetext', 'protect' ) ),
 479+ self::$title->getUserPermissionsErrors( 'edit',
 480+ self::$user ) );
 481+ $this->setUserPerm( array( "edit", "editprotected" ) );
 482+ $this->assertEquals( array( array( 'badaccess-group0' ),
 483+ array( 'protectedpagetext', 'bogus' ),
 484+ array( 'protectedpagetext', 'protect' ),
 485+ array( 'protectedpagetext', 'protect' ) ),
 486+ self::$title->getUserPermissionsErrors( 'bogus',
 487+ self::$user ) );
 488+ $this->assertEquals( array( ),
 489+ self::$title->getUserPermissionsErrors( 'edit',
 490+ self::$user ) );
 491+ self::$title->mCascadeRestriction = true;
 492+ $this->assertEquals( false,
 493+ self::$title->quickUserCan( 'bogus', false ) );
 494+ $this->assertEquals( false,
 495+ self::$title->quickUserCan( 'edit', false ) );
 496+ $this->assertEquals( array( array( 'badaccess-group0' ),
 497+ array( 'protectedpagetext', 'bogus' ),
 498+ array( 'protectedpagetext', 'protect' ),
 499+ array( 'protectedpagetext', 'protect' ) ),
 500+ self::$title->getUserPermissionsErrors( 'bogus',
 501+ self::$user ) );
 502+ $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
 503+ array( 'protectedpagetext', 'protect' ),
 504+ array( 'protectedpagetext', 'protect' ) ),
 505+ self::$title->getUserPermissionsErrors( 'edit',
 506+ self::$user ) );
 507+ }
 508+
 509+ function testCascadingSourcesRestrictions() {
 510+ global $wgUser;
 511+ $wgUser = self::$user;
 512+ $this->setTitle( NS_MAIN, "test page" );
 513+ $this->setUserPerm( array( "edit", "bogus" ) );
 514+
 515+ self::$title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) );
 516+ self::$title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
 517+
 518+ $this->assertEquals( false,
 519+ self::$title->userCan( 'bogus' ) );
 520+ $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
 521+ array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
 522+ self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 523+
 524+ $this->assertEquals( true,
 525+ self::$title->userCan( 'edit' ) );
 526+ $this->assertEquals( array( ),
 527+ self::$title->getUserPermissionsErrors( 'edit', self::$user ) );
 528+
 529+ }
 530+
 531+ function testActionPermissions() {
 532+ global $wgUser;
 533+ $wgUser = self::$user;
 534+
 535+ $this->setUserPerm( array( "createpage" ) );
 536+ $this->setTitle( NS_MAIN, "test page" );
 537+ self::$title->mTitleProtection['pt_create_perm'] = '';
 538+ self::$title->mTitleProtection['pt_user'] = self::$user->getID();
 539+ self::$title->mTitleProtection['pt_expiry'] = Block::infinity();
 540+ self::$title->mTitleProtection['pt_reason'] = 'test';
 541+ self::$title->mCascadeRestriction = false;
 542+
 543+ $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
 544+ self::$title->getUserPermissionsErrors( 'create', self::$user ) );
 545+ $this->assertEquals( false,
 546+ self::$title->userCan( 'create' ) );
 547+
 548+ self::$title->mTitleProtection['pt_create_perm'] = 'sysop';
 549+ $this->setUserPerm( array( 'createpage', 'protect' ) );
 550+ $this->assertEquals( array( ),
 551+ self::$title->getUserPermissionsErrors( 'create', self::$user ) );
 552+ $this->assertEquals( true,
 553+ self::$title->userCan( 'create' ) );
 554+
 555+
 556+ $this->setUserPerm( array( 'createpage' ) );
 557+ $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
 558+ self::$title->getUserPermissionsErrors( 'create', self::$user ) );
 559+ $this->assertEquals( false,
 560+ self::$title->userCan( 'create' ) );
 561+
 562+ $this->setTitle( NS_MEDIA, "test page" );
 563+ $this->setUserPerm( array( "move" ) );
 564+ $this->assertEquals( false,
 565+ self::$title->userCan( 'move' ) );
 566+ $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
 567+ self::$title->getUserPermissionsErrors( 'move', self::$user ) );
 568+
 569+ $this->setTitle( NS_MAIN, "test page" );
 570+ $this->assertEquals( array( ),
 571+ self::$title->getUserPermissionsErrors( 'move', self::$user ) );
 572+ $this->assertEquals( true,
 573+ self::$title->userCan( 'move' ) );
 574+
 575+ self::$title->mInterwiki = "no";
 576+ $this->assertEquals( array( array( 'immobile-page' ) ),
 577+ self::$title->getUserPermissionsErrors( 'move', self::$user ) );
 578+ $this->assertEquals( false,
 579+ self::$title->userCan( 'move' ) );
 580+
 581+ $this->setTitle( NS_MEDIA, "test page" );
 582+ $this->assertEquals( false,
 583+ self::$title->userCan( 'move-target' ) );
 584+ $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
 585+ self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
 586+
 587+ $this->setTitle( NS_MAIN, "test page" );
 588+ $this->assertEquals( array( ),
 589+ self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
 590+ $this->assertEquals( true,
 591+ self::$title->userCan( 'move-target' ) );
 592+
 593+ self::$title->mInterwiki = "no";
 594+ $this->assertEquals( array( array( 'immobile-target-page' ) ),
 595+ self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
 596+ $this->assertEquals( false,
 597+ self::$title->userCan( 'move-target' ) );
 598+
 599+ }
 600+
 601+ function testUserBlock() {
 602+ global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
 603+ $wgEmailConfirmToEdit = true;
 604+ $wgEmailAuthentication = true;
 605+ $wgUser = self::$user;
 606+
 607+ $this->setUserPerm( array( "createpage", "move" ) );
 608+ $this->setTitle( NS_MAIN, "test page" );
 609+
 610+ # $short
 611+ $this->assertEquals( array( array( 'confirmedittext' ) ),
 612+ self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
 613+ $this->assertEquals( true, self::$title->userCan( 'move-target' ) );
 614+
 615+ $wgEmailConfirmToEdit = false;
 616+ # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
 617+ $this->assertEquals( array( ),
 618+ self::$title->getUserPermissionsErrors( 'move-target',
 619+ self::$user ) );
 620+
 621+ global $wgLang;
 622+ $prev = time();
 623+ $now = time() + 120;
 624+ self::$user->mBlockedby = self::$user->getId();
 625+ self::$user->mBlock = new Block( '127.0.8.1', self::$user->getId(), self::$user->getId(),
 626+ 'no reason given', $prev + 3600, 1, 0 );
 627+ self::$user->mBlock->mTimestamp = 0;
 628+ $this->assertEquals( array( array( 'autoblockedtext',
 629+ '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
 630+ 'Useruser', 0, 'infinite', '127.0.8.1',
 631+ $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ),
 632+ self::$title->getUserPermissionsErrors( 'move-target',
 633+ self::$user ) );
 634+
 635+ $this->assertEquals( true,
 636+ self::$title->userCan( 'move-target', self::$user ) );
 637+
 638+ global $wgLocalTZoffset;
 639+ $wgLocalTZoffset = -60;
 640+ self::$user->mBlockedby = self::$user->getName();
 641+ self::$user->mBlock = new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
 642+ $this->assertEquals( array( array( 'blockedtext',
 643+ '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
 644+ 'Useruser', 0, '23:00, 31 December 1969', '127.0.8.1',
 645+ $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ),
 646+ self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
 647+
 648+ # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
 649+ # $user->blockedFor() == ''
 650+ # $user->mBlock->mExpiry == 'infinity'
 651+ }
 652+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/TitlePermissionTest.php
___________________________________________________________________
Added: svn:eol-style
1653 + native
Added: svn:eol-syle
2654 + native
Index: trunk/phase3/maintenance/tests/phpunit/includes/LocalFileTest.php
@@ -0,0 +1,104 @@
 2+<?php
 3+
 4+/**
 5+ * These tests should work regardless of $wgCapitalLinks
 6+ */
 7+
 8+class LocalFileTest extends PHPUnit_Framework_TestCase {
 9+ function setUp() {
 10+ global $wgContLang, $wgCapitalLinks;
 11+
 12+ $wgContLang = new Language;
 13+ $wgCapitalLinks = true;
 14+ $info = array(
 15+ 'name' => 'test',
 16+ 'directory' => '/testdir',
 17+ 'url' => '/testurl',
 18+ 'hashLevels' => 2,
 19+ 'transformVia404' => false,
 20+ );
 21+ $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
 22+ $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
 23+ $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
 24+ $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
 25+ $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
 26+ $this->file_lc = $this->repo_lc->newFile( 'test!' );
 27+ }
 28+
 29+ function tearDown() {
 30+ global $wgContLang;
 31+ unset( $wgContLang );
 32+ }
 33+
 34+ function testGetHashPath() {
 35+ $this->assertEquals( '', $this->file_hl0->getHashPath() );
 36+ $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
 37+ $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
 38+ }
 39+
 40+ function testGetRel() {
 41+ $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
 42+ $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
 43+ $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
 44+ }
 45+
 46+ function testGetUrlRel() {
 47+ $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
 48+ $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
 49+ $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
 50+ }
 51+
 52+ function testGetArchivePath() {
 53+ $this->assertEquals( '/testdir/archive', $this->file_hl0->getArchivePath() );
 54+ $this->assertEquals( '/testdir/archive/a/a2', $this->file_hl2->getArchivePath() );
 55+ $this->assertEquals( '/testdir/archive/!', $this->file_hl0->getArchivePath( '!' ) );
 56+ $this->assertEquals( '/testdir/archive/a/a2/!', $this->file_hl2->getArchivePath( '!' ) );
 57+ }
 58+
 59+ function testGetThumbPath() {
 60+ $this->assertEquals( '/testdir/thumb/Test!', $this->file_hl0->getThumbPath() );
 61+ $this->assertEquals( '/testdir/thumb/a/a2/Test!', $this->file_hl2->getThumbPath() );
 62+ $this->assertEquals( '/testdir/thumb/Test!/x', $this->file_hl0->getThumbPath( 'x' ) );
 63+ $this->assertEquals( '/testdir/thumb/a/a2/Test!/x', $this->file_hl2->getThumbPath( 'x' ) );
 64+ }
 65+
 66+ function testGetArchiveUrl() {
 67+ $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
 68+ $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
 69+ $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
 70+ $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
 71+ }
 72+
 73+ function testGetThumbUrl() {
 74+ $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
 75+ $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
 76+ $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
 77+ $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
 78+ }
 79+
 80+ function testGetArchiveVirtualUrl() {
 81+ $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
 82+ $this->assertEquals( 'mwrepo://test/public/archive/a/a2', $this->file_hl2->getArchiveVirtualUrl() );
 83+ $this->assertEquals( 'mwrepo://test/public/archive/%21', $this->file_hl0->getArchiveVirtualUrl( '!' ) );
 84+ $this->assertEquals( 'mwrepo://test/public/archive/a/a2/%21', $this->file_hl2->getArchiveVirtualUrl( '!' ) );
 85+ }
 86+
 87+ function testGetThumbVirtualUrl() {
 88+ $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
 89+ $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
 90+ $this->assertEquals( 'mwrepo://test/thumb/Test%21/%21', $this->file_hl0->getThumbVirtualUrl( '!' ) );
 91+ $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21/%21', $this->file_hl2->getThumbVirtualUrl( '!' ) );
 92+ }
 93+
 94+ function testGetUrl() {
 95+ $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
 96+ $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
 97+ }
 98+
 99+ function testWfLocalFile() {
 100+ $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
 101+ $this->assertThat( $file, $this->isInstanceOf( 'LocalFile' ), 'wfLocalFile() returns LocalFile for valid Titles' );
 102+ }
 103+}
 104+
 105+
Property changes on: trunk/phase3/maintenance/tests/phpunit/includes/LocalFileTest.php
___________________________________________________________________
Added: svn:eol-style
1106 + native
Index: trunk/phase3/maintenance/tests/phpunit/suite.xml
@@ -0,0 +1,33 @@
 2+<?xml version="1.0" encoding="UTF-8"?>
 3+
 4+<phpunit bootstrap="./bootstrap.php"
 5+ colors="false"
 6+ backupGlobals="false"
 7+ convertErrorsToExceptions="true"
 8+ convertNoticesToExceptions="true"
 9+ convertWarningsToExceptions="true"
 10+ stopOnFailure="false">
 11+ <testsuites>
 12+ <testsuite name="includes">
 13+ <directory>./includes</directory>
 14+ </testsuite>
 15+ <testsuite name="includes">
 16+ <directory>./includes</directory>
 17+ </testsuite>
 18+ <testsuite name="languages">
 19+ <directory>./languages</directory>
 20+ </testsuite>
 21+ <testsuite name="skins">
 22+ <directory>./skins</directory>
 23+ </testsuite>
 24+ <testsuite name="uploadfromurl">
 25+ <file>./suites/UploadFromUrlTestSuite.php</file>
 26+ </testsuite>
 27+ </testsuites>
 28+ <groups>
 29+ <exclude>
 30+ <group>Broken</group>
 31+ <group>Stub</group>
 32+ </exclude>
 33+ </groups>
 34+</phpunit>
\ No newline at end of file
Index: trunk/phase3/maintenance/tests/phpunit/suites/UploadFromUrlTestSuite.php
@@ -0,0 +1,181 @@
 2+<?php
 3+
 4+require_once( dirname( dirname( __FILE__ ) ) . '/includes/UploadFromUrlTest.php' );
 5+
 6+class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
 7+ public static function addTables( &$tables ) {
 8+ $tables[] = 'user_properties';
 9+ $tables[] = 'filearchive';
 10+ $tables[] = 'logging';
 11+ $tables[] = 'updatelog';
 12+ $tables[] = 'iwlinks';
 13+
 14+ return true;
 15+ }
 16+
 17+ function setUp() {
 18+ global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
 19+ $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
 20+ $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
 21+ $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
 22+ $wgThumbnailScriptPath, $wgScriptPath,
 23+ $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
 24+
 25+ $wgScript = '/index.php';
 26+ $wgScriptPath = '/';
 27+ $wgArticlePath = '/wiki/$1';
 28+ $wgStyleSheetPath = '/skins';
 29+ $wgStylePath = '/skins';
 30+ $wgThumbnailScriptPath = false;
 31+ $wgLocalFileRepo = array(
 32+ 'class' => 'LocalRepo',
 33+ 'name' => 'local',
 34+ 'directory' => wfTempDir() . '/test-repo',
 35+ 'url' => 'http://example.com/images',
 36+ 'deletedDir' => wfTempDir() . '/test-repo/delete',
 37+ 'hashLevels' => 2,
 38+ 'transformVia404' => false,
 39+ );
 40+ $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
 41+ $wgNamespaceAliases['Image'] = NS_FILE;
 42+ $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
 43+
 44+
 45+ $wgEnableParserCache = false;
 46+ $wgDeferredUpdateList = array();
 47+ $wgMemc =& wfGetMainCache();
 48+ $messageMemc =& wfGetMessageCacheStorage();
 49+ $parserMemc =& wfGetParserCacheStorage();
 50+
 51+ // $wgContLang = new StubContLang;
 52+ $wgUser = new User;
 53+ $wgLang = new StubUserLang;
 54+ $wgOut = new StubObject( 'wgOut', 'OutputPage' );
 55+ $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
 56+ $wgRequest = new WebRequest;
 57+
 58+ $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
 59+ array( $messageMemc, $wgUseDatabaseMessages,
 60+ $wgMsgCacheExpiry ) );
 61+ if ( $wgStyleDirectory === false ) {
 62+ $wgStyleDirectory = "$IP/skins";
 63+ }
 64+
 65+ }
 66+
 67+ public function tearDown() {
 68+ $this->teardownUploadDir( $this->uploadDir );
 69+ }
 70+
 71+ private $uploadDir;
 72+ private $keepUploads;
 73+
 74+ /**
 75+ * Remove the dummy uploads directory
 76+ */
 77+ private function teardownUploadDir( $dir ) {
 78+ if ( $this->keepUploads ) {
 79+ return;
 80+ }
 81+
 82+ // delete the files first, then the dirs.
 83+ self::deleteFiles(
 84+ array (
 85+ "$dir/3/3a/Foobar.jpg",
 86+ "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
 87+ "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
 88+ "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
 89+ "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
 90+
 91+ "$dir/0/09/Bad.jpg",
 92+ )
 93+ );
 94+
 95+ self::deleteDirs(
 96+ array (
 97+ "$dir/3/3a",
 98+ "$dir/3",
 99+ "$dir/thumb/6/65",
 100+ "$dir/thumb/6",
 101+ "$dir/thumb/3/3a/Foobar.jpg",
 102+ "$dir/thumb/3/3a",
 103+ "$dir/thumb/3",
 104+
 105+ "$dir/0/09/",
 106+ "$dir/0/",
 107+
 108+ "$dir/thumb",
 109+ "$dir",
 110+ )
 111+ );
 112+ }
 113+
 114+ /**
 115+ * Delete the specified files, if they exist.
 116+ *
 117+ * @param $files Array: full paths to files to delete.
 118+ */
 119+ private static function deleteFiles( $files ) {
 120+ foreach ( $files as $file ) {
 121+ if ( file_exists( $file ) ) {
 122+ unlink( $file );
 123+ }
 124+ }
 125+ }
 126+
 127+ /**
 128+ * Delete the specified directories, if they exist. Must be empty.
 129+ *
 130+ * @param $dirs Array: full paths to directories to delete.
 131+ */
 132+ private static function deleteDirs( $dirs ) {
 133+ foreach ( $dirs as $dir ) {
 134+ if ( is_dir( $dir ) ) {
 135+ rmdir( $dir );
 136+ }
 137+ }
 138+ }
 139+
 140+ /**
 141+ * Create a dummy uploads directory which will contain a couple
 142+ * of files in order to pass existence tests.
 143+ *
 144+ * @return String: the directory
 145+ */
 146+ private function setupUploadDir() {
 147+ global $IP;
 148+
 149+ if ( $this->keepUploads ) {
 150+ $dir = wfTempDir() . '/mwParser-images';
 151+
 152+ if ( is_dir( $dir ) ) {
 153+ return $dir;
 154+ }
 155+ } else {
 156+ $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
 157+ }
 158+
 159+ wfDebug( "Creating upload directory $dir\n" );
 160+
 161+ if ( file_exists( $dir ) ) {
 162+ wfDebug( "Already exists!\n" );
 163+ return $dir;
 164+ }
 165+
 166+ wfMkdirParents( $dir . '/3/3a' );
 167+ copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
 168+
 169+ wfMkdirParents( $dir . '/0/09' );
 170+ copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
 171+
 172+ return $dir;
 173+ }
 174+
 175+ public static function suite() {
 176+ // Hack to invoke the autoloader required to get phpunit to recognize
 177+ // the UploadFromUrlTest class
 178+ class_exists( 'UploadFromUrlTest' );
 179+ $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );
 180+ return $suite;
 181+ }
 182+}
Property changes on: trunk/phase3/maintenance/tests/phpunit/suites/UploadFromUrlTestSuite.php
___________________________________________________________________
Added: svn:eol-style
1183 + native
Added: svn:eol-syle
2184 + native
Index: trunk/phase3/maintenance/tests/phpunit/suites/ExtensionsTestSuite.php
@@ -0,0 +1,4 @@
 2+<?php
 3+/**
 4+ * This is where a PHPUnit_Framework_TestSuite that runs extension tests through a hook or something should go.
 5+ */
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/tests/phpunit/suites/ExtensionsTestSuite.php
___________________________________________________________________
Added: svn:eol-style
16 + native
Property changes on: trunk/phase3/maintenance/tests
___________________________________________________________________
Added: svn:mergeinfo
27 Merged /branches/phpunit-restructure/maintenance/tests:r72257-72560

Follow-up revisions

RevisionCommit summaryAuthorDate
r72574Follow-up r72566: svn eol-style:nativesiebrand06:17, 8 September 2010
r72609Initialise wgContLang and $wgLang....platonides20:38, 8 September 2010
r72858Follow up r72566. Per CR r9132#c9132 these files were intended to explicitely...platonides13:42, 12 September 2010
r74553Readd after r72566 a phpunit.php so that globals are kept global.platonides18:15, 9 October 2010

Comments

#Comment by Bryan (talk | contribs)   11:33, 8 September 2010

This causes a lot of tests to fail, and UploadFromUrlTest to fatal, but only if it is run after other tests (i.e. it does not fatal with --filter "UploadFrom*")

D:\wwwroot\phase3\maintenance\tests\phpunit>phpunit --configuration suite.xml --verbose
PHPUnit 3.4.15 by Sebastian Bergmann.

Test Suite
 includes
   ApiTest
  ........I

  ApiWatchTest
  F.....E.

  CdbTest
  I

  DatabaseSqliteTest
  II

  DatabaseTest
  .........

  ExtraParserTest
  .

  GlobalTest
  ...........

  HttpTest
  IIIIIIIIIIIIIIIIIIIIIIIIII

  ImageFunctionsTest
  .

  IPTest
  ....

  LanguageConverterTest
  .........

  LicensesTest


  LocalFileTest
  ...........

  MessageTest
  ....

  Parser tests
  ..........................................................
  ..........................................................
  ..........................................................
  ..........................................................
  ...........................................F.......FFFFFF.
  ......F.F.................................................
  ..........................................................
  ..........................................................
  ......................................F...................
  ..................................................F.......
  ..........................

  ParserUnitTest
  F

  ResourceLoaderFileModuleTest
  .

  ResourceLoaderTest
  .

  RevisionTest
  ........

  SanitizerTest
  ........

  SearchDbTest
  .....

  SearchUpdateTest
  .

  SiteConfigurationTest
  ......

  TimeAdjustTest
  .

  TitlePermissionTest
  ........

  TitleTest
  .

  UploadFromUrlTest
  ...PHP Fatal error:  Call to a member function getCode() on a non-object in D:\wwwroot\phase3\includes\parser\ParserOptions.php on line 210

Fatal error: Call to a member function getCode() on a non-object in D:\wwwroot\phase3\includes\parser\ParserOptions.php on line 210

D:\wwwroot\phase3\maintenance\tests\phpunit>

#Comment by Trevor Parscal (WMF) (talk | contribs)   16:34, 8 September 2010

The suite.xml file could be changed so that test runs first.

#Comment by 😂 (talk | contribs)   17:10, 8 September 2010

A workaround, maybe, but not a solution. Any subset of the tests should be runnable, the order should be irrelevant.

#Comment by Trevor Parscal (WMF) (talk | contribs)   17:14, 8 September 2010

I don't know the specific reasons why this test doesn't like to be run after others, but the notion that any test should be executable in any order is odd - PHPUnit specifically gives you the ability to say that some tests depend on others, and even lets you build suites in PHP so you can get REALLY specific about the order in which to run tests. This is not a weakness necessarily in our testing plan, it's probably a sign of a weakness in our software (global state is evil).

#Comment by Bryan (talk | contribs)   20:24, 8 September 2010

It did work before the revision, so we should find out the changes in this commit that causes this problem.

I think both the fatal in UploadFromUrlTest, as well as the failing parser tests are caused by some globals that are not properly setup.

#Comment by 😂 (talk | contribs)   11:39, 8 September 2010

A more minor note, but this has confused my IDE. It can't find the phpunit directory, just an empty file.

#Comment by 😂 (talk | contribs)   14:01, 8 September 2010

Take that back, it sorted itself out.

#Comment by Platonides (talk | contribs)   20:40, 8 September 2010

Parser tests inside phpunit are now using $wgScriptPath from LocalSettings (shown as broken paths in images).

ApiTest is also relying on LocalSettings data that may not be there.

#Comment by Platonides (talk | contribs)   22:03, 11 September 2010

You removed the entries from the AutoLoader

How are {ApiTest,ApiWatchTest,UploadFromUrlTest} expected to find ApiTestSetup class now? Idem for SearchEngineTest with MediaWikiTestSetup

#Comment by Trevor Parscal (WMF) (talk | contribs)   02:03, 12 September 2010

They include them explicitly. Cluttering the autoloader (which is used in production for every request) with information about tests, which have simple needs, seemed silly.

#Comment by 😂 (talk | contribs)   13:18, 12 September 2010

We shouldn't have to manually include them in test files. Maybe add to $wgAutoloadClasses during bootstrap?

#Comment by Platonides (talk | contribs)   13:43, 12 September 2010

I shouldn't have included ApiTest in the list. It does indeed have a require to ApiSetup.php

The other three files didn't have any require. Thus the question.

Fixed in r72858.

#Comment by MaxSem (talk | contribs)   17:51, 9 October 2010

Hooks don't work anymore, $wgHooks is empty. Needed at least for UnitTestsList.

#Comment by Trevor Parscal (WMF) (talk | contribs)   21:21, 12 October 2010

This appears to be resolved in r74553.

Status & tagging log