Merge branch 'MDL-51434-master' of git://github.com/jleyva/moodle
[moodle.git] / lib / tests / lock_config_test.php
blob63aef074d70c428f5fb15887874c342ccb931fbb
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * lock unit tests
20 * @package core
21 * @category lock
22 * @copyright 2013 Damyon Wiese
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
29 /**
30 * Unit tests for our locking configuration.
32 * @package core
33 * @category lock
34 * @copyright 2013 Damyon Wiese
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class lock_config_testcase extends advanced_testcase {
39 /**
40 * Tests the static parse charset method
41 * @return void
43 public function test_lock_config() {
44 global $CFG;
45 $original = null;
46 if (isset($CFG->lock_factory)) {
47 $original = $CFG->lock_factory;
50 // Test no configuration.
51 unset($CFG->lock_factory);
53 $factory = \core\lock\lock_config::get_lock_factory('cache');
55 $this->assertNotEmpty($factory, 'Get a default factory with no configuration');
57 $CFG->lock_factory = '\core\lock\file_lock_factory';
59 $factory = \core\lock\lock_config::get_lock_factory('cache');
60 $this->assertTrue($factory instanceof \core\lock\file_lock_factory,
61 'Get a default factory with a set configuration');
63 $CFG->lock_factory = '\core\lock\db_record_lock_factory';
65 $factory = \core\lock\lock_config::get_lock_factory('cache');
66 $this->assertTrue($factory instanceof \core\lock\db_record_lock_factory,
67 'Get a default factory with a changed configuration');
69 if ($original) {
70 $CFG->lock_factory = $original;
71 } else {
72 unset($CFG->lock_factory);