X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FWebRequestTest.php;h=0d5c59b0dee41b0c6f1340743bac60368d6cd30f;hp=07c307e64e2d0911cada6445d42b01c957892249;hb=04d1aa3033f40a38d721f7f0e88b5bac440d2869;hpb=8785fa24c96f08f18f308a9e36f9e17d1b62552b diff --git a/tests/phpunit/includes/WebRequestTest.php b/tests/phpunit/includes/WebRequestTest.php index 07c307e64e..0d5c59b0de 100644 --- a/tests/phpunit/includes/WebRequestTest.php +++ b/tests/phpunit/includes/WebRequestTest.php @@ -4,16 +4,19 @@ * @group WebRequest */ class WebRequestTest extends MediaWikiTestCase { - protected $oldServer; protected function setUp() { parent::setUp(); $this->oldServer = $_SERVER; + $this->oldWgRequest = $GLOBALS['wgRequest']; + $this->oldWgServer = $GLOBALS['wgServer']; } protected function tearDown() { $_SERVER = $this->oldServer; + $GLOBALS['wgRequest'] = $this->oldWgRequest; + $GLOBALS['wgServer'] = $this->oldWgServer; parent::tearDown(); } @@ -368,11 +371,27 @@ class WebRequestTest extends MediaWikiTestCase { $this->assertSame( [ 'x' ], $req->getValueNames( [ 'y' ] ), 'Exclude keys' ); } + /** + * @covers WebRequest + */ + public function testGetFullRequestURL() { + // Stub this for wfGetServerUrl() + $GLOBALS['wgServer'] = '//wiki.test'; + $req = $this->getMock( WebRequest::class, [ 'getRequestURL', 'getProtocol' ] ); + $req->method( 'getRequestURL' )->willReturn( '/path' ); + $req->method( 'getProtocol' )->willReturn( 'https' ); + + $this->assertSame( + 'https://wiki.test/path', + $req->getFullRequestURL() + ); + } + /** * @dataProvider provideGetIP * @covers WebRequest::getIP */ - public function testGetIP( $expected, $input, $squid, $xffList, $private, $description ) { + public function testGetIP( $expected, $input, $cdn, $xffList, $private, $description ) { $this->setServerVars( $input ); $this->setMwGlobals( [ 'wgUsePrivateIPs' => $private, @@ -386,7 +405,7 @@ class WebRequestTest extends MediaWikiTestCase { ] ] ); - $this->setService( 'ProxyLookup', new ProxyLookup( [], $squid ) ); + $this->setService( 'ProxyLookup', new ProxyLookup( [], $cdn ) ); $request = new WebRequest(); $result = $request->getIP(); @@ -568,8 +587,8 @@ class WebRequestTest extends MediaWikiTestCase { public function testGetIpLackOfRemoteAddrThrowAnException() { // ensure that local install state doesn't interfere with test $this->setMwGlobals( [ - 'wgSquidServersNoPurge' => [], - 'wgSquidServers' => [], + 'wgCdnServers' => [], + 'wgCdnServersNoPurge' => [], 'wgUsePrivateIPs' => false, 'wgHooks' => [], ] );