diff --git a/tests/LessRulesetTest.php b/tests/LessRulesetTest.php new file mode 100644 index 00000000..1f56c1cf --- /dev/null +++ b/tests/LessRulesetTest.php @@ -0,0 +1,112 @@ + 'auto']); + + $this->assertSame('.foo', $set->getSelector()); + $this->assertSame( + <<<'EOT' +.foo { +width: auto; +} +EOT + , + $set->renderCss() + ); + } + + public function testSetWithoutSelectorIsCorrectlyRendered() + { + $set = new LessRulesetWithTestableRenderCss(); + $set->setProperties(['width' => 'auto', 'height' => 'auto']); + + $this->assertSame(['width' => 'auto', 'height' => 'auto'], $set->getProperties()); + $this->assertSame( + <<<'EOT' +width: auto; +height: auto; +EOT + , + $set->renderCss() + ); + } + + public function testNestedSetsAreCorrectlyRendered() + { + $set = LessRulesetWithTestableRenderCss::create('.level1', ['width' => 'auto']); + $set->addRuleset( + LessRulesetWithTestableRenderCss::create('.level2', ['width' => '2em']) + ->add('.level3', ['width' => '1em']) + ); + + $this->assertSame( + <<<'EOT' +.level1 { +width: auto; +.level2 { +width: 2em; +.level3 { +width: 1em; +} +} +} +EOT + , + $set->renderCss() + ); + } + + public function testSetsCanBeAdjustedAfterCreation() + { + $set = LessRulesetWithTestableRenderCss::create('.foo', ['width' => 'auto']); + $set->setProperty('line-height', 1.5); + $set['color'] = '#abc'; + + $this->assertSame('#abc', $set['color']); + $this->assertSame('1.5', $set->getProperty('line-height')); + $this->assertSame( + <<<'EOT' +.foo { +width: auto; +line-height: 1.5; +color: #abc; +} +EOT + , + $set->renderCss() + ); + } + + public function testAccessingAMissingPropertyThrowsIfGetPropertyIsUsed() + { + $set = new LessRuleset(); + + try { + $set->getProperty('missing'); + } catch (ErrorException $_) { + // $this->expectException() didn't work on GitHub for an unknown reason + $this->assertTrue(true); + } + } + + public function testAccessingAMissingPropertyThrowsIfOffsetAccessIsUsed() + { + $set = new LessRuleset(); + + try { + $set['missing']; + } catch (ErrorException $_) { + // $this->expectException() didn't work on GitHub for an unknown reason + $this->assertTrue(true); + } + } +} diff --git a/tests/Lib/LessRulesetWithTestableRenderCss.php b/tests/Lib/LessRulesetWithTestableRenderCss.php new file mode 100644 index 00000000..773ba71d --- /dev/null +++ b/tests/Lib/LessRulesetWithTestableRenderCss.php @@ -0,0 +1,10 @@ +renderLess(); + } +}