mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +02:00
Merge branch '26STABLE-wip-MDL45846' of git://github.com/jennymgray/moodle into MOODLE_26_STABLE
This commit is contained in:
commit
fde80766e2
2 changed files with 33 additions and 1 deletions
|
@ -120,7 +120,12 @@ class core_useragent {
|
||||||
protected function __construct($forceuseragent = null) {
|
protected function __construct($forceuseragent = null) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
if (!empty($CFG->devicedetectregex)) {
|
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) {
|
if ($forceuseragent !== null) {
|
||||||
$this->useragent = $forceuseragent;
|
$this->useragent = $forceuseragent;
|
||||||
|
|
|
@ -126,4 +126,31 @@ class core_theme_config_testcase extends advanced_testcase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue