return $this->requestUrl;
}
+ public function getFullRequestURL() {
+ // Pass an explicit PROTO constant instead of PROTO_CURRENT so that we
+ // do not rely on state from the global $wgRequest object (which it would,
+ // via wfGetServerUrl/wfExpandUrl/$wgRequest->protocol).
+ if ( $this->protocol === 'http' ) {
+ return wfGetServerUrl( PROTO_HTTP ) . $this->getRequestURL();
+ } else {
+ return wfGetServerUrl( PROTO_HTTPS ) . $this->getRequestURL();
+ }
+ }
+
public function getProtocol() {
return $this->protocol;
}
use MediaWikiCoversValidator;
use PHPUnit4And6Compat;
+ public function setUp() {
+ parent::setUp();
+ $this->orgWgServer = $GLOBALS['wgServer'];
+ }
+
+ public function tearDown() {
+ $GLOBALS['wgServer'] = $this->orgWgServer;
+ parent::tearDown();
+ }
+
/**
* @covers FauxRequest::__construct
*/
/**
* @covers FauxRequest::getRequestURL
*/
- public function testGetRequestURL() {
+ public function testGetRequestURL_disallowed() {
$req = new FauxRequest();
$this->setExpectedException( MWException::class );
$req->getRequestURL();
$this->assertEquals( 'https://example.org', $req->getRequestURL() );
}
+ /**
+ * @covers FauxRequest::getFullRequestURL
+ */
+ public function testGetFullRequestURL_disallowed() {
+ $GLOBALS['wgServer'] = '//wiki.test';
+ $req = new FauxRequest();
+
+ $this->setExpectedException( MWException::class );
+ $req->getFullRequestURL();
+ }
+
+ /**
+ * @covers FauxRequest::getFullRequestURL
+ */
+ public function testGetFullRequestURL_http() {
+ $GLOBALS['wgServer'] = '//wiki.test';
+ $req = new FauxRequest();
+ $req->setRequestURL( '/path' );
+
+ $this->assertSame(
+ 'http://wiki.test/path',
+ $req->getFullRequestURL()
+ );
+ }
+
+ /**
+ * @covers FauxRequest::getFullRequestURL
+ */
+ public function testGetFullRequestURL_https() {
+ $GLOBALS['wgServer'] = '//wiki.test';
+ $req = new FauxRequest( [], false, null, 'https' );
+ $req->setRequestURL( '/path' );
+
+ $this->assertSame(
+ 'https://wiki.test/path',
+ $req->getFullRequestURL()
+ );
+ }
+
/**
* @covers FauxRequest::__construct
* @covers FauxRequest::getProtocol