MDL-53661 mod_lti: Fix lti_prepare_type_for_save forcessl config
authorSam Chaffee <sam@moodlerooms.com>
Wed, 30 Mar 2016 23:24:49 +0000 (17:24 -0600)
committerSam Chaffee <sam@moodlerooms.com>
Thu, 31 Mar 2016 00:32:34 +0000 (18:32 -0600)
mod/lti/locallib.php
mod/lti/tests/locallib_test.php

index 52a04f7..19578c9 100644 (file)
@@ -1404,10 +1404,8 @@ function lti_prepare_type_for_save($type, $config) {
         $type->secureicon = $config->lti_secureicon;
     }
 
-    if (isset($config->lti_forcessl)) {
-        $type->forcessl = !empty($config->lti_forcessl) ? $config->lti_forcessl : 0;
-        $config->lti_forcessl = $type->forcessl;
-    }
+    $type->forcessl = !empty($config->lti_forcessl) ? $config->lti_forcessl : 0;
+    $config->lti_forcessl = $type->forcessl;
 
     $type->timemodified = time();
 
index 350e5aa..50c785b 100644 (file)
@@ -264,4 +264,32 @@ class mod_lti_locallib_testcase extends advanced_testcase {
 
         $this->assertEquals($ncount, $rncount, 'All newline characters should be a combination of \r\n');
     }
+
+    /**
+     * Tests lti_prepare_type_for_save's handling of the "Force SSL" configuration.
+     */
+    public function test_lti_prepare_type_for_save_forcessl() {
+        $type = new stdClass();
+        $config = new stdClass();
+
+        // Try when the forcessl config property is not set.
+        lti_prepare_type_for_save($type, $config);
+        $this->assertObjectHasAttribute('lti_forcessl', $config);
+        $this->assertEquals(0, $config->lti_forcessl);
+        $this->assertEquals(0, $type->forcessl);
+
+        // Try when forcessl config property is set.
+        $config->lti_forcessl = 1;
+        lti_prepare_type_for_save($type, $config);
+        $this->assertObjectHasAttribute('lti_forcessl', $config);
+        $this->assertEquals(1, $config->lti_forcessl);
+        $this->assertEquals(1, $type->forcessl);
+
+        // Try when forcessl config property is set to 0.
+        $config->lti_forcessl = 0;
+        lti_prepare_type_for_save($type, $config);
+        $this->assertObjectHasAttribute('lti_forcessl', $config);
+        $this->assertEquals(0, $config->lti_forcessl);
+        $this->assertEquals(0, $type->forcessl);
+    }
 }