wiki.techinc.nl/tests/phpunit/unit/includes/GlobalFunctions/wfAppendQueryTest.php
Amir Sarabadani 06f645c453 Load GlobalFunctions.php to tests/phpunit/bootstrap.php
That mostly enables testing global functions

Bug: T87781
Change-Id: Ib42c56a67926ebcdba53f4c6c54a5bff98cb77a3
2019-07-14 01:28:07 +02:00

79 lines
1.9 KiB
PHP

<?php
/**
* @group GlobalFunctions
* @covers ::wfAppendQuery
*/
class WfAppendQueryTest extends MediaWikiUnitTestCase {
/**
* @dataProvider provideAppendQuery
*/
public function testAppendQuery( $url, $query, $expected, $message = null ) {
$this->assertEquals( $expected, wfAppendQuery( $url, $query ), $message );
}
public static function provideAppendQuery() {
return [
[
'http://www.example.org/index.php',
'',
'http://www.example.org/index.php',
'No query'
],
[
'http://www.example.org/index.php',
[ 'foo' => 'bar' ],
'http://www.example.org/index.php?foo=bar',
'Set query array'
],
[
'http://www.example.org/index.php?foz=baz',
'foo=bar',
'http://www.example.org/index.php?foz=baz&foo=bar',
'Set query string'
],
[
'http://www.example.org/index.php?foo=bar',
'',
'http://www.example.org/index.php?foo=bar',
'Empty string with query'
],
[
'http://www.example.org/index.php?foo=bar',
[ 'baz' => 'quux' ],
'http://www.example.org/index.php?foo=bar&baz=quux',
'Add query array'
],
[
'http://www.example.org/index.php?foo=bar',
'baz=quux',
'http://www.example.org/index.php?foo=bar&baz=quux',
'Add query string'
],
[
'http://www.example.org/index.php?foo=bar',
[ 'baz' => 'quux', 'foo' => 'baz' ],
'http://www.example.org/index.php?foo=bar&baz=quux&foo=baz',
'Modify query array'
],
[
'http://www.example.org/index.php?foo=bar',
'baz=quux&foo=baz',
'http://www.example.org/index.php?foo=bar&baz=quux&foo=baz',
'Modify query string'
],
[
'http://www.example.org/index.php#baz',
'foo=bar',
'http://www.example.org/index.php?foo=bar#baz',
'URL with fragment'
],
[
'http://www.example.org/index.php?foo=bar#baz',
'quux=blah',
'http://www.example.org/index.php?foo=bar&quux=blah#baz',
'URL with query string and fragment'
]
];
}
}