Merge branch 'MDL-76985-MOODLE_400_STABLE' of https://github.com/sh-csg/moodle into...
[moodle.git] / lib / tests / scss_test.php
blobea53368e423240a08a3a4a6032a375d624783a0c
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.
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/>.
17 namespace core;
19 use core_scss;
21 /**
22 * This file contains the unittests for core scss.
24 * @package core
25 * @category phpunit
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 {
31 /**
32 * Data provider for is_valid_file
33 * @return array
35 public function is_valid_file_provider() {
36 $themedirectory = \core_component::get_component_directory('theme_boost');
37 $realroot = realpath($themedirectory);
38 return [
39 "File import 1" => [
40 "path" => "../test.php",
41 "valid" => false
43 "File import 2" => [
44 "path" => "../test.py",
45 "valid" => false
47 "File import 3" => [
48 "path" => $realroot . "/scss/moodle.scss",
49 "valid" => true
51 "File import 4" => [
52 "path" => $realroot . "/scss/../../../config.php",
53 "valid" => false
55 "File import 5" => [
56 "path" => "/../../../../etc/passwd",
57 "valid" => false
59 "File import 6" => [
60 "path" => "random",
61 "valid" => false
66 /**
67 * Test cases for SassC compilation.
69 public function scss_compilation_provider() {
70 return [
71 'simple' => [
72 'scss' => '$font-stack: Helvetica, sans-serif;
73 $primary-color: #333;
75 body {
76 font: 100% $font-stack;
77 color: $primary-color;
78 }',
79 'expected' => <<<CSS
80 body {
81 font: 100% Helvetica, sans-serif;
82 color: #333; }
84 CSS
86 'nested' => [
87 'scss' => 'nav {
88 ul {
89 margin: 0;
90 padding: 0;
91 list-style: none;
94 li { display: inline-block; }
96 a {
97 display: block;
98 padding: 6px 12px;
99 text-decoration: none;
102 'expected' => <<<CSS
103 nav ul {
104 margin: 0;
105 padding: 0;
106 list-style: none; }
108 nav li {
109 display: inline-block; }
111 nav a {
112 display: block;
113 padding: 6px 12px;
114 text-decoration: none; }
122 * @dataProvider is_valid_file_provider
124 public function test_is_valid_file($path, $valid) {
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) {
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);