Merge branch 'install_35_STABLE' of https://git.in.moodle.com/amosbot/moodle-install...
[moodle.git] / lib / tests / scss_test.php
blob55e7cd902fe8f89f9023195f3edce2d70b227684
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 /**
18 * This file contains the unittests for core scss.
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
26 defined('MOODLE_INTERNAL') || die();
28 /**
29 * This file contains the unittests for core scss.
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
36 class core_scss_testcase extends advanced_testcase {
38 /**
39 * Data provider for is_valid_file
40 * @return array
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
50 "File import 2" => [
51 "path" => "../test.py",
52 "valid" => false
54 "File import 3" => [
55 "path" => $realroot . "/scss/moodle.scss",
56 "valid" => true
58 "File import 4" => [
59 "path" => $realroot . "/scss/../../../config.php",
60 "valid" => false
62 "File import 5" => [
63 "path" => "/../../../../etc/passwd",
64 "valid" => false
66 "File import 6" => [
67 "path" => "random",
68 "valid" => false
73 /**
74 * Test cases for SassC compilation.
76 public function scss_compilation_provider() {
77 return [
78 'simple' => [
79 'scss' => '$font-stack: Helvetica, sans-serif;
80 $primary-color: #333;
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; }
91 CSS
93 'nested' => [
94 'scss' => 'nav {
95 ul {
96 margin: 0;
97 padding: 0;
98 list-style: none;
101 li { display: inline-block; }
104 display: block;
105 padding: 6px 12px;
106 text-decoration: none;
109 'expected' => <<<CSS
110 nav ul {
111 margin: 0;
112 padding: 0;
113 list-style: none; }
115 nav li {
116 display: inline-block; }
118 nav a {
119 display: block;
120 padding: 6px 12px;
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);