mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-24 21:03:19 +09:00
Add unit tests for concatCSS() and concatJS()
This commit is contained in:
parent
7363f71d4a
commit
b5a10e850f
10 changed files with 120 additions and 2 deletions
|
|
@ -337,7 +337,7 @@ class Formatter
|
|||
unset($path_converter);
|
||||
if ($media !== null)
|
||||
{
|
||||
$content = "@media $media {\n\n$content\n\n}";
|
||||
$content = "@media $media {\n\n" . trim($content) . "\n\n}";
|
||||
}
|
||||
$original_filename = starts_with(\RX_BASEDIR, $filename) ? substr($filename, strlen(\RX_BASEDIR)) : $filename;
|
||||
$result .= '/* Original file: ' . $original_filename . ' */' . "\n\n" . trim($content) . "\n\n";
|
||||
|
|
@ -374,7 +374,7 @@ class Formatter
|
|||
$content = utf8_clean(file_get_contents($filename));
|
||||
if ($targetie !== null)
|
||||
{
|
||||
$content = 'if (' . self::convertIECondition($targetie) . ') {' . "\n\n" . $content . "\n\n" . '}';
|
||||
$content = 'if (' . self::convertIECondition($targetie) . ') {' . "\n\n" . trim($content) . ";\n\n" . '}';
|
||||
}
|
||||
$original_filename = starts_with(\RX_BASEDIR, $filename) ? substr($filename, strlen(\RX_BASEDIR)) : $filename;
|
||||
$result .= '/* Original file: ' . $original_filename . ' */' . "\n\n" . trim($content) . ";\n\n";
|
||||
|
|
|
|||
4
tests/_data/formatter/concat.source1.css
Normal file
4
tests/_data/formatter/concat.source1.css
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
@charset "UTF-8";
|
||||
.rhymix {
|
||||
background: url("foo/bar.jpg");
|
||||
}
|
||||
6
tests/_data/formatter/concat.source1.js
Normal file
6
tests/_data/formatter/concat.source1.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(function($) {
|
||||
$(".foo").click(function(event) {
|
||||
event.preventDefault();
|
||||
$(this).attr("bar", "baz");
|
||||
});
|
||||
})(jQuery);
|
||||
7
tests/_data/formatter/concat.source2.css
Normal file
7
tests/_data/formatter/concat.source2.css
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
@charset "UTF-8";
|
||||
.wordpress {
|
||||
border-radius: 4px;
|
||||
}
|
||||
.xpressengine {
|
||||
margin: 320px;
|
||||
}
|
||||
3
tests/_data/formatter/concat.source2.js
Normal file
3
tests/_data/formatter/concat.source2.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(function($) {
|
||||
$(".xe").hide();
|
||||
})(jQuery);
|
||||
16
tests/_data/formatter/concat.target1.css
Normal file
16
tests/_data/formatter/concat.target1.css
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/* Original file: tests/_data/formatter/concat.source1.css */
|
||||
|
||||
@charset "UTF-8";
|
||||
.rhymix {
|
||||
background: url("../_data/formatter/foo/bar.jpg");
|
||||
}
|
||||
|
||||
/* Original file: tests/_data/formatter/concat.source2.css */
|
||||
|
||||
@charset "UTF-8";
|
||||
.wordpress {
|
||||
border-radius: 4px;
|
||||
}
|
||||
.xpressengine {
|
||||
margin: 320px;
|
||||
}
|
||||
14
tests/_data/formatter/concat.target1.js
Normal file
14
tests/_data/formatter/concat.target1.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/* Original file: tests/_data/formatter/concat.source1.js */
|
||||
|
||||
(function($) {
|
||||
$(".foo").click(function(event) {
|
||||
event.preventDefault();
|
||||
$(this).attr("bar", "baz");
|
||||
});
|
||||
})(jQuery);;
|
||||
|
||||
/* Original file: tests/_data/formatter/concat.source2.js */
|
||||
|
||||
(function($) {
|
||||
$(".xe").hide();
|
||||
})(jQuery);;
|
||||
20
tests/_data/formatter/concat.target2.css
Normal file
20
tests/_data/formatter/concat.target2.css
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* Original file: tests/_data/formatter/concat.source1.css */
|
||||
|
||||
@media screen and (max-width: 640px) {
|
||||
|
||||
@charset "UTF-8";
|
||||
.rhymix {
|
||||
background: url("../_data/formatter/foo/bar.jpg");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Original file: tests/_data/formatter/concat.source2.css */
|
||||
|
||||
@charset "UTF-8";
|
||||
.wordpress {
|
||||
border-radius: 4px;
|
||||
}
|
||||
.xpressengine {
|
||||
margin: 320px;
|
||||
}
|
||||
18
tests/_data/formatter/concat.target2.js
Normal file
18
tests/_data/formatter/concat.target2.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* Original file: tests/_data/formatter/concat.source1.js */
|
||||
|
||||
(function($) {
|
||||
$(".foo").click(function(event) {
|
||||
event.preventDefault();
|
||||
$(this).attr("bar", "baz");
|
||||
});
|
||||
})(jQuery);;
|
||||
|
||||
/* Original file: tests/_data/formatter/concat.source2.js */
|
||||
|
||||
if ((/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] >= 6) && (/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] <= 8)) {
|
||||
|
||||
(function($) {
|
||||
$(".xe").hide();
|
||||
})(jQuery);;
|
||||
|
||||
};
|
||||
|
|
@ -132,6 +132,36 @@ class FormatterTest extends \Codeception\TestCase\Test
|
|||
unlink($test_target);
|
||||
}
|
||||
|
||||
public function testConcatCSS()
|
||||
{
|
||||
$source1 = \RX_BASEDIR . 'tests/_data/formatter/concat.source1.css';
|
||||
$source2 = \RX_BASEDIR . 'tests/_data/formatter/concat.source2.css';
|
||||
$real_target1 = \RX_BASEDIR . 'tests/_data/formatter/concat.target1.css';
|
||||
$real_target2 = \RX_BASEDIR . 'tests/_data/formatter/concat.target2.css';
|
||||
$test_target = \RX_BASEDIR . 'tests/_output/concat.target.css';
|
||||
|
||||
$test_without_media_query = Rhymix\Framework\Formatter::concatCSS(array($source1, $source2), $test_target);
|
||||
$this->assertEquals(trim(file_get_contents($real_target1)), trim($test_without_media_query));
|
||||
|
||||
$test_with_media_query = Rhymix\Framework\Formatter::concatCSS(array(array($source1, 'screen and (max-width: 640px)'), $source2), $test_target);
|
||||
$this->assertEquals(trim(file_get_contents($real_target2)), trim($test_with_media_query));
|
||||
}
|
||||
|
||||
public function testConcatJS()
|
||||
{
|
||||
$source1 = \RX_BASEDIR . 'tests/_data/formatter/concat.source1.js';
|
||||
$source2 = \RX_BASEDIR . 'tests/_data/formatter/concat.source2.js';
|
||||
$real_target1 = \RX_BASEDIR . 'tests/_data/formatter/concat.target1.js';
|
||||
$real_target2 = \RX_BASEDIR . 'tests/_data/formatter/concat.target2.js';
|
||||
$test_target = \RX_BASEDIR . 'tests/_output/concat.target.js';
|
||||
|
||||
$test_without_targetie = Rhymix\Framework\Formatter::concatJS(array($source1, $source2), $test_target);
|
||||
$this->assertEquals(trim(file_get_contents($real_target1)), trim($test_without_targetie));
|
||||
|
||||
$test_with_targetie = Rhymix\Framework\Formatter::concatJS(array($source1, array($source2, '(gte IE 6) & (lte IE 8)')), $test_target);
|
||||
$this->assertEquals(trim(file_get_contents($real_target2)), trim($test_with_targetie));
|
||||
}
|
||||
|
||||
public function testConvertIECondition()
|
||||
{
|
||||
$this->assertEquals('window.navigator.userAgent.match(/MSIE\s/)', Rhymix\Framework\Formatter::convertIECondition('IE'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue