2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * This file contains the unittests for core scss.
22 * @copyright 2016 onwards Ankit Agarwal
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') ||
die();
29 * This file contains the unittests for core scss.
33 * @copyright 2016 onwards Ankit Agarwal
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class core_scss_testcase
extends advanced_testcase
{
39 * Data provider for is_valid_file
42 public function is_valid_file_provider() {
43 $themedirectory = core_component
::get_component_directory('theme_boost');
44 $realroot = realpath($themedirectory);
47 "path" => "../test.php",
51 "path" => "../test.py",
55 "path" => $realroot . "/scss/moodle.scss",
59 "path" => $realroot . "/scss/../../../config.php",
63 "path" => "/../../../../etc/passwd",
74 * Test cases for SassC compilation.
76 public function scss_compilation_provider() {
79 'scss' => '$font-stack: Helvetica, sans-serif;
83 font: 100% $font-stack;
84 color: $primary-color;
88 font: 100% Helvetica, sans-serif;
101 li { display: inline-block; }
106 text-decoration: none;
116 display: inline-block; }
121 text-decoration: none; }
129 * @dataProvider is_valid_file_provider
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);
138 * Test that we can use the SassC compiler if it's provided.
140 * @dataProvider scss_compilation_provider
141 * @param string $scss The raw scss to compile.
142 * @param string $expectedcss The expected CSS output.
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');
149 $this->resetAfterTest();
150 set_config('pathtosassc', PHPUNIT_PATH_TO_SASSC
);
151 $compiler = new core_scss();
152 $this->assertSame($compiler->compile($scss), $expectedcss);