From 4aef583beff58cbf2c30b7f1c920fb9d61929f2a Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Tue, 7 Jun 2016 16:01:39 +0200
Subject: [PATCH] Add some tests for SimpleSAML\Utils\HTTP::addURLParameters().

---
 tests/lib/SimpleSAML/Utils/HTTPTest.php | 47 +++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/tests/lib/SimpleSAML/Utils/HTTPTest.php b/tests/lib/SimpleSAML/Utils/HTTPTest.php
index e17ac9ba7..f73a6dbfe 100644
--- a/tests/lib/SimpleSAML/Utils/HTTPTest.php
+++ b/tests/lib/SimpleSAML/Utils/HTTPTest.php
@@ -6,14 +6,57 @@ use SimpleSAML\Utils\HTTP;
 class HTTPTest extends \PHPUnit_Framework_TestCase
 {
 
+    /**
+     * Test SimpleSAML\Utils\HTTP::addURLParameters().
+     *
+     * @expectedException \InvalidArgumentException
+     */
+    public function testAddURLParametersInvalidURL()
+    {
+        HTTP::addURLParameters(array(), array());
+    }
+
+    /**
+     * Test SimpleSAML\Utils\HTTP::addURLParameters().
+     *
+     * @expectedException \InvalidArgumentException
+     */
+    public function testAddURLParametersInvalidParameters()
+    {
+        HTTP::addURLParameters('string', 'string');
+    }
+
+    /**
+     * Test SimpleSAML\Utils\HTTP::addURLParameters().
+     */
+    public function testAddURLParameters()
+    {
+        $url = 'http://example.com/';
+        $params = array(
+            'foo' => 'bar',
+            'bar' => 'foo',
+        );
+        $this->assertEquals($url.'?foo=bar&bar=foo', HTTP::addURLParameters($url, $params));
+
+        $url = 'http://example.com/?';
+        $params = array(
+            'foo' => 'bar',
+            'bar' => 'foo',
+        );
+        $this->assertEquals($url.'foo=bar&bar=foo', HTTP::addURLParameters($url, $params));
+
+        $url = 'http://example.com/?foo=bar';
+        $params = array(
+            'bar' => 'foo',
+        );
+        $this->assertEquals($url.'&bar=foo', HTTP::addURLParameters($url, $params));
+    }
 
     /**
      * Test SimpleSAML\Utils\HTTP::guessBasePath().
      */
     public function testGuessBasePath()
     {
-        global $_SERVER;
-
         $original = $_SERVER;
 
         $_SERVER['REQUEST_URI'] = '/simplesaml/module.php';
-- 
GitLab