Skip to content

Commit

Permalink
added unit test facility.
Browse files Browse the repository at this point in the history
fixed occurence of !important without ending semicolon (if last rule)

closes issue #2
  • Loading branch information
Raphael Schweikert committed Nov 8, 2010
1 parent 1797145 commit d2a9d1c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CSSParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ private function parseRule() {
if($this->comes('!')) {
$this->consume('!');
$this->consumeWhiteSpace();
$sImportantMarker = $this->consumeUntil(';');
$sImportantMarker = $this->consume(strlen('important'));
if(mb_convert_case($sImportantMarker, MB_CASE_LOWER) !== 'important') {
throw new Exception("! was not followed by “important”");
throw new Exception("! was followed by".$sImportantMarker."”. Expected “important”");
}
$oRule->setIsImportant(true);
}
Expand Down
28 changes: 28 additions & 0 deletions tests/CSSParserTests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

require_once('CSSParser.php');

class CSSParserTests extends PHPUnit_Framework_TestCase {
function testCssFiles() {

$sDirectory = dirname(__FILE__).DIRECTORY_SEPARATOR.'files';
if($rHandle = opendir($sDirectory)) {
/* This is the correct way to loop over the directory. */
while (false !== ($sFileName = readdir($rHandle))) {
if(strpos($sFileName, '.') === 0) {
continue;
}
if(strrpos($sFileName, '.css') !== strlen($sFileName)-strlen('.css')) {
continue;
}
$oParser = new CSSParser(file_get_contents($sDirectory.DIRECTORY_SEPARATOR.$sFileName));
try {
$oParser->parse();
} catch(Exception $e) {
$this->fail($e);
}
}
closedir($rHandle);
}
}
}
8 changes: 8 additions & 0 deletions tests/files/important.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
div.rating-cancel,div.star-rating{float:left;width:17px;height:15px;text-indent:-999em;cursor:pointer;display:block;background:transparent;overflow:hidden}
div.rating-cancel,div.rating-cancel a{background:url(images/delete.gif) no-repeat 0 -16px}
div.star-rating,div.star-rating a{background:url(images/star.gif) no-repeat 0 0px}
div.rating-cancel a,div.star-rating a{display:block;width:16px;height:100%;background-position:0 0px;border:0}
div.star-rating-on a{background-position:0 -16px!important}
div.star-rating-hover a{background-position:0 -32px}
div.star-rating-readonly a{cursor:default !important}
div.star-rating{background:transparent!important; overflow:hidden!important}

0 comments on commit d2a9d1c

Please sign in to comment.