-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Introduce case for
LessRuleset
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace ipl\Tests\Web; | ||
|
||
use ErrorException; | ||
use ipl\Tests\Web\Lib\LessRulesetWithTestableRenderCss; | ||
use ipl\Web\LessRuleset; | ||
|
||
class LessRulesetTest extends TestCase | ||
{ | ||
public function testSetWithSelectorIsCorrectlyRendered() | ||
{ | ||
$set = LessRulesetWithTestableRenderCss::create('.foo', ['width' => '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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace ipl\Tests\Web\Lib; | ||
|
||
use ipl\Web\LessRuleset; | ||
|
||
class LessRulesetWithTestableRenderCss extends LessRuleset | ||
{ | ||
use TestableRenderCss; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace ipl\Tests\Web\Lib; | ||
|
||
use ipl\Web\LessRuleset; | ||
|
||
trait TestableRenderCss | ||
{ | ||
public function renderCss(): string | ||
{ | ||
return $this->renderLess(); | ||
} | ||
} |