See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
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 * This file contains the unittests for core scss. 19 * 20 * @package core 21 * @category phpunit 22 * @copyright 2016 onwards Ankit Agarwal 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * This file contains the unittests for core scss. 30 * 31 * @package core 32 * @category phpunit 33 * @copyright 2016 onwards Ankit Agarwal 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class core_scss_testcase extends advanced_testcase { 37 38 /** 39 * Data provider for is_valid_file 40 * @return array 41 */ 42 public function is_valid_file_provider() { 43 $themedirectory = core_component::get_component_directory('theme_boost'); 44 $realroot = realpath($themedirectory); 45 return [ 46 "File import 1" => [ 47 "path" => "../test.php", 48 "valid" => false 49 ], 50 "File import 2" => [ 51 "path" => "../test.py", 52 "valid" => false 53 ], 54 "File import 3" => [ 55 "path" => $realroot . "/scss/moodle.scss", 56 "valid" => true 57 ], 58 "File import 4" => [ 59 "path" => $realroot . "/scss/../../../config.php", 60 "valid" => false 61 ], 62 "File import 5" => [ 63 "path" => "/../../../../etc/passwd", 64 "valid" => false 65 ], 66 "File import 6" => [ 67 "path" => "random", 68 "valid" => false 69 ] 70 ]; 71 } 72 73 /** 74 * Test cases for SassC compilation. 75 */ 76 public function scss_compilation_provider() { 77 return [ 78 'simple' => [ 79 'scss' => '$font-stack: Helvetica, sans-serif; 80 $primary-color: #333; 81 82 body { 83 font: 100% $font-stack; 84 color: $primary-color; 85 }', 86 'expected' => <<<CSS 87 body { 88 font: 100% Helvetica, sans-serif; 89 color: #333; } 90 91 CSS 92 ], 93 'nested' => [ 94 'scss' => 'nav { 95 ul { 96 margin: 0; 97 padding: 0; 98 list-style: none; 99 } 100 101 li { display: inline-block; } 102 103 a { 104 display: block; 105 padding: 6px 12px; 106 text-decoration: none; 107 } 108 }', 109 'expected' => <<<CSS 110 nav ul { 111 margin: 0; 112 padding: 0; 113 list-style: none; } 114 115 nav li { 116 display: inline-block; } 117 118 nav a { 119 display: block; 120 padding: 6px 12px; 121 text-decoration: none; } 122 123 CSS 124 ] 125 ]; 126 } 127 128 /** 129 * @dataProvider is_valid_file_provider 130 */ 131 public function test_is_valid_file($path, $valid) { 132 $scss = new \core_scss(); 133 $pathvalid = phpunit_util::call_internal_method($scss, 'is_valid_file', [$path], \core_scss::class); 134 $this->assertSame($valid, $pathvalid); 135 } 136 137 /** 138 * Test that we can use the SassC compiler if it's provided. 139 * 140 * @dataProvider scss_compilation_provider 141 * @param string $scss The raw scss to compile. 142 * @param string $expectedcss The expected CSS output. 143 */ 144 public function test_scss_compilation_with_sassc($scss, $expectedcss) { 145 if (!defined('PHPUNIT_PATH_TO_SASSC')) { 146 $this->markTestSkipped('Path to SassC not provided'); 147 } 148 149 $this->resetAfterTest(); 150 set_config('pathtosassc', PHPUNIT_PATH_TO_SASSC); 151 $compiler = new core_scss(); 152 $this->assertSame($compiler->compile($scss), $expectedcss); 153 } 154 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body