moodle/lib/tests/scss_test.php
Eloy Lafuente (stronk7) 4003e31983 MDL-73785 phpunit: Move more tests to use correct names and namespaces
Applied the following changes to various testcase classes:

- Namespaced with component[\level2-API]
- Moved to level2-API subdirectory when required.
- Fixed incorrect use statements with leading backslash.
- Remove file phpdoc block
- Remove MOODLE_INTERNAL if not needed.
- Changed code to point to global scope when needed.
- Fix some relative paths and comments here and there.
- All them passing individually.
- Complete runs passing too.

Special mention to:

- When belonging to other components and being valid api:
  - analytics related tests have been moved to tests/analytics subdir.
  - backup & restore related tests have been moved to tests/backup subdir.
  - events related tests have been moved to tests/event subdir.
  - privacy related tests have been moved to tests/privacy.
  - task related tests have been moved to tests/task subdir.
- Some simple renames, not including the component part anymore (not
  needed now that they are namespaced):
  - some xxxlib_test.php have been renamed lib_test.php
    (when they where testing the corresponding lib.php).
  - cache stores tests have been all renamed store_test, originally
    each one had its own name (file_test, apcu_test, redis_test...)
  - assign feedback tests have been all renamed feedback_test, originally
    each one had its own name (file_test, editpdf_test...)
2022-03-03 12:19:30 +01:00

148 lines
4.3 KiB
PHP

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core;
use core_scss;
/**
* This file contains the unittests for core scss.
*
* @package core
* @category phpunit
* @copyright 2016 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scss_test extends \advanced_testcase {
/**
* Data provider for is_valid_file
* @return array
*/
public function is_valid_file_provider() {
$themedirectory = \core_component::get_component_directory('theme_boost');
$realroot = realpath($themedirectory);
return [
"File import 1" => [
"path" => "../test.php",
"valid" => false
],
"File import 2" => [
"path" => "../test.py",
"valid" => false
],
"File import 3" => [
"path" => $realroot . "/scss/moodle.scss",
"valid" => true
],
"File import 4" => [
"path" => $realroot . "/scss/../../../config.php",
"valid" => false
],
"File import 5" => [
"path" => "/../../../../etc/passwd",
"valid" => false
],
"File import 6" => [
"path" => "random",
"valid" => false
]
];
}
/**
* Test cases for SassC compilation.
*/
public function scss_compilation_provider() {
return [
'simple' => [
'scss' => '$font-stack: Helvetica, sans-serif;
$primary-color: #333;
body {
font: 100% $font-stack;
color: $primary-color;
}',
'expected' => <<<CSS
body {
font: 100% Helvetica, sans-serif;
color: #333; }
CSS
],
'nested' => [
'scss' => 'nav {
ul {
margin: 0;
padding: 0;
list-style: none;
}
li { display: inline-block; }
a {
display: block;
padding: 6px 12px;
text-decoration: none;
}
}',
'expected' => <<<CSS
nav ul {
margin: 0;
padding: 0;
list-style: none; }
nav li {
display: inline-block; }
nav a {
display: block;
padding: 6px 12px;
text-decoration: none; }
CSS
]
];
}
/**
* @dataProvider is_valid_file_provider
*/
public function test_is_valid_file($path, $valid) {
$scss = new \core_scss();
$pathvalid = \phpunit_util::call_internal_method($scss, 'is_valid_file', [$path], \core_scss::class);
$this->assertSame($valid, $pathvalid);
}
/**
* Test that we can use the SassC compiler if it's provided.
*
* @dataProvider scss_compilation_provider
* @param string $scss The raw scss to compile.
* @param string $expectedcss The expected CSS output.
*/
public function test_scss_compilation_with_sassc($scss, $expectedcss) {
if (!defined('PHPUNIT_PATH_TO_SASSC')) {
$this->markTestSkipped('Path to SassC not provided');
}
$this->resetAfterTest();
set_config('pathtosassc', PHPUNIT_PATH_TO_SASSC);
$compiler = new core_scss();
$this->assertSame($compiler->compile($scss), $expectedcss);
}
}