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/>.
22 * This file contains the unittests for core scss.
26 * @copyright 2016 onwards Ankit Agarwal
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 class scss_test
extends \advanced_testcase
{
32 * Data provider for is_valid_file
35 public function is_valid_file_provider() {
36 $themedirectory = \core_component
::get_component_directory('theme_boost');
37 $realroot = realpath($themedirectory);
40 "path" => "../test.php",
44 "path" => "../test.py",
48 "path" => $realroot . "/scss/moodle.scss",
52 "path" => $realroot . "/scss/../../../config.php",
56 "path" => "/../../../../etc/passwd",
67 * Test cases for SassC compilation.
69 public function scss_compilation_provider() {
72 'scss' => '$font-stack: Helvetica, sans-serif;
76 font: 100% $font-stack;
77 color: $primary-color;
81 font: 100% Helvetica, sans-serif;
94 li { display: inline-block; }
99 text-decoration: none;
109 display: inline-block; }
114 text-decoration: none; }
122 * @dataProvider is_valid_file_provider
124 public function test_is_valid_file($path, $valid): void
{
125 $scss = new \
core_scss();
126 $pathvalid = \phpunit_util
::call_internal_method($scss, 'is_valid_file', [$path], \core_scss
::class);
127 $this->assertSame($valid, $pathvalid);
131 * Test that we can use the SassC compiler if it's provided.
133 * @dataProvider scss_compilation_provider
134 * @param string $scss The raw scss to compile.
135 * @param string $expectedcss The expected CSS output.
137 public function test_scss_compilation_with_sassc($scss, $expectedcss): void
{
138 if (!defined('PHPUNIT_PATH_TO_SASSC')) {
139 $this->markTestSkipped('Path to SassC not provided');
142 $this->resetAfterTest();
143 set_config('pathtosassc', PHPUNIT_PATH_TO_SASSC
);
144 $compiler = new core_scss();
145 $this->assertSame($compiler->compile($scss), $expectedcss);