diff --git a/src/Property/Import.php b/src/Property/Import.php index d7c24d7a..b9075504 100644 --- a/src/Property/Import.php +++ b/src/Property/Import.php @@ -8,6 +8,7 @@ use Sabberworm\CSS\OutputFormat; use Sabberworm\CSS\Position\Position; use Sabberworm\CSS\Position\Positionable; +use Sabberworm\CSS\ShortClassNameProvider; use Sabberworm\CSS\Value\URL; /** @@ -17,6 +18,7 @@ class Import implements AtRule, Positionable { use CommentContainer; use Position; + use ShortClassNameProvider; /** * @var URL @@ -90,6 +92,11 @@ public function getMediaQuery(): ?string */ public function getArrayRepresentation(): array { - throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); + return [ + 'class' => $this->getShortClassName(), + // We're using the term "uri" here to match the wording used in the specs: + // https://www.w3.org/TR/CSS22/cascade.html#at-import + 'uri' => $this->location->getArrayRepresentation(), + ]; } } diff --git a/tests/Unit/Property/ImportTest.php b/tests/Unit/Property/ImportTest.php index 3164bc20..77a4f136 100644 --- a/tests/Unit/Property/ImportTest.php +++ b/tests/Unit/Property/ImportTest.php @@ -36,10 +36,36 @@ public function implementsCSSListItem(): void /** * @test */ - public function getArrayRepresentationThrowsException(): void + public function getArrayRepresentationIncludesClassName(): void { - $this->expectException(\BadMethodCallException::class); + $subject = new Import(new URL(new CSSString('https://example.org/')), null); - $this->subject->getArrayRepresentation(); + $result = $subject->getArrayRepresentation(); + + self::assertSame('Import', $result['class']); + } + + /** + * @test + */ + public function getArrayRepresentationIncludesUri(): void + { + $uri = 'https://example.com'; + $url = new URL(new CSSString($uri)); + + $subject = new Import($url, null); + + $result = $subject->getArrayRepresentation(); + + self::assertSame( + [ + 'class' => 'URL', + 'uri' => [ + 'class' => 'CSSString', + 'contents' => $uri, + ], + ], + $result['uri'] + ); } }