wiki.techinc.nl/tests/phpunit/includes/http/HttpTest.php

112 lines
3.4 KiB
PHP
Raw Normal View History

<?php
/**
* @covers Http
* @group Http
* @group small
*/
class HttpTest extends MediaWikiTestCase {
/**
* Test Http::isValidURI()
* T29854 : Http::isValidURI is too lax
* @dataProvider provideURI
* @covers Http::isValidURI
*/
public function testIsValidUri( $expect, $URI, $message = '' ) {
$this->assertEquals(
$expect,
(bool)Http::isValidURI( $URI ),
$message
);
}
/**
* @covers Http::getProxy
*/
public function testGetProxy() {
$this->hideDeprecated( 'Http::getProxy' );
$this->setMwGlobals( 'wgHTTPProxy', false );
$this->assertEquals(
'',
Http::getProxy(),
'default setting'
);
$this->setMwGlobals( 'wgHTTPProxy', 'proxy.domain.tld' );
$this->assertEquals(
'proxy.domain.tld',
Http::getProxy()
);
}
/**
* Feeds URI to test a long regular expression in Http::isValidURI
*/
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
public static function provideURI() {
/** Format: 'boolean expectation', 'URI to test', 'Optional message' */
return [
[ false, '¿non sens before!! http://a', 'Allow anything before URI' ],
# (http|https) - only two schemes allowed
[ true, 'http://www.example.org/' ],
[ true, 'https://www.example.org/' ],
[ true, 'http://www.example.org', 'URI without directory' ],
[ true, 'http://a', 'Short name' ],
[ true, 'http://étoile', 'Allow UTF-8 in hostname' ], # 'étoile' is french for 'star'
[ false, '\\host\directory', 'CIFS share' ],
[ false, 'gopher://host/dir', 'Reject gopher scheme' ],
[ false, 'telnet://host', 'Reject telnet scheme' ],
2011-10-26 04:15:09 +00:00
# :\/\/ - double slashes
[ false, 'http//example.org', 'Reject missing colon in protocol' ],
[ false, 'http:/example.org', 'Reject missing slash in protocol' ],
[ false, 'http:example.org', 'Must have two slashes' ],
# Following fail since hostname can be made of anything
[ false, 'http:///example.org', 'Must have exactly two slashes, not three' ],
# (\w+:{0,1}\w*@)? - optional user:pass
[ true, 'http://user@host', 'Username provided' ],
[ true, 'http://user:@host', 'Username provided, no password' ],
[ true, 'http://user:pass@host', 'Username and password provided' ],
# (\S+) - host part is made of anything not whitespaces
// commented these out in order to remove @group Broken
// @todo are these valid tests? if so, fix Http::isValidURI so it can handle them
// [ false, 'http://!"èèè¿¿¿~~\'', 'hostname is made of any non whitespace' ],
// [ false, 'http://exam:ple.org/', 'hostname can not use colons!' ],
# (:[0-9]+)? - port number
[ true, 'http://example.org:80/' ],
[ true, 'https://example.org:80/' ],
[ true, 'http://example.org:443/' ],
[ true, 'https://example.org:443/' ],
# Part after the hostname is / or / with something else
[ true, 'http://example/#' ],
[ true, 'http://example/!' ],
[ true, 'http://example/:' ],
[ true, 'http://example/.' ],
[ true, 'http://example/?' ],
[ true, 'http://example/+' ],
[ true, 'http://example/=' ],
[ true, 'http://example/&' ],
[ true, 'http://example/%' ],
[ true, 'http://example/@' ],
[ true, 'http://example/-' ],
[ true, 'http://example//' ],
[ true, 'http://example/&' ],
# Fragment
[ true, 'http://exam#ple.org', ], # This one is valid, really!
[ true, 'http://example.org:80#anchor' ],
[ true, 'http://example.org/?id#anchor' ],
[ true, 'http://example.org/?#anchor' ],
[ false, 'http://a ¿non !!sens after', 'Allow anything after URI' ],
];
}
}