wiki.techinc.nl/tests/phpunit/includes/GlobalFunctions/WfExpandUrlTest.php
Aryeh Gregor 472a914c63 Refactor URL-parsing global functions to class
The new class, UrlUtils, is usable standalone or as a service. Using it
as a service will just automatically load a few settings from site
configuration.

In addition to just making our code cleaner, this will enable making
some of Setup.php's dynamic configuration more sane.

Test coverage is all lines except invalid URLs -- I couldn't find any.

Bug: T305093
Change-Id: I706ef8a50aafb518e13222719575d274c3583b90
2022-04-12 15:14:35 +03:00

35 lines
1.1 KiB
PHP

<?php
use MediaWiki\Utils\UrlUtils;
/**
* @group GlobalFunctions
* @covers ::wfExpandUrl
*/
class WfExpandUrlTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provideExpandableUrls
*/
public function testWfExpandUrl( string $input, array $conf,
string $currentProto, $defaultProto, string $expected
) {
$this->setMwGlobals( $conf );
$this->setRequest( new FauxRequest( [], false, null, $currentProto ) );
$this->assertEquals( $expected, wfExpandUrl( $input, $defaultProto ) );
}
public static function provideExpandableUrls() {
// Same tests as the UrlUtils method to ensure they don't fall out of sync
foreach (
UrlUtilsTest::provideExpand() as $key => [ $input, $options, $defaultProto, $expected ]
) {
$conf = [
'wgServer' => $options[UrlUtils::SERVER] ?? null,
'wgCanonicalServer' => $options[UrlUtils::CANONICAL_SERVER] ?? null,
'wgInternalServer' => $options[UrlUtils::INTERNAL_SERVER] ?? null,
'wgHttpsPort' => $options[UrlUtils::HTTPS_PORT] ?? 443,
];
yield $key =>
[ $input, $conf, $options[UrlUtils::FALLBACK_PROTOCOL], $defaultProto, $expected ];
}
}
}