Skip to content

Commit

Permalink
Merge branch '26STABLE-wip-MDL45846' of git://github.com/jennymgray/m…
Browse files Browse the repository at this point in the history
…oodle into MOODLE_26_STABLE
  • Loading branch information
marinaglancy committed Jun 10, 2014
2 parents 2f3c3ab + 1d20e99 commit fde8076
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/classes/useragent.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ public static function instance($reload = false, $forceuseragent = null) {
protected function __construct($forceuseragent = null) {
global $CFG;
if (!empty($CFG->devicedetectregex)) {
$this->devicetypecustoms = json_decode($CFG->devicedetectregex);
$this->devicetypecustoms = json_decode($CFG->devicedetectregex, true);
}
if ($this->devicetypecustoms === null) {
// This shouldn't happen unless you're hardcoding the config value.
debugging('Config devicedetectregex is not valid JSON object');
$this->devicetypecustoms = array();
}
if ($forceuseragent !== null) {
$this->useragent = $forceuseragent;
Expand Down
27 changes: 27 additions & 0 deletions lib/tests/theme_config_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,31 @@ public function test_svg_image_use() {
}
}
}

/**
* This function will test custom device detection regular expression setting.
*/
public function test_devicedetectregex() {
global $CFG;

$this->resetAfterTest();

// Check config currently empty.
$this->assertEmpty(json_decode($CFG->devicedetectregex));
$this->assertTrue(core_useragent::set_user_device_type('tablet'));
$exceptionoccured = false;
try {
core_useragent::set_user_device_type('featurephone');
} catch (moodle_exception $e) {
$exceptionoccured = true;
}
$this->assertTrue($exceptionoccured);

// Set config and recheck.
$config = array('featurephone' => '(Symbian|MIDP-1.0|Maemo|Windows CE)');
$CFG->devicedetectregex = json_encode($config);
core_useragent::instance(true); // Clears singleton cache.
$this->assertTrue(core_useragent::set_user_device_type('tablet'));
$this->assertTrue(core_useragent::set_user_device_type('featurephone'));
}
}

0 comments on commit fde8076

Please sign in to comment.