Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Property/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -17,6 +18,7 @@ class Import implements AtRule, Positionable
{
use CommentContainer;
use Position;
use ShortClassNameProvider;

/**
* @var URL
Expand Down Expand Up @@ -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(),
];
}
}
32 changes: 29 additions & 3 deletions tests/Unit/Property/ImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
}
}