Joby Elliott
4bff7f2f87
Brought phpstan and phpunit versions up, and fixed phpunit deprecations. I just deleted a bunch of tests of abstract classes, because phpunit has deprecated it and that stuff should all be getting tested every which way downstream anyway.
58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace ByJoby\HTML\Helpers;
|
|
|
|
use PHPUnit\Framework\Attributes\Depends;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class StylesTest extends TestCase
|
|
{
|
|
public function testConstruction(): Styles
|
|
{
|
|
$styles = new Styles();
|
|
$this->assertEquals([], $styles->getArray());
|
|
$styles = new Styles(['foo' => 'bar', 'baz' => null]);
|
|
$this->assertEquals(['foo' => 'bar'], $styles->getArray());
|
|
return $styles;
|
|
}
|
|
|
|
public function testGettingAndSetting(): void
|
|
{
|
|
$styles = new Styles();
|
|
$styles['a'] = 'b';
|
|
$this->assertEquals('b', $styles['a']);
|
|
unset($styles['foo']);
|
|
$this->assertNull($styles['foo']);
|
|
$this->assertTrue(isset($styles['a']));
|
|
$this->assertFalse(isset($styles['foo']));
|
|
}
|
|
|
|
public function testToString(): void
|
|
{
|
|
$styles = new Styles(['a' => 'b', 'b' => 'c']);
|
|
$this->assertEquals('a:b;b:c', $styles->__toString());
|
|
}
|
|
|
|
public function testInvalidInputs(): void
|
|
{
|
|
$styles = new Styles(['foo' => 'bar']);
|
|
// null assignments don't work
|
|
$styles[] = 'b';
|
|
$this->assertEquals(['foo' => 'bar'], $styles->getArray());
|
|
// empty attribute doesn't work
|
|
$styles[''] = 'b';
|
|
$this->assertEquals(['foo' => 'bar'], $styles->getArray());
|
|
// attributes that trim to nothing don't work
|
|
$styles[' '] = 'b';
|
|
$this->assertEquals(['foo' => 'bar'], $styles->getArray());
|
|
// empty values don't work
|
|
$styles['quux'] = '';
|
|
$this->assertEquals(['foo' => 'bar'], $styles->getArray());
|
|
// values containing ; don't work
|
|
$styles['quux'] = 'x;y';
|
|
$this->assertEquals(['foo' => 'bar'], $styles->getArray());
|
|
// values containing : don't work
|
|
$styles['quux'] = 'x:y';
|
|
$this->assertEquals(['foo' => 'bar'], $styles->getArray());
|
|
}
|
|
}
|