From 3cdcd2dcc098368530fc3bd6a16a46a2866117a8 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 6 Jan 2021 21:50:27 +0900 Subject: [PATCH] Accommodate formatter changes --- common/framework/formatter.php | 2 +- tests/unit/framework/FormatterTest.php | 29 +++++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/common/framework/formatter.php b/common/framework/formatter.php index 66f1aecc5..d1ed6f325 100644 --- a/common/framework/formatter.php +++ b/common/framework/formatter.php @@ -224,7 +224,7 @@ class Formatter try { $scss_compiler = new \ScssPhp\ScssPhp\Compiler; - $scss_compiler->setFormatter($minify ? '\ScssPhp\ScssPhp\Formatter\Crunched' : '\ScssPhp\ScssPhp\Formatter\Expanded'); + $scss_compiler->setOutputStyle($minify ? \ScssPhp\ScssPhp\OutputStyle::COMPRESSED : \ScssPhp\ScssPhp\OutputStyle::EXPANDED); $scss_compiler->setImportPaths(array(dirname(is_array($source_filename) ? array_first($source_filename) : $source_filename))); if ($variables) { diff --git a/tests/unit/framework/FormatterTest.php b/tests/unit/framework/FormatterTest.php index 7688cd7df..a8bc15626 100644 --- a/tests/unit/framework/FormatterTest.php +++ b/tests/unit/framework/FormatterTest.php @@ -25,25 +25,25 @@ class FormatterTest extends \Codeception\TestCase\Test public function testMarkdown2HTML() { $markdown = file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdown2html.source.md'); - $html1 = file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdown2html.target1.html'); - $html2 = file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdown2html.target2.html'); - $html3 = file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdown2html.target3.html'); - $html4 = file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdown2html.target4.html'); + $html1 = $this->_removeSpace(file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdown2html.target1.html')); + $html2 = $this->_removeSpace(file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdown2html.target2.html')); + $html3 = $this->_removeSpace(file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdown2html.target3.html')); + $html4 = $this->_removeSpace(file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdown2html.target4.html')); - $this->assertEquals($html1, Rhymix\Framework\Formatter::markdown2html($markdown)); - $this->assertEquals($html2, Rhymix\Framework\Formatter::markdown2html($markdown, Rhymix\Framework\Formatter::MD_NEWLINE_AS_BR)); - $this->assertEquals($html3, Rhymix\Framework\Formatter::markdown2html($markdown, Rhymix\Framework\Formatter::MD_NEWLINE_AS_BR | Rhymix\Framework\Formatter::MD_ENABLE_EXTRA)); - $this->assertEquals($html4, Rhymix\Framework\Formatter::markdown2html($markdown, Rhymix\Framework\Formatter::MD_ENABLE_EXTRA)); + $this->assertEquals($html1, $this->_removeSpace(Rhymix\Framework\Formatter::markdown2html($markdown))); + $this->assertEquals($html2, $this->_removeSpace(Rhymix\Framework\Formatter::markdown2html($markdown, Rhymix\Framework\Formatter::MD_NEWLINE_AS_BR))); + $this->assertEquals($html3, $this->_removeSpace(Rhymix\Framework\Formatter::markdown2html($markdown, Rhymix\Framework\Formatter::MD_NEWLINE_AS_BR | Rhymix\Framework\Formatter::MD_ENABLE_EXTRA))); + $this->assertEquals($html4, $this->_removeSpace(Rhymix\Framework\Formatter::markdown2html($markdown, Rhymix\Framework\Formatter::MD_ENABLE_EXTRA))); } public function testMarkdownExtra() { $markdown = file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdownextra.source.md'); - $html1 = file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdownextra.target1.html'); - $html2 = file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdownextra.target2.html'); + $html1 = $this->_removeSpace(file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdownextra.target1.html')); + $html2 = $this->_removeSpace(file_get_contents(\RX_BASEDIR . 'tests/_data/formatter/markdownextra.target2.html')); - $this->assertEquals($html1, Rhymix\Framework\Formatter::markdown2html($markdown)); - $this->assertEquals($html2, Rhymix\Framework\Formatter::markdown2html($markdown, Rhymix\Framework\Formatter::MD_ENABLE_EXTRA)); + $this->assertEquals($html1, $this->_removeSpace(Rhymix\Framework\Formatter::markdown2html($markdown))); + $this->assertEquals($html2, $this->_removeSpace(Rhymix\Framework\Formatter::markdown2html($markdown, Rhymix\Framework\Formatter::MD_ENABLE_EXTRA))); } public function testHTML2Markdown() @@ -202,4 +202,9 @@ class FormatterTest extends \Codeception\TestCase\Test $target = '!(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] < 8) || (/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] < 6)'; $this->assertEquals($target, Rhymix\Framework\Formatter::convertIECondition($source)); } + + protected function _removeSpace($str) + { + return preg_replace('/\s+/', '', $str); + } }