2015-09-11 14:21:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiReference
|
|
|
|
|
*/
|
phpunit: Repair GLOBALS reset in MediaWikiUnitTestCase
This code didn't work because the $GLOBALS array is exposed by reference.
Once this reference was broken by unset(), the rest just manipulated a
local array that happens to be called "GLOBALS". It must not be unset or
re-assigned. It can only be changed in-place.
Before this, the execution of a MediaWikiUnitTestCase test stored a
copy of GLOBALS in unitGlobals, then lost the GLOBALS pointer and
created a new variable called "GLOBALS". As such, the tearDown() function
didn't do what it meant to do, either – which then results in odd
failures like T230023
Rewrite it as follows:
* In setup, store the current GLOBALS keys and values, then reduce
GLOBALS to only the whitelisted keys and values.
* In teardown, restore the original state.
* As optimisation, do this from setUpBeforeClass as well, so that
there are relatively few globals to reset between tests.
(Thanks @Simetrical!)
The following tests were previously passing by accident under
MediaWikiUnitTestCase but actually did depend on global config.
* MainSlotRoleHandlerTest (…, ContentHandler, $wgContentHandlers)
* SlotRecordTest (…, ContentHandler, $wgContentHandlers)
* WikiReferenceTest (wfParseUrl, $wgUrlProtocols)
* DifferenceEngineSlotDiffRendererTest (DifferenceEngine, wfDebug, …)
* SlotDiffRendererTest (…, ContentHandler, $wgContentHandlers)
* FileBackendDBRepoWrapperTest (wfWikiID, "Backend domain ID not provided")
* JpegMetadataExtractorTest (…, wfDebug, …, LoggerFactory, …)
* ParserFactoryTest (…, wfDebug, …, LoggerFactory, InvalidArgumentException)
* MediaWikiPageNameNormalizerTest (…, wfDebug, …, LoggerFactory, …)
* SiteExporterTest (SiteImporter, wfLogWarning, …)
* SiteImporterTest (Site::newForType, $wgSiteTypes)
* ZipDirectoryReaderTest (…, wfDebug, …, LoggerFactory, …)
Bug: T230023
Change-Id: Ic22075bb5e81b7c2c4c1b8647547aa55306a10a7
2019-08-07 13:40:55 +00:00
|
|
|
class WikiReferenceTest extends MediaWikiIntegrationTestCase {
|
2017-12-29 23:22:37 +00:00
|
|
|
|
2015-09-11 14:21:16 +00:00
|
|
|
public function provideGetDisplayName() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
'http' => [ 'foo.bar', 'http://foo.bar' ],
|
|
|
|
|
'https' => [ 'foo.bar', 'http://foo.bar' ],
|
2015-09-11 14:21:16 +00:00
|
|
|
|
|
|
|
|
// apparently, this is the expected behavior
|
2016-02-17 09:09:32 +00:00
|
|
|
'invalid' => [ 'purple kittens', 'purple kittens' ],
|
|
|
|
|
];
|
2015-09-11 14:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetDisplayName
|
|
|
|
|
*/
|
|
|
|
|
public function testGetDisplayName( $expected, $canonicalServer ) {
|
2015-10-01 17:12:07 +00:00
|
|
|
$reference = new WikiReference( $canonicalServer, '/wiki/$1' );
|
2015-09-11 14:21:16 +00:00
|
|
|
$this->assertEquals( $expected, $reference->getDisplayName() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetCanonicalServer() {
|
2015-10-01 17:12:07 +00:00
|
|
|
$reference = new WikiReference( 'https://acme.com', '/wiki/$1', '//acme.com' );
|
2015-09-11 14:21:16 +00:00
|
|
|
$this->assertEquals( 'https://acme.com', $reference->getCanonicalServer() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetCanonicalUrl() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
'no fragment' => [
|
2015-10-01 20:22:07 +00:00
|
|
|
'https://acme.com/wiki/Foo',
|
|
|
|
|
'https://acme.com',
|
|
|
|
|
'//acme.com',
|
|
|
|
|
'/wiki/$1',
|
|
|
|
|
'Foo',
|
|
|
|
|
null
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'empty fragment' => [
|
2015-10-01 20:22:07 +00:00
|
|
|
'https://acme.com/wiki/Foo',
|
|
|
|
|
'https://acme.com',
|
|
|
|
|
'//acme.com',
|
|
|
|
|
'/wiki/$1',
|
|
|
|
|
'Foo',
|
|
|
|
|
''
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'fragment' => [
|
2015-10-01 20:22:07 +00:00
|
|
|
'https://acme.com/wiki/Foo#Bar',
|
|
|
|
|
'https://acme.com',
|
|
|
|
|
'//acme.com',
|
|
|
|
|
'/wiki/$1',
|
|
|
|
|
'Foo',
|
|
|
|
|
'Bar'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'double fragment' => [
|
2015-10-01 20:22:07 +00:00
|
|
|
'https://acme.com/wiki/Foo#Bar%23Xus',
|
|
|
|
|
'https://acme.com',
|
|
|
|
|
'//acme.com',
|
|
|
|
|
'/wiki/$1',
|
|
|
|
|
'Foo',
|
|
|
|
|
'Bar#Xus'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'escaped fragment' => [
|
2015-10-01 20:22:07 +00:00
|
|
|
'https://acme.com/wiki/Foo%23Bar',
|
|
|
|
|
'https://acme.com',
|
|
|
|
|
'//acme.com',
|
|
|
|
|
'/wiki/$1',
|
|
|
|
|
'Foo#Bar',
|
|
|
|
|
null
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'empty path' => [
|
2015-10-01 20:22:07 +00:00
|
|
|
'https://acme.com/Foo',
|
|
|
|
|
'https://acme.com',
|
|
|
|
|
'//acme.com',
|
|
|
|
|
'/$1',
|
|
|
|
|
'Foo',
|
|
|
|
|
null
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2015-09-11 14:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetCanonicalUrl
|
|
|
|
|
*/
|
2015-10-03 13:44:47 +00:00
|
|
|
public function testGetCanonicalUrl(
|
|
|
|
|
$expected, $canonicalServer, $server, $path, $page, $fragmentId
|
|
|
|
|
) {
|
2015-10-01 17:12:07 +00:00
|
|
|
$reference = new WikiReference( $canonicalServer, $path, $server );
|
2015-09-11 14:17:52 +00:00
|
|
|
$this->assertEquals( $expected, $reference->getCanonicalUrl( $page, $fragmentId ) );
|
2015-09-11 14:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetCanonicalUrl
|
2015-09-11 17:34:54 +00:00
|
|
|
* @note getUrl is an alias for getCanonicalUrl
|
2015-09-11 14:21:16 +00:00
|
|
|
*/
|
2015-09-11 14:17:52 +00:00
|
|
|
public function testGetUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
|
2015-10-01 17:12:07 +00:00
|
|
|
$reference = new WikiReference( $canonicalServer, $path, $server );
|
2015-09-11 14:17:52 +00:00
|
|
|
$this->assertEquals( $expected, $reference->getUrl( $page, $fragmentId ) );
|
2015-09-11 14:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetFullUrl() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
'no fragment' => [
|
2015-10-01 20:22:07 +00:00
|
|
|
'//acme.com/wiki/Foo',
|
|
|
|
|
'https://acme.com',
|
|
|
|
|
'//acme.com',
|
|
|
|
|
'/wiki/$1',
|
|
|
|
|
'Foo',
|
|
|
|
|
null
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'empty fragment' => [
|
2015-10-01 20:22:07 +00:00
|
|
|
'//acme.com/wiki/Foo',
|
|
|
|
|
'https://acme.com',
|
|
|
|
|
'//acme.com',
|
|
|
|
|
'/wiki/$1',
|
|
|
|
|
'Foo',
|
|
|
|
|
''
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'fragment' => [
|
2015-10-01 20:22:07 +00:00
|
|
|
'//acme.com/wiki/Foo#Bar',
|
|
|
|
|
'https://acme.com',
|
|
|
|
|
'//acme.com',
|
|
|
|
|
'/wiki/$1',
|
|
|
|
|
'Foo',
|
|
|
|
|
'Bar'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'double fragment' => [
|
2015-10-01 20:22:07 +00:00
|
|
|
'//acme.com/wiki/Foo#Bar%23Xus',
|
|
|
|
|
'https://acme.com',
|
|
|
|
|
'//acme.com',
|
|
|
|
|
'/wiki/$1',
|
|
|
|
|
'Foo',
|
|
|
|
|
'Bar#Xus'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'escaped fragment' => [
|
2015-10-01 20:22:07 +00:00
|
|
|
'//acme.com/wiki/Foo%23Bar',
|
|
|
|
|
'https://acme.com',
|
|
|
|
|
'//acme.com',
|
|
|
|
|
'/wiki/$1',
|
|
|
|
|
'Foo#Bar',
|
|
|
|
|
null
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'empty path' => [
|
2015-10-01 20:22:07 +00:00
|
|
|
'//acme.com/Foo',
|
|
|
|
|
'https://acme.com',
|
|
|
|
|
'//acme.com',
|
|
|
|
|
'/$1',
|
|
|
|
|
'Foo',
|
|
|
|
|
null
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2015-09-11 14:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetFullUrl
|
|
|
|
|
*/
|
2015-09-11 14:17:52 +00:00
|
|
|
public function testGetFullUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
|
2015-10-01 17:12:07 +00:00
|
|
|
$reference = new WikiReference( $canonicalServer, $path, $server );
|
2015-09-11 14:17:52 +00:00
|
|
|
$this->assertEquals( $expected, $reference->getFullUrl( $page, $fragmentId ) );
|
2015-09-11 14:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|