|
4 | 4 |
|
5 | 5 | use Sabberworm\CSS\Parser;
|
6 | 6 | use Sabberworm\CSS\Rule\Rule;
|
| 7 | +use Sabberworm\CSS\Value\Size; |
7 | 8 |
|
8 | 9 | class DeclarationBlockTest extends \PHPUnit_Framework_TestCase {
|
9 | 10 |
|
@@ -223,5 +224,44 @@ public function testOverrideRules() {
|
223 | 224 | $this->assertEquals('right', $aRules[0]->getRule());
|
224 | 225 | $this->assertEquals('-10px', $aRules[0]->getValue());
|
225 | 226 | }
|
| 227 | + |
| 228 | + public function testRuleInsertion() { |
| 229 | + $sCss = '.wrapper { left: 10px; text-align: left; }'; |
| 230 | + $oParser = new Parser($sCss); |
| 231 | + $oDoc = $oParser->parse(); |
| 232 | + $aContents = $oDoc->getContents(); |
| 233 | + $oWrapper = $aContents[0]; |
| 234 | + |
| 235 | + $oFirst = $oWrapper->getRules('left'); |
| 236 | + $this->assertCount(1, $oFirst); |
| 237 | + $oFirst = $oFirst[0]; |
| 238 | + |
| 239 | + $oSecond = $oWrapper->getRules('text-'); |
| 240 | + $this->assertCount(1, $oSecond); |
| 241 | + $oSecond = $oSecond[0]; |
| 242 | + |
| 243 | + $oBefore = new Rule('left'); |
| 244 | + $oBefore->setValue(new Size(16, 'em')); |
| 245 | + |
| 246 | + $oMiddle = new Rule('text-align'); |
| 247 | + $oMiddle->setValue(new Size(1)); |
| 248 | + |
| 249 | + $oAfter = new Rule('border-bottom-width'); |
| 250 | + $oAfter->setValue(new Size(1, 'px')); |
| 251 | + |
| 252 | + $oWrapper->addRule($oAfter); |
| 253 | + $oWrapper->addRule($oBefore, $oFirst); |
| 254 | + $oWrapper->addRule($oMiddle, $oSecond); |
| 255 | + |
| 256 | + $aRules = $oWrapper->getRules(); |
| 257 | + |
| 258 | + $this->assertSame($oBefore, $aRules[0]); |
| 259 | + $this->assertSame($oFirst, $aRules[1]); |
| 260 | + $this->assertSame($oMiddle, $aRules[2]); |
| 261 | + $this->assertSame($oSecond, $aRules[3]); |
| 262 | + $this->assertSame($oAfter, $aRules[4]); |
| 263 | + |
| 264 | + $this->assertSame('.wrapper {left: 16em;left: 10px;text-align: 1;text-align: left;border-bottom-width: 1px;}', $oDoc->render()); |
| 265 | + } |
226 | 266 |
|
227 | 267 | }
|
0 commit comments