diff --git a/src/Strategies/BackgroundStrategy.php b/src/Strategies/BackgroundStrategy.php index f65e578..0914d1b 100755 --- a/src/Strategies/BackgroundStrategy.php +++ b/src/Strategies/BackgroundStrategy.php @@ -5,6 +5,7 @@ namespace CssGenerator\Strategies; use function join; +use function is_string; class BackgroundStrategy implements StrategyInterfaceWithMediaMapping { @@ -35,6 +36,10 @@ public function convert(array $variantStyle, array $mediaMapping = []): string continue; } + if ($variantStyleValue['type'] === 'solid' && (is_string($variantStyleValue['value']) || empty($variantStyleValue['value'][1]))) { + return 'background: '.$variantStyleValue['value'].';'; + } + $color = $this->parseValue($variantStyleValue['type'], $variantStyleValue['value'], $mediaMapping); $data = $variantStyleValue['type'] === 'image' ? $variantStyleValue['value']['data'] : $this->defaultBackgroundProps; @@ -48,7 +53,7 @@ public function convert(array $variantStyle, array $mediaMapping = []): string } if (empty($styles)) { - return 'background: none;'; + return ''; } return join('', [ diff --git a/tests/Unit/CssGeneratorTest.php b/tests/Unit/CssGeneratorTest.php index 525ba9d..fcbf136 100644 --- a/tests/Unit/CssGeneratorTest.php +++ b/tests/Unit/CssGeneratorTest.php @@ -243,7 +243,7 @@ public function testGenerate_WhenGivenWithBreakpoints_GeneratesBasedOnBreakpoint $css = $generator->generate(); $expectedBreakpoint1 = '[data-widget-hash="random-hash"]:hover {color: rgb(0, 0, 0);}'; - $expectedBreakpoint3 = '[data-widget-hash="random-hash"] {font-family: "Helvetica";}'; + $expectedBreakpoint3 = '[data-widget-hash="random-hash"] {font-family: Helvetica;}'; $this->assertEquals($expectedBreakpoint1, $css[1]); $this->assertEquals($expectedBreakpoint3, $css[3]); } diff --git a/tests/Unit/Strategies/BackgroundStrategyTest.php b/tests/Unit/Strategies/BackgroundStrategyTest.php index 5f63101..2cf95d9 100644 --- a/tests/Unit/Strategies/BackgroundStrategyTest.php +++ b/tests/Unit/Strategies/BackgroundStrategyTest.php @@ -25,7 +25,7 @@ public function testConvert_WhenGivenSolidBackground_ReturnsGeneratedCss(): void $backgroundStrategy = new BackgroundStrategy(); $css = $backgroundStrategy->convert($variantsStyles); - $expected = 'background: linear-gradient(rgba(253, 247, 237, 1), rgba(253, 247, 237, 1));background-size: auto;background-position: 0px 0px;background-repeat: no-repeat;background-attachment: scroll;'; + $expected = 'background: rgba(253, 247, 237, 1);'; $this->assertEquals($expected, $css); } @@ -45,7 +45,7 @@ public function testConvert_WhenGivenSolidBackgroundAndActiveIsFalse_ReturnsNone $backgroundStrategy = new BackgroundStrategy(); $css = $backgroundStrategy->convert($variantsStyles); - $expected = 'background: none;'; + $expected = ''; $this->assertEquals($expected, $css); } diff --git a/tests/Unit/Strategies/DefaultStrategyTest.php b/tests/Unit/Strategies/DefaultStrategyTest.php index 9fd88b4..166c628 100644 --- a/tests/Unit/Strategies/DefaultStrategyTest.php +++ b/tests/Unit/Strategies/DefaultStrategyTest.php @@ -37,18 +37,4 @@ public function testConvert_SimpleCase_ReturnsPropertyValue(): void $this->assertEquals($assertion[$index], $css); } } - - public function testConvert_WhenGivenFontFamily_ReturnsValueWrappedWithQuote(): void - { - $variantsStyles = [ - 'type' => 'font-family', - 'value' => "Something Fam'ily" - ]; - - $defaultStrategy = new DefaultStrategy(); - - $css = $defaultStrategy->convert($variantsStyles); - - $this->assertEquals('font-family: "Something Fam\'ily";', $css); - } }