Skip to content

Commit d2a9d1c

Browse files
author
Raphael Schweikert
committed
added unit test facility.
fixed occurence of !important without ending semicolon (if last rule) closes issue MyIntervals#2
1 parent 1797145 commit d2a9d1c

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

CSSParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ private function parseRule() {
209209
if($this->comes('!')) {
210210
$this->consume('!');
211211
$this->consumeWhiteSpace();
212-
$sImportantMarker = $this->consumeUntil(';');
212+
$sImportantMarker = $this->consume(strlen('important'));
213213
if(mb_convert_case($sImportantMarker, MB_CASE_LOWER) !== 'important') {
214-
throw new Exception("! was not followed by “important”");
214+
throw new Exception("! was followed by".$sImportantMarker."”. Expected “important”");
215215
}
216216
$oRule->setIsImportant(true);
217217
}

tests/CSSParserTests.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
require_once('CSSParser.php');
4+
5+
class CSSParserTests extends PHPUnit_Framework_TestCase {
6+
function testCssFiles() {
7+
8+
$sDirectory = dirname(__FILE__).DIRECTORY_SEPARATOR.'files';
9+
if($rHandle = opendir($sDirectory)) {
10+
/* This is the correct way to loop over the directory. */
11+
while (false !== ($sFileName = readdir($rHandle))) {
12+
if(strpos($sFileName, '.') === 0) {
13+
continue;
14+
}
15+
if(strrpos($sFileName, '.css') !== strlen($sFileName)-strlen('.css')) {
16+
continue;
17+
}
18+
$oParser = new CSSParser(file_get_contents($sDirectory.DIRECTORY_SEPARATOR.$sFileName));
19+
try {
20+
$oParser->parse();
21+
} catch(Exception $e) {
22+
$this->fail($e);
23+
}
24+
}
25+
closedir($rHandle);
26+
}
27+
}
28+
}

tests/files/important.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
div.rating-cancel,div.star-rating{float:left;width:17px;height:15px;text-indent:-999em;cursor:pointer;display:block;background:transparent;overflow:hidden}
2+
div.rating-cancel,div.rating-cancel a{background:url(images/delete.gif) no-repeat 0 -16px}
3+
div.star-rating,div.star-rating a{background:url(images/star.gif) no-repeat 0 0px}
4+
div.rating-cancel a,div.star-rating a{display:block;width:16px;height:100%;background-position:0 0px;border:0}
5+
div.star-rating-on a{background-position:0 -16px!important}
6+
div.star-rating-hover a{background-position:0 -32px}
7+
div.star-rating-readonly a{cursor:default !important}
8+
div.star-rating{background:transparent!important; overflow:hidden!important}

0 commit comments

Comments
 (0)