Add test cases for wfAppendQuery
authorSergio Santoro <santoro.srg@gmail.com>
Tue, 5 Aug 2014 13:11:56 +0000 (15:11 +0200)
committerKrinkle <krinklemail@gmail.com>
Mon, 29 Sep 2014 22:56:21 +0000 (22:56 +0000)
Change-Id: I51e0e1764ad70d922466d62f1ddf3f8e3fb4568f

tests/phpunit/includes/GlobalFunctions/wfAppendQueryTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/includes/GlobalFunctions/wfAppendQueryTest.php b/tests/phpunit/includes/GlobalFunctions/wfAppendQueryTest.php
new file mode 100644 (file)
index 0000000..54e1f89
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+/**
+ * @group GlobalFunctions
+ * @covers ::wfAppendQuery
+ */
+class WfAppendQueryTest extends MediaWikiTestCase {
+       /**
+        * @dataProvider provideAppendQuery
+        */
+       public function testAppendQuery( $url, $query, $expected, $message = null ) {
+               $this->assertEquals( $expected, wfAppendQuery( $url, $query ), $message );
+       }
+
+       public static function provideAppendQuery() {
+               return array(
+                       array(
+                               'http://www.example.org/index.php',
+                               '',
+                               'http://www.example.org/index.php',
+                               'No query'
+                       ),
+                       array(
+                               'http://www.example.org/index.php',
+                               array( 'foo' => 'bar' ),
+                               'http://www.example.org/index.php?foo=bar',
+                               'Set query array'
+                       ),
+                       array(
+                               'http://www.example.org/index.php?foz=baz',
+                               'foo=bar',
+                               'http://www.example.org/index.php?foz=baz&foo=bar',
+                               'Set query string'
+                       ),
+                       array(
+                               'http://www.example.org/index.php?foo=bar',
+                               '',
+                               'http://www.example.org/index.php?foo=bar',
+                               'Empty string with query'
+                       ),
+                       array(
+                               'http://www.example.org/index.php?foo=bar',
+                               array( 'baz' => 'quux' ),
+                               'http://www.example.org/index.php?foo=bar&baz=quux',
+                               'Add query array'
+                       ),
+                       array(
+                               'http://www.example.org/index.php?foo=bar',
+                               'baz=quux',
+                               'http://www.example.org/index.php?foo=bar&baz=quux',
+                               'Add query string'
+                       ),
+                       array(
+                               'http://www.example.org/index.php?foo=bar',
+                               array( 'baz' => 'quux', 'foo' => 'baz' ),
+                               'http://www.example.org/index.php?foo=bar&baz=quux&foo=baz',
+                               'Modify query array'
+                       ),
+                       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'
+                       )
+               );
+       }
+}