Skip to content

Commit bfb9ea6

Browse files
committed
Added CSSSize->isSize() to determine whether a CSSSize really represents a size or some other value with a unit like seconds or degrees.
1 parent 0ad0fab commit bfb9ea6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/CSSValue.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public function setSize($fSize) {
2828
public function getSize() {
2929
return $this->fSize;
3030
}
31+
32+
public function isSize() {
33+
return $this->sUnit !== 'deg' && $this->sUnit !== 's';
34+
}
3135

3236
public function isRelative() {
3337
if($this->sUnit === '%' || $this->sUnit === 'em' || $this->sUnit === 'ex') {

tests/CSSParserTests.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ function testFunctionSyntax() {
172172
$oDoc = $this->parsedStructureForFile('functions');
173173
$sExpected = 'div.main {background-image: linear-gradient(rgb(0, 0, 0),rgb(255, 255, 255));}.collapser::before, .collapser::-moz-before, .collapser::-webkit-before {content: "»";font-size: 1.2em;margin-right: 0.2em;-moz-transition-property: -moz-transform;-moz-transition-duration: 0.2s;-moz-transform-origin: center 60%;}.collapser.expanded::before, .collapser.expanded::-moz-before, .collapser.expanded::-webkit-before {-moz-transform: rotate(90deg);}.collapser + * {height: 0;overflow: hidden;-moz-transition-property: height;-moz-transition-duration: 0.3s;}.collapser.expanded + * {height: auto;}';
174174
$this->assertSame($sExpected, $oDoc->__toString());
175+
176+
foreach($oDoc->getAllValues(null, true) as $mValue) {
177+
if($mValue instanceof CSSSize && $mValue->isSize()) {
178+
$mValue->setSize($mValue->getSize()*3);
179+
}
180+
}
181+
$sExpected = str_replace(array('1.2em', '0.2em', '60%'), array('3.6em', '0.6em', '180%'), $sExpected);
182+
$this->assertSame($sExpected, $oDoc->__toString());
183+
175184
foreach($oDoc->getAllValues(null, true) as $mValue) {
176185
if($mValue instanceof CSSSize && !$mValue->isRelative()) {
177186
$mValue->setSize($mValue->getSize()*2);

0 commit comments

Comments
 (0)