diff --git a/lib/outputlib.php b/lib/outputlib.php index e5a8514d980..00e9fffd2a4 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -1475,7 +1475,7 @@ class theme_config { // Compile! $compiled = $compiler->to_css(); - } catch (\Leafo\ScssPhp\Exception $e) { + } catch (\Exception $e) { $compiled = false; debugging('Error while compiling SCSS: ' . $e->getMessage(), DEBUG_DEVELOPER); } diff --git a/lib/tests/scss_test.php b/lib/tests/scss_test.php index 80f3cb54c8e..55e7cd902fe 100644 --- a/lib/tests/scss_test.php +++ b/lib/tests/scss_test.php @@ -70,6 +70,61 @@ class core_scss_testcase extends advanced_testcase { ]; } + /** + * 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' => << [ + 'scss' => 'nav { + ul { + margin: 0; + padding: 0; + list-style: none; + } + + li { display: inline-block; } + + a { + display: block; + padding: 6px 12px; + text-decoration: none; + } + }', + 'expected' => <<assertSame($valid, $pathvalid); } -} \ No newline at end of file + + /** + * 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); + } +} diff --git a/theme/boost/tests/scss_test.php b/theme/boost/tests/scss_test.php new file mode 100644 index 00000000000..5b1fc8adb76 --- /dev/null +++ b/theme/boost/tests/scss_test.php @@ -0,0 +1,50 @@ +. + +/** + * This file contains the unittests for boost's scss compilation. + * + * @package theme_boost + * @copyright 2018 Cameron Ball + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Unit tests for scss compilation. + * + * @package theme_boost + * @copyright 2016 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class theme_boost_scss_testcase extends advanced_testcase { + /** + * Test that boost can be compiled using SassC (the defacto implemention). + */ + public function test_scss_compilation_with_sassc() { + if (!defined('PHPUNIT_PATH_TO_SASSC')) { + $this->markTestSkipped('Path to SassC not provided'); + } + + $this->resetAfterTest(); + set_config('pathtosassc', PHPUNIT_PATH_TO_SASSC); + + $this->assertNotEmpty( + theme_config::load('boost')->get_css_content_debug('scss', null, null) + ); + } +}