Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-20245 grade: added tests for set_user_preference() and the 1333 l…

…imit

Added to tests to check that both the "limit" case of using 1333
chars is allowed and 1334 causes coding exception to happen
  • Loading branch information...
commit 1b5afe64c468b4f7f594dfa6454e77bd2844cf8d 1 parent 5831b4c
@stronk7 stronk7 authored
Showing with 16 additions and 0 deletions.
  1. +16 −0 lib/simpletest/testmoodlelib.php
View
16 lib/simpletest/testmoodlelib.php
@@ -1164,6 +1164,22 @@ public function test_set_user_preference() {
unset_user_preference('_test_user_preferences_pref');
$this->assertTrue(!isset($USER->preference['_test_user_preferences_pref']));
+ // Test 1333 char values (no need for unicode, there are already tests for that in DB tests)
+ $longvalue = str_repeat('a', 1333);
+ set_user_preference('_test_long_user_preference', $longvalue);
+ $this->assertEqual($longvalue, get_user_preferences('_test_long_user_preference'));
+ $this->assertEqual($longvalue,
+ $DB->get_field('user_preferences', 'value', array('userid' => $USER->id, 'name' => '_test_long_user_preference')));
+
+ // Test > 1333 char values, coding_exception expected
+ $longvalue = str_repeat('a', 1334);
+ try {
+ set_user_preference('_test_long_user_preference', $longvalue);
+ $this->assertFail('Exception expected - longer than 1333 chars not allowed as preference value');
+ } catch (Exception $e) {
+ $this->assertTrue($e instanceof coding_exception);
+ }
+
//test invalid params
try {
set_user_preference('_test_user_preferences_pref', array());
Please sign in to comment.
Something went wrong with that request. Please try again.