[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 /** 18 * PHPUnit testcase class for atto equation upgrade lib. 19 * 20 * @package atto_equation 21 * @copyright 2015 Sam Chaffee <sam@moodlerooms.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 defined('MOODLE_INTERNAL') || die(); 25 26 /** 27 * PHPUnit testcase class for atto equation upgrade lib. 28 * 29 * @package atto_equation 30 * @copyright 2015 Sam Chaffee <sam@moodlerooms.com> 31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 */ 33 class atto_equation_upgradelib_testcase extends advanced_testcase { 34 /** 35 * The name of the plugin in config_plugins. 36 */ 37 const SETTING_PLUGIN = 'atto_equation'; 38 39 /** 40 * The name of the setting in config_plugins. 41 */ 42 const SETTING_NAME = 'librarygroup4'; 43 44 /** 45 * Does testsuite set up. 46 */ 47 public function setUp() { 48 $this->resetAfterTest(); 49 } 50 51 /** 52 * Tests the upgradelib atto_equation_update_librarygroup4_setting function. 53 */ 54 public function test_update_librarygroup4_update() { 55 global $CFG; 56 require_once($CFG->libdir . '/editor/atto/plugins/equation/db/upgradelib.php'); 57 58 $originaldefaults = [ 59 '\sum{a,b}', 60 '\int_{a}^{b}{c}', 61 '\iint_{a}^{b}{c}', 62 '\iiint_{a}^{b}{c}', 63 '\oint{a}', 64 '(a)', 65 '[a]', 66 '\lbrace{a}\rbrace', 67 '\left| \begin{matrix} a_1 & a_2 \\ a_3 & a_4 \end{matrix} \right|', 68 ]; 69 70 $newconfig = ' 71 \sum{a,b} 72 \sqrt[a]{b+c} 73 \int_{a}^{b}{c} 74 \iint_{a}^{b}{c} 75 \iiint_{a}^{b}{c} 76 \oint{a} 77 (a) 78 [a] 79 \lbrace{a}\rbrace 80 \left| \begin{matrix} a_1 & a_2 \\ a_3 & a_4 \end{matrix} \right| 81 \frac{a}{b+c} 82 \vec{a} 83 \binom {a} {b} 84 {a \brack b} 85 {a \brace b} 86 '; 87 88 // Test successful update using windows line endings. 89 $originaldefaultswindows = "\r\n" . implode("\r\n", $originaldefaults) . "\r\n"; 90 set_config(self::SETTING_NAME, $originaldefaultswindows, self::SETTING_PLUGIN); 91 atto_equation_update_librarygroup4_setting(); 92 93 $this->assertEquals($newconfig, get_config(self::SETTING_PLUGIN, self::SETTING_NAME)); 94 95 // Test successful update using linux line . 96 $originaldefaultslinux = "\n" . implode("\n", $originaldefaults) . "\n"; 97 set_config(self::SETTING_NAME, $originaldefaultslinux, self::SETTING_PLUGIN); 98 atto_equation_update_librarygroup4_setting(); 99 100 $this->assertEquals($newconfig, get_config(self::SETTING_PLUGIN, self::SETTING_NAME)); 101 102 // Alter the original configuration by removing one of the equations. 103 $alteredconfig = array_slice($originaldefaults, 0, -1); 104 105 // Test no update using windows line endings. 106 $alteredconfigwindows = "\r\n" . implode("\r\n", $alteredconfig) . "\r\n"; 107 set_config(self::SETTING_NAME, $alteredconfigwindows, self::SETTING_PLUGIN); 108 atto_equation_update_librarygroup4_setting(); 109 110 $this->assertEquals($alteredconfigwindows, get_config(self::SETTING_PLUGIN, self::SETTING_NAME)); 111 112 // Test no update using linux line endings. 113 $alteredconfiglinux = "\n" . implode("\n", $alteredconfig) . "\n"; 114 set_config(self::SETTING_NAME, $alteredconfiglinux, self::SETTING_PLUGIN); 115 atto_equation_update_librarygroup4_setting(); 116 117 $this->assertEquals($alteredconfiglinux, get_config(self::SETTING_PLUGIN, self::SETTING_NAME)); 118 119 // Test no configuration. 120 unset_config(self::SETTING_NAME, self::SETTING_PLUGIN); 121 atto_equation_update_librarygroup4_setting(); 122 123 $this->assertFalse(get_config(self::SETTING_PLUGIN, self::SETTING_NAME)); 124 } 125 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |