Differences Between: [Versions 310 and 311] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]
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. 13 // 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/>. 16 17 namespace core; 18 19 /** 20 * Unit tests for our locking configuration. 21 * 22 * @package core 23 * @category test 24 * @copyright 2013 Damyon Wiese 25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 */ 27 class lock_config_test extends \advanced_testcase { 28 29 /** 30 * Tests the static parse charset method 31 * @return void 32 */ 33 public function test_lock_config() { 34 global $CFG; 35 $original = null; 36 if (isset($CFG->lock_factory)) { 37 $original = $CFG->lock_factory; 38 } 39 $originalfilelocking = null; 40 if (isset($CFG->preventfilelocking)) { 41 $originalfilelocking = $CFG->preventfilelocking; 42 } 43 44 // Test no configuration. 45 unset($CFG->lock_factory); 46 $CFG->preventfilelocking = 0; 47 $factory = \core\lock\lock_config::get_lock_factory('cache'); 48 $this->assertNotEmpty($factory, 'Get a default factory with no configuration'); 49 50 // Test explicit broken lock. 51 $CFG->lock_factory = '\core\lock\not_a_lock_factory'; 52 try { 53 $factory = \core\lock\lock_config::get_lock_factory('cache'); 54 $this->fail('Exception expected'); 55 } catch (\moodle_exception $ex) { 56 $this->assertInstanceOf('coding_exception', $ex); 57 } 58 59 // Test explicit file locks. 60 $CFG->lock_factory = '\core\lock\file_lock_factory'; 61 $factory = \core\lock\lock_config::get_lock_factory('cache'); 62 $this->assertTrue($factory instanceof \core\lock\file_lock_factory, 63 'Get an explicit file lock factory'); 64 65 // Test explicit file locks but with file locks prevented. 66 $CFG->preventfilelocking = 1; 67 try { 68 $factory = \core\lock\lock_config::get_lock_factory('cache'); 69 $this->fail('Exception expected'); 70 } catch (\moodle_exception $ex) { 71 $this->assertInstanceOf('coding_exception', $ex); 72 } 73 74 // Test explicit db locks. 75 $CFG->lock_factory = '\core\lock\db_record_lock_factory'; 76 $factory = \core\lock\lock_config::get_lock_factory('cache'); 77 $this->assertTrue($factory instanceof \core\lock\db_record_lock_factory, 78 'Get an explicit db record lock factory'); 79 80 if ($original) { 81 $CFG->lock_factory = $original; 82 } else { 83 unset($CFG->lock_factory); 84 } 85 if ($originalfilelocking) { 86 $CFG->preventfilelocking = $originalfilelocking; 87 } else { 88 unset($CFG->preventfilelocking); 89 } 90 } 91 } 92
title
Description
Body
title
Description
Body
title
Description
Body
title
Body